:root {
  --header-h: 52px;
  --ink: #2c3f57;
  --ink-soft: #6b83a0;
  --line: #d9e6f2;
  --green: #2fbf71;
  --green-dark: #24a05d;
  --orange: #ff9f43;
  --red: #ef6c5b;
  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: #eaf4ff;
  color: var(--ink);
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.screen.hidden { display: none; }
.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 var(--line);
}
.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #eef6ff;
  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: #dceaf9; }
.icon-btn-spacer { width: 44px; flex: 0 0 auto; }
.region-title { font-size: 17px; font-weight: bold; color: var(--ink); }

/* ---------- ホーム画面 ---------- */
#screen-home { background: linear-gradient(180deg, #eaf4ff 0%, #ffffff 70%); }
.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 20px 32px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
}

.mastered-box {
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  text-align: center;
}
.mastered-label { font-size: 13px; color: var(--ink-soft); }
.mastered-count { font-size: 26px; font-weight: bold; color: var(--green-dark); margin: 2px 0 8px; }
.mastered-bar {
  height: 10px;
  background: #eef2f6;
  border-radius: 999px;
  overflow: hidden;
}
.mastered-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7fe0a8, var(--green));
  border-radius: 999px;
  transition: width 0.4s ease-out;
}

.voice-warning {
  background: #fff6e5;
  border: 1px solid #f5d79a;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #8a6320;
}

.start-btn {
  border: none;
  border-radius: 24px;
  padding: 22px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #ffffff;
  background: linear-gradient(135deg, #ffb457, var(--orange));
  box-shadow: 0 5px 0 rgba(190, 110, 25, 0.35);
}
.start-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(190, 110, 25, 0.35); }
.start-btn-icon { font-size: 40px; line-height: 1; }
.start-btn-title { font-size: 26px; font-weight: bold; }
.start-btn-sub { font-size: 13px; opacity: 0.95; text-align: center; }

.category-label { font-size: 13px; color: var(--ink-soft); text-align: center; }
.category-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
}
.category-btn {
  border: 2px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 16px;
  padding: 10px 6px;
  min-height: 72px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.category-btn-icon { font-size: 24px; }
.category-btn.active {
  border-color: var(--green);
  background: #e9fbf1;
  color: var(--green-dark);
}

/* ---------- クイズ画面 ---------- */
.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: var(--ink); }
.quiz-score { font-size: 12px; color: var(--ink-soft); }

.quiz-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 18px;
  width: 100%;
  max-width: 620px;
  margin: 0 auto;
}
.quiz-question-sub { font-size: 14px; color: var(--ink-soft); }

.big-play-btn {
  flex: 0 0 auto;
  width: clamp(96px, 20vh, 140px);
  height: clamp(96px, 20vh, 140px);
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #ffb457, var(--orange));
  box-shadow: 0 6px 0 rgba(190, 110, 25, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: #fff;
}
.big-play-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(190, 110, 25, 0.35); }
.big-play-icon { font-size: clamp(38px, 9vh, 54px); line-height: 1; }
.big-play-label { font-size: 15px; font-weight: bold; }
.big-play-btn.playing { animation: play-pulse 0.7s ease-in-out infinite; }
@keyframes play-pulse {
  0%, 100% { box-shadow: 0 6px 0 rgba(190, 110, 25, 0.35), 0 0 0 0 rgba(255, 159, 67, 0.5); }
  50% { box-shadow: 0 6px 0 rgba(190, 110, 25, 0.35), 0 0 0 16px rgba(255, 159, 67, 0); }
}

.choice-grid {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
}
.choice-grid.is-locked { pointer-events: none; }
.choice-btn {
  border: 3px solid var(--line);
  background: #ffffff;
  border-radius: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 96px;
  box-shadow: 0 3px 0 rgba(44, 63, 87, 0.08);
}
.choice-btn:active { background: #f2f8ff; transform: translateY(2px); }
.choice-btn img {
  width: 82%;
  height: 82%;
  max-width: 160px;
  object-fit: contain;
  pointer-events: none;
}
.choice-btn.is-correct {
  border-color: var(--green);
  background: #e9fbf1;
  animation: pop-bounce 0.35s ease-out;
}
.choice-btn.is-wrong { border-color: var(--red); background: #fdeeeb; }
@keyframes pop-bounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ---------- こたえの画面 ---------- */
.answer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}
.answer-overlay.hidden { display: none; }
.answer-card {
  background: #ffffff;
  border-radius: 26px;
  padding: 22px;
  width: min(360px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  animation: pop-in 0.22s ease-out;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@keyframes pop-in {
  0% { transform: scale(0.9); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}
.answer-badge {
  font-size: 24px;
  font-weight: bold;
  border-radius: 999px;
  padding: 8px 0;
}
.answer-badge-correct { color: var(--green-dark); background: #e9fbf1; }
.answer-badge-wrong { color: #b34a3a; background: #fdeeeb; }
.answer-illust {
  width: min(48vw, 150px);
  height: min(48vw, 150px);
  object-fit: contain;
  margin: 2px auto 0;
}
.answer-en {
  font-size: 20px;
  font-weight: bold;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}
.answer-ja { font-size: 26px; font-weight: bold; color: var(--ink); }
.replay-btn {
  border: 2px solid var(--line);
  background: #eef6ff;
  color: var(--ink);
  border-radius: 14px;
  padding: 12px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  min-height: 48px;
}
.replay-btn:active { background: #dceaf9; }

/* ---------- 結果画面 ---------- */
.completion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 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: 22px;
  padding: 24px;
  text-align: center;
  width: min(380px, 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: 23px; font-weight: bold; color: var(--ink); margin-bottom: 6px; }
.completion-sub { font-size: 16px; color: var(--green-dark); font-weight: bold; margin-bottom: 14px; }
.result-list { margin-bottom: 14px; }
.result-list-heading { font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; text-align: left; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.result-item {
  border: 2px solid var(--line);
  background: #ffffff;
  border-radius: 14px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--ink);
  cursor: pointer;
}
.result-item:active { background: #f2f8ff; }
.result-item img { width: 44px; height: 44px; object-fit: contain; }
.completion-buttons { display: flex; flex-direction: column; gap: 10px; }
.completion-btn {
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 17px;
  font-weight: bold;
  color: #ffffff;
  background: var(--green);
  cursor: pointer;
  min-height: 52px;
}
.completion-btn:active { background: var(--green-dark); }
.completion-btn-secondary { background: #eef6ff; color: var(--ink); }
.completion-btn-wrong { background: var(--orange); }

/* ---------- せってい画面 ---------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 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: 520px;
  max-height: 84vh;
  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 var(--line);
  flex: 0 0 auto;
}
.settings-title { font-size: 18px; font-weight: bold; }
.settings-body { overflow-y: auto; padding: 8px 16px 28px; }
.settings-group { padding: 14px 0; border-bottom: 1px solid #f0f5fa; }
.settings-group-label { font-size: 14px; color: var(--ink-soft); margin-bottom: 8px; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-option {
  border: 2px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
}
.settings-option.active {
  border-color: var(--green);
  background: #e9fbf1;
  color: var(--green-dark);
  font-weight: bold;
}
.settings-option-danger { border-color: #f3c9c2; color: #b34a3a; }
.settings-note { font-size: 12px; color: #9aabbe; margin-top: 8px; line-height: 1.5; }

/* ---------- よこ長の画面（iPad横向き・PC） ---------- */
@media (min-width: 700px) and (orientation: landscape) {
  .quiz-body {
    flex-direction: row;
    align-items: stretch;
    gap: 24px;
    max-width: 1000px;
    padding: 16px 20px 20px;
  }
  .quiz-body .quiz-question-sub { display: none; }
  .big-play-btn {
    align-self: center;
    width: clamp(120px, 26vh, 180px);
    height: clamp(120px, 26vh, 180px);
  }
  .big-play-icon { font-size: clamp(46px, 11vh, 64px); }
}
