/* 亮色主題（2026-07-11 station-sign-ui spec：還原參考網站淺色調性）
   圖層對比階序：背景底圖最淡 < 未來路段 < 已完成/目前路段最醒目 */
:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --panel-light: #f1f5f9;
  --border: #dbe3ec;
  --accent: #0284c7;
  --accent-warm: #f97316;
  --text: #1e293b;
  --text-dim: #64748b;
  --correct: #16a34a;
  --incorrect: #dc2626;
  --future: #cbd5e1;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1 { font-size: 1.5rem; margin: 4px 0 2px; }
.sub { font-size: .85rem; color: var(--text-dim); margin-bottom: 18px; text-align: center; }
.hidden { display: none !important; }

#loading-screen { color: var(--text-dim); padding: 40px; }

#setup-screen, #end-screen {
  width: min(920px, 96vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 4px 16px rgba(30, 41, 59, .06);
}

/* ── #game-screen 全螢幕滿版（openspec fullscreen-map-and-label-collision，2026-07-12）──
   只有「進入遊戲後」的畫面全螢幕化：setup（#network-canvas）與結算（#replay-canvas）
   版面本次不動，維持上面 #setup-screen/#end-screen 共用的卡片樣式。 */
#game-screen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: #f6f8fa;
  z-index: 5;
  overflow: hidden;
}

body.mobile-game-active {
  overflow: hidden;
  overscroll-behavior: none;
}

body.mobile-game-active #game-screen {
  touch-action: none;
  overscroll-behavior: none;
}

#info-bar,
#question-card,
#recenter-btn,
button {
  touch-action: manipulation;
}

.field { margin-bottom: 16px; position: relative; }
.field label { display: block; font-size: .8rem; color: var(--text-dim); margin-bottom: 6px; }

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  font-size: .95rem;
  border-radius: 8px;
  border: 1px solid var(--panel-light);
  background: var(--panel-light);
  color: var(--text);
}
input[type="text"]:focus { outline: 2px solid var(--accent); }

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel-light);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 5;
  box-shadow: 0 8px 20px rgba(0,0,0,.4);
}
.suggestion-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: .9rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.suggestion-item:hover, .suggestion-item.highlighted { background: var(--accent); color: #fff; }
.suggestion-item .s-en { color: var(--text-dim); font-size: .8rem; }
.suggestion-item:hover .s-en, .suggestion-item.highlighted .s-en { color: #e0f2fe; }

.mode-toggle { display: flex; gap: 8px; }
.mode-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--panel-light);
  background: var(--panel-light);
  color: var(--text-dim);
  cursor: pointer;
  font-size: .85rem;
}
.mode-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.mode-btn.small { margin-left: auto; padding: 5px 10px; font-size: .75rem; }

.error {
  background: rgba(220,38,38,.08);
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: .85rem;
  margin-bottom: 14px;
}

.primary-btn {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }

#quick-practice { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--panel-light); }
#quick-practice-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-practice-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.quick-practice-btn:hover { filter: brightness(1.12); }

/* #info-bar：遊戲進行中固定貼在全螢幕地圖左上方，維持既有「實體卡片」白底/陰影觀感
   （不做 backdrop-filter 透明化，station-sign-ui spec「維持實體卡片」新增 Requirement）。 */
#info-bar {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: .85rem;
  color: var(--text-dim);
  margin-bottom: 0;
  max-width: calc(100vw - 80px);
  background: var(--panel);
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(30, 41, 59, .12);
}
#info-progress, #info-combo { color: var(--text); font-weight: 600; }

canvas {
  width: 100%;
  height: auto;
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: block;
}

#network-canvas { margin-bottom: 18px; }

/* #map-canvas：遊戲進行畫面全螢幕滿版，鋪滿可視區域當背景層（在 #info-bar/#question-card
   之下）；內部繪圖解析度由 script.js resizeGameCanvas() 動態讀 window.innerWidth/innerHeight。 */
#map-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  border: none;
  border-radius: 0;
  z-index: 1;
  cursor: grab;
}
#map-canvas.dragging { cursor: grabbing; }

/* 「回到目前進度」定位按鈕（manual-camera-pan-zoom，2026-07-13）：比照 Google Maps
   右下角「顯示你的位置」圓形圖示按鈕，只在鏡頭處於 manual 模式時顯示（見 .hidden 切換）。 */
#recenter-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 16;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: #101418;
  font-size: 1.4rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(30, 41, 59, .22);
}
#recenter-btn:hover { filter: brightness(1.08); }

/* ── 站名告示牌題目卡（station-sign-ui spec；原創重繪，參照北捷月台告示牌構圖） ── */

/* #question-card：Eason 拍板「下方打字站牌訊息一樣維持實體」——固定貼在全螢幕地圖下方，
   但不透明、不模糊（不加 backdrop-filter），維持既有白底＋黑框的告示牌實體卡片觀感。 */
#question-card {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 15;
  width: min(720px, 92vw);
  margin-top: 0;
  text-align: center;
  background: #fff;
  border: 3px solid #101418;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 6px 18px rgba(16, 20, 24, .18);
}
#sign-operator {
  position: absolute;
  top: 12px;
  left: 14px;
  text-align: left;
  font-size: .85rem;
  font-weight: 800;
  color: #101418;
  line-height: 1.2;
}
#sign-operator span {
  display: block;
  font-size: .55rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: #64748b;
}
#sign-county {
  font-size: .75rem;
  letter-spacing: 4px;
  color: var(--text-dim);
  padding-top: 10px;
  min-height: 1em;
}
#question-station {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 12px;
  color: #101418;
  margin: 2px 0 0;
  text-indent: 12px; /* 抵銷最後一字的 letter-spacing，維持視覺置中 */
}
#question-target {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.5rem;
  letter-spacing: 2px;
  padding: 2px 8px 12px;
}
#question-target .char { padding: 0 1px; border-bottom: 2px solid transparent; }
#question-target .char.pending { color: #9aa8b6; }
#question-target .char.correct { color: var(--correct); border-bottom-color: var(--correct); }
#question-target .char.incorrect { color: var(--incorrect); border-bottom-color: var(--incorrect); }
#question-target .char.cursor { background: rgba(2,132,199,.18); border-radius: 3px; }

#sign-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  min-height: 52px;
  color: #fff;
  transition: background-color .4s ease; /* 跨線轉乘變色的平滑過渡 */
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.sign-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sign-side .arrow { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.sign-texts { text-align: left; }
#sign-next .sign-texts { text-align: right; }
.sign-name { display: block; font-size: 1.05rem; font-weight: 700; white-space: nowrap; }
.sign-sub { display: block; font-size: .68rem; letter-spacing: 1px; text-transform: uppercase; opacity: .9; white-space: nowrap; }

.native-type-input {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: .01;
}

#mobile-keyboard {
  display: none !important;
}
.keyboard-row {
  display: grid;
  gap: 6px;
}
.keyboard-key {
  min-height: 44px;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(30, 41, 59, .08);
  touch-action: manipulation;
}
.keyboard-key:hover { filter: brightness(1.04); }
.keyboard-key:active { transform: translateY(1px); }
.keyboard-key.backspace { background: #fff7ed; }
.keyboard-key.space { letter-spacing: 1px; }

#stats { display: flex; gap: 24px; justify-content: center; margin: 12px 0 18px; }
.stat { text-align: center; }
.stat-label { display: block; font-size: .8rem; color: var(--text-dim); }
.stat-value { display: block; font-size: 1.6rem; font-weight: 800; color: var(--accent); }

#end-screen h2 { text-align: center; margin-top: 0; }
#restart-btn { margin-top: 16px; }

#data-credits {
  margin-top: 24px;
  font-size: 11px;
  color: #4b5d70;
}
#data-credits a { color: #5b7a99; }

/* ── 音效靜音切換（sound-feedback spec；比照 game-2048 圖示按鈕慣例，全域固定位置） ── */
#sound-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 20;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(30, 41, 59, .12);
}
#sound-toggle:hover { filter: brightness(1.05); }

/* 介面語言切換：跟 #sound-toggle 並排在右上角，往左挪一顆按鈕的寬度+間距
   （interface-language-toggle design.md 決策 #2）。 */
#lang-toggle {
  position: fixed;
  top: 14px;
  right: 62px;
  z-index: 20;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(30, 41, 59, .12);
}
#lang-toggle:hover { filter: brightness(1.05); }

/* ── 次要按鈕（歷史紀錄入口，比照 primary-btn 但降低視覺權重） ── */
.secondary-btn {
  width: 100%;
  padding: 10px;
  margin-top: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
.secondary-btn:hover { filter: brightness(0.97); }

/* ── 歷史紀錄檢視面板（game-history spec；比照 game-2048 history-modal 慣例） ── */
#history-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
#history-modal.hidden { display: none; }

#history-panel {
  width: min(560px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .3);
}
#history-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
#history-header h2 { margin: 0; font-size: 1.1rem; }
#history-close {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 8px;
}

#history-list { display: flex; flex-direction: column; gap: 8px; }
.history-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto auto auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-light);
  font-size: .8rem;
}
.history-date { color: var(--text-dim); }
.history-route { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-mode, .history-accuracy, .history-wpm, .history-score, .history-rank { white-space: nowrap; color: var(--text-dim); }
.history-rank { font-weight: 600; }
#history-empty { color: var(--text-dim); font-size: .85rem; padding: 12px 0; text-align: center; }

/* ── 暫停疊層視窗（game-pause spec；比照上方 #history-modal 疊層結構/z-index） ── */
#pause-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}
#pause-modal.hidden { display: none; }

#pause-panel {
  width: min(320px, 92vw);
  background: var(--panel);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, .3);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
#pause-title { margin: 0 0 6px; font-size: 1.2rem; }
#pause-panel button { width: 100%; }

/* ── 計時賽模式（circuit-timed-mode spec）／隨機開局／稱號等級（circuit-random-and-rank-modes） ──
   .secondary-btn 沿用上方「次要按鈕」既有定義（歷史紀錄入口與此處的隨機開局按鈕共用同一視覺語言，
   不重複定義同一個 class，避免後定義覆蓋前定義造成不可預期的按鈕外觀）。 */
#timed-mode-panel { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--panel-light); }
#timed-line-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.timed-line-btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: 2px solid transparent;
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.timed-line-btn.active { border-color: #101418; }
#timed-mode-panel .mode-toggle { margin-bottom: 10px; }

#info-timer {
  font-weight: 800;
  color: var(--accent-warm);
}
#info-timer.time-low { color: var(--incorrect); }

#end-reason {
  text-align: center;
  font-size: .9rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}
#end-reason.reason-time-up { color: var(--incorrect); }
#end-reason.reason-completed { color: var(--correct); }

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  h1 {
    font-size: 1.25rem;
    text-align: center;
  }

  .sub {
    margin-bottom: 14px;
  }

  #setup-screen,
  #end-screen {
    width: min(100%, 720px);
    padding: 14px;
  }

  #game-screen {
    --mobile-visual-height: 100dvh;
    --mobile-keyboard-inset: 0px;
    --mobile-visual-offset-top: 0px;
    position: fixed;
    inset-inline: 0;
    top: var(--mobile-visual-offset-top);
    width: 100vw;
    height: var(--mobile-visual-height);
    min-height: 0;
    overflow: hidden;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    margin: 0;
    background: #f6f8fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  #game-screen.keyboard-open {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #info-bar {
    position: static;
    width: 100%;
    max-width: none;
    margin-bottom: 0;
    gap: 10px;
    padding: 10px 12px;
  }

  #info-bar .mode-btn.small {
    margin-left: 0;
  }

  #map-canvas {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    border-radius: 12px;
    touch-action: none;
  }

  #question-card {
    position: relative;
    width: 100%;
    transform: none;
    left: auto;
    bottom: auto;
    margin-top: 0;
  }

  .native-type-input.hidden {
    display: none;
  }

  #question-station {
    font-size: 1.9rem;
    letter-spacing: 6px;
    text-indent: 6px;
  }

  #question-target {
    font-size: 1.15rem;
    padding-bottom: 10px;
  }

  #sign-operator {
    top: 10px;
    left: 12px;
    font-size: .75rem;
  }

  #sign-operator span {
    font-size: .5rem;
  }

  #sign-county {
    padding-top: 8px;
    letter-spacing: 3px;
  }

  #sign-band {
    gap: 8px;
    padding: 8px 12px;
    min-height: 48px;
  }

  .sign-side .arrow {
    font-size: 1.35rem;
  }

  .sign-name {
    font-size: .9rem;
  }

  .sign-sub {
    font-size: .58rem;
  }

  .keyboard-row {
    gap: 5px;
  }

  .keyboard-key {
    min-height: 42px;
    font-size: .82rem;
    padding: 8px 4px;
    border-radius: 9px;
  }
}

/* The native input is an invisible keyboard bridge, not a second gameplay UI. */
.native-input-bridge {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 1px !important;
  min-width: 1px !important;
  height: 1px !important;
  min-height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  opacity: 0 !important;
  background: transparent !important;
  color: transparent !important;
  caret-color: transparent !important;
  box-shadow: none !important;
  outline: none !important;
  pointer-events: none !important;
  z-index: 0;
}
