/* ==========================================================================
   日本統一の旅 - スタイルシート
   「勉強アプリ」ではなく、マンガ風の戦国RPGとして遊べる見た目を目指す。
   パステルカラー・丸文字は使わず、濃い色面＋太いフチ＋厚みのある影で
   「ちょっとかっこいい」手触りを作る。地方カラーを画面全体の軸にする。
   ========================================================================== */

:root {
  --bg: #FAF7F0;        /* 生成り */
  --ink: #1A1A1A;        /* 墨 */
  --gold: #E8A33D;        /* 金縁 */
  --paper: #FFFFFF;
  --paper-dim: #F1ECE0;
  --line: #E3DBC8;
  --good: #1F8A4C;
  --bad: #C23B3B;
  --warn: #D9A62A;

  /* 地方カラー：地図でも問題画面でも、この色を軸にする */
  --r-hokkaido: #3D8BD6;
  --r-tohoku:   #3FA96B;
  --r-kanto:    #E8A33D;
  --r-chubu:    #7E57C2;
  --r-kinki:    #E03131;
  --r-chugoku:  #00A0A0;
  --r-shikoku:  #F0862A;
  --r-kyushu:   #D6478F;

  --shadow-card: 4px 4px 0 rgba(26,26,26,.16);
  --shadow-pop: 6px 6px 0 rgba(26,26,26,.25);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: var(--bg);
  /* うっすらスクリーントーン風のドット地紋でマンガっぽさを足す */
  background-image: radial-gradient(rgba(26,26,26,.05) 1px, transparent 1px);
  background-size: 9px 9px;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic Medium", "Yu Gothic", "Noto Sans JP", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  touch-action: manipulation;
}
input { font-family: inherit; }

/* ステッカー風の極太文字：白フチ＋濃い影 */
.sticker {
  font-weight: 900;
  color: var(--ink);
  -webkit-text-stroke: 5px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(2px 3px 0 rgba(26,26,26,.5));
}

/* 押すと沈む立体ボタンの共通スタイル */
.btn-3d {
  border: 3px solid var(--ink);
  box-shadow: 0 6px 0 rgba(0,0,0,.35);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn-3d:active {
  transform: translateY(6px);
  box-shadow: 0 0 0 rgba(0,0,0,.35);
}

/* ================= ヘッダー ================= */

#app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 18px 10px;
  background: var(--ink);
  color: #fff;
  border-bottom: 4px solid var(--gold);
  flex-wrap: wrap;
}

.brand-btn { display: flex; align-items: center; gap: 8px; padding: 6px 4px; }
.brand-emoji { font-size: 26px; }
.brand-title { font-size: 18px; font-weight: 900; color: #fff; letter-spacing: .5px; }

.header-status { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.status-chip {
  background: #2b2b2b;
  border: 2px solid var(--gold);
  border-radius: 6px;
  padding: 5px 12px;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
}

.header-nav { display: flex; gap: 2px; }
.header-nav button { font-size: 23px; padding: 6px 9px; border-radius: 8px; }
.header-nav button:active { background: rgba(255,255,255,0.2); }

/* ================= 画面共通 ================= */

#app-main { max-width: 720px; margin: 0 auto; padding: 18px 18px calc(60px + var(--safe-bottom)); }

.screen { display: none; }
.screen.is-active { display: block; animation: fadeIn .22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.section-title {
  font-size: 24px;
  margin: 22px 0 12px;
  padding-bottom: 8px;
  border-bottom: 5px solid var(--ink);
}
.screen-subtext { color: #5a5346; font-size: 14px; margin: -4px 0 16px; line-height: 1.6; font-weight: 600; }

.progress-track { background: var(--paper-dim); border: 2px solid var(--ink); border-radius: 6px; height: 16px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--gold); transition: width .4s ease; }

/* ================= ホーム：位のバー（細いストリップ） ================= */
/* 主役は地図なので、位表示はここでは控えめ・コンパクトにまとめる */

.rank-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-card);
}
.rank-bar-body { flex: 1; min-width: 0; }
.rank-bar-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
.rank-bar-name { font-size: 15px; font-weight: 900; }
.rank-bar-sub { font-size: 11.5px; color: #5a5346; font-weight: 700; }
.rank-bar-track { height: 7px; margin-top: 4px; }

/* ================= 階級シルエット（images/rank1〜6.svg を差し替え可能に表示） ================= */
/* 背景の家紋風の円と放射線＋シルエット縁の地方カラーのリムライトはここで一括制御する。
   images/ の中身を差し替えるだけで見た目を更新できるよう、枠側の演出とキャラ画像を分離している。 */

.rank-portrait {
  position: relative;
  width: 74px; height: 90px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.rank-portrait::before {
  content: "";
  position: absolute; inset: -8px;
  border-radius: 50%;
  background:
    repeating-conic-gradient(from 0deg, rgba(26,26,26,.14) 0deg 3deg, transparent 3deg 16deg),
    radial-gradient(circle, rgba(232,163,61,.22) 0%, transparent 65%);
  z-index: 0;
}
.rank-portrait img {
  position: relative; z-index: 1;
  height: 100%;
  filter: drop-shadow(0 0 5px var(--region-color, var(--gold))) drop-shadow(0 0 2px var(--region-color, var(--gold)));
}
.rank-portrait--bar { width: 42px; height: 52px; }
.rank-portrait--cutin { width: 190px; height: 232px; }
.rank-portrait--cutin img {
  filter: drop-shadow(0 0 12px var(--region-color, var(--gold))) drop-shadow(0 0 5px var(--region-color, var(--gold)));
}

/* ================= 忍犬（相棒）ウィジェット ================= */

.ninken-svg { width: 100%; height: 100%; display: block; }
.ninken-figure {
  width: 92px; height: 92px; flex-shrink: 0;
  filter: drop-shadow(3px 4px 0 rgba(26,26,26,.3));
}
.ninken-figure--mini { width: 42px; height: 42px; }

.ninken-home {
  display: flex; align-items: flex-end; gap: 14px;
  margin: 18px 0 6px;
}
.speech-bubble {
  position: relative;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 14px;
  line-height: 1.4;
  max-width: 230px;
  box-shadow: 3px 3px 0 rgba(26,26,26,.2);
}
.speech-bubble::before {
  content: "";
  position: absolute;
  left: -13px; bottom: 16px;
  border: 9px solid transparent;
  border-right-color: var(--ink);
}
.speech-bubble::after {
  content: "";
  position: absolute;
  left: -8px; bottom: 17.5px;
  border: 7.5px solid transparent;
  border-right-color: #fff;
}
/* 忍犬の下に置くふきだし用：矢印を左向きではなく上向きにする */
.speech-bubble--below::before {
  left: 50%; bottom: auto; top: -13px; transform: translateX(-50%);
  border-right-color: transparent; border-bottom-color: var(--ink);
}
.speech-bubble--below::after {
  left: 50%; bottom: auto; top: -7px; transform: translateX(-50%);
  border-right-color: transparent; border-bottom-color: #fff;
}
@keyframes bubblePop {
  0% { transform: scale(.82); opacity: .3; }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); opacity: 1; }
}
.bubble-pop { animation: bubblePop .28s ease; }

.ninken-mini {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 8px;
}
.ninken-mini[hidden] { display: none; }
.ninken-mini .ninken-figure--mini { width: 34px; height: 34px; }
.speech-bubble--mini { font-size: 11.5px; padding: 5px 10px; max-width: 200px; }

/* ================= 本日の任務 ================= */

.missions-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.mission-item {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: var(--shadow-card);
  display: flex; align-items: center; gap: 12px;
}
.mission-item.is-done { background: #EAF4EC; border-color: var(--good); }
.mission-check { font-size: 24px; flex-shrink: 0; }
.mission-body { flex: 1; min-width: 0; }
.mission-desc { font-weight: 800; font-size: 15px; }
.mission-item.is-done .mission-desc { text-decoration: line-through; color: #9a9482; }
.mission-progress-track { margin-top: 6px; height: 8px; background: var(--paper-dim); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.mission-progress-fill { height: 100%; background: var(--good); transition: width .3s ease; }
.mission-reward { font-size: 13px; font-weight: 900; color: var(--gold); flex-shrink: 0; text-shadow: 1px 1px 0 rgba(26,26,26,.25); }

/* ================= 戦況（統計カード） ================= */

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat-card { background: var(--paper); border: 2px solid var(--line); border-radius: 10px; padding: 16px; text-align: center; box-shadow: var(--shadow-card); }
.stat-num { font-size: 28px; -webkit-text-stroke-width: 4px; }
.stat-label { font-size: 12.5px; color: #5a5346; margin-top: 4px; font-weight: 700; }
.stat-grid--2 .stat-card { padding: 20px; }
.stat-grid--2 .stat-num { font-size: 34px; }

/* ================= 出陣ボタン ================= */

.mode-buttons { display: flex; flex-direction: column; gap: 14px; }
.mode-btn {
  display: flex; align-items: center; gap: 16px;
  padding: 20px; border-radius: 10px; text-align: left; min-height: 84px;
}
.mode-btn-emoji { font-size: 38px; flex-shrink: 0; filter: drop-shadow(2px 2px 0 rgba(0,0,0,.25)); }
.mode-btn-title { display: block; font-size: 19px; font-weight: 900; }
.mode-btn-desc { display: block; font-size: 12.5px; margin-top: 3px; opacity: .92; font-weight: 700; }

.mode-btn--card { background: #2F6FBD; color: #fff; }
.mode-btn--quiz { background: #C23B3B; color: #fff; }
.mode-btn--challenge { background: var(--gold); color: var(--ink); }

/* ================= 学習セッション画面 ================= */
/* 選択肢ボタンを画面の下半分に置きたいので、このセクションだけビューポート高さ基準の
   縦flexにし、.quiz-choices を margin-top:auto で下側へ押し出す。 */

#screen-session.is-active {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 96px);
}

.stage-title { font-size: 15px; margin-bottom: 6px; -webkit-text-stroke-width: 4px; }
.session-topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.exit-btn {
  font-size: 18px; font-weight: 900;
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--paper);
  border: 2px solid var(--ink);
  flex-shrink: 0;
}
.session-progress-track { flex: 1; }
.session-timer {
  font-size: 16px; font-weight: 900;
  background: var(--bad); color: #fff;
  border: 2px solid var(--ink);
  padding: 5px 12px; border-radius: 6px; flex-shrink: 0;
}
.session-info-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13.5px; color: #5a5346; font-weight: 800; margin-bottom: 4px;
}
.combo-badge {
  background: var(--ink); color: var(--gold);
  border: 2px solid var(--gold);
  padding: 4px 12px; border-radius: 6px;
  animation: comboPulse .4s ease;
}
.score-badge { background: var(--ink); color: #fff; border: 2px solid var(--gold); padding: 4px 12px; border-radius: 6px; }
@keyframes comboPulse { 0% { transform: scale(1.3); } 100% { transform: scale(1); } }

.study-question-area { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.shake-screen { animation: shakeScreen .35s ease; }
@keyframes shakeScreen {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(4px); }
}

/* 地方の後出し表示：出題前は隠しておき、回答した後に「◯◯県は◯◯地方だ」を見せる */
.region-reveal {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 14px;
  border-radius: 4px;
  font-weight: 900;
  color: #fff;
  border: 2px solid var(--ink);
  font-size: 12.5px;
  letter-spacing: .5px;
  text-shadow: 1px 1px 0 rgba(0,0,0,.3);
  background: var(--region-color, var(--gold));
  animation: popIn .3s ease;
}
/* display:inline-blockを明示しているため、[hidden]属性より詳細度で負けないよう上書きする */
.region-reveal[hidden] { display: none; }

/* 4択の難易度タグ（箱の番号にもとづく3段階） */
.difficulty-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 4px;
  font-weight: 900;
  border: 2px solid var(--ink);
  margin-bottom: 12px;
  font-size: 12.5px;
  letter-spacing: 1px;
}
.difficulty-tag--easy { background: var(--good); color: #fff; }
.difficulty-tag--normal { background: var(--warn); color: var(--ink); }
.difficulty-tag--hard { background: var(--bad); color: #fff; }

/* --- カードモード --- */
.flip-card {
  --region-color: var(--gold);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-top: 10px solid var(--region-color);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  min-height: 260px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 20px; text-align: center; position: relative;
}
.flip-card-label { font-size: 13.5px; color: #8a8374; font-weight: 800; margin-bottom: 10px; }
.flip-card-pref { font-size: 38px; font-weight: 900; color: var(--ink); }
.flip-card-hint { margin-top: 18px; font-size: 14.5px; color: var(--region-color); font-weight: 800; }
.flip-card-capital { font-size: 34px; font-weight: 900; color: var(--ink); animation: popIn .3s ease; }
@keyframes popIn { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.card-actions { margin-top: 22px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card-actions[hidden] { display: none; }
.card-action-btn { padding: 16px 8px; border-radius: 10px; font-size: 15px; font-weight: 900; min-height: 66px; }
.card-action-btn--ok { background: var(--good); color: #fff; }
.card-action-btn--unsure { background: var(--warn); color: var(--ink); }
.card-action-btn--ng { background: var(--bad); color: #fff; }

/* --- クイズモード --- */
.quiz-pref {
  --region-color: var(--gold);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-top: 10px solid var(--region-color);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 18px 18px; text-align: center; margin-bottom: 14px;
}
.quiz-pref-label { font-size: 12.5px; color: #8a8374; font-weight: 800; margin-bottom: 6px; }
.quiz-pref-name { font-size: 28px; font-weight: 900; }

/* 問題文＋4つの選択肢がiPad縦(768×1024)でもスクロールなしで収まる高さにする。
   選択肢の高さは以前の6割程度が目安。 */
.quiz-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 10px;
  height: 27vh;
}

/* 問題文と選択肢のあいだの余白を、大きな忍犬で埋める。
   ここがflex:1で残りの高さを吸収するので、.quiz-choicesは自然に下側へ押し出される。 */
.ninken-quiz-stage {
  flex: 1;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
}
.ninken-figure--quiz {
  width: 130px; height: 130px;
  filter: drop-shadow(4px 5px 0 rgba(26,26,26,.3));
}
/* 正解：うれしそうに跳ねる */
.ninken-figure--happy { animation: ninkenHappy .6s ease; }
@keyframes ninkenHappy {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-16px) scale(1.06); }
  55% { transform: translateY(2px) scale(0.97); }
  75% { transform: translateY(-7px) scale(1.02); }
}
/* 不正解：うつむく */
.ninken-figure--sad { animation: ninkenSad .4s ease forwards; }
@keyframes ninkenSad {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(8px) rotate(-5deg); }
}
.quiz-choice-btn {
  padding: 10px; border-radius: 10px;
  background: var(--paper); box-shadow: var(--shadow-card);
  font-size: 17px; font-weight: 900; color: var(--ink);
  border: 3px solid var(--ink);
}
.quiz-choice-btn:active { transform: scale(0.96); }
.quiz-choice-btn.is-correct { background: var(--good); color: #fff; border-color: var(--ink); animation: correctBounce .4s ease; }
.quiz-choice-btn.is-wrong { background: var(--bad); color: #fff; border-color: var(--ink); animation: shake .4s ease; }
.quiz-choice-btn.is-disabled { opacity: .5; }
/* 不正解のときに正解を金色に光らせる */
.quiz-choice-btn.is-correct-reveal {
  background: var(--gold); color: var(--ink); border-color: var(--ink);
  animation: correctGlow .9s ease-in-out infinite;
}
@keyframes correctGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,163,61,.7); }
  50% { box-shadow: 0 0 20px 7px rgba(232,163,61,.9); }
}

@keyframes correctBounce { 0% { transform: scale(1); } 40% { transform: scale(1.07); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.quiz-next-btn {
  margin-top: 20px; width: 100%; padding: 18px; border-radius: 10px;
  background: var(--ink); color: #fff; font-size: 17px; font-weight: 900;
}

/* --- 小判が飛ぶ演出（集中を妨げないよう一瞬だけ） --- */
.coin-float {
  font-size: 20px; font-weight: 900; color: var(--gold);
  text-shadow: 2px 2px 0 rgba(26,26,26,.7);
  pointer-events: none;
  animation: coinFloat .9s ease forwards;
}
@keyframes coinFloat {
  0% { opacity: 0; transform: translateY(0) scale(.8); }
  15% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: translateY(-42px) scale(1); }
}

/* --- 正解時のマンガ集中線 --- */
.speed-lines-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 55; opacity: 0;
  background: repeating-conic-gradient(from 0deg, rgba(26,26,26,.5) 0deg 3deg, transparent 3deg 11deg);
}
.speed-lines-overlay.is-flashing { animation: speedFlash .4s ease-out; }
@keyframes speedFlash {
  0% { opacity: 0; transform: scale(.82); }
  25% { opacity: .55; }
  100% { opacity: 0; transform: scale(1.06); }
}

/* --- コンボ中：画面のふちが地方カラーで光る --- */
.combo-glow-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 56; opacity: 0;
  transition: opacity .25s ease;
}
.combo-glow-overlay.is-active {
  opacity: 1;
  box-shadow: inset 0 0 24px 7px var(--glow-color, var(--gold)), inset 0 0 68px 16px var(--glow-color, var(--gold));
  animation: comboGlowPulse 1.1s ease-in-out infinite;
}
@keyframes comboGlowPulse { 0%, 100% { opacity: .7; } 50% { opacity: 1; } }

/* --- 正解時の擬音文字（「ズバッ」など）が一瞬だけ出る --- */
.impact-text {
  position: fixed; top: 42%; left: 50%; z-index: 65; pointer-events: none;
  transform: translate(-50%, -50%) scale(.6) rotate(-4deg);
  font-size: 38px; font-weight: 900; color: var(--bad);
  -webkit-text-stroke: 4px #fff;
  paint-order: stroke fill;
  filter: drop-shadow(3px 4px 0 rgba(26,26,26,.5));
  animation: impactPop .55s cubic-bezier(.2,1.6,.4,1) forwards;
}
.impact-text--big { font-size: 54px; color: var(--gold); }
@keyframes impactPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-8deg); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); }
  60% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05) rotate(0deg); }
}

/* --- 5連撃ごとの必殺技風カットイン --- */
.combo-cutin {
  position: fixed; inset: 0; z-index: 90; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0); opacity: 0;
}
.combo-cutin.is-active { animation: comboCutinBg .9s ease forwards; }
@keyframes comboCutinBg {
  0% { opacity: 0; background: rgba(0,0,0,0); }
  15% { opacity: 1; background: rgba(0,0,0,.55); }
  75% { opacity: 1; background: rgba(0,0,0,.55); }
  100% { opacity: 0; background: rgba(0,0,0,0); }
}
.combo-cutin-text {
  font-size: 46px; font-weight: 900; color: #fff;
  -webkit-text-stroke: 7px var(--region-color, var(--gold));
  paint-order: stroke fill;
  filter: drop-shadow(3px 4px 0 rgba(0,0,0,.6));
  transform: scale(.3) rotate(-8deg); opacity: 0;
}
.combo-cutin.is-active .combo-cutin-text { animation: comboCutinText .9s cubic-bezier(.2,1.4,.4,1) forwards; }
@keyframes comboCutinText {
  0% { transform: scale(.3) rotate(-8deg); opacity: 0; }
  35% { transform: scale(1.18) rotate(2deg); opacity: 1; }
  55% { transform: scale(1) rotate(0deg); opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05) rotate(0deg); }
}

/* ================= 日本地図（タイルマップ） ================= */
/* ホーム画面の主役。47都道府県のタイルだけを、指定された座標表(PREF_GRID_POS)の
   とおりに13列×13行のCSS Gridへそのまま配置する。地方の「箱」は作らない。
   空いているマスにはタイルを生成しないので、枠線も背景も出ない。 */

/* 「出陣する」ボタンまでスクロールなしで収まるよう、地図全体の高さを抑える
   （正方形タイル×13行なので、横幅を絞ると縦も一緒に小さくなる） */
.map-grid {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 2px;
  max-width: 430px;
  margin: 0 auto 10px;
}
.pref-tile {
  aspect-ratio: 1;
  width: 100%;
  border-radius: 4px;
  background: var(--paper-dim);
  display: flex; align-items: center; justify-content: center;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 9.5px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: var(--ink);
}
/* 神奈川・鹿児島・和歌山・北海道など3文字の県名は、さらに小さくして正方形に収める */
.pref-tile--long { font-size: 7.5px; letter-spacing: 0; }
.pref-tile.is-conquered { box-shadow: 0 0 0 2px var(--gold) inset; }
.pref-tile.tile-just-conquered { animation: tileConquer .6s ease; position: relative; z-index: 5; }
@keyframes tileConquer {
  0% { transform: scale(1); }
  35% { transform: scale(1.6); box-shadow: 0 0 0 3px var(--gold); }
  100% { transform: scale(1); }
}

/* 地方カラーの凡例：地図の外に8色チップで並べる */
.map-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px 16px; margin-bottom: 20px; }
.legend-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 800; color: var(--ink); }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }

.map-detail { margin-top: 4px; background: var(--paper); border: 2px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow-card); font-weight: 700; line-height: 1.7; }

/* ================= 勲章の間 ================= */

.badges-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .badges-grid { grid-template-columns: repeat(3, 1fr); } }
.badge-card { background: var(--paper); border: 2px solid var(--gold); border-radius: 10px; padding: 16px 10px; text-align: center; box-shadow: var(--shadow-card); }
.badge-card.is-locked { opacity: .4; filter: grayscale(1); border-color: var(--line); }
.badge-card-emoji { font-size: 32px; }
.badge-card-name { font-size: 13.5px; font-weight: 900; margin-top: 6px; }
.badge-card-desc { font-size: 11px; color: #5a5346; margin-top: 4px; line-height: 1.4; font-weight: 600; }

/* ================= 宝箱の間 ================= */

.gacha-machine { text-align: center; margin-bottom: 20px; }
.gacha-collect-count { font-weight: 800; margin-bottom: 10px; color: #5a5346; }
.gacha-pull-btn {
  background: var(--ink); color: var(--gold);
  font-size: 18px; font-weight: 900;
  padding: 20px 28px; border-radius: 10px;
  border: 3px solid var(--gold);
  box-shadow: var(--shadow-pop);
}
.gacha-pull-btn:disabled { opacity: .5; }

.gacha-collection-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (min-width: 560px) { .gacha-collection-grid { grid-template-columns: repeat(6, 1fr); } }
.gacha-item { background: var(--paper); border: 2px solid var(--line); border-radius: 8px; padding: 10px 4px; text-align: center; box-shadow: var(--shadow-card); font-size: 11px; }
.gacha-item.is-locked { opacity: .35; }
.gacha-item-emoji { font-size: 22px; }
.gacha-item-name { font-weight: 700; margin-top: 2px; }

/* ================= 保護者画面 ================= */

.parent-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.parent-tab-btn { flex: 1; padding: 12px; border-radius: 8px; background: var(--paper-dim); border: 2px solid var(--line); font-weight: 800; font-size: 14.5px; }
.parent-tab-btn.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.parent-stat-list { display: flex; flex-direction: column; gap: 10px; }
.parent-stat-row { background: var(--paper); border: 2px solid var(--line); border-radius: 8px; padding: 14px 16px; box-shadow: var(--shadow-card); display: flex; justify-content: space-between; font-size: 14.5px; }
.parent-stat-row strong { font-size: 16px; }

.reward-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.reward-row { background: var(--paper); border: 2px solid var(--line); border-radius: 8px; padding: 12px 16px; box-shadow: var(--shadow-card); display: flex; align-items: center; justify-content: space-between; }
.reward-row-label { font-weight: 700; }
.reward-row-cost { color: var(--gold); font-weight: 900; text-shadow: 1px 1px 0 rgba(26,26,26,.3); }
.reward-row-del { color: var(--bad); font-size: 20px; padding: 4px 8px; font-weight: 900; }

.reward-add-form { display: flex; gap: 8px; margin-bottom: 24px; }
.reward-add-form input { border: 2px solid var(--line); border-radius: 8px; padding: 12px; font-size: 15px; }
#reward-input-label { flex: 2; min-width: 0; }
#reward-input-cost { flex: 1; min-width: 0; }
.reward-add-form button { background: var(--ink); color: #fff; font-weight: 800; padding: 0 18px; border-radius: 8px; }

.danger-btn { width: 100%; padding: 14px; border-radius: 8px; background: #FBEAEA; color: var(--bad); font-weight: 700; border: 2px solid var(--bad); }

/* ================= モーダル共通 ================= */

.modal-overlay { position: fixed; inset: 0; background: rgba(26, 26, 26, 0.62); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-overlay[hidden] { display: none; }

.modal-box { background: var(--paper); border: 3px solid var(--ink); border-radius: 10px; padding: 28px 26px; max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow-pop); animation: popIn .22s ease; }
.modal-box h3 { font-size: 19px; margin: 0 0 12px; font-weight: 900; }

.modal-btn-row { display: flex; gap: 10px; margin-top: 18px; }
.modal-btn { flex: 1; padding: 16px; border-radius: 8px; font-weight: 900; font-size: 15px; border: 3px solid var(--ink); }
.modal-btn--primary { background: var(--ink); color: var(--gold); }
.modal-btn--ghost { background: var(--paper-dim); color: var(--ink); }

/* 保護者ゲート */
.gate-question { font-size: 25px; font-weight: 900; margin: 14px 0; }
.gate-answer-input { width: 100%; padding: 14px; font-size: 20px; text-align: center; border-radius: 8px; border: 2px solid var(--line); }
.gate-error { color: var(--bad); font-size: 13px; margin-top: 8px; font-weight: 700; }

/* 昇格カットイン：暗転 → 集中線 → 新しいシルエットが大きく出る演出 */
.modal-overlay--cutin { background: rgba(0, 0, 0, 0.94); flex-direction: column; }
.cutin-flash {
  position: absolute; inset: 0; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.5) 0deg 3deg, transparent 3deg 11deg);
  opacity: 0;
  animation: cutinFlash .4s ease-out;
}
@keyframes cutinFlash { 0% { opacity: 0; } 15% { opacity: .9; } 100% { opacity: 0; } }

.cutin-stage { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; }
.cutin-stage .rank-portrait {
  margin-bottom: 8px;
  opacity: 0;
  animation: cutinPortraitIn .5s cubic-bezier(.2,1.4,.4,1) both;
  animation-delay: .15s;
}
@keyframes cutinPortraitIn {
  0% { opacity: 0; transform: scale(.3) translateX(60px); }
  70% { opacity: 1; transform: scale(1.12) translateX(0); }
  100% { opacity: 1; transform: scale(1) translateX(0); }
}
.cutin-label, .cutin-rank-name, .cutin-text, .cutin-btn {
  opacity: 0;
  animation: fadeInUp .4s ease both;
}
.cutin-label { font-weight: 900; letter-spacing: 8px; color: var(--gold); font-size: 12.5px; animation-delay: .5s; }
.cutin-rank-name { font-size: 30px; font-weight: 900; color: #fff; margin: 8px 0; animation-delay: .58s; }
.cutin-text { font-size: 14px; color: #ddd; line-height: 1.7; margin-bottom: 18px; font-weight: 700; animation-delay: .66s; }
.cutin-btn { width: 160px; animation-delay: .74s; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* 勲章獲得 */
.badge-pop-emoji { font-size: 54px; animation: badgeSpin .55s ease; }
@keyframes badgeSpin { 0% { transform: rotate(-15deg) scale(0.5); opacity: 0; } 100% { transform: rotate(0) scale(1); opacity: 1; } }
.badge-pop-title { font-size: 13px; color: var(--gold); font-weight: 900; margin-top: 8px; letter-spacing: 2px; }
.badge-pop-name { font-size: 21px; font-weight: 900; margin-top: 4px; }
.badge-pop-desc { font-size: 13px; color: #5a5346; margin-top: 6px; font-weight: 700; }

/* 宝箱の結果 */
.gacha-result-emoji { font-size: 58px; animation: popIn .4s ease; }
.gacha-result-pref { font-size: 13px; color: #8a8374; font-weight: 800; margin-top: 8px; }
.gacha-result-item { font-size: 21px; font-weight: 900; margin-top: 4px; }
.gacha-result-dup { font-size: 13px; color: var(--gold); margin-top: 8px; font-weight: 800; }

/* セッション終了 */
.session-end-emoji { font-size: 44px; }
.session-end-stats { margin: 14px 0; display: flex; flex-direction: column; gap: 6px; font-size: 14.5px; color: #5a5346; font-weight: 700; }
.session-end-stats strong { color: var(--ink); }
.challenge-best-note { font-weight: 900; color: var(--gold); text-shadow: 1px 1px 0 rgba(26,26,26,.3); }

/* ================= トースト ================= */

.toast-layer {
  position: fixed; top: calc(70px + var(--safe-top)); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  background: var(--ink); color: #fff; border: 2px solid var(--gold);
  padding: 9px 18px; border-radius: 8px; font-size: 13.5px; font-weight: 800;
  box-shadow: var(--shadow-card);
  animation: toastIn .3s ease, toastOut .3s ease 2.2s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
