/* ThaiPath — saffron accent, class colours: blue mid · red high · green low */
/* Noto Sans Thai Looped (SIL Open Font License) — bundled so letters look the same on every device, offline too. */
@font-face {
  font-family: "Noto Sans Thai Looped"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("fonts/noto-sans-thai-looped-thai-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Thai Looped"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("fonts/noto-sans-thai-looped-thai-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans Thai Looped"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("fonts/noto-sans-thai-looped-thai-700-normal.woff2") format("woff2");
}
:root {
  color-scheme: light dark;
  --bg: #f7f5f1;
  --card: #ffffff;
  --ink: #1c1a17;
  --muted: #6d675f;
  --line: rgba(0, 0, 0, .08);
  --accent: #e8731f;
  --accent-ink: #fff;
  --mid: #2f6fe0;
  --high: #d6453a;
  --low: #1f9a5a;
  --good: #1f9a5a;
  --warn: #c76a00;
  --radius: 18px;
  --thai: "Noto Sans Thai Looped", "Thonburi", "Leelawadee UI", "Noto Sans Thai", sans-serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, var(--thai);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12110f;
    --card: #1f1d1a;
    --ink: #f1ede6;
    --muted: #a39c92;
    --line: rgba(255, 255, 255, .09);
    --mid: #5b93ff;
    --high: #ff6b5e;
    --low: #3ccf83;
    --good: #3ccf83;
  }
}

* { box-sizing: border-box; min-width: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--ui);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: clip;
}
a { color: inherit; text-decoration: none; }
h2.section { font-size: 13px; font-weight: 600; color: var(--muted); margin: 26px 4px 8px; }
h3 { font-size: 17px; margin: 22px 0 10px; }
.th { font-family: var(--thai); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.note { font-size: 14px; color: var(--muted); margin: 10px 4px; }
.okmsg { color: var(--good); font-weight: 600; }
.warnmsg { color: var(--warn); font-weight: 600; }
.okmsg.big, .warnmsg.big { font-size: 19px; margin: 6px 0; }
.pad1 { padding: 16px; }

/* ---------- chrome */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-left)) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 22px; margin: 0; font-family: var(--ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { border: 0; background: none; color: var(--accent); font: 600 17px var(--ui); padding: 6px 6px 6px 0; cursor: pointer; }
.view { max-width: 760px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) 32px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--muted); padding: 4px 0; border-radius: 12px; }
.tabs a span { font-size: 22px; line-height: 1.2; filter: grayscale(1) opacity(.7); }
.tabs a.on { color: var(--accent); font-weight: 600; }
.tabs a.on span { filter: none; }

/* ---------- building blocks */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 12px 16px; border: 0; background: none; color: inherit; font: inherit; text-align: left;
  border-bottom: 1px solid var(--line); cursor: pointer; min-height: 52px;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.row.disabled { opacity: .45; cursor: default; }
.row-text { display: flex; flex-direction: column; flex: 1; }
.row-text small { color: var(--muted); font-size: 13px; }
.row .glyphs { font-size: 20px; letter-spacing: 2px; }
.chev { color: var(--muted); font-size: 20px; margin-left: auto; }
.w6 { width: 70px; } .w3 { width: 40px; }
.big2 { font-size: 26px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 600 15px var(--ui); white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--high); margin-top: 12px; }
.btn.rec { background: var(--high); color: #fff; }
.btn.wide { width: 100%; }
.btn small { opacity: .7; font-weight: 400; }
.btns { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btns.center { justify-content: center; flex-direction: row; }
.spacer { flex: 1; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.badge {
  display: inline-block; padding: 4px 12px; border-radius: 99px; font-size: 13px; font-weight: 600;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
}
.warn { background: color-mix(in srgb, var(--warn) 13%, transparent); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; font-size: 14px; }
.warn p { margin: 6px 0 0; }

/* ---------- ring */
.ring { position: relative; flex: none; }
.ring svg { width: 100%; height: 100%; display: block; }
.ring svg circle:last-child { transition: stroke-dasharray .6s ease; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.ring-label b { font-size: 1.05em; font-variant-numeric: tabular-nums; }
.ring-label small { font-size: 11px; color: var(--muted); }
.ring[style*="52px"] .ring-label b { font-size: 12px; }

/* ---------- today */
.hero { display: flex; align-items: center; gap: 20px; margin-bottom: 14px; }
.hero > div:last-child { display: flex; flex-direction: column; gap: 2px; }
.streak { font-weight: 700; font-size: 18px; color: var(--muted); }
.streak.on { color: var(--accent); }
.sync { font-size: 12px; color: var(--muted); }
.sync.ok { color: var(--good); }
.task {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 10px;
  background: var(--card); border-radius: var(--radius);
}
.task:hover { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.task.disabled { opacity: .6; }
.task-icon {
  width: 46px; height: 46px; flex: none; border-radius: 13px; display: grid; place-items: center; font-size: 22px;
  background: color-mix(in srgb, var(--accent) 13%, transparent); font-family: var(--thai); color: var(--accent); font-weight: 700;
}
.task.done .task-icon { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.task-text { display: flex; flex-direction: column; flex: 1; }
.task-text small { color: var(--muted); font-size: 14px; font-family: var(--ui); }

/* ---------- tiles & chart */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile, .chart-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 8px;
  border-radius: 14px; border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background: color-mix(in srgb, var(--c) 9%, var(--card));
}
.tile .big, .chart-cell .big { font-size: 44px; line-height: 1.25; }
.bar { display: block; width: 100%; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--c, var(--accent)) 18%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 3px; }
.chart { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 12px; }
.chart-cell { background: color-mix(in srgb, var(--c) var(--m), var(--card)); }
.chart-cell small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chart-cell code { font-size: 11px; color: var(--c); }
.seg { display: inline-flex; background: color-mix(in srgb, var(--ink) 7%, transparent); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 9px; font: 600 14px var(--ui); color: var(--muted); cursor: pointer; min-height: 36px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.vowel-form { font-size: 32px; width: 92px; flex: none; }

/* ---------- letter detail */
.glyph {
  font-size: clamp(120px, 34vw, 180px); line-height: 1.2; border: 0; background: none; color: var(--ink); cursor: pointer;
  padding: 0 24px; border-radius: 24px;
}
.glyph:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.facts { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; text-align: center; }
.facts-name { font-size: 24px; }
.facts .emoji { font-size: 26px; }
.cells { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 460px; }
.cell { background: color-mix(in srgb, var(--ink) 5%, transparent); border-radius: 12px; padding: 10px 12px; text-align: left; }
.cell small { display: block; color: var(--muted); font-size: 12px; }
.cell b { font-size: 19px; }
.echo { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin: 8px 0; }
.echo small { flex-basis: 100%; text-align: center; }

/* ---------- writing */
.write { display: flex; flex-direction: column; gap: 12px; }
.write-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.prompt { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.prompt b { font-size: 19px; }
.prompt small { color: var(--muted); font-size: 14px; }
.pad-host { width: min(100%, 62vh, 560px); margin: 0 auto; }
.pad {
  position: relative; aspect-ratio: 1; width: 100%;
  border-radius: 22px; background: var(--card); overflow: hidden; color: var(--ink);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c, var(--accent)) 30%, transparent);
}
.pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.pad-ink { touch-action: none; cursor: crosshair; }
.done-box { padding: 40px 0; }
.done-icon { font-size: 64px; }

/* ---------- flashcards */
.cards { display: flex; flex-direction: column; gap: 14px; }
.card-meta { display: flex; justify-content: space-between; font-size: 13px; }
.flashcard {
  min-height: 380px; width: 100%; border: 0; border-radius: 26px; background: var(--card); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px;
  cursor: pointer; font: inherit; box-shadow: 0 6px 24px rgba(0,0,0,.06);
}
.flashcard hr { width: 100%; border: 0; border-top: 1px solid var(--line); }
.card-glyph { font-size: 110px; line-height: 1.2; text-align: center; }
.card-glyph.long { font-size: clamp(44px, 12vw, 72px); }
.card-en { font-size: 30px; font-weight: 700; text-align: center; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade { flex-direction: column; gap: 0; color: #fff; border: 0; min-height: 54px; }
.grade small { font-size: 11px; }
.grade.again { background: #d6453a; } .grade.hard { background: #d98a10; }
.grade.good { background: #1f9a5a; } .grade.easy { background: #2f6fe0; }

/* ---------- words */
.search { width: 100%; min-height: 44px; font: 16px var(--ui); padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); margin-bottom: 10px; }
.word.card { margin: 12px 0; }
.word.compact { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.word-main { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.word-th { font-size: 22px; }
.word.card .word-th { font-size: 40px; line-height: 1.3; }
.word-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

/* ---------- progress */
.rings { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: 1fr auto; margin: 0; }
.stats dt, .stats dd { padding: 9px 0; border-bottom: 1px solid var(--line); margin: 0; }
.stats dd { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.classbar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; margin: 6px 0 14px; }
.classbar .bar { grid-column: 1 / -1; height: 8px; }
.map { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.map a {
  aspect-ratio: 1; display: grid; place-items: center; border-radius: 9px; font-size: 18px;
  background: color-mix(in srgb, var(--accent) var(--m), transparent);
}
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 15px; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; }
.form input[type=text], .form input[type=password] { min-height: 44px; font: 16px var(--ui); padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.form input[type=range] { accent-color: var(--accent); }
.prose p { margin: 8px 0 14px; }

@media (min-width: 900px) {
  .view { padding-top: 24px; }
  .tabs { left: 50%; right: auto; transform: translateX(-50%); bottom: 14px; width: 560px; border-radius: 20px; border: 1px solid var(--line); padding-bottom: 6px; }
  body { padding-bottom: 100px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
