:root {
  --bg: #faf6ee;
  --surface: #ffffff;
  --surface-2: #f3ecdd;
  --text: #2b2520;
  --muted: #6b6158;
  --border: #e6dccb;
  --accent: #a0611a;
  --accent-soft: #f6e6cc;
  --quote-bg: #fbf3e4;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 4px 16px rgba(60, 40, 10, .05);
  --radius: 14px;
  --font-body: "Sarabun", system-ui, sans-serif;
  --font-head: "Noto Serif Thai", "Sarabun", serif;
  --base: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --surface: #211d17;
    --surface-2: #2a251e;
    --text: #ece4d6;
    --muted: #a99d8c;
    --border: #3a3329;
    --accent: #e0a458;
    --accent-soft: #3a2c18;
    --quote-bg: #2a2219;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17140f;
  --surface: #211d17;
  --surface-2: #2a251e;
  --text: #ece4d6;
  --muted: #a99d8c;
  --border: #3a3329;
  --accent: #e0a458;
  --accent-soft: #3a2c18;
  --quote-bg: #2a2219;
  --shadow: none;
  color-scheme: dark;
}

:root[data-font="lg"] { --base: 20px; }
:root[data-font="xl"] { --base: 22px; }

* { box-sizing: border-box; }
html { font-size: var(--base); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.4; margin: 0 0 .5em; }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
main { min-height: 70vh; padding-top: 1.5rem; padding-bottom: 3rem; outline: none; }

/* header */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-family: var(--font-head); font-weight: 700; font-size: 1.05rem; white-space: nowrap; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; align-items: center; gap: 4px; flex: none; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .9rem; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font: inherit; font-size: .9rem; line-height: 1;
}
.icon-btn small { font-size: .65em; }
.nav .lang-btn { display: inline-grid; place-items: center; width: auto; min-width: 36px; padding: 0 8px; text-decoration: none; font-size: .8rem; font-weight: 600; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }

/* hero */
.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.3rem); }
.hero p { color: var(--muted); max-width: 34em; margin: 0 auto; }

/* daily */
.daily {
  margin: 1.5rem 0 2rem; padding: 1.4rem 1.5rem;
  background: var(--accent-soft); border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.daily .label { font-size: .8rem; color: var(--accent); font-weight: 600; letter-spacing: .02em; }
.daily h2 { font-size: 1.3rem; margin: .25rem 0 .4rem; }
.daily p { margin: 0 0 .8rem; }
.btn {
  display: inline-block; background: var(--accent); color: #fff; text-decoration: none;
  padding: .45rem 1rem; border-radius: 999px; font-size: .9rem; font-weight: 500;
}
:root[data-theme="dark"] .btn { color: #17140f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn { color: #17140f; } }

/* search + filters */
.tools { display: grid; gap: 12px; margin-bottom: 1.25rem; }
.search {
  width: 100%; padding: .7rem 1rem; font: inherit; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: .3rem .85rem; border-radius: 999px; cursor: pointer; font: inherit; font-size: .85rem;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; text-decoration: none; color: var(--text); box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card h3 { font-size: 1.05rem; margin: 0; }
.lesson { font-size: .75rem; font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.card .sub { color: var(--muted); font-size: .9rem; }
.card .tags { margin-top: auto; padding-top: .5rem; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: .72rem; background: var(--surface-2); color: var(--muted); padding: .1rem .55rem; border-radius: 999px; }
.empty { text-align: center; color: var(--muted); padding: 2rem 0; }

/* detail */
.back { display: inline-block; margin-bottom: 1rem; text-decoration: none; font-size: .9rem; }
.article header { margin-bottom: 1.5rem; }
.article h1 { font-size: clamp(1.5rem, 4.5vw, 2rem); margin-bottom: .2rem; }
.article .sub { color: var(--muted); font-size: 1.05rem; }
.article .ref { font-size: .85rem; color: var(--muted); margin-top: .5rem; }
.quote {
  margin: 0 0 1.75rem; padding: 1.2rem 1.4rem; background: var(--quote-bg);
  border-left: 4px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0;
}
.quote .pali { font-family: var(--font-head); font-size: 1.05rem; color: var(--accent); margin: 0 0 .5rem; }
.quote .th { margin: 0; }
.section { margin-bottom: 1.75rem; }
.section h2 { font-size: 1.15rem; display: flex; align-items: center; gap: .5rem; }
.section h2 .num {
  display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-family: var(--font-body); font-weight: 600;
}
.section p { margin: 0 0 .9em; }
.simple { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.4rem; box-shadow: var(--shadow); }
.practice { padding-left: 1.2rem; margin: 0; }
.practice li { margin-bottom: .5rem; }
.terms { display: grid; gap: 8px; margin: 0; }
.terms div { background: var(--surface-2); border-radius: 10px; padding: .6rem .9rem; }
.terms dt { font-weight: 600; display: inline; }
.terms dt::after { content: " — "; color: var(--muted); font-weight: 400; }
.terms dd { display: inline; margin: 0; color: var(--muted); }
.detail { margin-bottom: 1.25rem; }
.detail h3 { font-size: 1.02rem; margin: 0 0 .4rem; }
.detail ul { padding-left: 1.2rem; margin: 0 0 .9em; }
.detail li { margin-bottom: .45rem; }
.figure { overflow-x: auto; margin: .5rem 0 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.figure svg { display: block; width: 100%; min-width: 480px; height: auto; }
.figure text { fill: var(--text); font-family: var(--font-body); }
.figure .t { font-size: 19px; font-weight: 600; text-anchor: middle; }
.figure .t2 { font-size: 15px; font-weight: 600; text-anchor: middle; }
.figure .m { font-size: 14px; text-anchor: middle; }
.figure .s { font-size: 13px; fill: var(--muted); text-anchor: middle; }
.figure .l { font-size: 14px; fill: var(--muted); }
.figure .bx { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.5; }
.figure .ac { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.figure .dash { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 6 5; }
.figure .ln { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.figure .mk { fill: var(--muted); }
.figure figcaption { font-size: .85rem; color: var(--muted); margin-top: .6rem; line-height: 1.6; }
.sort-score { color: var(--accent); font-weight: 600; }
.sort { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.sort li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .9rem; }
.sort li[data-done="right"] { border-color: #4f8a5b; }
.sort li[data-done="wrong"] { border-color: #b5523b; }
.sort-q { flex: 1 1 14rem; }
.sort-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.sort-btns button {
  font: inherit; font-size: .85rem; padding: .25rem .8rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.sort-btns button:hover:not(:disabled) { border-color: var(--accent); }
.sort-btns button:disabled { cursor: default; opacity: .55; }
.sort-btns button.is-ans { opacity: 1; background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.sort-why { flex-basis: 100%; font-size: .88rem; color: var(--muted); }
.keypoints { background: var(--accent-soft); border-radius: var(--radius); padding: 1.1rem 1.4rem; }
.keypoints ul { padding-left: 1.2rem; margin: 0; }
.keypoints li { margin-bottom: .35rem; }
.quiz { display: grid; gap: 8px; }
.quiz details { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .7rem 1rem; }
.quiz summary { cursor: pointer; font-weight: 600; }
.quiz details p { margin: .6rem 0 0; color: var(--muted); }
.pager { display: flex; justify-content: space-between; gap: 12px; border-top: 1px solid var(--border); padding-top: 1.25rem; margin-top: 2rem; }
.pager a { text-decoration: none; font-size: .9rem; max-width: 48%; }
.pager .next { margin-left: auto; text-align: right; }

/* about */
.prose h1 { font-size: 1.7rem; }
.prose h2 { font-size: 1.2rem; margin-top: 1.5rem; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; padding: 1.5rem 0; text-align: center; }
.site-footer p { margin: .2rem 0; }

@media (max-width: 520px) {
  .brand span { font-size: .95rem; }
  .nav a { padding: 6px 6px; }
  #nav-home { display: none; }
  .daily, .simple, .quote, .keypoints { padding: 1rem 1.1rem; }
}
