:root {
  --bg: #FBF7EF;
  --surface: #FFFFFF;
  --ink: #1B2A2F;
  --ink-soft: #3F4F54;
  --primary: #0F5C5C;
  --primary-ink: #FFFFFF;
  --accent: #E0892B;
  --line: #E4DAC6;
  --pill-bg: #F1E3C8;
  --radius: 14px;
  --gutter: 16px;
}

* { box-sizing: border-box; }

html { font-size: 18px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR",
    "Noto Sans Lao", "Leelawadee UI", system-ui, sans-serif;
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.topbar, main {
  max-width: 480px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

.topbar { padding-top: 14px; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  background:
    radial-gradient(circle at 50% 50%, var(--accent) 0 28%, transparent 30%),
    var(--primary);
}
.brand-name { margin: 0; font-weight: 800; letter-spacing: .06em; line-height: 1.2; }
.brand-tagline { margin: 0; color: var(--ink-soft); font-size: .89rem; line-height: 1.3; }

.lang-buttons { display: flex; gap: 8px; margin-top: 14px; }
.lang-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 0 6px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .89rem;
  font-weight: 600;
  cursor: pointer;
}
.lang-btn[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

main { padding-top: 6px; padding-bottom: 24px; }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 18px 0 8px; }
h2 { font-size: 1rem; margin: 18px 0 8px; color: var(--primary); }
p { margin: 0 0 10px; }
.lead { font-size: 1rem; }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  counter-increment: step;
  position: relative;
  padding: 10px 12px 10px 52px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
  font-size: .89rem;
  display: grid;
  place-items: center;
}

.notice, .status {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: var(--pill-bg);
  border-radius: 8px;
  font-size: .89rem;
}

.btn {
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { border: 0; background: var(--primary); color: var(--primary-ink); font-size: 1.05rem; }
.btn-quiet {
  margin-top: 16px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
}

/* The main action stays reachable without scrolling. */
.actionbar {
  position: sticky;
  bottom: 0;
  margin: 14px calc(var(--gutter) * -1) 0;
  padding: 10px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(251, 247, 239, 0), var(--bg) 22%);
}

.modules { list-style: none; margin: 12px 0 0; padding: 0; }
.module {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.module > div { min-width: 0; }
.module-name { margin: 0; font-weight: 700; }
.module-desc { margin: 2px 0 0; color: var(--ink-soft); font-size: .89rem; line-height: 1.4; }
.pill {
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--ink);
  font-size: .89rem;
  font-weight: 600;
  white-space: nowrap;
}

.load-error {
  margin-top: 20px;
  padding: 14px;
  border: 2px solid #A32020;
  border-radius: var(--radius);
  background: var(--surface);
}
.load-error::before { content: "⚠ "; font-weight: 700; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .lang-btn { transition: background-color .15s, border-color .15s; }
}

/* Welcome voice controls */
.voice { margin: 12px 0 4px; }
.voice-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-voice {
  flex: 1 1 auto;
  min-height: 48px;
  padding: 6px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .89rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-voice-main { flex-basis: 100%; border-color: var(--primary); color: var(--primary); font-size: 1rem; }
.btn-voice-main[data-state="playing"] { background: var(--primary); color: var(--primary-ink); }
.btn-voice-main[data-state="blocked"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(224, 137, 43, .35); }
.btn-voice:disabled { opacity: .45; cursor: not-allowed; }
.btn-voice[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.voice-icon::before { content: "▶ "; }
[data-state="playing"] > .voice-icon::before { content: "⏸ "; }
[data-state="loading"] > .voice-icon::before { content: "… "; }
.voice-status { min-height: 1.5em; margin: 8px 0 0; color: var(--ink-soft); font-size: .89rem; }

/* Home: a module that is open */
.modules > li { list-style: none; }
.module-open { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; border: 2px solid var(--primary); min-height: 64px; }
.module-open > span:first-child { min-width: 0; display: block; }
.module-open .module-name, .module-open .module-desc { display: block; }
.module-arrow { flex: none; color: var(--primary); font-size: 1.8rem; line-height: 1; font-weight: 700; }

/* Find an expression */
.btn-back {
  min-height: 48px;
  margin-top: 6px;
  padding: 0 14px 0 8px;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.field-label { display: block; margin: 16px 0 6px; font-weight: 700; }
.field {
  width: 100%;
  min-height: 54px;
  padding: 10px 14px;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 48px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .89rem;
  font-weight: 600;
  cursor: pointer;
}
.chip[aria-pressed="true"] { border-color: var(--primary); background: var(--primary); color: var(--primary-ink); }
.result-count { margin: 16px 0 8px; color: var(--ink-soft); font-size: .89rem; }
.results { list-style: none; margin: 0; padding: 0; }
.card {
  padding: 14px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card-meaning { margin: 0 0 6px; font-weight: 700; }
.card-lao {
  margin: 0;
  font-family: "Noto Sans Lao", "Leelawadee UI", "Lao Sangam MN", "Saysettha OT", sans-serif;
  font-size: 1.7rem;
  line-height: 1.6;
  color: var(--primary);
}
.card-roman { margin: 0 0 6px; color: var(--ink-soft); font-size: .89rem; }
.card-roman b { color: var(--ink); font-size: 1rem; }
.card-note { margin: 0 0 8px; font-size: .89rem; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.btn-audio {
  min-height: 48px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-ink);
  font: inherit;
  font-size: .89rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-audio[data-state="playing"] { background: var(--accent); color: var(--ink); }
.badge {
  padding: 4px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--ink);
  font-size: .89rem;
}
.card-error { margin: 8px 0 0; color: #8A1C1C; font-size: .89rem; font-weight: 600; }
.card-error::before { content: "⚠ "; }

/* Lao basics */
.lesson-list { list-style: none; margin: 8px 0 0; padding: 0; }
.lesson-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 64px; padding: 10px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.lesson-row > span:nth-child(2) { flex: 1 1 auto; min-width: 0; }
.lesson-num {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--pill-bg); color: var(--ink); font-weight: 700;
}
.lesson-row[data-done="true"] .lesson-num { background: var(--primary); color: var(--primary-ink); }
.lesson-row .module-name, .lesson-row .module-desc { display: block; }
.lesson-number { margin: 12px 0 0; color: var(--ink-soft); font-size: .89rem; font-weight: 700; }
#lesson-title { margin-top: 2px; }
.lesson-text { margin: 0 0 12px; white-space: pre-line; }
.lesson-heading { margin: 22px 0 8px; font-size: 1.05rem; color: var(--primary); }
.tip {
  margin: 14px 0; padding: 12px 14px;
  background: #E6F1EF; border-left: 4px solid var(--primary); border-radius: 8px;
}
.item-grid { list-style: none; margin: 0 0 12px; padding: 0; }
.item {
  display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: center;
  padding: 12px 14px; margin-bottom: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.item-main { min-width: 0; }
.item-head {
  margin: 0; color: var(--primary); line-height: 1.5; font-size: 1.9rem;
  font-family: "Noto Sans Lao", "Leelawadee UI", "Lao Sangam MN", "Saysettha OT", sans-serif;
}
.item-head small { margin-left: 10px; color: var(--ink); font-size: 1rem; font-weight: 700; font-family: inherit; }
.item-lao {
  margin: 0; line-height: 1.6; font-size: 1.45rem;
  font-family: "Noto Sans Lao", "Leelawadee UI", "Lao Sangam MN", "Saysettha OT", sans-serif;
}
.item-lao b { margin-left: 10px; font-size: 1rem; font-family: "Segoe UI", system-ui, sans-serif; }
.item-gloss { margin: 2px 0 0; color: var(--ink-soft); font-size: .89rem; line-height: 1.45; }
.item-play {
  width: 52px; height: 52px; border: 0; border-radius: 50%;
  background: var(--primary); color: var(--primary-ink); font-size: 1.1rem; cursor: pointer;
}
.item-play[data-state="playing"] { background: var(--accent); color: var(--ink); }
.item .card-error { grid-column: 1 / -1; }

/* Language menu (five languages no longer fit as buttons on a phone) */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar .brand { min-width: 0; }
.lang { flex: none; }
.lang-select {
  min-height: 48px; max-width: 132px; padding: 0 10px;
  border: 2px solid var(--primary); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: .89rem; font-weight: 700;
}
body { font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", "Noto Sans Lao", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif; }
.home-section { margin: 22px 0 0; font-size: 1.05rem; color: var(--primary); }
.lesson-figure { margin: 0 0 12px; }
.lesson-figure img { display: block; width: 100%; height: auto; border-radius: var(--radius); }

/* EPS-TOPIK practice */
.exam-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.exam-meta { margin: 0; color: var(--ink-soft); font-size: .89rem; font-weight: 700; text-align: right; }
.exam-timer { margin: 4px 0 0; padding: 6px 12px; border-radius: 8px; background: var(--pill-bg); font-weight: 700; text-align: center; }
.exam-passage {
  margin: 12px 0 0; padding: 12px 14px; white-space: pre-line;
  background: var(--surface); border: 2px solid var(--ink); border-radius: 8px; font-size: 1.05rem; line-height: 1.7;
}
.exam-prompt { margin: 14px 0 10px; font-size: 1.15rem; line-height: 1.5; }
.options { display: grid; gap: 8px; margin-top: 12px; }
.option {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 56px; padding: 8px 14px;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  color: var(--ink); font: inherit; font-size: 1.05rem; text-align: left; cursor: pointer;
}
.option-num {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; border: 2px solid var(--ink); font-weight: 700; font-size: .89rem;
}
.option[aria-pressed="true"] { border-color: var(--primary); background: #E6F1EF; }
.option[aria-pressed="true"] .option-num { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.option[data-mark="right"] { border-color: #1E6B34; background: #E4F3E7; }
.option[data-mark="right"]::after { content: "✓"; margin-left: auto; color: #1E6B34; font-weight: 700; }
.option[data-mark="wrong"] { border-color: #8A1C1C; background: #F8E6E6; }
.option[data-mark="wrong"]::after { content: "✕"; margin-left: auto; color: #8A1C1C; font-weight: 700; }
.option:disabled { cursor: default; opacity: 1; }
.exam-feedback { min-height: 1.6em; margin: 12px 0 0; font-weight: 700; }
.exam-feedback[data-kind="right"] { color: #1E6B34; }
.exam-feedback[data-kind="wrong"] { color: #8A1C1C; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.result-score { margin: 8px 0 4px; color: var(--primary); font-size: 2.2rem; font-weight: 800; line-height: 1.2; }
.floor-list { list-style: none; margin: 0 0 12px; padding: 0; }
.floor-row { display: flex; gap: 10px; padding: 10px 12px; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.floor-mark { flex: none; font-weight: 800; }
.floor-row[data-cleared="true"] .floor-mark { color: #1E6B34; }
.floor-row[data-cleared="false"] .floor-mark { color: #8A1C1C; }
#result-again { margin-top: 16px; }
