/* ============================================================
   WordQuest — design tokens
   ธีม: แผนที่การเดินทางตอนกลางคืน (night-map) + การ์ดกระดาษ parchment
   สัญลักษณ์เฉพาะ: เส้นทาง (trail) เชื่อม 4 ด่าน A1→B2 แบบตราประทับพาสปอร์ต
   ============================================================ */

:root {
  /* สีพื้นหลัง / โครงสร้าง */
  --bg-night: #1b1530;
  --bg-night-2: #241c3f;
  --bg-night-3: #2d2350;
  --parchment: #fff8ec;
  --parchment-dim: #f3e9d6;
  --ink: #2b2440;
  --ink-soft: #6a6189;
  --ink-faint: #9a92b8;

  /* สี 4 ระดับ CEFR (terrain) */
  --a1: #4f9d69;
  --a1-dark: #387a4d;
  --a2: #e0a458;
  --a2-dark: #c2823a;
  --b1: #4d6fa8;
  --b1-dark: #37548a;
  --b2: #7c5cbf;
  --b2-dark: #5e3f9c;
  --c1: #e0b341;
  --c1-dark: #b88a26;

  /* accent / สถานะ */
  --ember: #ff6f3c;
  --ember-dark: #e0552a;
  --gold: #ffd166;
  --success: #4f9d69;
  --danger: #e0552a;
  --white: #ffffff;

  /* typography */
  --font-display: 'Fredoka', 'Chonburi', sans-serif;
  --font-body: 'Manrope', 'Noto Sans Thai', sans-serif;
  --font-mono: 'JetBrains Mono', 'Noto Sans Thai', monospace;

  /* layout */
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow-card: 0 16px 40px rgba(10, 6, 25, 0.45);
  --shadow-soft: 0 6px 18px rgba(10, 6, 25, 0.25);
  --max-width: 1080px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: radial-gradient(ellipse at 20% -10%, var(--bg-night-3), var(--bg-night) 60%);
  color: var(--parchment);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ฝุ่นดาวพื้นหลัง ให้ความรู้สึก "แผนที่ตอนกลางคืน" */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(2px 2px at 10% 20%, rgba(255,255,255,0.25) 0, transparent 50%),
    radial-gradient(2px 2px at 80% 10%, rgba(255,255,255,0.18) 0, transparent 50%),
    radial-gradient(1.5px 1.5px at 60% 70%, rgba(255,255,255,0.2) 0, transparent 50%),
    radial-gradient(1.5px 1.5px at 30% 85%, rgba(255,255,255,0.15) 0, transparent 50%),
    radial-gradient(2px 2px at 90% 60%, rgba(255,255,255,0.2) 0, transparent 50%),
    radial-gradient(1.5px 1.5px at 45% 35%, rgba(255,255,255,0.15) 0, transparent 50%);
  background-size: 100% 100%;
  z-index: 0;
}

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
a { color: inherit; }
.hidden { display: none !important; }

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}

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

/* ============================================================
   Toasts
   ============================================================ */
#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 380px);
}
.toast {
  background: var(--ink);
  color: var(--parchment);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 0.92rem;
  box-shadow: var(--shadow-soft);
  border-left: 4px solid var(--ember);
  animation: toast-in 0.25s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Screens — generic
   ============================================================ */
.screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */
#screen-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

.auth-wrap {
  width: 100%;
  max-width: 920px;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--bg-night-2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}

.auth-hero {
  position: relative;
  padding: 40px 32px;
  background: linear-gradient(160deg, var(--b1-dark), var(--b2-dark) 55%, var(--bg-night-3));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 420px;
}

.auth-hero .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.auth-hero .brand-title {
  font-size: 1.5rem;
  color: var(--white);
}
.auth-hero .brand-sub {
  margin-top: 6px;
  color: rgba(255,255,255,0.75);
  font-size: 0.95rem;
  line-height: 1.5;
}

.auth-hero .hero-trail {
  position: relative;
  margin-top: 24px;
}

.mini-trail {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mini-node {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.8rem;
  color: var(--white);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  flex-shrink: 0;
}
.mini-rail {
  flex: 1;
  height: 0;
  border-top: 3px dashed rgba(255,255,255,0.4);
  min-width: 12px;
}

.auth-hero .fox {
  width: 120px;
  margin-top: 20px;
}

.auth-card {
  padding: 40px 36px;
  background: var(--parchment);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--parchment-dim);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 8px;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.95rem;
  transition: all 0.15s ease;
}
.tab-btn.active {
  background: var(--white);
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--ink-soft);
}
.form-group input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(43, 36, 64, 0.12);
  font-size: 1rem;
  background: var(--white);
  color: var(--ink);
  transition: border-color 0.15s ease;
}
.form-group input:focus {
  border-color: var(--b2);
  outline: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--ember), var(--ember-dark));
  color: var(--white);
  box-shadow: 0 8px 18px rgba(224, 85, 42, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 22px rgba(224, 85, 42, 0.45); }

.btn-block { width: 100%; }

.form-error {
  color: var(--danger);
  font-size: 0.88rem;
  margin-top: 4px;
  min-height: 1.2em;
}

.auth-foot {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid rgba(0,0,0,0.08);
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
  /* การ์ดฝั่งนี้พื้นสีครีม ต้องใช้สีเข้ม ไม่ใช่สีขาว */
  color: var(--ink-faint, #8a7fb0);
}

@media (max-width: 760px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { min-height: 220px; }
  .auth-hero .fox { display: none; }
}

/* ============================================================
   HUD (top bar after login)
   ============================================================ */
#hud {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(27, 21, 48, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
#hud .container {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
}
.hud-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-night-3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid var(--gold);
  cursor: pointer;
  font-size: 1.3rem;
  transition: transform 0.12s ease;
  position: relative;
}
.hud-avatar:hover { transform: scale(1.08); }
.hud-avatar::after {
  content: '';
  position: absolute;
  bottom: -3px;
  right: -3px;
  width: 16px;
  height: 16px;
  background: var(--ember);
  color: var(--white);
  border-radius: 50%;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--bg-night);
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0 4px;
}
.avatar-option {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(43, 36, 64, 0.12);
  background: var(--white);
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.avatar-option:hover { transform: translateY(-2px); border-color: var(--b2); }
.avatar-option.selected {
  border-color: var(--ember);
  background: rgba(255, 111, 60, 0.12);
  box-shadow: 0 0 0 3px rgba(255, 111, 60, 0.25);
}
.hud-id { flex-shrink: 0; cursor: pointer; }
.hud-username {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.1;
}
.hud-level-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--gold);
  letter-spacing: 0.02em;
}
.hud-exp-wrap {
  flex: 1;
  min-width: 0;
}
.hud-exp-bar-bg {
  position: relative;
  height: 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}
.hud-exp-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--ember), var(--gold));
  border-radius: 8px;
  transition: width 0.6s cubic-bezier(.2,.9,.3,1.2);
}
.hud-exp-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
  margin-top: 3px;
  text-align: right;
}
.hud-icon-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--gold);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 1rem;
  flex-shrink: 0;
}
.hud-icon-btn:hover { background: rgba(255,255,255,0.08); }

.hud-logout {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--parchment);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.hud-logout:hover { background: rgba(255,255,255,0.08); }

/* floating +EXP popup */
.exp-pop {
  position: fixed;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.7);
  pointer-events: none;
  z-index: 200;
  animation: exp-float 1.1s ease-out forwards;
}
@keyframes exp-float {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -8px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -64px) scale(1); }
}

/* ============================================================
   MAP / DASHBOARD SCREEN
   ============================================================ */
#screen-map { padding: 36px 0 60px; }

.map-heading { text-align: center; margin-bottom: 8px; }
.map-heading h1 {
  font-size: 1.7rem;
  color: var(--white);
}
.map-heading p {
  color: var(--ink-faint);
  margin-top: 6px;
  font-size: 0.95rem;
}

.trail-track {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 40px auto 0;
  max-width: 760px;
}

.trail-node-row {
  display: flex;
  align-items: center;
}

.trail-node {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  color: var(--parchment);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}
.trail-node:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
}

.node-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.node-scene svg {
  position: absolute;
  right: -10px;
  top: 0;
  height: 100%;
  width: 220px;
  opacity: 0.4;
}
.node-scene::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--bg-night-2) 45%, transparent 88%);
}

.stamp {
  position: relative;
  z-index: 1;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--white);
  border: 3px solid rgba(255,255,255,0.55);
}
.stamp::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px dashed currentColor;
  opacity: 0.5;
}
.stamp svg { position: absolute; inset: 0; }
.stamp-label { position: relative; z-index: 2; }

.node-a1 .stamp { background: var(--a1); }
.node-a2 .stamp { background: var(--a2); }
.node-b1 .stamp { background: var(--b1); }
.node-b2 .stamp { background: var(--b2); }
.node-c1 .stamp { background: var(--c1); }

.node-info { flex: 1; min-width: 0; position: relative; z-index: 1; }
.node-title {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--white);
  text-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
.node-sub {
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin-top: 2px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
.node-progress-bar-bg {
  margin-top: 8px;
  height: 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
}
.node-progress-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s ease;
}
.node-a1 .node-progress-bar-fill { background: var(--a1); }
.node-a2 .node-progress-bar-fill { background: var(--a2); }
.node-b1 .node-progress-bar-fill { background: var(--b1); }
.node-b2 .node-progress-bar-fill { background: var(--b2); }
.node-c1 .node-progress-bar-fill { background: var(--c1); }

.node-cta {
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--gold);
  white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}

.rail {
  width: 3px;
  height: 26px;
  margin-left: 31px;
  background-image: linear-gradient(rgba(255,255,255,0.35) 60%, transparent 40%);
  background-size: 100% 10px;
}

@media (max-width: 600px) {
  .trail-node { padding: 14px; gap: 12px; }
  .stamp { width: 52px; height: 52px; font-size: 1rem; }
  .node-title { font-size: 0.95rem; }
}

/* ============================================================
   GAME / FLASHCARD SCREEN
   ============================================================ */
#screen-game {
  padding: 24px 0 40px;
  align-items: center;
}

.game-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.game-exit {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--parchment);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 700;
}
.game-level-chip {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--white);
}

.footprints {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 0 auto 28px;
  max-width: 520px;
}
.footprint {
  width: 16px;
  height: 16px;
  border-radius: 50% 50% 50% 10%;
  background: rgba(255,255,255,0.15);
  transition: background 0.2s ease, transform 0.2s ease;
}
.footprint.done { background: var(--gold); }
.footprint.current {
  background: var(--ember);
  transform: scale(1.25);
}

.card-stage {
  position: relative;
  width: min(92vw, 380px);
  height: 260px;
  margin: 0 auto;
}

.deck-shadow {
  position: absolute;
  inset: 10px 6px -10px 6px;
  border-radius: var(--radius-lg);
  background: var(--bg-night-3);
  transform: rotate(-3deg);
  z-index: 0;
}
.deck-shadow.two {
  inset: 16px 10px -14px 10px;
  transform: rotate(3deg);
  background: var(--bg-night-2);
  z-index: -1;
}

.flip-card {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  perspective: 1400px;
  z-index: 2;
}
.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }

.flip-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  backface-visibility: hidden;
  background: var(--parchment);
  color: var(--ink);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px;
  text-align: center;
  border: 1px solid rgba(0,0,0,0.06);
}
.flip-face-back { transform: rotateY(180deg); }

.card-level-tag {
  position: absolute;
  top: 18px;
  left: 18px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--white);
}
.card-pos-chip {
  position: absolute;
  top: 18px;
  right: 18px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: rgba(43,36,64,0.08);
  color: var(--ink-soft);
  padding: 5px 10px;
  border-radius: 999px;
}

.card-word {
  font-family: var(--font-display);
  font-size: 2.1rem;
  line-height: 1.15;
  word-break: break-word;
  margin-top: 12px;
}
.card-hint {
  margin-top: 18px;
  color: var(--ink-faint);
  font-size: 0.85rem;
}
.card-compass {
  margin-top: 22px;
  opacity: 0.65;
}

.card-pos-full {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  margin-top: 14px;
}
.card-pos-raw {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-faint);
  margin-top: 4px;
}
.card-stamp-big {
  margin-top: 18px;
}
.card-question {
  margin-top: 18px;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.answer-row {
  display: flex;
  gap: 14px;
  width: min(92vw, 380px);
  margin: 24px auto 0;
}
.answer-btn {
  flex: 1;
  padding: 16px 10px;
  border-radius: var(--radius-md);
  font-weight: 800;
  font-size: 0.98rem;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s ease;
}
.answer-btn:active { transform: scale(0.96); }
.answer-btn small { font-weight: 600; opacity: 0.85; font-size: 0.74rem; }
.answer-no {
  background: rgba(224, 85, 42, 0.14);
  color: #ffb199;
  border: 2px solid var(--ember-dark);
}
.answer-yes {
  background: rgba(79, 157, 105, 0.16);
  color: #9fe3b6;
  border: 2px solid var(--a1-dark);
}

.card-question {
  margin-top: 18px;
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.quiz-face {
  justify-content: flex-start;
  padding-top: 56px;
}
.quiz-loading {
  margin-top: 20px;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.quiz-choices {
  width: min(92vw, 380px);
  margin: 20px auto 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-choice {
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.1);
  color: var(--parchment);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 700;
  text-align: left;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}
.quiz-choice:hover:not(:disabled) {
  border-color: var(--gold);
  transform: translateY(-1px);
}
.quiz-choice:disabled { cursor: default; }
.quiz-choice.correct {
  background: rgba(79, 157, 105, 0.22);
  border-color: var(--a1);
  color: #bdf0cd;
}
.quiz-choice.wrong {
  background: rgba(224, 85, 42, 0.22);
  border-color: var(--ember-dark);
  color: #ffc4ad;
}
.quiz-choice .choice-mark { float: right; }

.quiz-next-btn {
  display: block;
  width: min(92vw, 380px);
  margin: 18px auto 0;
}

/* ============================================================
   LEVEL UP MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 25, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-card {
  background: var(--parchment);
  color: var(--ink);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.modal-card h2 {
  font-size: 1.6rem;
  margin-top: 12px;
}
.modal-card p {
  color: var(--ink-soft);
  margin-top: 8px;
  font-size: 0.95rem;
}
.confetti-dash {
  position: absolute;
  width: 6px;
  height: 16px;
  border-radius: 3px;
  opacity: 0.8;
  animation: confetti-fall 1.6s ease-in forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-40px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(220px) rotate(280deg); opacity: 0; }
}

/* ============================================================
   SESSION SUMMARY SCREEN
   ============================================================ */
#screen-summary {
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}
.summary-card {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-card);
}
.summary-card h2 { font-size: 1.5rem; color: var(--white); }
.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0;
}
.summary-stat {
  background: var(--bg-night-3);
  border-radius: var(--radius-md);
  padding: 14px 8px;
}
.summary-stat .num {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  color: var(--gold);
  font-weight: 700;
}
.summary-stat .lbl {
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 4px;
}
.summary-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--parchment);
  border: 1px solid rgba(255,255,255,0.18);
}

/* ============================================================
   LEADERBOARD SCREEN
   ============================================================ */
.leaderboard-list {
  max-width: 560px;
  margin: 24px auto 40px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  padding: 12px 16px;
}
.leaderboard-row.is-me {
  border-color: var(--gold);
  background: rgba(255, 209, 102, 0.1);
}
.leaderboard-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  width: 36px;
  flex-shrink: 0;
  text-align: center;
  color: var(--ink-faint);
}
.leaderboard-row.rank-1 .leaderboard-rank { color: #ffd166; font-size: 1.2rem; }
.leaderboard-row.rank-2 .leaderboard-rank { color: #d8d8e0; font-size: 1.1rem; }
.leaderboard-row.rank-3 .leaderboard-rank { color: #e0a458; font-size: 1.05rem; }
.leaderboard-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-night-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.leaderboard-info { flex: 1; min-width: 0; }
.leaderboard-username {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.leaderboard-level {
  font-size: 0.74rem;
  color: var(--ink-faint);
}
.leaderboard-exp {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--gold);
  flex-shrink: 0;
}
.leaderboard-divider {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.8rem;
  padding: 4px 0;
}

/* ============================================================
   PROFILE MODAL (username + avatar)
   ============================================================ */
.profile-username-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.profile-username-row input {
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(43, 36, 64, 0.12);
  font-size: 1rem;
  font-weight: 700;
  background: var(--white);
  color: var(--ink);
}
.profile-username-row input:focus { border-color: var(--b2); outline: none; }
.profile-section-label {
  text-align: left;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: 18px;
}

/* ============================================================
   VERSION TAG
   ============================================================ */
.version-tag {
  position: fixed;
  bottom: 8px;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: rgba(255,255,255,0.3);
  z-index: 1000;
  pointer-events: none;
}

/* utility */
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}


/* ============================================================
   GRAMMAR LESSONS
   ============================================================ */
.grammar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.grammar-header-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--parchment);
  font-weight: 800;
}
.grammar-chapter-badge {
  background: var(--gold);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

/* Intro card */
.grammar-intro-card {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
}
.grammar-intro-icon {
  font-size: 2.2rem;
  flex-shrink: 0;
}
.grammar-intro-title {
  font-weight: 800;
  color: var(--white);
  font-size: 0.98rem;
}
.grammar-intro-sub {
  color: var(--ink-faint);
  font-size: 0.82rem;
  margin-top: 2px;
}

/* Chapter list */
.grammar-chapters {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chapter-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  color: var(--parchment);
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}
.chapter-card:hover {
  transform: translateX(4px);
  border-color: var(--gold);
  box-shadow: var(--shadow-soft);
}
.chapter-card.completed { border-color: var(--a1); }
.chapter-icon-wrap {
  width: 52px; height: 52px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  border-radius: 12px;
  color: var(--white);
}
.chapter-info { flex: 1; min-width: 0; }
.chapter-num {
  font-size: 0.72rem;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.chapter-title-text {
  font-weight: 800;
  font-size: 1rem;
  color: var(--white);
  margin-top: 2px;
}
.chapter-sub {
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin-top: 2px;
}
.chapter-score {
  flex-shrink: 0;
  text-align: right;
  font-size: 0.82rem;
  color: var(--ink-faint);
}
.chapter-score .star { font-size: 1.2rem; }
.chapter-score.done { color: var(--gold); font-weight: 700; }

/* Lesson content */
.grammar-lesson-head {
  text-align: center;
  padding: 20px 16px;
  background: var(--bg-night-2);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.lesson-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}
.lesson-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--white);
  font-weight: 800;
}
.lesson-intro {
  color: var(--ink-faint);
  font-size: 0.9rem;
  margin-top: 6px;
  line-height: 1.5;
}
.grammar-lesson-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}
.section-card {
  background: var(--parchment);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
}
.section-heading {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  border-bottom: 2px solid rgba(0,0,0,0.08);
  padding-bottom: 6px;
  margin-bottom: 10px;
}
.section-content {
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.65;
}
.section-content b { color: var(--ember); font-weight: 700; }
.examples-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.example-item {
  background: #f6efe0;
  border-left: 3px solid var(--gold);
  padding: 8px 12px;
  border-radius: 6px;
}
.example-en {
  font-family: var(--font-body);
  color: var(--ink);
  font-size: 0.92rem;
}
.example-en b { color: var(--ember); font-weight: 700; }
.example-th {
  color: var(--ink-soft);
  font-size: 0.82rem;
  margin-top: 3px;
}
.grammar-lesson-actions {
  padding-bottom: 24px;
}

/* Quiz */
.grammar-quiz-progress {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  overflow: hidden;
  margin: 8px 0 6px;
}
.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--ember));
  border-radius: 6px;
  transition: width 0.3s ease;
  width: 0%;
}
.grammar-quiz-count {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.82rem;
  font-family: var(--font-mono);
  margin-bottom: 14px;
}
.grammar-quiz-question {
  background: var(--parchment);
  color: var(--ink);
  padding: 18px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: 1.4;
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}
.grammar-quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-choice {
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.12);
  color: var(--parchment);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}
.quiz-choice:hover {
  border-color: var(--gold);
  transform: translateX(3px);
}
.quiz-choice:disabled { cursor: default; }
.quiz-choice.chosen {
  border-color: var(--gold);
  background: rgba(255,209,102,0.1);
}
.quiz-choice.correct {
  border-color: #4caf50;
  background: rgba(76,175,80,0.18);
  color: #a7e5ac;
}
.quiz-choice.wrong {
  border-color: #f44336;
  background: rgba(244,67,54,0.18);
  color: #ffb0b0;
}

/* Result */
.gr-score {
  font-family: var(--font-display);
  font-size: 2.6rem;
  color: var(--gold);
  font-weight: 800;
  margin: 4px 0;
}
.gr-message {
  color: var(--ink-faint);
  font-size: 0.92rem;
  margin-bottom: 8px;
}
.gr-review {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  margin: 16px 0;
  max-height: 300px;
  overflow-y: auto;
}
.gr-review-item {
  background: var(--bg-night-3);
  border-left: 3px solid rgba(255,255,255,0.2);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.gr-review-item.correct { border-left-color: #4caf50; }
.gr-review-item.wrong { border-left-color: #f44336; }
.gr-review-q {
  color: var(--parchment);
  font-weight: 700;
  margin-bottom: 4px;
  font-size: 0.85rem;
}
.gr-review-a {
  color: var(--ink-faint);
  font-size: 0.8rem;
  line-height: 1.5;
}
.gr-review-a b { color: var(--gold); font-weight: 700; }

/* ============================================================
   HOME SCREEN
   ============================================================ */
#screen-home {
  padding: 32px 0 60px;
}
.home-heading {
  text-align: center;
  margin-bottom: 32px;
}
.home-heading h1 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  color: var(--white);
  font-weight: 800;
}
.home-heading p {
  color: var(--ink-faint);
  font-size: 0.95rem;
  margin-top: 6px;
}
.home-menu {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
  margin: 0 auto;
}
.home-menu-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 20px;
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-lg);
  color: var(--parchment);
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.2s ease;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.home-menu-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 40%, rgba(255,255,255,0.05) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
  pointer-events: none;
}
.home-menu-card:hover::before { transform: translateX(100%); }
.home-menu-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.35);
}
.grammar-card:hover { border-color: #c14a4a; }
.vocab-card:hover { border-color: #e0a458; }

.home-menu-icon {
  width: 68px; height: 68px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(0,0,0,0.15));
}
.grammar-card .home-menu-icon { background: linear-gradient(135deg, #c14a4a, #8a2f2f); }
.vocab-card .home-menu-icon { background: linear-gradient(135deg, #e0a458, #b57a2a); }

.home-menu-info { flex: 1; min-width: 0; }
.home-menu-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--white);
  font-weight: 800;
}
.home-menu-sub {
  color: var(--ink-faint);
  font-size: 0.85rem;
  margin-top: 4px;
}
.home-menu-arrow {
  font-size: 1.4rem;
  color: var(--gold);
  flex-shrink: 0;
  opacity: 0.7;
  transition: transform 0.15s ease;
}
.home-menu-card:hover .home-menu-arrow {
  transform: translateX(6px);
  opacity: 1;
}
.map-back-btn { margin-bottom: 8px; }

/* ============================================================
   PROFILE PICTURE UPLOAD
   ============================================================ */
.hud-avatar.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
}
.leaderboard-avatar.has-image {
  padding: 0;
  overflow: hidden;
}
.leaderboard-avatar.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-pic-section {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 12px;
  background: var(--bg-night-3);
  border-radius: var(--radius-sm);
}
.profile-pic-preview {
  width: 84px; height: 84px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-night-2);
  border: 3px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  font-size: 2.6rem;
}
.profile-pic-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-pic-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
}
.profile-pic-hint {
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 2px;
}

/* ============================================================
   IN-LESSON PRACTICE EXERCISES
   ============================================================ */
.practice-wrap {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.practice-block {
  background: linear-gradient(135deg, #fff4d6, #ffeab8);
  border: 2px dashed #e0a848;
  border-radius: 10px;
  padding: 14px 16px;
}
.practice-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  color: #7a5a1a;
  background: #ffd166;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}
.practice-prompt {
  color: var(--ink);
  font-weight: 700;
  font-size: 0.94rem;
  margin-bottom: 10px;
  line-height: 1.4;
}
.practice-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.practice-choice {
  background: #fff;
  border: 2px solid rgba(0,0,0,0.1);
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s ease;
  width: 100%;
}
.practice-choice:hover:not(:disabled) {
  border-color: #e0a848;
  transform: translateX(3px);
}
.practice-choice:disabled { cursor: default; opacity: 0.75; }
.practice-choice.correct {
  border-color: #4caf50;
  background: #e8f5e9;
  color: #1b5e20;
  font-weight: 700;
  opacity: 1;
}
.practice-choice.wrong {
  border-color: #f44336;
  background: #ffebee;
  color: #b71c1c;
  font-weight: 700;
  opacity: 1;
}
.practice-feedback {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
}
.practice-feedback.correct {
  background: rgba(76,175,80,0.15);
  color: #1b5e20;
  border-left: 3px solid #4caf50;
}
.practice-feedback.wrong {
  background: rgba(244,67,54,0.12);
  color: #b71c1c;
  border-left: 3px solid #f44336;
}
.practice-explain {
  display: block;
  font-weight: 400;
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  line-height: 1.4;
}

/* ============================================================
   MODE SELECTOR (quiz difficulty & exam type)
   ============================================================ */
.mode-selector-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--parchment);
  font-weight: 800;
  margin-bottom: 12px;
  text-align: center;
}
.mode-selector-sub {
  font-size: 0.8rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 16px 0 8px;
  font-weight: 700;
}
.mode-selector-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.mode-selector-empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 20px;
  font-style: italic;
}
.mode-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--parchment);
  text-align: left;
  min-height: 78px;
}
.mode-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}
.mode-card.perfect {
  background: linear-gradient(135deg, var(--bg-night-2), rgba(255,209,102,0.1));
}
.mode-card-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  color: #fff;
}
.mode-card-body { flex: 1; min-width: 0; }
.mode-card-name {
  font-weight: 800;
  color: var(--white);
  font-size: 0.95rem;
}
.mode-card-count {
  font-size: 0.75rem;
  color: var(--ink-faint);
  margin-top: 2px;
}
.mode-card-score {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gold);
  text-align: right;
  flex-shrink: 0;
}
.mode-card-score.not-done { color: var(--ink-faint); font-weight: 400; font-size: 0.72rem; }

.chapter-badge.multi {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--gold);
  background: rgba(255,209,102,0.12);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}

/* ============================================================
   QUIZ PASSAGE (TOEIC / TOEFL)
   ============================================================ */
.grammar-quiz-passage {
  background: #f6efe0;
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-soft);
  border-left: 4px solid var(--gold);
}
.grammar-quiz-passage .passage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.grammar-quiz-passage .passage-title {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--ink);
  font-size: 0.92rem;
}
.grammar-quiz-passage .passage-toggle {
  background: transparent;
  border: 1px solid rgba(0,0,0,0.2);
  color: var(--ink-soft);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
  font-weight: 600;
}
.grammar-quiz-passage .passage-body {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--ink-soft);
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  transition: max-height 0.3s ease;
}
.grammar-quiz-passage.collapsed .passage-body {
  max-height: 0;
  overflow: hidden;
  padding: 0;
}

/* ============================================================
   PWA / SAFE AREA — เมื่อเปิดจากไอคอนบนหน้าจอโทรศัพท์
   iPhone ที่มีรอยบาก (notch) หรือแถบ home indicator ด้านล่าง
   จะต้องเว้นระยะไม่ให้เนื้อหาโดนบัง
   ============================================================ */
#hud {
  padding-top: env(safe-area-inset-top, 0px);
}
#hud .container {
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}
body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* ปุ่ม/แถบที่ตรึงติดขอบล่าง ก็ต้องเว้นระยะเช่นกัน */
#toast-container {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* เปิดในโหมดแอป (standalone) — ปิดการเลือกข้อความโดยไม่ตั้งใจ
   และปิด pull-to-refresh ที่ทำให้เลื่อนแล้วรีเฟรชหน้าโดยบังเอิญ */
@media (display-mode: standalone) {
  html, body {
    overscroll-behavior-y: contain;
  }
  .quiz-choice,
  .practice-choice,
  .mode-card,
  .chapter-card,
  .btn {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}

/* ปิดไฮไลต์สีฟ้าตอนแตะปุ่มบนมือถือ */
button, a, .chapter-card, .mode-card {
  -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   ลืมรหัสผ่าน / ตั้งรหัสผ่านใหม่
   ============================================================ */
.link-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 6px;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s ease;
}
.link-btn:hover { color: var(--ember, #e07b3c); }

.auth-note {
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 0 0 16px;
}

.form-success {
  background: rgba(79, 157, 105, 0.14);
  border-left: 3px solid var(--success, #4f9d69);
  color: #1b5e20;
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 12px;
}

/* ============================================================
   ONLINE BADGE + FRIENDS
   ============================================================ */
.online-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 6px 14px;
  background: rgba(79,157,105,0.15);
  border: 1px solid rgba(79,157,105,0.35);
  border-radius: 999px;
  font-size: 0.82rem;
  color: #8fd6a6;
  font-weight: 600;
}
.online-badge.offline {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
  color: var(--ink-faint);
}
.online-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 0 rgba(76,175,80,0.7);
  animation: pulse-dot 2s infinite;
}
.online-badge.offline .online-dot { background: #888; animation: none; }
@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(76,175,80,0.6); }
  70%  { box-shadow: 0 0 0 7px rgba(76,175,80,0); }
  100% { box-shadow: 0 0 0 0 rgba(76,175,80,0); }
}

/* การ์ดเมนูเพื่อนบนหน้าหลัก */
.home-menu-card.friends-card .home-menu-icon { background: linear-gradient(135deg,#5aa76b,#3d7a4d); }
.menu-badge {
  min-width: 22px; height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger, #e0552a);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* แถบค้นหา */
.friends-search {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.friends-search input {
  flex: 1;
  min-width: 0;
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.1);
  color: var(--parchment);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 0.95rem;
}
.friends-search input:focus {
  outline: none;
  border-color: var(--gold);
}
.friends-search .btn { flex-shrink: 0; padding: 12px 20px; }

.friends-section { margin-top: 22px; }
.friends-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--parchment);
  margin-bottom: 10px;
}
.count-pill {
  background: rgba(255,255,255,0.12);
  color: var(--parchment);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.75rem;
  font-family: var(--font-body);
}

.friend-list { display: flex; flex-direction: column; gap: 8px; }

.friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius-md);
  padding: 11px 14px;
}
.friend-avatar-wrap { position: relative; flex-shrink: 0; }
.friend-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--bg-night-3);
  border: 2px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  overflow: hidden;
}
.friend-avatar.has-image { padding: 0; }
.friend-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.status-dot {
  position: absolute;
  right: -1px; bottom: -1px;
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2px solid var(--bg-night-2);
}
.status-dot.online  { background: #4caf50; }
.status-dot.offline { background: #6b6b7d; }

.friend-info { flex: 1; min-width: 0; }
.friend-name {
  font-weight: 700;
  color: var(--white);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.friend-meta { font-size: 0.76rem; color: var(--ink-faint); margin-top: 2px; }
.online-text { color: #7cc98f; font-weight: 700; }

.friend-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn {
  border: none;
  border-radius: 8px;
  padding: 7px 13px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.mini-btn:active { transform: scale(0.95); }
.mini-btn:disabled { opacity: 0.5; cursor: default; }
.mini-btn.accept { background: var(--success, #4f9d69); color: #fff; }
.mini-btn.ghost {
  background: transparent;
  color: var(--ink-faint);
  border: 1px solid rgba(255,255,255,0.15);
}
.mini-btn.ghost:hover { color: var(--danger, #e0552a); border-color: var(--danger, #e0552a); }

.relation-tag {
  font-size: 0.75rem;
  color: var(--ink-faint);
  padding: 6px 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  white-space: nowrap;
}
.friend-empty {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.86rem;
  padding: 22px 14px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-md);
  border: 1px dashed rgba(255,255,255,0.1);
}

@media (max-width: 420px) {
  .friend-actions { flex-direction: column; }
  .mini-btn { padding: 6px 10px; font-size: 0.72rem; }
}

/* ============================================================
   BATTLE ROOM — ห้องแข่งคำศัพท์
   ============================================================ */
.home-menu-card.battle-card .home-menu-icon {
  background: linear-gradient(135deg, #c14a4a, #8e2f2f);
}

.battle-panel {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 16px;
}
.battle-panel-title {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--parchment);
  margin-bottom: 14px;
  font-size: 1.02rem;
}
.battle-label {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-faint);
  margin: 12px 0 7px;
  font-weight: 700;
}
.level-picker { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 6px; }
.level-chip {
  background: var(--bg-night-3);
  border: 2px solid rgba(255,255,255,0.1);
  color: var(--ink-faint);
  border-radius: 999px;
  padding: 7px 15px;
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s ease;
}
.level-chip.active {
  background: var(--gold);
  border-color: var(--gold);
  color: #2b2440;
}

/* กล่องรหัสห้อง */
.room-code-box {
  text-align: center;
  background: linear-gradient(135deg, rgba(255,209,102,0.14), rgba(224,123,60,0.10));
  border: 2px dashed var(--gold);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  margin-bottom: 18px;
}
.room-code-label { font-size: 0.8rem; color: var(--ink-faint); margin-bottom: 8px; }
.room-code {
  font-family: var(--font-mono, monospace);
  font-size: 2.3rem;
  font-weight: 800;
  letter-spacing: 0.32em;
  color: var(--gold);
  margin-bottom: 12px;
  text-indent: 0.32em; /* ชดเชย letter-spacing ให้ดูอยู่กึ่งกลางจริง */
}
.battle-hint {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.85rem;
  margin-top: 14px;
}

/* แถบบนตอนแข่ง */
.battle-hud {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.battle-q-count {
  font-size: 0.82rem;
  color: var(--ink-faint);
  font-weight: 700;
  white-space: nowrap;
}
.battle-timer-wrap {
  flex: 1;
  height: 9px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
}
.battle-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #4caf50, #8bc34a);
  border-radius: 999px;
  transition: background 0.3s ease;
}
.battle-timer-fill.warning {
  background: linear-gradient(90deg, #e0552a, #ff8a4c);
}
.battle-score {
  font-family: var(--font-mono, monospace);
  font-weight: 800;
  color: var(--gold);
  font-size: 1.05rem;
  min-width: 52px;
  text-align: right;
}

/* กระดานคะแนนสด */
.battle-scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.78rem;
}
.sb-item.me { border-color: var(--gold); background: rgba(255,209,102,0.12); }
.sb-rank { color: var(--ink-faint); font-weight: 700; }
.sb-name {
  color: var(--parchment);
  font-weight: 600;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-score { color: var(--gold); font-weight: 800; }
.sb-check { color: #7cc98f; }

.battle-question {
  background: var(--parchment);
  border-radius: var(--radius-md);
  padding: 26px 20px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
}
.battle-q-kind {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-bottom: 10px;
  font-weight: 700;
}
.battle-q-prompt {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--ink);
  word-break: break-word;
}
.battle-progress {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.8rem;
  margin-top: 12px;
  min-height: 18px;
}

/* หน้าผลการแข่ง */
.rank-num {
  width: 34px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gold);
  flex-shrink: 0;
}
.rank-score {
  font-family: var(--font-mono, monospace);
  font-weight: 800;
  color: var(--gold);
  flex-shrink: 0;
}
.friend-row.me-row {
  border-color: var(--gold);
  background: rgba(255,209,102,0.1);
}

@media (max-width: 420px) {
  .room-code { font-size: 1.8rem; letter-spacing: 0.22em; text-indent: 0.22em; }
  .battle-q-prompt { font-size: 1.5rem; }
}

/* ============================================================
   BOTTOM NAVIGATION (Phase 1A)
   ============================================================ */
#bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  background: rgba(27, 21, 48, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  /* เว้นขอบล่างสำหรับ home indicator ของ iPhone */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#bottom-nav.hidden { display: none; }

.nav-item {
  position: relative;
  flex: 1;
  background: none;
  border: none;
  color: var(--ink-faint, #8a7fb0);
  font-family: var(--font-body);
  cursor: pointer;
  padding: 8px 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.nav-item .nav-icon {
  font-size: 1.35rem;
  line-height: 1;
  filter: grayscale(0.4);
  transition: filter 0.15s ease, transform 0.15s ease;
}
.nav-item .nav-label {
  font-size: 0.68rem;
  font-weight: 600;
}
.nav-item.active {
  color: var(--gold, #ffd166);
}
.nav-item.active .nav-icon {
  filter: grayscale(0);
  transform: translateY(-1px) scale(1.08);
}
.nav-item:active .nav-icon { transform: scale(0.92); }

.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger, #e0552a);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-badge.hidden { display: none; }

/* เว้นที่ด้านล่างให้เนื้อหาไม่โดน nav บัง (เฉพาะตอนมี nav) */
#app-shell:not(.hidden) .screen {
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

/* จอกว้าง (แท็บเล็ต/เดสก์ท็อป): จำกัดความกว้าง nav ให้อยู่กลาง อ่านง่าย */
@media (min-width: 720px) {
  #bottom-nav {
    max-width: 560px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 18px 18px 0 0;
    border-left: 1px solid rgba(255,255,255,0.1);
    border-right: 1px solid rgba(255,255,255,0.1);
  }
}

/* ============================================================
   DASHBOARD (Phase 1A)
   ============================================================ */
.dash-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, rgba(255,209,102,0.12), rgba(224,123,60,0.08));
  border: 1px solid rgba(255,209,102,0.25);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.dash-hero-ring {
  position: relative;
  width: 72px;
  height: 72px;
  flex-shrink: 0;
}
.dash-hero-ring svg { width: 72px; height: 72px; transform: rotate(-90deg); }
.dash-hero-ring .ring-bg {
  fill: none;
  stroke: rgba(255,255,255,0.12);
  stroke-width: 6;
}
.dash-hero-ring .ring-fill {
  fill: none;
  stroke: var(--gold, #ffd166);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}
.dash-hero-level {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.dash-lv-num {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold, #ffd166);
}
.dash-lv-word {
  font-size: 0.52rem;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  margin-top: 1px;
}
.dash-hero-info { flex: 1; min-width: 0; }
.dash-hero-exp {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--white);
  font-size: 1.05rem;
}
.dash-hero-next { font-size: 0.78rem; color: var(--ink-faint); margin-top: 2px; }
.dash-hero-stats {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--parchment);
}

.dash-continue {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, var(--ember, #e07b3c), #c25a28);
  border: none;
  border-radius: var(--radius-md);
  padding: 15px 18px;
  cursor: pointer;
  margin-bottom: 22px;
  box-shadow: 0 4px 14px rgba(224,123,60,0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.dash-continue:active { transform: scale(0.98); }
.dash-continue-label {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.8);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: left;
}
.dash-continue-detail {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  text-align: left;
  margin-top: 2px;
}
.dash-continue-go {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.dash-section-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--parchment);
  margin: 0 0 10px;
}
.dash-progress { margin-bottom: 24px; }
.dash-progress-loading {
  color: var(--ink-faint);
  font-size: 0.85rem;
  text-align: center;
  padding: 16px;
}
.dash-level-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  cursor: pointer;
}
.dash-level-tag {
  width: 34px;
  height: 24px;
  border-radius: 6px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dash-level-bar {
  flex: 1;
  height: 9px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
}
.dash-level-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s ease;
}
.dash-level-count {
  font-size: 0.74rem;
  color: var(--ink-faint);
  min-width: 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   DASHBOARD REVIEW CARD (Phase 2A - SRS)
   ============================================================ */
.dash-review {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #3d7a4d, #2d5c3a);
  border: 1px solid rgba(124,201,143,0.3);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  cursor: pointer;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(61,122,77,0.25);
  transition: transform 0.12s ease;
}
.dash-review.hidden { display: none; }
.dash-review:active { transform: scale(0.98); }
.dash-review-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}
.dash-review-text { flex: 1; text-align: left; }
.dash-review-count {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
}
.dash-review-label {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.85);
  margin-top: 1px;
}
.dash-review-go {
  flex-shrink: 0;
  background: rgba(255,255,255,0.22);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: 999px;
}

/* ============================================================
   MASTERY + MY MISTAKES (Phase 2B)
   ============================================================ */
.dash-mastery { margin-bottom: 20px; }
.dash-mastery-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.dash-mastery-label {
  font-size: 0.8rem;
  color: var(--parchment);
  min-width: 92px;
  flex-shrink: 0;
}
.dash-mastery-bar {
  flex: 1;
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
}
.dash-mastery-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s ease;
}
.dash-mastery-pct {
  font-size: 0.78rem;
  color: var(--ink-faint);
  min-width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dash-mistakes {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #b23a48, #7d2531);
  border: 1px solid rgba(255,150,150,0.25);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  cursor: pointer;
  margin-bottom: 22px;
  box-shadow: 0 4px 14px rgba(178,58,72,0.25);
  transition: transform 0.12s ease;
}
.dash-mistakes.hidden { display: none; }
.dash-mistakes:active { transform: scale(0.98); }
.dash-mistakes-icon { font-size: 1.8rem; flex-shrink: 0; }
.dash-mistakes-text { flex: 1; text-align: left; }
.dash-mistakes-count {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
}
.dash-mistakes-label {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.85);
  margin-top: 1px;
}
.dash-mistakes-go {
  flex-shrink: 0;
  background: rgba(255,255,255,0.22);
  color: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: 999px;
}

/* ============================================================
   WORD DICTIONARY CONTENT (Phase 2C)
   ============================================================ */
.card-ipa {
  font-family: 'Noto Sans', 'Segoe UI', 'Lucida Sans Unicode', sans-serif; /* ฟอนต์ที่รองรับสัญลักษณ์ IPA */
  font-size: 1rem;
  color: var(--ink-soft, #5a5070);
  margin-top: 4px;
  letter-spacing: 0.02em;
}
.card-ipa.hidden { display: none; }

.word-dict {
  margin-top: 14px;
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-left: 3px solid var(--gold, #ffd166);
  border-radius: var(--radius-sm, 10px);
  padding: 12px 14px;
}
.word-dict.hidden { display: none; }
.word-dict-head {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.word-dict-def {
  color: var(--parchment);
  font-size: 0.92rem;
  line-height: 1.5;
}
.word-dict-ex {
  color: var(--ink-faint);
  font-size: 0.86rem;
  font-style: italic;
  margin-top: 6px;
  line-height: 1.5;
}
.word-dict-ex.hidden, .word-dict-syn.hidden { display: none; }
.word-dict-syn {
  color: var(--ink-faint);
  font-size: 0.8rem;
  margin-top: 6px;
}

/* ============================================================
   ADMIN PANEL (Phase 2D)
   ============================================================ */
.dash-admin {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-night-2);
  border: 1px dashed rgba(255,209,102,0.45);
  color: var(--parchment);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.dash-admin.hidden { display: none; }
.dash-admin-badge {
  margin-left: auto;
  font-size: 0.74rem;
  color: #ffb4a2;
  font-weight: 700;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.admin-stat {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm, 10px);
  padding: 10px 8px;
  text-align: center;
}
.admin-stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--gold);
}
.admin-stat span { font-size: 0.68rem; color: var(--ink-faint); }
.admin-stat.warn b { color: #ff8a73; }

.admin-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.admin-filters select,
.admin-filters input,
.admin-modal-card input,
.admin-modal-card textarea {
  background: var(--bg-night-2);
  border: 2px solid rgba(255,255,255,0.1);
  color: var(--parchment);
  border-radius: var(--radius-sm, 10px);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 0.88rem;
}
.admin-filters input { flex: 1; min-width: 140px; }
.admin-filters select:focus,
.admin-filters input:focus,
.admin-modal-card input:focus,
.admin-modal-card textarea:focus { outline: none; border-color: var(--gold); }
.admin-hint { font-size: 0.74rem; color: var(--ink-faint); margin-bottom: 12px; }

.admin-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.admin-row-main { flex: 1; min-width: 0; }
.admin-row-word {
  font-weight: 800;
  color: var(--white);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.admin-tag {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  color: var(--ink-faint);
}
.admin-tag.warn { background: rgba(255,138,115,0.18); color: #ffb4a2; }
.admin-tag.ok { background: rgba(124,201,143,0.18); color: #9fdcae; }
.admin-row-ipa { font-size: 0.82rem; color: var(--ink-faint); margin-top: 3px; }
.admin-row-def { font-size: 0.85rem; color: var(--parchment); margin-top: 4px; line-height: 1.45; }
.admin-row-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }

.admin-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--ink-faint);
}

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 6, 24, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.admin-modal.hidden { display: none; }
.admin-modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-night);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
}
.admin-modal-card input,
.admin-modal-card textarea { width: 100%; box-sizing: border-box; resize: vertical; }
.admin-edit-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 800; color: var(--white); }
.admin-edit-meta { font-size: 0.76rem; color: var(--ink-faint); margin-bottom: 4px; }
.admin-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

@media (max-width: 480px) {
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   PLACEMENT TEST (Phase 3A)
   ============================================================ */
.dash-placement {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, #3b4a8c, #2a3466);
  border: 1px solid rgba(140,160,255,0.3);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  cursor: pointer;
  margin-bottom: 14px;
  text-align: left;
  transition: transform 0.12s ease;
}
.dash-placement:active { transform: scale(0.98); }
.dash-placement-icon { font-size: 1.7rem; flex-shrink: 0; }
.dash-placement-text { flex: 1; min-width: 0; }
.dash-placement-title { font-family: var(--font-display); font-weight: 800; color: #fff; font-size: 1rem; }
.dash-placement-sub { font-size: 0.76rem; color: rgba(255,255,255,0.8); margin-top: 2px; }
.dash-placement-go { color: rgba(255,255,255,0.7); font-size: 1.6rem; flex-shrink: 0; }

.pl-panel { margin-top: 6px; }
.pl-panel.hidden { display: none; }
.pl-title { font-family: var(--font-display); color: var(--white); font-size: 1.4rem; margin: 0 0 8px; }
.pl-text { color: var(--parchment); line-height: 1.6; font-size: 0.92rem; }
.pl-list { color: var(--parchment); font-size: 0.88rem; line-height: 1.8; padding-left: 20px; }
.pl-disclaimer {
  font-size: 0.78rem;
  color: var(--ink-faint);
  background: rgba(255,255,255,0.04);
  border-left: 3px solid rgba(140,160,255,0.6);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 14px 0;
  line-height: 1.55;
}

.pl-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--ink-faint);
  margin-bottom: 6px;
}
.pl-progress { height: 6px; background: rgba(255,255,255,0.1); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.pl-progress-fill { height: 100%; background: #8ca0ff; border-radius: 999px; transition: width 0.3s ease; }
.pl-question-label { font-size: 0.78rem; color: var(--ink-faint); font-weight: 700; margin-bottom: 6px; }
.pl-question {
  background: var(--parchment);
  color: var(--ink);
  border-radius: var(--radius-md);
  padding: 18px;
  font-size: 1.05rem;
  line-height: 1.55;
  margin-bottom: 14px;
}
.pl-nav { display: flex; justify-content: space-between; margin-top: 14px; }

.pl-result-label {
  text-align: center;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  font-weight: 700;
  margin-top: 8px;
}
.pl-result-overall {
  text-align: center;
  font-family: var(--font-display);
  font-size: 3.4rem;
  font-weight: 800;
  color: #8ca0ff;
  line-height: 1.1;
  margin: 4px 0 14px;
}
.pl-result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pl-result-item {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm, 10px);
  padding: 10px;
  text-align: center;
}
.pl-result-item span { display: block; font-size: 0.72rem; color: var(--ink-faint); }
.pl-result-item b { font-family: var(--font-display); font-size: 1.2rem; color: var(--white); }
.pl-recommend { color: var(--parchment); text-align: center; margin: 14px 0 0; font-size: 0.92rem; line-height: 1.5; }

.pl-review-row {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.07);
  border-left: 3px solid #7cc98f;
  border-radius: 8px;
  padding: 10px 12px;
}
.pl-review-row.bad { border-left-color: #ff8a73; }
.pl-review-q { color: var(--parchment); font-size: 0.86rem; line-height: 1.5; }
.pl-review-a { color: var(--ink-faint); font-size: 0.8rem; margin-top: 4px; }

/* ============================================================
   LEARNING PATH (Phase 3B)
   ============================================================ */
.path-head { margin: 6px 0 16px; }
.path-title { font-family: var(--font-display); color: var(--white); font-size: 1.45rem; margin: 0; }
.path-sub { color: var(--ink-faint); font-size: 0.8rem; margin: 4px 0 0; line-height: 1.5; }

.path-level {
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  overflow: hidden;
}
.path-level.locked { opacity: 0.7; }
.path-level-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: none;
  border: none;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font-family: var(--font-body);
}
.path-level-tag {
  width: 42px; height: 42px;
  border-radius: 12px;
  color: #fff;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.path-level-name { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.path-level-name b { color: var(--white); font-family: var(--font-display); font-size: 1rem; }
.path-level-name small { color: var(--ink-faint); font-size: 0.76rem; }
.path-level-chev { color: var(--ink-faint); font-size: 1rem; }

.path-units { display: flex; flex-direction: column; gap: 6px; padding: 0 12px 12px; }
.path-unit {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-night-3, rgba(255,255,255,0.04));
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font-family: var(--font-body);
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.path-unit:not(:disabled):active { transform: scale(0.98); }
.path-unit.available { border-color: rgba(255,209,102,0.45); }
.path-unit.completed { border-color: rgba(124,201,143,0.45); }
.path-unit:disabled { cursor: not-allowed; opacity: 0.5; }
.path-unit-icon { font-size: 1.5rem; flex-shrink: 0; width: 32px; text-align: center; }
.path-unit-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.path-unit-title { color: var(--white); font-weight: 700; font-size: 0.9rem; }
.path-unit-meta { color: var(--ink-faint); font-size: 0.72rem; }
.path-unit-bar { height: 5px; background: rgba(255,255,255,0.1); border-radius: 999px; overflow: hidden; }
.path-unit-bar span { display: block; height: 100%; background: var(--gold, #ffd166); border-radius: 999px; }
.path-unit.completed .path-unit-bar span { background: #7cc98f; }
.path-unit-badge { font-size: 0.74rem; font-weight: 700; color: var(--ink-faint); flex-shrink: 0; }
.path-unit.completed .path-unit-badge { color: #9fdcae; }

/* ปุ่มบนการ์ดสามารถใช้คีย์บอร์ดได้ — แสดงกรอบโฟกัสชัดเจน */
.path-unit:focus-visible, .path-level-head:focus-visible {
  outline: 2px solid var(--gold, #ffd166);
  outline-offset: 2px;
}

/* ============================================================
   UNIT TEST + BOSS (Phase 3C)
   ============================================================ */
.path-unit-row { display: flex; gap: 6px; align-items: stretch; }
.path-unit-row .path-unit { flex: 1; min-width: 0; }
.path-test-btn {
  flex-shrink: 0;
  width: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--bg-night-3, rgba(255,255,255,0.04));
  border: 1px solid rgba(140,160,255,0.35);
  border-radius: 12px;
  color: var(--parchment);
  font-size: 1.1rem;
  cursor: pointer;
  font-family: var(--font-body);
}
.path-test-btn span { font-size: 0.66rem; font-weight: 700; color: #b9c4ff; }
.path-test-btn:active { transform: scale(0.96); }
.path-test-btn:focus-visible { outline: 2px solid #8ca0ff; outline-offset: 2px; }

.path-boss {
  margin: 4px 12px 12px;
  padding: 14px 16px;
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 0.86rem;
  color: var(--parchment);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.path-boss.available {
  width: calc(100% - 24px);
  border: 2px solid #f0b429;
  background: linear-gradient(135deg, rgba(240,180,41,0.22), rgba(193,74,74,0.18));
  cursor: pointer;
  text-align: left;
  font-size: 1.2rem;
}
.path-boss.available b { font-size: 0.98rem; color: #ffe08a; }
.path-boss.available small { width: 100%; font-size: 0.74rem; color: var(--ink-faint); }
.path-boss.cleared { background: rgba(124,201,143,0.12); border: 1px solid rgba(124,201,143,0.35); }
.path-boss.locked { background: rgba(255,255,255,0.03); border: 1px dashed rgba(255,255,255,0.12); color: var(--ink-faint); font-size: 0.78rem; }

/* ============================================================
   LISTENING (Phase 4A)
   ============================================================ */
.speak-btn {
  display: block;
  margin: 8px auto 0;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.65);
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.speak-btn.hidden { display: none; }
.speak-btn:active { transform: scale(0.92); }
.speak-btn:focus-visible { outline: 3px solid var(--gold, #ffd166); outline-offset: 2px; }
#word-dict-ex-speak { margin-top: 8px; }
#word-dict-ex-speak.hidden { display: none; }

.path-mode {
  display: inline-flex;
  margin-top: 12px;
  background: var(--bg-night-2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 999px;
  padding: 3px;
}
.path-mode-btn {
  border: none;
  background: none;
  color: var(--ink-faint);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.path-mode-btn.active { background: var(--gold, #ffd166); color: #2b2440; }
.path-mode-btn:focus-visible { outline: 2px solid var(--gold, #ffd166); outline-offset: 2px; }
.path-mode-note { margin-top: 8px; font-size: 0.78rem; color: #7fd8d8; }
.path-mode-note.hidden { display: none; }
.admin-row-flag { font-size: 0.78rem; color: #ffb4a2; margin-top: 4px; line-height: 1.45; }
.admin-row-src { font-size: 0.72rem; color: var(--ink-faint); margin-top: 3px; }
.admin-row-src code { font-size: 0.72rem; }

/* ============================================================
   VOCABULARY BROWSER + CARD (V5) — สไตล์พื้นฐาน (V6 จะปรับทั้งระบบ)
   ============================================================ */
/* ซ่อนจากตา แต่ screen reader ยังอ่านได้ (ใช้กับ label ของช่องฟอร์ม) */
.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; }
.vb-open { margin-top: 10px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.18); background: var(--bg-night-2); color: var(--parchment); font: inherit; font-weight: 700; cursor: pointer; }
.vb-search { width: 100%; box-sizing: border-box; min-height: 48px; margin: 12px 0; padding: 0 16px; border-radius: 14px; border: 2px solid rgba(255,255,255,0.12); background: var(--bg-night-2); color: var(--white); font: inherit; font-size: 1rem; }
.vb-search:focus { outline: none; border-color: var(--gold); }
.vb-levels { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.vb-chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 2px solid var(--chip, rgba(255,255,255,0.25)); background: transparent; color: var(--parchment); font: inherit; font-weight: 700; cursor: pointer; }
.vb-chip span { opacity: 0.7; font-weight: 400; margin-left: 4px; }
.vb-chip.active { background: var(--chip, var(--gold)); color: #fff; }
.vb-chip:focus-visible, .vb-row:focus-visible, .vc-rate-btn:focus-visible, .vc-other:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.vb-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.vb-filters select { flex: 1 1 140px; min-height: 44px; padding: 0 10px; border-radius: 10px; border: 2px solid rgba(255,255,255,0.12); background: var(--bg-night-2); color: var(--parchment); font: inherit; }
.vb-count { font-size: 0.85rem; color: var(--ink-faint); margin: 6px 0 10px; }
.vb-list { display: flex; flex-direction: column; gap: 8px; }
.vb-row { display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left; padding: 12px 14px; border-radius: 14px; border: 1px solid rgba(255,255,255,0.08); background: var(--bg-night-2); color: inherit; font: inherit; cursor: pointer; }
.vb-row-main { display: flex; flex-direction: column; gap: 2px; }
.vb-row-word { font-size: 1.15rem; font-weight: 800; color: var(--white); }
.vb-row-word i { font-weight: 400; font-size: 0.9rem; color: var(--ink-faint); }
.vb-row-thai { color: var(--parchment); line-height: 1.6; }
.vb-pending { font-size: 0.7rem; padding: 1px 6px; border-radius: 999px; background: rgba(255,170,90,0.2); color: #ffc58a; }
.vb-row-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.8rem; color: var(--ink-faint); }
.vb-badge { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--chip, #888); color: #fff; font-weight: 800; font-size: 0.78rem; }
.vc-card { margin-top: 12px; padding: 22px 18px; border-radius: 20px; background: var(--parchment); color: var(--ink); display: flex; flex-direction: column; gap: 16px; }
.vc-word { font-family: var(--font-display); font-size: 2.2rem; margin: 0; line-height: 1.15; word-break: break-word; }
.vc-label { color: #6b6080; }
.vc-badges { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.vc-pos { font-size: 0.9rem; color: #5a5070; }
.vc-sound { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.vc-ipa { font-family: 'Noto Sans', 'Segoe UI', sans-serif; font-size: 1.1rem; color: #4a4060; }
.vc-speak { margin: 0; }
.vc-section-label { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.05em; color: #7a6f8f; margin-bottom: 4px; }
.vc-thai-text { font-size: 1.4rem; font-weight: 700; line-height: 1.6; }
.vc-note { font-size: 0.82rem; color: #7a5a3a; line-height: 1.5; }
.vc-more-btn { align-self: flex-start; color: #4b3fb0; min-height: 44px; }
.vc-more.hidden { display: none; }
.vc-more section { margin-bottom: 10px; }
.vc-def, .vc-ex { margin: 0; line-height: 1.6; }
.vc-ex { font-style: italic; }
.vc-others { display: flex; flex-direction: column; gap: 6px; }
.vc-other { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; text-align: left; min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.12); background: rgba(255,255,255,0.6); color: inherit; font: inherit; cursor: pointer; }
.vc-other-thai { color: #4a4060; }
.vc-rate-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.vc-rate-btn { min-height: 48px; border-radius: 12px; border: 2px solid rgba(0,0,0,0.15); background: #fff; color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.vc-rate-result { font-size: 0.85rem; color: #2f7a4a; margin-top: 4px; }
.vc-source { font-size: 0.75rem; color: #7a6f8f; line-height: 1.6; border-top: 1px solid rgba(0,0,0,0.08); padding-top: 10px; }
.vc-source code { font-size: 0.75rem; }
