/* ============================================================================
   NOVA — design tokens + base + components (v1)
   ที่มา: 01_Approved_Design (Arcade V2 / Master UI) — โทนฟ้า-ม่วง-ชมพู เงาเรืองแสง
   ไฟล์เดียวจบ เพื่อให้แอปเริ่มได้โดยไม่มี build step
   ========================================================================== */
:root {
  /* ---------- brand ---------- */
  --blue-900: #061033;
  --blue-800: #0a1c4d;
  --blue-700: #10306f;
  --blue-600: #1e5bd8;
  --blue-500: #2e7bf6;
  --cyan-400: #22d3ee;
  --cyan-300: #7ee7ff;
  --violet-500: #7c5cff;
  --violet-400: #a58bff;
  --pink-500: #ff4d8d;
  --pink-400: #ff86b3;
  --amber-500: #ffb020;
  --amber-400: #ffd166;
  --green-500: #12c48b;
  --green-400: #4ade9f;
  --rose-500: #f43f5e;

  /* ---------- surface ---------- */
  --bg: #071033;
  --surface: #ffffff;
  --surface-2: #f4f7ff;
  --surface-3: #e8eefc;
  --ink: #0e1b3a;
  --ink-2: #33456b;
  --muted: #6b7c9e;
  --muted-2: #9aa8c4;
  --line: rgba(14, 27, 58, 0.09);
  --line-2: rgba(14, 27, 58, 0.05);

  /* ---------- type ---------- */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Noto Sans Thai",
    "Thonburi", "Segoe UI", sans-serif;
  --fs-xs: 11px;
  --fs-sm: 12.5px;
  --fs-body: 15px;
  --fs-h3: 17px;
  --fs-h2: 20px;
  --fs-h1: 26px;
  --fs-display: clamp(24px, 6.8vw, 32px);

  /* ---------- shape / motion ---------- */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 26px;
  --r-pill: 999px;

  --sh-1: 0 1px 2px rgba(10, 25, 60, 0.06), 0 6px 16px -10px rgba(10, 25, 60, 0.35);
  --sh-2: 0 2px 8px rgba(10, 25, 60, 0.07), 0 18px 40px -24px rgba(10, 25, 60, 0.55);
  --sh-glow-cyan: 0 14px 34px -16px rgba(34, 211, 238, 0.75);
  --sh-glow-violet: 0 14px 34px -16px rgba(124, 92, 255, 0.75);

  --t-fast: 120ms;
  --t-mid: 200ms;
  --t-slow: 320ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* ---------- layout ---------- */
  --pad: 18px;
  --tab-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ============================================================ reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: var(--fs-body);
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--cyan-400); outline-offset: 3px; border-radius: 8px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ============================================================ shell */
.app {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1000px 560px at 8% -14%, #1c4bb0 0%, transparent 62%),
    radial-gradient(760px 480px at 106% 2%, #5a2fa8 0%, transparent 58%),
    linear-gradient(180deg, #0a1b4a 0%, #081334 45%, #061033 100%);
  background-attachment: fixed;
}
.app::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 16% 18%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1.3px 1.3px at 74% 10%, rgba(170,220,255,.55), transparent 60%),
    radial-gradient(1.6px 1.6px at 86% 56%, rgba(255,200,240,.45), transparent 60%),
    radial-gradient(1.3px 1.3px at 30% 74%, rgba(150,255,240,.4), transparent 60%);
  opacity: .7;
}
.view {
  position: relative; z-index: 1; flex: 1;
  padding: calc(var(--safe-t) + 12px) var(--pad) calc(var(--tab-h) + var(--safe-b) + 26px);
  max-width: 560px; width: 100%; margin: 0 auto;
}
.view--flush { padding-left: 0; padding-right: 0; }

/* ============================================================ topbar */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.avatar svg { width: 100%; height: 100%; }
.nova-mascot { display: block; }
.nova-happy, .nova-welcome, .nova-listening { animation: nova-float 3.4s ease-in-out infinite; }
.nova-celebrate { animation: nova-pop 900ms var(--ease-out) 1; }
@keyframes nova-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes nova-pop { 0% { transform: scale(.82); } 55% { transform: scale(1.06); } 100% { transform: scale(1); } }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  border: 2px solid rgba(126, 231, 255, 0.6);
  background: radial-gradient(circle at 50% 35%, #d9f4ff, #a9c6ff 70%, #8f9bff);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, .18);
  display: grid; place-items: center;
}
.lvl { min-width: 0; flex: 1; }
.lvl__row { display: flex; align-items: baseline; gap: 6px; }
.lvl__name { font-size: var(--fs-sm); font-weight: 900; letter-spacing: -.01em; color: #fff; text-shadow: 0 1px 3px rgba(4,30,90,.9); }
.lvl__xp { font-size: 10.5px; color: #eaf6ff; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(4,30,90,.9); }
.xpbar {
  height: 6px; border-radius: 99px; background: rgba(255,255,255,.14);
  margin-top: 5px; overflow: hidden;
}
.xpbar > i {
  display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, var(--cyan-300), var(--violet-400));
  box-shadow: 0 0 10px rgba(126, 231, 255, .8);
  transition: width var(--t-slow) var(--ease-out);
}
.stats { display: flex; gap: 6px; flex: 0 0 auto; }
.stat-chip {
  display: flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 800; color: #fff;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16);
  border-radius: var(--r-pill); padding: 5px 9px; white-space: nowrap;
}
.stat-chip b { font-variant-numeric: tabular-nums; }

/* ============================================================ typography */
.display {
  font-size: var(--fs-display); line-height: 1.1; letter-spacing: -.035em;
  font-weight: 800; margin: 0; color: #fff;
}
.h1 { font-size: var(--fs-h1); line-height: 1.15; letter-spacing: -.025em; font-weight: 800; margin: 0; color: #fff; }
.h2 { font-size: var(--fs-h2); line-height: 1.2; letter-spacing: -.02em; font-weight: 800; margin: 0; color: #fff; }
.h3 { font-size: var(--fs-h3); line-height: 1.25; letter-spacing: -.015em; font-weight: 700; margin: 0; }
.on-dark { color: #fff; }
.muted-light { color: rgba(255,255,255,.66); }
.body-dim { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.num { font-variant-numeric: tabular-nums; }

/* ============================================================ cards */
.card {
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--sh-2); padding: 15px; color: var(--ink);
  border: 1px solid rgba(255,255,255,.6);
}
.card--glass {
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.16);
  color: #fff; box-shadow: none; backdrop-filter: blur(12px);
}
.card--flat { box-shadow: var(--sh-1); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card__title { font-size: 14.5px; font-weight: 800; letter-spacing: -.015em; }
.link { font-size: var(--fs-sm); font-weight: 700; color: var(--cyan-300); }

.section { margin-top: 18px; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.section__title { font-size: 15.5px; font-weight: 800; color: #fff; letter-spacing: -.015em; }

/* ============================================================ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: var(--r-md);
  font-size: 15px; font-weight: 800; letter-spacing: -.01em;
  background: var(--surface-3); color: var(--ink);
  transition: transform var(--t-fast) var(--ease), filter var(--t-fast);
}
.btn:active { transform: scale(.975); }
.btn--primary {
  background: linear-gradient(135deg, #2e7bf6, #7c5cff 62%, #ff4d8d 130%);
  color: #fff; box-shadow: 0 12px 26px -14px rgba(46, 123, 246, .95), inset 0 1px 0 rgba(255,255,255,.32);
}
.btn--cyan {
  background: linear-gradient(135deg, #22d3ee, #2e7bf6);
  color: #04122b; box-shadow: 0 12px 26px -14px rgba(34, 211, 238, .9), inset 0 1px 0 rgba(255,255,255,.4);
}
.btn--ghost { background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.2); }
/* ปุ่ม ghost บนพื้นสว่าง (ใน panel) — ไม่งั้นตัวหนังสือขาวบนขาวจะมองไม่เห็น */
.panel .btn--ghost,
.card .btn--ghost,
.res-card .btn--ghost,
.sheet__card .btn--ghost,
.mini .btn--ghost,
.pa .btn--ghost {
  background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--line);
}
.btn--block { width: 100%; }
.btn:disabled { opacity: .45; }

/* ============================================================ tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 8px calc(var(--pad) - 4px) calc(var(--safe-b) + 8px);
  background: linear-gradient(180deg, rgba(6,16,51,.35), rgba(6,16,51,.92) 42%);
  backdrop-filter: blur(18px);
  border-top: 1px solid rgba(255,255,255,.08);
}
.tabbar__row { display: flex; align-items: flex-end; justify-content: space-between; max-width: 560px; margin: 0 auto; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 48px; padding: 4px 0; color: rgba(255,255,255,.5);
  font-size: 10.5px; font-weight: 700; letter-spacing: .01em;
  transition: color var(--t-mid), transform var(--t-fast);
}
.tab__icon { font-size: 20px; line-height: 1; filter: grayscale(.35); }
.tab[aria-current="page"] { color: #fff; }
.tab[aria-current="page"] .tab__icon { filter: none; transform: translateY(-1px) scale(1.08); }
.tab--hero {
  flex: 0 0 auto; width: 66px; margin-bottom: 12px;
  width: 62px; height: 62px; border-radius: 50%;
  background: linear-gradient(135deg, #22d3ee, #2e7bf6 55%, #7c5cff);
  box-shadow: 0 12px 30px -10px rgba(46,123,246,.95), inset 0 2px 0 rgba(255,255,255,.45);
  display: grid; place-items: center; font-size: 26px;
  border: 3px solid rgba(6,16,51,.9);
  transform: translateY(-10px);
}
.tab--hero[aria-current="page"] { box-shadow: 0 14px 36px -8px rgba(34,211,238,1), inset 0 2px 0 rgba(255,255,255,.5); }

/* ============================================================ arcade grid */
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mode {
  position: relative; overflow: hidden; text-align: left; color: #fff;
  border-radius: var(--r-lg); padding: 14px 14px 13px; min-height: 118px;
  display: flex; flex-direction: column; justify-content: flex-end;
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: var(--sh-2), inset 0 1px 0 rgba(255,255,255,.35);
  transition: transform var(--t-fast) var(--ease);
}
.mode:active { transform: scale(.975); }
.mode::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 80% at 15% 0%, rgba(255,255,255,.38), transparent 55%);
  pointer-events: none;
}
.mode__icon { font-size: 26px; margin-bottom: auto; filter: drop-shadow(0 3px 8px rgba(0,0,0,.3)); }
.mode__name { font-size: 14.5px; font-weight: 800; letter-spacing: -.02em; }
.mode__th { font-size: 11px; opacity: .88; margin-top: 2px; }
.mode__meta { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.pill {
  font-size: 9.5px; font-weight: 800; letter-spacing: .02em;
  padding: 2px 7px; border-radius: var(--r-pill);
  background: rgba(0,0,0,.28); color: #fff;
}
.pill--hot { background: rgba(255,255,255,.92); color: #b5175c; }

/* mode tints */
.mode--speak   { background: linear-gradient(150deg, #ff5fa2, #e0399b 70%, #a82ec0); }
.mode--listen  { background: linear-gradient(150deg, #2ec8f0, #2b7bf6 70%, #2b52d8); }
.mode--sound   { background: linear-gradient(150deg, #a06bff, #7c5cff 68%, #5b34d6); }
.mode--spell   { background: linear-gradient(150deg, #24d9a0, #12a97c 70%, #0d7f5e); }
.mode--words   { background: linear-gradient(150deg, #ffc247, #f59e0b 70%, #c2740a); }
.mode--sentence{ background: linear-gradient(150deg, #4d9bff, #2e6ff0 70%, #1d4fc4); }
.mode--story   { background: linear-gradient(150deg, #b07bff, #8248f0 68%, #5f28c4); }
.mode--roleplay{ background: linear-gradient(150deg, #ff7a9c, #ef476f 70%, #c42b52); }

/* ============================================================ lesson player */
.player { display: flex; flex-direction: column; gap: 14px; }
.player__top { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 40px; height: 40px; flex: 0 0 auto; border-radius: 12px; display: grid; place-items: center;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.16);
  color: #fff; font-size: 16px;
}
.icon-btn:active { transform: scale(.95); }
.steps { flex: 1; display: flex; gap: 4px; }
.steps > i {
  flex: 1; height: 5px; border-radius: 99px; background: rgba(255,255,255,.16);
  transition: background var(--t-mid), box-shadow var(--t-mid);
}
.steps > i.is-done { background: linear-gradient(90deg, var(--cyan-300), var(--violet-400)); }
.steps > i.is-now { background: #fff; box-shadow: 0 0 10px rgba(255,255,255,.7); }
.step-label { font-size: 11px; color: rgba(255,255,255,.6); font-weight: 700; letter-spacing: .04em; }

.panel {
  background: var(--surface); border-radius: var(--r-xl); padding: 18px;
  box-shadow: var(--sh-2); color: var(--ink);
}
.panel__kicker {
  font-size: 10.5px; font-weight: 900; letter-spacing: .16em; text-transform: uppercase;
  color: var(--blue-500); margin-bottom: 8px;
}
.panel__title { font-size: 21px; font-weight: 800; letter-spacing: -.025em; margin: 0 0 6px; }
.panel__sub { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0; }

/* NPC bubble */
.npc { display: flex; gap: 10px; align-items: flex-start; }
.npc__face {
  width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%;
  background: linear-gradient(135deg, #d9ecff, #b8d4ff);
  display: grid; place-items: center; font-size: 22px;
  border: 2px solid rgba(46,123,246,.3);
}
.npc__bubble {
  position: relative; background: var(--surface-2); border-radius: 16px 16px 16px 4px;
  padding: 11px 13px; font-size: 14.5px; line-height: 1.5; color: var(--ink);
  border: 1px solid var(--line);
}
.npc__name { font-size: 11.5px; font-weight: 800; color: var(--blue-500); margin-bottom: 3px; }
.npc__th { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* answer cards */
.answers { display: flex; flex-direction: column; gap: 9px; }
.answer {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  padding: 13px 14px; border-radius: var(--r-md);
  background: var(--surface-2); border: 2px solid transparent;
  color: var(--ink); font-size: 15px; font-weight: 600; line-height: 1.35;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.answer:active { transform: scale(.985); }
.answer.is-correct { border-color: var(--green-500); background: #e8fbf3; }
.answer.is-wrong { border-color: var(--rose-500); background: #fdeef1; }
.answer__key {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 8px; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 900; background: #fff; border: 1px solid var(--line); color: var(--muted);
}
.answer__speak {
  margin-left: auto; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 10px;
  display: grid; place-items: center; background: #fff; border: 1px solid var(--line); font-size: 15px;
}

/* tiles */
.tiles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tile {
  min-width: 44px; min-height: 44px; padding: 0 13px; border-radius: 12px;
  display: inline-grid; place-items: center; font-size: 16px; font-weight: 700;
  background: #fff; border: 2px solid var(--surface-3); color: var(--ink);
  box-shadow: var(--sh-1);
  transition: transform var(--t-fast), opacity var(--t-fast);
}
.tile:active { transform: scale(.94); }
.tile.is-used { opacity: .25; pointer-events: none; }
.tray {
  min-height: 58px; border-radius: var(--r-md); border: 2px dashed var(--surface-3);
  padding: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: #fbfcff;
}
.tray__empty { color: var(--muted-2); font-size: 13px; padding: 0 4px; }
.tray .tile { box-shadow: none; border-color: var(--blue-500); background: #eef4ff; }

/* scene */
.scene { position: relative; border-radius: var(--r-md); overflow: hidden; background: #dfe9fb; }
.scene__img { width: 100%; display: block; }
.hotspot {
  position: absolute; border-radius: 10px; border: 0; background: transparent;
  transition: background var(--t-fast);
}
.hotspot:active { background: rgba(255,255,255,.35); }
.hotspot.is-found { background: rgba(18,196,139,.28); box-shadow: 0 0 0 2px var(--green-500) inset; }
.hotspot.is-miss { background: rgba(244,63,94,.22); }

/* mic */
.mic {
  width: 108px; height: 108px; border-radius: 50%; margin: 16px auto 6px; display: grid; place-items: center;
  font-size: 40px; color: #fff;
  background: radial-gradient(circle at 35% 30%, #7ee7ff, #2e7bf6 55%, #5b34d6);
  box-shadow: 0 18px 44px -14px rgba(46,123,246,.95), inset 0 3px 0 rgba(255,255,255,.4);
  border: 0; transition: transform var(--t-fast);
}
.mic:active { transform: scale(.95); }
.mic.is-rec { background: radial-gradient(circle at 35% 30%, #ff9ecb, #f43f5e 55%, #a3103f); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(244,63,94,.5); } 50% { box-shadow: 0 0 0 18px rgba(244,63,94,0); } }

/* feedback */
.feedback {
  border-radius: var(--r-md); padding: 12px 14px; font-size: 14px; line-height: 1.5;
  display: flex; gap: 10px; align-items: flex-start;
}
.feedback--good { background: #e8fbf3; color: #0b6b4e; border: 1px solid rgba(18,196,139,.35); }
.feedback--try { background: #fdeef1; color: #8c1436; border: 1px solid rgba(244,63,94,.3); }
.feedback--info { background: #eef4ff; color: #1a3f8f; border: 1px solid rgba(46,123,246,.28); }

/* result */
.stars { display: flex; gap: 6px; justify-content: center; font-size: 34px; margin: 6px 0 12px; }
.star { filter: grayscale(1) opacity(.35); transition: filter var(--t-mid), transform var(--t-mid); }
.star.is-on { filter: none; transform: scale(1.08); }
.cando { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.cando__item { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; line-height: 1.45; }
.cando__tick { color: var(--green-500); font-weight: 900; }

/* misc */
.row { display: flex; gap: 10px; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.center { text-align: center; }
.progress-line { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress-line > i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan-400), var(--violet-500)); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
