/* =========================================================
   THAI METRO TYPING — design tokens
   Palette: underground control-room navy + Bangkok gold-hour accent
   Type: Kanit (display) / Noto Sans Thai + Inter (UI) / IBM Plex Mono (data)
   ========================================================= */

:root {
  --bg-deep: #0a0f1c;
  --bg-panel: #121a2b;
  --bg-raised: #1a2438;
  --bg-raised-2: #23304a;
  --hairline: #2b3752;

  --text-primary: #f2efe6;
  --text-secondary: #9fb0ce;
  --text-muted: #5c6a8a;

  --accent-gold: #f2b807;
  --accent-gold-dim: #7a5e12;
  --accent-good: #57d38c;
  --accent-bad: #f2564a;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --font-display: "Kanit", "Noto Sans Thai", sans-serif;
  --font-body-th: "Noto Sans Thai", "Inter", sans-serif;
  --font-body-en: "Inter", "Noto Sans Thai", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-body-en);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 12% -10%, rgba(242, 184, 7, 0.08), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(87, 211, 140, 0.06), transparent 45%);
  min-height: 100vh;
}

body[dir-lang="th"] { font-family: var(--font-body-th); }

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

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: inherit; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.sub {
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* ---------------- App shell ---------------- */

#app { min-height: 100vh; display: flex; flex-direction: column; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(10, 15, 28, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
  padding: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent-gold), #a97e05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--bg-deep);
  font-size: 15px;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.brand-th { font-family: var(--font-display); font-size: 1rem; font-weight: 600; }
.brand-en { font-size: 0.62rem; letter-spacing: 0.14em; color: var(--text-muted); text-transform: uppercase; }

.lang-switch {
  display: flex;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  background: var(--bg-panel);
  flex-shrink: 0;
}

.lang-switch button {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}

.lang-switch button[aria-pressed="true"] {
  background: var(--accent-gold);
  color: var(--bg-deep);
}

main { flex: 1; display: flex; flex-direction: column; }

.screen { animation: fade-up 0.35s ease both; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Home screen ---------------- */

.hero {
  position: relative;
  padding: 56px 20px 40px;
  text-align: center;
  overflow: hidden;
  border-bottom: 1px solid var(--hairline);
}

.hero-strip {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.hero-strip span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  opacity: 0.85;
}

.hero h1 {
  font-size: clamp(2.1rem, 6vw, 3.6rem);
  line-height: 1.05;
}

.hero .hero-en {
  display: block;
  font-size: 0.9rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-top: 14px;
  font-family: var(--font-mono);
}

.hero p.tagline {
  max-width: 520px;
  margin: 18px auto 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.board {
  display: inline-flex;
  gap: 10px;
  margin-top: 30px;
  padding: 10px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-gold);
  letter-spacing: 0.08em;
}

.board .divider { color: var(--text-muted); }

.section {
  padding: 36px 20px;
  max-width: 1040px;
  margin: 0 auto;
  width: 100%;
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
}

.section-title .num {
  font-family: var(--font-mono);
  color: var(--accent-gold);
  font-size: 0.8rem;
}

.section-title h2 { font-size: 1.3rem; }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.mode-card {
  text-align: left;
  background: var(--bg-panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 22px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  position: relative;
  overflow: hidden;
}

.mode-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 40%, rgba(242, 184, 7, 0.08) 100%);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.mode-card:hover, .mode-card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent-gold-dim);
}

.mode-card:hover::after { opacity: 1; }

.mode-card .icon-dot {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raised);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent-gold);
  border: 1px solid var(--hairline);
}

.mode-card h3 { font-size: 1.05rem; }
.mode-card .card-en { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.1em; color: var(--text-muted); text-transform: uppercase; }
.mode-card p { margin: 0; color: var(--text-secondary); font-size: 0.85rem; line-height: 1.5; }

.stat-strip {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  padding: 18px 20px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  background: var(--bg-panel);
  justify-content: center;
}

.stat-strip .stat { text-align: center; }
.stat-strip .stat b { display: block; font-family: var(--font-mono); font-size: 1.4rem; color: var(--accent-gold); }
.stat-strip .stat span { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------------- Select screen ---------------- */

.select-header {
  padding: 26px 20px 6px;
  max-width: 1040px;
  margin: 0 auto;
  width: 100%;
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  padding: 6px 0;
  margin-bottom: 10px;
}

.crumb:hover { color: var(--accent-gold); }

.step-list {
  max-width: 1040px;
  margin: 0 auto;
  width: 100%;
  padding: 10px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.step-block .step-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.step-block .step-label .step-index {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-gold);
  color: var(--bg-deep);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 10px; }

.chip {
  border: 1px solid var(--hairline);
  background: var(--bg-panel);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s;
}

.chip .chip-en { color: var(--text-muted); font-size: 0.68rem; font-family: var(--font-mono); }

.chip[aria-pressed="true"] {
  border-color: var(--accent-gold);
  background: var(--bg-raised);
  box-shadow: 0 0 0 1px var(--accent-gold) inset;
}

.chip:hover { border-color: var(--accent-gold-dim); }

.system-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.system-card {
  border: 1px solid var(--hairline);
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  padding: 14px;
  color: var(--text-primary);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.system-card[aria-pressed="true"] {
  border-color: var(--accent-gold);
  background: var(--bg-raised);
}

.system-card .sys-th { font-weight: 600; font-size: 0.95rem; }
.system-card .sys-en { font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.line-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.line-card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  padding: 0;
  overflow: hidden;
  text-align: left;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.line-card:hover { transform: translateY(-2px); border-color: var(--accent-gold-dim); }

.line-card[aria-pressed="true"] { border-color: var(--accent-gold); }

.line-card .badge-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.line-badge {
  width: 34px; height: 34px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.line-card .line-names { display: flex; flex-direction: column; line-height: 1.2; }
.line-card .line-th { font-weight: 600; font-size: 0.92rem; }
.line-card .line-en { font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); }

.line-card .station-count {
  padding: 8px 14px 12px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--hairline);
}

.start-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: center;
  padding: 16px 20px 26px;
  background: linear-gradient(to top, var(--bg-deep) 60%, transparent);
}

.btn-primary {
  background: var(--accent-gold);
  color: var(--bg-deep);
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 14px 34px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn-primary:disabled {
  background: var(--bg-raised);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-primary:not(:disabled):hover { transform: translateY(-2px); filter: brightness(1.05); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 0.88rem;
}

.btn-ghost:hover { border-color: var(--accent-gold-dim); color: var(--text-primary); }

/* ---------------- Game screen ---------------- */

.game-shell {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 18px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.route-panel {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  padding: 18px 18px 14px;
  box-shadow: var(--shadow-card);
}

.route-panel .route-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
  flex-wrap: wrap;
}

.route-head .line-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.route-head .dot { width: 10px; height: 10px; border-radius: 50%; }

.route-strip {
  position: relative;
  display: flex;
  align-items: center;
  overflow-x: auto;
  padding: 20px 6px 8px;
  scrollbar-width: thin;
}

.route-strip::before {
  content: "";
  position: absolute;
  left: 16px; right: 16px;
  top: 32px;
  height: 3px;
  background: var(--hairline);
  border-radius: 3px;
}

.route-stop {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.route-stop .node {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--bg-raised-2);
  border: 2px solid var(--hairline);
  z-index: 1;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.route-stop.passed .node { background: var(--accent-gold); border-color: var(--accent-gold); }
.route-stop.current .node { transform: scale(1.35); border-color: var(--accent-gold); }
.route-stop label { font-size: 0.55rem; color: var(--text-muted); text-align: center; max-width: 54px; }
.route-stop.passed label, .route-stop.current label { color: var(--text-secondary); }

.train-icon {
  position: absolute;
  top: 22px;
  transform: translateX(-50%);
  font-size: 1.1rem;
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

.hud {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.hud .hud-item {
  background: var(--bg-panel);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  text-align: center;
  min-width: 86px;
}

.hud .hud-item b { display: block; font-family: var(--font-mono); font-size: 1.25rem; color: var(--accent-gold); }
.hud .hud-item span { font-size: 0.62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.challenge-card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  padding: 36px 26px;
  text-align: center;
  box-shadow: var(--shadow-card);
  position: relative;
}

.challenge-lang-tag {
  position: absolute;
  top: 18px; left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-gold-dim);
  color: var(--accent-gold);
}

.target-word {
  margin-top: 26px;
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 6vw, 3rem);
  min-height: 1.3em;
}

.target-word .char { transition: color 0.1s; }
.target-word .char.correct { color: var(--accent-good); }
.target-word .char.wrong { color: var(--accent-bad); text-decoration: underline wavy var(--accent-bad); }
.target-word .char.pending { color: var(--text-muted); }

.target-secondary {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.type-input {
  margin-top: 24px;
  width: 100%;
  max-width: 420px;
  background: var(--bg-raised);
  border: 1px solid var(--hairline);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 1.1rem;
  text-align: center;
  font-family: var(--font-body-en);
}

.type-input.state-wrong { border-color: var(--accent-bad); }
.type-input.state-good { border-color: var(--accent-good); }

.game-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.result-card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  padding: 32px 26px;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.result-card .result-score {
  font-family: var(--font-mono);
  font-size: 3rem;
  color: var(--accent-gold);
  margin: 14px 0;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 22px 0;
}

.result-grid .cell {
  background: var(--bg-raised);
  border-radius: var(--radius-md);
  padding: 12px;
}

.result-grid .cell b { display: block; font-family: var(--font-mono); font-size: 1.2rem; color: var(--text-primary); }
.result-grid .cell span { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }

footer.site-footer {
  padding: 22px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.72rem;
  border-top: 1px solid var(--hairline);
}

@media (max-width: 640px) {
  .result-grid { grid-template-columns: 1fr 1fr; }
  .hero { padding: 44px 16px 30px; }
  .section { padding: 26px 16px; }
}
