/* ============================================================
   認識世界 — geography knowledge quiz
   Country → capital / capital → country / country → continent
   ============================================================ */

:root {
  --bg: #eef5fb;
  --bg2: #dcebf7;
  --card: #ffffff;
  --text: #1f3a52;
  --text-light: #6b8196;
  --accent: #2e7ab8;
  --accent-dark: #1e5a8f;
  --accent-light: #d4e6f4;
  --border: #b9d3e7;
  --border-thick: #7aaed1;
  --correct: #4fb071;
  --correct-bg: #dcf1e2;
  --wrong: #d95656;
  --wrong-bg: #f7dede;
  --btn-bg: #eaf2f8;
  --shadow: 0 4px 20px rgba(30, 90, 143, 0.12);
  --shadow-btn: 0 3px 10px rgba(30, 90, 143, 0.15);
  --radius: 20px;

  --title-font: 28px;
  --stat-label-font: 14px;
  --stat-value-font: 28px;
  --q-pre-font: 20px;
  --q-main-font: 34px;
  --flag-font: 72px;
  --choice-font: 24px;
  --text-btn-font: 18px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: -apple-system, 'PingFang TC', 'Noto Sans TC', 'Helvetica Neue', sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--text);
}

.app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.title {
  font-size: var(--title-font);
  font-weight: 800;
  color: var(--accent-dark);
  letter-spacing: 4px;
}

.help-btn, .back-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--accent);
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  flex-shrink: 0;
}
.help-btn:active, .back-btn:active {
  background: var(--accent-light);
  border-color: var(--accent);
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 10px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 80px;
}

.stat-label {
  font-size: var(--stat-label-font);
  color: var(--text-light);
  letter-spacing: 2px;
  font-weight: 600;
}

.stat-value {
  font-size: var(--stat-value-font);
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.stat-value.accent { color: var(--accent); }
.stat-value .muted { color: var(--text-light); font-size: 0.6em; margin-left: 2px; }

.stat-btn {
  border: 2px dashed var(--border);
  background: var(--accent-light);
  border-radius: 14px;
  padding: 6px 14px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  font-family: inherit;
  color: inherit;
}
.stat-btn:active {
  transform: scale(0.96);
  background: var(--border);
}

/* Prompt */
.prompt-wrap {
  flex: 1 1 0;
  min-height: 0;
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 16px;
  text-align: center;
}

.q-flag {
  font-size: var(--flag-font);
  line-height: 1;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  min-height: 0;
  animation: q-in 0.3s ease-out;
}
.q-flag:empty { display: none; }

.q-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.q-pre, .q-post {
  font-size: var(--q-pre-font);
  color: var(--text-light);
  letter-spacing: 2px;
}
.q-pre:empty, .q-post:empty { display: none; }

.q-main {
  font-size: var(--q-main-font);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 4px;
  padding: 6px 20px;
  background: var(--accent-light);
  border-radius: 14px;
  animation: q-in 0.3s ease-out;
}

@keyframes q-in {
  0%   { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1);    opacity: 1; }
}

/* Answer choices */
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex-shrink: 0;
}

.choice {
  padding: 20px 12px;
  border: 3px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  font-size: var(--choice-font);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  box-shadow: var(--shadow-btn);
  letter-spacing: 2px;
  min-height: 72px;
  text-align: center;
}
.choice:active {
  transform: scale(0.97);
  background: var(--accent-light);
}
.choice.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
  color: var(--correct);
  animation: pulse-correct 0.4s ease-out;
}
.choice.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong);
  color: var(--wrong);
  animation: shake-wrong 0.4s ease-out;
}
.choice.locked { pointer-events: none; }

@keyframes pulse-correct {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes shake-wrong {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(-8px); }
  50%  { transform: translateX(8px); }
  75%  { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

/* Text buttons */
.text-btn {
  padding: 14px 28px;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  font-size: var(--text-btn-font);
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.15s;
  box-shadow: var(--shadow-btn);
  font-family: inherit;
}
.text-btn:active { transform: scale(0.96); background: var(--btn-bg); }
.text-btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.text-btn.primary:active { background: var(--accent-dark); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.5);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 100;
}
.modal-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--card);
  border-radius: 28px;
  padding: 36px;
  text-align: center;
  max-width: 520px;
  width: 88%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  border: 3px solid var(--border);
  max-height: 90vh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 30px;
  margin-bottom: 12px;
  color: var(--text);
}

.end-sub {
  color: var(--text-light);
  font-size: 18px;
  margin-bottom: 20px;
}

.end-stats {
  display: flex;
  justify-content: center;
  gap: 36px;
  margin-bottom: 24px;
}

.end-stat .label {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 4px;
  letter-spacing: 1px;
}
.end-stat .value {
  font-size: 34px;
  font-weight: 800;
  color: var(--accent);
}
.end-stat .value .muted { color: var(--text-light); font-size: 0.6em; margin-left: 2px; }

.target-options {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.target-option {
  padding: 14px 10px;
  border: 3px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: all 0.15s;
  box-shadow: var(--shadow-btn);
}
.target-option:active { transform: scale(0.96); background: var(--accent-light); }
.target-option.current {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(46, 122, 184, 0.25), var(--shadow-btn);
}
.target-option .opt-label {
  font-size: 18px;
  color: var(--accent-dark);
  letter-spacing: 4px;
  font-weight: 700;
}
.target-option .opt-value {
  font-size: 13px;
  color: var(--text-light);
  font-weight: 500;
  line-height: 1;
  min-height: 13px;
}

.help-content {
  text-align: left;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
}
.help-content h3 {
  font-size: 21px;
  margin: 18px 0 10px;
  color: var(--accent);
}
.help-content h3:first-child { margin-top: 0; }
.help-content p, .help-content li {
  font-size: 18px;
  line-height: 1.7;
  color: var(--text);
}
.help-content ul {
  padding-left: 22px;
  margin-bottom: 14px;
}

/* =============================================================
   TABLET (iPad)
   ============================================================= */
@media (min-width: 700px) {
  :root {
    --title-font: 42px;
    --stat-label-font: 20px;
    --stat-value-font: 40px;
    --q-pre-font: 30px;
    --q-main-font: 56px;
    --flag-font: 140px;
    --choice-font: 32px;
    --text-btn-font: 22px;
  }

  .app {
    max-width: none;
    padding: 16px 24px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(24px + env(safe-area-inset-left, 0px));
    padding-right: calc(24px + env(safe-area-inset-right, 0px));
    gap: 18px;
  }

  .title { letter-spacing: 8px; }
  .help-btn, .back-btn { width: 60px; height: 60px; font-size: 28px; }

  .status-bar { padding: 14px 22px; }
  .stat { min-width: 110px; }

  .prompt-wrap { padding: 32px 28px; gap: 22px; }
  .q-main { padding: 10px 28px; border-radius: 18px; }

  .choices { gap: 16px; }
  .choice { padding: 28px 16px; min-height: 100px; border-radius: 22px; }
}

/* Landscape: prompt on left, choices on right */
@media (min-width: 700px) and (orientation: landscape) {
  .app {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    grid-template-rows: auto auto 1fr;
    gap: 14px 24px;
  }

  .header { grid-column: 1 / -1; }
  .status-bar { grid-column: 1 / -1; }

  .prompt-wrap {
    grid-column: 1;
    grid-row: 3;
  }

  .choices {
    grid-column: 2;
    grid-row: 3;
    align-self: stretch;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
  }
  .choice { min-height: 0; }
}

@media (min-width: 1024px) {
  :root {
    --title-font: 52px;
    --q-main-font: 68px;
    --flag-font: 180px;
    --choice-font: 38px;
  }
}

/* Small phones */
@media (max-width: 380px) {
  :root {
    --title-font: 22px;
    --stat-label-font: 11px;
    --stat-value-font: 22px;
    --q-pre-font: 14px;
    --q-main-font: 24px;
    --flag-font: 56px;
    --choice-font: 17px;
    --text-btn-font: 14px;
  }
  .app { padding: 10px 12px; gap: 10px; }
  .title { letter-spacing: 2px; }
  .stat { min-width: 56px; }
  .target-options { grid-template-columns: 1fr 1fr; }
  .choice { padding: 14px 8px; min-height: 60px; }
}
