/* ============================================================
   注意力 × 時間 × 記憶 —— 實驗 App 樣式
   style.css
   ------------------------------------------------------------
   設計方向：「安靜的實驗室」。
   暖紙色背景、深青綠主色、大而清晰的倒數計時器，
   避免過度裝飾干擾受試者。所有顏色都定義在下方「設計變數」。
   ============================================================ */

/* ---------- 一、設計變數（改這裡即可改變整體配色） ---------- */
:root {
  /* 背景與表面 */
  --bg: #f4f1ea;          /* 頁面暖紙色背景 */
  --bg-soft: #ebe6db;     /* 較深的暖色背景 */
  --surface: #ffffff;     /* 卡片表面 */
  --border: #e0dbd0;      /* 一般邊框 */
  --border-strong: #cdc6b8;

  /* 文字 */
  --ink: #24262c;         /* 主要文字（深墨色） */
  --ink-soft: #4b4e57;    /* 次要文字 */
  --muted: #7c8088;       /* 輔助說明文字 */

  /* 主色（深青綠） */
  --accent: #0f6b5f;
  --accent-strong: #0b554c;
  --accent-soft: #e2f0ec;
  --accent-white: #ffffff;

  /* 遊戲符號：○ 綠、× 紅 */
  --o: #1e8e4e;
  --o-soft: #e3f3ea;
  --x: #c2382b;
  --x-soft: #fbe9e7;

  /* 警示（倒數最後幾秒） */
  --warn: #c2382b;

  /* 陰影 */
  --shadow-sm: 0 1px 2px rgba(24, 32, 28, 0.06), 0 4px 14px rgba(24, 32, 28, 0.05);
  --shadow-md: 0 10px 30px -12px rgba(11, 85, 76, 0.25);

  /* 圓角與字型 */
  --radius: 14px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

/* ---------- 二、基本重置 ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

input,
select,
textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

/* ---------- 三、開發測試模式橫幅 ---------- */
#dev-badge {
  background: #fff3cd;
  color: #6d5a00;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  border-bottom: 1px solid #f0dfa0;
}

/* ---------- 四、頁首 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(244, 241, 234, 0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-title {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1px;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-badge {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 4px 12px;
}

/* ---------- 五、按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  user-select: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-white);
}

.btn-primary:hover {
  background: var(--accent-strong);
  box-shadow: var(--shadow-md);
}

.btn-outline {
  background: transparent;
  color: var(--accent-strong);
  border-color: var(--accent);
}

.btn-outline:hover {
  background: var(--accent-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn-danger-soft {
  background: transparent;
  color: var(--x);
  border-color: #e7b8b2;
}

.btn-danger-soft:hover {
  background: var(--x-soft);
}

.btn-lg {
  width: 100%;
  padding: 14px 20px;
  font-size: 17px;
}

/* ---------- 六、畫面切換 ---------- */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

#screens {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---------- 七、首頁（設定 + 歷史） ---------- */
.start-wrap {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 760px;
  margin: 0 auto;
}

.start-card,
.records-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px;
}

.start-title {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 4px;
}

.start-intro {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 22px;
}

.field {
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fdfcf9;
  padding: 10px 12px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%230f6b5f' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

/* 模式選擇（兩張可選卡片） */
.mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-option {
  position: relative;
  display: block;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-card {
  display: block;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: #fdfcf9;
  transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  cursor: pointer;
}

.mode-option input:checked + .mode-card {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--shadow-sm);
}

.mode-name {
  display: block;
  font-weight: 900;
  font-size: 16px;
  color: var(--ink);
}

.mode-desc {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.mode-option input:checked + .mode-card .mode-name {
  color: var(--accent-strong);
}

.start-error {
  background: var(--x-soft);
  color: var(--x);
  border: 1px solid #e7b8b2;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* 歷史紀錄 */
.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.records-title {
  font-size: 18px;
  font-weight: 900;
}

.records-actions {
  display: flex;
  gap: 8px;
}

.table-scroll {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.history-table th,
.history-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.history-table th {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.empty-hint {
  color: var(--muted);
  text-align: center;
  padding: 24px 0;
  font-size: 14px;
}

/* ---------- 八、階段徽章與大型倒數計時器 ---------- */
.phase-badge {
  display: inline-block;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 4px 16px;
  margin-bottom: 10px;
}

.timer {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(64px, 14vw, 120px);
  font-weight: 800;
  line-height: 1.1;
  color: var(--accent-strong);
  letter-spacing: 2px;
}

.timer-large {
  font-size: clamp(88px, 18vw, 168px);
}

/* 最後幾秒：轉紅 + 脈動 */
.timer.warn {
  color: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

/* ---------- 九、背誦階段 ---------- */
.study-top {
  text-align: center;
  margin-bottom: 26px;
}

.study-hint {
  color: var(--muted);
  font-size: 15px;
  margin-top: 6px;
}

/* 左字詞 / 右遊戲 的雙欄版面（桌面） */
.study-layout {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 22px;
  align-items: stretch;
}

.words-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

/* 20 個字詞網格：5 欄 × 4 列（兩種模式共用同一份樣式） */
.words-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.word-tile {
  background: #fdfcf9;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 6px;
  text-align: center;
  font-size: clamp(19px, 2.4vw, 30px);
  font-weight: 500;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* 右側面板：遊戲干擾模式放遊戲；無干擾模式保持空白 */
.side-panel {
  min-height: 380px;
  border-radius: var(--radius);
}

.side-panel.game {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

/* ---------- 十、○ / × 注意力遊戲 ---------- */
.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.game-title {
  font-size: 16px;
  font-weight: 900;
  color: var(--ink);
}

.game-score {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 800;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 4px 10px;
}

.game-meta {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 6px;
}

.game-area {
  position: relative;
  height: 300px;
  overflow: hidden;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: #faf8f3;
}

/* 遊戲符號 */
.game-symbol {
  position: absolute;
  width: 84px;
  height: 84px;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  line-height: 1;
  color: #ffffff;
  user-select: none;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}

.game-symbol.is-o {
  background: var(--o);
  box-shadow: 0 6px 16px -6px rgba(30, 142, 78, 0.5);
}

.game-symbol.is-x {
  background: var(--x);
  box-shadow: 0 6px 16px -6px rgba(194, 56, 43, 0.5);
}

.game-symbol:active {
  transform: scale(0.9);
}

/* ---------- 十一、回憶階段 ---------- */
#screen-recall {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
}

.recall-hint {
  color: var(--ink-soft);
  font-size: 15px;
  margin: 8px 0 18px;
}

.textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: #fdfcf9;
  padding: 14px 16px;
  line-height: 1.9;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.recall-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.recall-note {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 十二、等待階段 ---------- */
#screen-wait {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
  padding-top: 30px;
}

.wait-hint {
  color: var(--ink-soft);
  font-size: 16px;
  margin-top: 18px;
}

/* ---------- 十三、結果畫面 ---------- */
#screen-result {
  max-width: 760px;
  margin: 0 auto;
  text-align: center;
}

.result-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 20px;
}

.result-cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 16px;
}

.result-card {
  flex: 0 1 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 18px 12px;
}

.result-card-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.result-card-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
}

.result-card-value small {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.result-note {
  font-size: 14px;
  font-weight: 700;
  color: var(--x);
  background: var(--x-soft);
  border: 1px solid #e7b8b2;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
}

.result-actions {
  margin-top: 8px;
}

/* ---------- 十四、續作確認視窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(30, 34, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  max-width: 440px;
  width: 100%;
}

.modal-title {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 10px;
}

.modal-info {
  color: var(--ink-soft);
  font-size: 15px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---------- 十五、響應式（窄螢幕自動堆疊） ---------- */
@media (max-width: 860px) {
  .study-layout {
    grid-template-columns: 1fr;
  }

  .mode-options {
    grid-template-columns: 1fr;
  }

  .records-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-area {
    height: 240px;
  }
}

@media (max-width: 520px) {
  #screens {
    padding: 20px 14px 48px;
  }

  .start-card,
  .records-card {
    padding: 20px;
  }

  .history-table {
    font-size: 12px;
  }

  .history-table th,
  .history-table td {
    padding: 6px 8px;
  }

  .words-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .word-tile {
    padding: 12px 4px;
    font-size: 18px;
  }
}
