:root {
  --header-h: 52px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  background: #eaf6ff;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none; }

/* ---------- 共通トップバー ---------- */
.top-bar {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: #ffffff;
  border-bottom: 1px solid #e0e6ea;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #f0f4f7;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.icon-btn:active { background: #dfe7ec; }
.icon-btn-spacer { width: 44px; flex: 0 0 auto; }
.region-title {
  font-size: 17px;
  font-weight: bold;
  color: #2b3a4a;
}
.timer-display {
  font-size: 12px;
  color: #8a97a3;
  font-variant-numeric: tabular-nums;
  width: 44px;
  text-align: right;
  flex: 0 0 auto;
}

/* ---------- ホーム画面 ---------- */
#screen-home {
  background: linear-gradient(180deg, #eaf6ff 0%, #ffffff 100%);
}
.home-title-wrap { flex: 1 1 auto; text-align: center; }
.home-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 20px 24px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}
.mode-btn {
  border: none;
  border-radius: 20px;
  padding: 20px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: #2b3a4a;
}
.mode-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.mode-btn-icon { font-size: 28px; }
.mode-btn-title { font-size: 20px; font-weight: bold; }
.mode-btn-sub { font-size: 13px; color: #5a6b7a; }
.mode-btn-1 { background: linear-gradient(135deg, #ffe1a8, #ffc978); }
.mode-btn-2 { background: linear-gradient(135deg, #bdf0d1, #8fe0b0); }
.mode-btn-3 { background: linear-gradient(135deg, #b6ddff, #8dc4ff); }

/* ---------- クイズ画面 ---------- */
.quiz-progress-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
}
.quiz-progress { font-size: 16px; font-weight: bold; color: #2b3a4a; }
.quiz-score { font-size: 12px; color: #5a6b7a; }

.quiz-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 20px;
  padding: 24px 16px;
  overflow-y: auto;
}
.quiz-question {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.quiz-question-flag {
  width: min(70vw, 240px);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  border: 1px solid #dde3e7;
}
.quiz-question-name {
  font-size: 26px;
  font-weight: bold;
  color: #2b3a4a;
  text-align: center;
}
.quiz-answer-area {
  width: 100%;
  max-width: 440px;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.choice-btn {
  border: 2px solid #e0e6ea;
  background: #ffffff;
  border-radius: 16px;
  cursor: pointer;
  min-height: 56px;
  font-size: 16px;
  font-weight: bold;
  color: #2b3a4a;
}
.choice-btn:active { background: #eef3f6; }
.choice-btn-name { padding: 14px 10px; }
.choice-btn-flag { padding: 10px; display: flex; align-items: center; justify-content: center; }
.choice-btn-flag img {
  width: 100%;
  max-width: 140px;
  border-radius: 6px;
  border: 1px solid #dde3e7;
}

.text-answer-form {
  display: flex;
  gap: 8px;
}
.text-answer-input {
  flex: 1 1 auto;
  font-size: 18px;
  padding: 14px;
  border: 2px solid #cfd8de;
  border-radius: 14px;
}
.text-answer-input:focus { outline: none; border-color: #4caf7d; }
.text-answer-submit {
  border: none;
  border-radius: 14px;
  padding: 0 20px;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  background: #4caf7d;
  cursor: pointer;
}

/* ---------- 正解画面（答えあわせカード） ---------- */
.answer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.answer-overlay.hidden { display: none; }
.answer-card {
  background: #ffffff;
  border-radius: 22px;
  padding: 24px;
  width: min(360px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  animation: pop-in 0.25s ease-out;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@keyframes pop-in {
  0%   { transform: scale(0.92); opacity: 0.6; }
  100% { transform: scale(1); opacity: 1; }
}
.answer-badge {
  font-size: 20px;
  font-weight: bold;
  border-radius: 999px;
  padding: 6px 0;
}
.answer-badge-correct { color: #227a4e; background: #eafaf1; }
.answer-badge-wrong { color: #b3541e; background: #fff2ea; }
.answer-flag {
  width: min(70%, 200px);
  margin: 4px auto 0;
  border-radius: 8px;
  border: 1px solid #dde3e7;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
}
.answer-name { font-size: 22px; font-weight: bold; color: #2b3a4a; }
.answer-name-en { font-size: 13px; color: #8a97a3; margin-top: -6px; }
.answer-trivia {
  text-align: left;
  font-size: 13.5px;
  line-height: 1.5;
  color: #6b5116;
  background: #fff6df;
  border: 1px solid #f2dfa0;
  border-radius: 12px;
  padding: 10px 12px;
}
.answer-trivia::before {
  content: "💡 ";
}
.answer-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  background: #f6f9fb;
  border-radius: 12px;
  padding: 10px 14px;
}
.answer-info:empty { display: none; padding: 0; }
.answer-info-row { display: flex; justify-content: space-between; font-size: 14px; }
.answer-info-label { color: #5a6b7a; }
.answer-info-value { color: #2b3a4a; font-weight: bold; text-align: right; margin-left: 12px; }
.answer-map-wrap { position: relative; border-radius: 12px; overflow: hidden; background: #dff0ff; }
.answer-map-svg { width: 100%; aspect-ratio: 16 / 10; display: block; }
.world-country {
  fill: #cfe4fa;
  stroke: #5b83ab;
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
}
.world-country-highlight {
  fill: #ff9f5a;
  stroke: #9c3d05;
  stroke-width: 1.6;
  vector-effect: non-scaling-stroke;
}
.world-marker { fill: #e63946; stroke: #ffffff; }

/* ---------- 正解画面の地図の隅にある「せかい全体でどこか」ミニマップ ---------- */
.answer-map-mini-wrap {
  position: absolute;
  left: 6px;
  bottom: 6px;
  width: 34%;
  max-width: 120px;
  border-radius: 8px;
  overflow: hidden;
  background: #eef6ff;
  border: 1.5px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.answer-map-mini-svg { width: 100%; aspect-ratio: 16 / 10; display: block; }
.world-mini-country { fill: #cfe4fa; stroke: #b9cfe6; stroke-width: 0.3; }
.world-mini-country-highlight { fill: #ff9f5a; }
.world-mini-marker { fill: #e63946; }
.world-mini-viewport {
  fill: rgba(255, 159, 90, 0.18);
  stroke: #e63946;
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
}

/* ---------- 完成/結果画面 ---------- */
.completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.completion-overlay.hidden { display: none; }
.completion-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 28px;
  text-align: center;
  width: min(360px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  animation: pop-in 0.3s ease-out;
}
.completion-title { font-size: 24px; font-weight: bold; color: #2b3a4a; margin-bottom: 8px; }
.completion-sub { font-size: 16px; color: #5a6b7a; margin-bottom: 16px; }
.result-wrong-heading { font-size: 13px; color: #8a97a3; margin-bottom: 8px; text-align: left; }
.result-wrong-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.result-wrong-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #2b3a4a;
}
.result-wrong-item img { width: 100%; border-radius: 4px; border: 1px solid #dde3e7; }
.completion-buttons { display: flex; flex-direction: column; gap: 10px; }
.completion-btn {
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-size: 16px;
  font-weight: bold;
  color: #ffffff;
  background: #4caf7d;
  cursor: pointer;
}
.completion-btn-secondary { background: #eef3f6; color: #2b3a4a; }
.completion-btn-wrong { background: #ff9f5a; }

/* ---------- せってい画面 ---------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 40, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2100;
}
.settings-overlay.hidden { display: none; }
.settings-card {
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -6px 24px rgba(0,0,0,0.25);
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e0e6ea;
  flex: 0 0 auto;
}
.settings-title { font-size: 18px; font-weight: bold; color: #2b3a4a; }
.settings-body { overflow-y: auto; padding: 8px 16px 24px; }
.settings-group { padding: 14px 0; border-bottom: 1px solid #f0f4f7; }
.settings-group-label { font-size: 14px; color: #5a6b7a; margin-bottom: 8px; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-option {
  border: 2px solid #e0e6ea;
  background: #ffffff;
  color: #2b3a4a;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
}
.settings-option.active {
  border-color: #4caf7d;
  background: #eafaf1;
  color: #227a4e;
  font-weight: bold;
}
