:root {
  color-scheme: light;
  --ink: #193247;
  --ink-soft: #566676;
  --paper: #fff9ef;
  --paper-deep: #f8eddc;
  --white: #ffffff;
  --red: #d94a57;
  --red-dark: #b92f42;
  --red-soft: #ffe6e5;
  --blue: #24445d;
  --gold: #efb83f;
  --green: #2f886f;
  --green-soft: #e4f4ed;
  --line: rgba(25, 50, 71, 0.14);
  --shadow: 0 22px 70px rgba(78, 48, 30, 0.12);
  --shadow-soft: 0 10px 30px rgba(78, 48, 30, 0.08);
  --radius: 24px;
  --radius-small: 15px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 7% 5%, rgba(239, 184, 63, 0.12), transparent 25rem),
    var(--paper);
  font-family: Inter, "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  line-height: 1.55;
}

button, input { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: var(--white);
  background: var(--blue);
  border-radius: 10px;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.08; }
h1, h2 { font-family: Georgia, "Noto Serif Thai", serif; }
h1 { font-size: clamp(2.5rem, 6vw, 5.4rem); letter-spacing: -0.045em; }
h2 { font-size: clamp(2rem, 4vw, 3.3rem); letter-spacing: -0.035em; }

.eyebrow {
  margin-bottom: 0.7rem;
  color: var(--red-dark);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.lead { color: var(--ink-soft); font-size: clamp(1rem, 2vw, 1.2rem); }
.tiny-note { color: var(--ink-soft); font-size: 0.78rem; line-height: 1.55; }

.button {
  min-height: 48px;
  padding: 0.78rem 1.15rem;
  border: 0;
  border-radius: 999px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.button:hover { transform: translateY(-2px); }
.button:focus-visible, .listen-button:focus-visible, .back-button:focus-visible, .choice:focus-visible, input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}
.button:disabled { cursor: wait; opacity: 0.65; transform: none; }
.button-primary { color: var(--white); background: var(--red); box-shadow: 0 12px 26px rgba(217, 74, 87, 0.27); }
.button-primary:hover { background: var(--red-dark); box-shadow: 0 15px 30px rgba(185, 47, 66, 0.31); }
.button-wide { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.button-quiet { min-height: 42px; background: rgba(255, 255, 255, 0.72); border: 1px solid var(--line); }

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(420px, 0.94fr);
}

.login-art {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  background: var(--red);
  isolation: isolate;
}
.login-art::before,
.login-art::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
}
.login-art::before {
  z-index: -3;
  background:
    linear-gradient(to bottom, transparent 0 13%, rgba(255,255,255,.93) 13% 18%, transparent 18% 35%, #24445d 35% 45%, transparent 45% 78%, rgba(255,255,255,.93) 78% 83%, transparent 83%),
    var(--red);
  opacity: 0.95;
}
.login-art::after {
  z-index: -1;
  inset: auto -12% -16% 12%;
  height: 55%;
  border-radius: 50% 50% 0 0;
  background: #173348;
  transform: rotate(-5deg);
}
.sun {
  position: absolute;
  top: 12%;
  left: 17%;
  width: min(24vw, 310px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 28px rgba(239, 184, 63, 0.18);
}
.sound-wave {
  position: absolute;
  z-index: 3;
  right: 8%;
  bottom: 12%;
  color: var(--white);
  font-family: "Noto Sans Thai", sans-serif;
  font-size: clamp(3.8rem, 8vw, 8.5rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  text-shadow: 0 15px 35px rgba(0,0,0,.25);
  transform: rotate(-3deg);
}
.temple {
  position: absolute;
  z-index: 2;
  bottom: 8%;
  width: 130px;
  height: 210px;
  background: var(--paper);
  clip-path: polygon(50% 0, 62% 24%, 72% 24%, 66% 38%, 83% 38%, 73% 52%, 88% 52%, 78% 65%, 84% 100%, 16% 100%, 22% 65%, 12% 52%, 27% 52%, 17% 38%, 34% 38%, 28% 24%, 39% 24%);
  opacity: 0.92;
}
.temple-one { left: 7%; }
.temple-two { left: 29%; bottom: 6%; transform: scale(.72); opacity: .58; }

.login-card {
  align-self: center;
  width: min(100%, 650px);
  padding: clamp(2rem, 7vw, 7rem);
}
.login-card h1 { margin-bottom: 1.4rem; font-size: clamp(2.8rem, 5vw, 5rem); }
.login-card h1 span { color: var(--red); }
.login-card .lead { max-width: 38rem; margin-bottom: 2.3rem; }
.login-card form { max-width: 430px; }
.login-card label { display: block; margin: 0.85rem 0 0.35rem; font-size: 0.84rem; font-weight: 800; }
.login-card input {
  width: 100%;
  min-height: 52px;
  padding: 0 1rem;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  box-shadow: 0 4px 0 rgba(25,50,71,.04);
}
.login-card .button { margin-top: 1.25rem; }
.form-message { min-height: 1.5rem; margin: 0.65rem 0 0; color: var(--red-dark); font-size: 0.88rem; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 76px;
  padding: 0 5vw;
  background: rgba(255, 249, 239, 0.89);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 0.7rem; color: var(--ink); text-decoration: none; font-size: 1.15rem; }
.brand strong { color: var(--red); }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: var(--white);
  background: var(--red);
  border-radius: 12px;
  font-family: "Noto Sans Thai", sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
}
.topbar-actions { display: flex; align-items: center; gap: 0.8rem; }
.momentum { padding: 0.5rem 0.8rem; background: var(--green-soft); border-radius: 999px; color: #1d6552; font-size: 0.84rem; font-weight: 800; }

.page-shell { width: min(1180px, 90vw); margin: 0 auto; padding: clamp(2.5rem, 7vw, 6.5rem) 0; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(330px, 0.72fr); align-items: center; gap: clamp(2rem, 7vw, 7rem); }
.hero-copy h1 { max-width: 780px; margin-bottom: 1.2rem; }
.hero-copy .lead { max-width: 620px; margin-bottom: 2rem; }

.phrase-card {
  position: relative;
  display: flex;
  min-height: 430px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 2.4rem;
  color: var(--white);
  text-align: center;
  background: var(--blue);
  border-radius: 42px 42px 42px 8px;
  box-shadow: var(--shadow);
}
.phrase-card::before {
  position: absolute;
  top: -84px;
  right: -65px;
  width: 220px;
  height: 220px;
  content: "";
  border: 34px solid rgba(239,184,63,.85);
  border-radius: 50%;
}
.phrase-card::after {
  position: absolute;
  left: -20px;
  bottom: 28px;
  width: 130px;
  height: 10px;
  content: "";
  background: var(--red);
  box-shadow: 0 24px 0 var(--white), 0 48px 0 var(--red);
  transform: rotate(-8deg);
  opacity: .7;
}
.phrase-label { z-index: 1; margin-bottom: 1.2rem; color: #b7d3de; font-size: .75rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.thai-script { z-index: 1; font-family: "Noto Sans Thai", sans-serif; font-size: clamp(3rem, 6vw, 5.2rem); font-weight: 700; line-height: 1.25; }
.romanization { z-index: 1; margin-top: .25rem; color: #ffe498; font-size: 1.2rem; font-weight: 700; }
.translation { z-index: 1; margin-top: .75rem; color: #dbe6ec; font-size: .93rem; }
.listen-button {
  z-index: 1;
  margin-top: 1.7rem;
  padding: .72rem 1rem;
  color: var(--white);
  background: rgba(255,255,255,.11);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  font-size: .84rem;
  font-weight: 800;
  cursor: pointer;
}
.listen-button:hover { background: rgba(255,255,255,.2); }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin: clamp(3rem, 7vw, 6rem) 0; }
.stat-card {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: .75rem;
  padding: 1.2rem 1.35rem;
  background: rgba(255,255,255,.64);
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
}
.stat-card strong { font-family: Georgia, serif; font-size: 2rem; line-height: 1; }
.stat-card > span:last-child { color: var(--ink-soft); font-size: .86rem; }
.stat-icon { display: grid; width: 38px; height: 38px; place-items: center; color: var(--red-dark); background: var(--red-soft); border-radius: 50%; font-weight: 900; }

.journey-section { padding-top: 1.4rem; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 2rem; }
.section-heading h2 { margin-bottom: 0; }
.section-heading > p { max-width: 310px; margin-bottom: .35rem; color: var(--ink-soft); }
.mission-list { position: relative; display: grid; gap: 1rem; }
.mission-list::before { position: absolute; top: 38px; bottom: 38px; left: 31px; width: 2px; content: ""; background: var(--line); }
.mission-card {
  position: relative;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.2rem;
  width: 100%;
  padding: 1.3rem 1.5rem 1.3rem .15rem;
  text-align: left;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 19px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}
.mission-card:hover:not(:disabled) { border-color: rgba(217,74,87,.52); transform: translateX(4px); }
.mission-card:disabled { cursor: not-allowed; opacity: .58; }
.mission-number { z-index: 2; display: grid; width: 48px; height: 48px; place-items: center; color: var(--white); background: var(--blue); border: 6px solid var(--paper); border-radius: 50%; font-weight: 900; }
.mission-card.is-complete .mission-number { background: var(--green); }
.mission-card.is-current .mission-number { background: var(--red); box-shadow: 0 0 0 5px var(--red-soft); }
.mission-copy strong { display: block; margin-bottom: .2rem; font-size: 1.08rem; }
.mission-copy span, .mission-meta { color: var(--ink-soft); font-size: .85rem; }
.mission-meta { white-space: nowrap; }

.back-button { margin-bottom: 2rem; padding: .5rem 0; color: var(--ink-soft); background: transparent; border: 0; font-weight: 800; cursor: pointer; }
.lesson-layout { display: grid; grid-template-columns: minmax(230px, .54fr) minmax(0, 1.25fr); gap: clamp(2rem, 7vw, 7rem); }
.lesson-sidebar { align-self: start; position: sticky; top: 112px; }
.lesson-sidebar h1 { margin-bottom: 1rem; font-size: clamp(2.5rem, 5vw, 4.4rem); }
.lesson-sidebar > p:not(.eyebrow):not(.tiny-note) { color: var(--ink-soft); font-size: 1.04rem; }
.step-dots { display: flex; gap: .5rem; margin: 2rem 0; }
.step-dot { width: 34px; height: 7px; background: var(--line); border-radius: 999px; }
.step-dot.is-active { background: var(--red); }
.step-dot.is-done { background: var(--green); }

.lesson-stage {
  min-height: 580px;
  padding: clamp(1.5rem, 5vw, 4rem);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 38px 38px 38px 8px;
  box-shadow: var(--shadow);
}
.learning-card { display: flex; min-height: 470px; flex-direction: column; justify-content: center; }
.learning-card h2 { margin-bottom: 1rem; }
.learning-card .thai-script { color: var(--blue); font-size: clamp(3.4rem, 8vw, 6.5rem); }
.learning-card .romanization { color: var(--red-dark); font-size: 1.3rem; }
.learning-body { max-width: 640px; margin: 1.4rem 0 2rem; color: var(--ink-soft); font-size: 1.08rem; }
.learning-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin-top: auto; padding-top: 2rem; }
.learning-actions .button-primary { margin-left: auto; }
.listen-light { color: var(--blue); background: #eef5f7; border-color: transparent; }

.mini-dialogue { display: grid; gap: .8rem; max-width: 560px; margin: 1rem 0 2rem; }
.speech-bubble { width: fit-content; max-width: 90%; padding: 1rem 1.2rem; background: var(--paper-deep); border-radius: 18px 18px 18px 4px; }
.speech-bubble.is-reply { justify-self: end; background: var(--blue); color: var(--white); border-radius: 18px 18px 4px 18px; }
.speech-bubble .thai-line { display: block; font-family: "Noto Sans Thai", sans-serif; font-size: 1.55rem; font-weight: 700; }
.speech-bubble small { display: block; margin-top: .2rem; opacity: .72; }

.quiz-header { margin-bottom: 2rem; }
.quiz-header h2 { margin-bottom: .8rem; }
.script-promise { margin: 1.25rem 0 0; padding: .9rem 1rem; color: var(--ink); background: #eef5f7; border-left: 4px solid var(--blue); border-radius: 0 12px 12px 0; font-size: .9rem; }
.quiz-question { margin: 0 0 2.2rem; padding: 0; border: 0; }
.quiz-question legend { width: 100%; margin-bottom: .8rem; font-weight: 800; }
.choice-grid { display: grid; gap: .7rem; }
.choice { position: relative; display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: .7rem; padding: .9rem 1rem; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; cursor: pointer; }
.choice:hover { border-color: rgba(217,74,87,.48); }
.choice input { position: absolute; opacity: 0; }
.choice-marker { display: grid; width: 30px; height: 30px; place-items: center; color: var(--ink-soft); background: var(--white); border: 1px solid var(--line); border-radius: 50%; font-weight: 800; }
.choice:has(input:checked) { background: var(--red-soft); border-color: var(--red); }
.choice:has(input:checked) .choice-marker { color: var(--white); background: var(--red); border-color: var(--red); }
.choice.is-correct { background: var(--green-soft); border-color: var(--green); }
.choice.is-wrong { background: var(--red-soft); border-color: var(--red-dark); }
.quiz-error { min-height: 1.5rem; color: var(--red-dark); font-weight: 700; }

.result-card { display: flex; min-height: 470px; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.result-badge { display: grid; width: 92px; height: 92px; place-items: center; margin-bottom: 1.5rem; color: var(--white); background: var(--green); border: 10px solid var(--green-soft); border-radius: 50%; font-size: 2.2rem; }
.result-card h2 { max-width: 580px; }
.result-card p { max-width: 560px; color: var(--ink-soft); }
.result-card .button { margin-top: 1rem; }

.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; max-width: min(390px, calc(100vw - 44px)); padding: 1rem 1.2rem; color: var(--white); background: var(--blue); border-radius: 15px; box-shadow: var(--shadow); font-weight: 700; }

@media (max-width: 860px) {
  .login-view { grid-template-columns: 1fr; }
  .login-art { min-height: 34vh; }
  .sound-wave { bottom: 5%; }
  .temple { height: 150px; }
  .login-card { justify-self: center; padding: 3rem 7vw 4rem; }
  .hero-grid, .lesson-layout { grid-template-columns: 1fr; }
  .hero-copy { text-align: center; }
  .hero-copy .lead { margin-left: auto; margin-right: auto; }
  .phrase-card { min-height: 370px; }
  .lesson-sidebar { position: static; }
  .lesson-sidebar h1 { margin-bottom: .65rem; }
  .lesson-sidebar .tiny-note { display: none; }
}

@media (max-width: 590px) {
  .topbar { min-height: 68px; padding: 0 4vw; }
  .momentum { display: none; }
  .button-quiet { min-height: 38px; padding: .5rem .8rem; font-size: .8rem; }
  .page-shell { width: min(92vw, 560px); padding: 2rem 0 4rem; }
  .hero-copy h1 { font-size: 3rem; }
  .phrase-card { min-height: 340px; padding: 1.5rem; border-radius: 30px 30px 30px 7px; }
  .thai-script { font-size: 3.5rem; }
  .stats-grid { grid-template-columns: 1fr; gap: .7rem; margin: 2.5rem 0 4rem; }
  .section-heading { display: block; }
  .section-heading > p { margin-top: 1rem; }
  .mission-card { grid-template-columns: 58px minmax(0, 1fr); padding-right: 1rem; }
  .mission-meta { grid-column: 2; }
  .lesson-stage { min-height: 540px; padding: 1.35rem; border-radius: 27px 27px 27px 7px; }
  .learning-card { min-height: 480px; }
  .learning-actions { align-items: stretch; }
  .learning-actions > * { width: 100%; }
  .learning-actions .button-primary { margin-left: 0; }
  .login-card h1 { font-size: 3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
