/* Thai Tutor — dictation practice styles.
   Kid-first: large tap targets (>=44px), big legible Thai, encouraging colors,
   works in portrait and landscape on a tablet. No external/CDN resources. */

/* --- Thai webfont ---------------------------------------------------------
   To self-host (offline-safe, Principle IV): drop a looped (มีหัว) OFL font
   such as Sarabun into public/assets/fonts/ and uncomment the @font-face below.
   Until then we fall back to the device's looped Thai system fonts, which on
   Android render tone marks and look-alike glyphs (ด/ต, บ/ป) clearly.

@font-face {
  font-family: "Sarabun";
  src: url("../assets/fonts/Sarabun-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Sarabun";
  src: url("../assets/fonts/Sarabun-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
--------------------------------------------------------------------------- */

:root {
  --bg: #fef9f3;
  --surface: #ffffff;
  --ink: #2b2b3a;
  --muted: #6b6b80;
  --brand: #2a7de1;
  --brand-dark: #1b5fb0;
  --correct: #1f9d57;
  --correct-bg: #e6f7ee;
  --wrong: #d6453f;
  --wrong-bg: #fdeceb;
  --highlight: #ffd23f;
  --tap-min: 48px;
  --radius: 16px;
  --thai-font: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--thai-font);
  font-size: 20px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
  min-height: 100vh;
}

.screen { animation: fade-in 0.2s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.muted { color: var(--muted); }

/* --- Buttons (all >= 48px tall) ------------------------------------------- */
button { font-family: inherit; cursor: pointer; }

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 12px 28px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  width: 100%;
}
.primary-btn { background: var(--brand); color: #fff; }
.primary-btn:active { background: var(--brand-dark); }
.primary-btn:disabled { background: #b9c7d6; }
.secondary-btn { background: #eceef3; color: var(--ink); }
.secondary-btn:active { background: #dde0e8; }

.link-btn {
  min-height: var(--tap-min);
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--brand);
  font-size: 1rem;
  font-weight: 600;
}

/* --- Week picker / home --------------------------------------------------- */
.app-title { font-size: 2rem; margin: 0.2em 0 0.6em; text-align: center; }
.app-subtitle { text-align: center; color: var(--muted); margin: 0 0 1.2em; }

/* Current week's test (the home default) */
.current-test { margin: 0 auto 1.6em; max-width: 30em; }
.current-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
  padding: 22px 20px;
}
.current-tag {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border-radius: 999px;
  padding: 4px 14px;
}
.current-label { font-size: 2.2rem; font-weight: 700; }
.current-card .test-date { font-size: 1.15rem; color: var(--ink); }
.current-card .current-count { font-size: 0.9rem; color: var(--muted); margin-bottom: 8px; }
.exercise-choices { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.exercise-choices .primary-btn,
.exercise-choices .secondary-btn { width: 100%; }

.no-test {
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  padding: 28px 20px;
}
.no-test-emoji { font-size: 3rem; display: block; }
.no-test p { font-size: 1.2rem; font-weight: 700; margin: 8px 0 0; }

/* Review past weeks */
.review-section { margin: 0 auto; max-width: 30em; }
.review-title { font-size: 1.1rem; color: var(--muted); text-align: center; margin: 0 0 0.8em; }

.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}
.week-tile {
  min-height: 88px;
  border: 3px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.week-tile:active { border-color: var(--brand); }
.week-tile .count { font-size: 0.85rem; font-weight: 400; color: var(--muted); }

/* --- Preview / study sheet ------------------------------------------------ */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.preview-meta { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.preview-label { font-size: 1.3rem; font-weight: 700; }
.preview-date { font-size: 0.9rem; color: var(--muted); }
.preview-hint { text-align: center; color: var(--muted); margin: 0 0 12px; }

/* The word table: responsive columns that fit one page; long words wrap.
   Capped to the viewport with graceful scroll if a list can't fit (FR-009). */
.preview-words {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  margin-bottom: 16px;
}
.preview-word {
  min-height: var(--tap-min);
  padding: 10px 12px;
  font-family: var(--thai-font);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid #e3e7ef;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: center;
}
.preview-word:active { border-color: var(--brand); background: #eef4fc; }

#preview .primary-btn { max-width: 28em; margin: 0 auto; display: flex; }

/* --- Fill-the-blank screen ------------------------------------------------ */
.fill-word {
  font-family: var(--thai-font);
  font-size: 3rem;
  font-weight: 700;
  text-align: center;
  margin: 18px 0 8px;
  word-break: break-word;
}
.fill-blank {
  display: inline-block;
  min-width: 0.9em;
  color: #aab2c2;
  border-bottom: 4px solid #d7dbe3;
  margin: 0 2px;
}
.fill-blank.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  background: #eef4fc;
  border-radius: 6px;
  padding: 0 2px;
}
.fill-filled { color: var(--correct); }
.fill-filled.revealed { color: var(--brand-dark); }

/* Feature 007: blank-count pre-screen */
.blank-count-title { text-align: center; font-size: 1.6rem; margin: 1em 0 0.2em; }
.blank-count-hint  { text-align: center; color: var(--muted); margin: 0 0 1.2em; }
.blank-count-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-width: 28em;
  margin: 0 auto;
}
.blank-count-btn {
  min-height: 96px;
  font-size: 2.4rem;
  font-weight: 700;
}
.blank-count-btn.selected { box-shadow: 0 0 0 3px var(--brand-dark) inset; }

.fill-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  max-width: 24em;
  margin: 18px auto 0;
}
.fill-option {
  min-height: 72px;
  font-family: var(--thai-font);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 3px solid #d7dbe3;
  border-radius: var(--radius);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.fill-option:active { border-color: var(--brand); background: #eef4fc; }
.fill-option:disabled { opacity: 0.5; }
.fill-option.wrong { border-color: var(--wrong); background: var(--wrong-bg); opacity: 1; }

#fill-feedback .answer { font-size: 2rem; font-weight: 700; color: var(--correct); }

/* --- Cloze (word-meaning) screen ------------------------------------------ */
.cloze-sentence {
  font-family: var(--thai-font);
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1.7;
  text-align: center;
  margin: 14px auto 6px;
  max-width: 26em;
  word-break: break-word;
}
.cloze-blank { color: var(--brand); letter-spacing: 2px; }
.cloze-filled { color: var(--correct); font-weight: 700; }
.cloze-meaning {
  text-align: center;
  color: var(--muted);
  font-size: 1.05rem;
  min-height: 1.4em;
  margin-bottom: 6px;
  max-width: 26em;
  margin-left: auto;
  margin-right: auto;
}
#cloze-feedback .answer { font-size: 1.8rem; font-weight: 700; color: var(--correct); }

/* per-word definition in the summary (feature 005) */
.word-row .meaning { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 400; }

/* --- Prompt screen -------------------------------------------------------- */
.prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.progress { color: var(--muted); font-weight: 600; }

.prompt-body { text-align: center; }

.play-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 160px;
  height: 160px;
  margin: 8px auto 4px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: #fff;
}
.play-btn:active { background: var(--brand-dark); }
.play-btn .play-icon { font-size: 3.4rem; line-height: 1; }
.play-btn .play-label { font-size: 1.05rem; font-weight: 700; }

.reading-hint {
  background: #fff6e0;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px auto;
  max-width: 28em;
}
.reading-hint .reveal-word {
  display: block;
  font-size: 2.6rem;
  font-weight: 700;
  margin-top: 6px;
}

#answer-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 28em;
  margin: 22px auto 0;
}
.answer-input {
  font-family: var(--thai-font);
  font-size: 2.2rem;
  text-align: center;
  padding: 16px;
  border: 3px solid #d7dbe3;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
.answer-input:focus { outline: none; border-color: var(--brand); }

/* --- Feedback / diff ------------------------------------------------------ */
.feedback {
  margin: 18px auto 0;
  max-width: 28em;
  font-size: 1.2rem;
  font-weight: 700;
}
.feedback.correct { color: var(--correct); }
.feedback.wrong { color: var(--wrong); }

.diff {
  font-size: 2.4rem;
  font-weight: 700;
  margin: 12px 0;
  letter-spacing: 0.02em;
}
.diff .row-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.diff .you { color: var(--wrong); }
.diff .answer { color: var(--correct); }
.diff .mark {
  background: var(--highlight);
  border-radius: 4px;
  padding: 0 2px;
}

.feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 28em;
  margin: 14px auto 0;
}
.feedback-actions .primary-btn,
.feedback-actions .secondary-btn { width: auto; flex: 1 1 40%; }

/* --- Summary -------------------------------------------------------------- */
.summary-title { text-align: center; font-size: 1.8rem; }
.score {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 12px 0 20px;
}
.score .stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 20px;
  text-align: center;
  min-width: 96px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.score .stat .num { display: block; font-size: 2rem; font-weight: 700; }
.score .stat .label { font-size: 0.8rem; color: var(--muted); }
.score .stat.ok .num { color: var(--correct); }
.score .stat.miss .num { color: var(--wrong); }

.word-results { list-style: none; padding: 0; margin: 0 0 20px; }
.word-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.word-row .word { font-size: 1.6rem; font-weight: 700; flex: 1; }
.word-row .status-icon { font-size: 1.4rem; }
.word-row.ok { background: var(--correct-bg); }
.word-row.miss { background: var(--wrong-bg); }
.word-row .replay {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  border: none;
  border-radius: 12px;
  background: #eef2f8;
  font-size: 1.2rem;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 28em;
  margin: 0 auto;
}

/* --- Landscape: put play + input side by side to reduce scrolling --------- */
@media (orientation: landscape) and (min-width: 700px) {
  .prompt-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    gap: 24px;
  }
  .prompt-body > .play-btn { grid-row: span 2; }
  #answer-form { margin-top: 0; }
}
