/*
  やまぐち駅探検クイズ
  - スマホ縦画面が最優先。ボタンは 48px 以上、文字は 18px 以上（ルビの rt を除く）
  - 書体: 外から読まない。子どもが読みやすい UD 書体（BIZ UDPGothic）か丸ゴシックを、入っていれば使う。
    無い端末（Android など）はその端末の日本語ゴシックになる
  - 色: 正解は青・まちがいは だいだい（色の見え方がちがっても区別しやすい組み合わせ）。色だけにせず ○×と言葉を添える
*/

:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --ink: #1f2a33;
  --ink-sub: #45525e;
  --line: #8a96a1;
  --primary: #0b4f8a;
  --primary-press: #083c69;
  --on-primary: #fffdf8;
  --good: #0b4f8a;
  --good-bg: #e3eefb;
  --try: #a33b00;
  --try-bg: #fdeee2;
  --shape: #3d6585;
  --shape-line: #1d3347;
  --map-town: #d3dce4;
  --map-answer: #f6aa00;
  --reveal-ms: 3000ms;
  --radius-s: 12px;
  --radius-m: 16px;
  --radius-l: 24px;
  font-family: "BIZ UDPGothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-size: 18px;
  line-height: 1.8; /* ルビが乗るので本文より広め */
  letter-spacing: 0.02em;
  /* 子ども向けの文は「わかち書き」（ことばの間に空白）なので、空白のところで折り返す。長い語ははみ出さず折る */
  word-break: keep-all;
  overflow-wrap: anywhere;
  background: var(--bg);
  color: var(--ink);
}

/* ルビが漢字より長くても、漢字の間をあけない */
ruby { ruby-position: over; ruby-align: center; }
rt {
  font-size: 0.55em;
  line-height: 1;
  letter-spacing: 0;
  font-weight: 400;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---- 上のバー ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 8px calc(16px + env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-status { min-width: 0; }
.progress {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}
.rank-badge {
  margin: 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-sub);
}

/* ---- 画面 ---- */
.screens {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 24px calc(16px + env(safe-area-inset-right, 0px)) 32px calc(16px + env(safe-area-inset-left, 0px));
}
.screen:focus, .screen *:focus:not(:focus-visible) { outline: none; }

.title, .lead, .question, .reveal-name, .result-text {
  margin: 0 0 16px;
  font-weight: 700;
  text-align: center;
  line-height: 1.7;
}
.title { font-size: 26px; }
.lead { font-size: 30px; }
.question { font-size: 24px; text-align: left; }
.reveal-name { font-size: 32px; margin-top: 16px; }
.body-text { font-size: 20px; margin: 0 0 16px; }
.step-label {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-sub);
}

/* 係員向けの補足（エラーの中身） */
.staff-note {
  margin: 24px 0 0;
  padding: 12px 16px 12px 32px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-sub);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
}
.staff-inline { font-size: 14px; color: var(--ink-sub); }

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 24px;
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-m);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 120ms ease-out, background 120ms ease-out, border-color 120ms ease-out;
}
.btn:active:not([aria-disabled="true"]) { transform: scale(0.97); }
.btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
.btn[aria-disabled="true"] { cursor: default; }

.btn-primary {
  width: 100%;
  min-height: 64px;
  font-size: 24px;
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}
.btn-primary:active { background: var(--primary-press); }

.btn-quiet {
  min-height: 48px;
  padding: 4px 16px;
  font-size: 16px;
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover:not([aria-disabled="true"]) { border-color: var(--primary); }
  .btn-primary:hover { background: var(--primary-press); }
}

.actions { margin-top: 24px; }

/* ---- ② なにかな？ ---- */
.reveal-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
}
.reveal-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.reveal-frame.is-photo .reveal-img { object-fit: cover; }
.reveal-img.is-waiting { opacity: 0; }

/* 切り抜き: 形のシルエット（真っ黒）→ ぼかし → くっきり */
.reveal-cutout { animation: reveal-cutout var(--reveal-ms) ease-in-out both; }
@keyframes reveal-cutout {
  0% { opacity: 0; filter: brightness(0) blur(0); }
  8% { opacity: 1; filter: brightness(0) blur(0); }
  40% { filter: brightness(0) blur(0); }
  70% { filter: brightness(1) blur(10px); }
  100% { opacity: 1; filter: brightness(1) blur(0); }
}

/* 写真: 暗くて強いぼかし → くっきり */
.reveal-photo { animation: reveal-photo var(--reveal-ms) ease-in-out both; }
@keyframes reveal-photo {
  0% { opacity: 0; filter: brightness(0.15) blur(28px); transform: scale(1.12); }
  8% { opacity: 1; }
  45% { filter: brightness(0.35) blur(18px); transform: scale(1.08); }
  100% { opacity: 1; filter: brightness(1) blur(0); transform: scale(1); }
}

.img-missing {
  margin: 0;
  padding: 24px;
  font-size: 20px;
  text-align: center;
}

/* ---- ③ クイズ ---- */
.choices {
  display: grid;
  gap: 12px;
}
.choice {
  width: 100%;
  min-height: 64px;
  justify-content: flex-start;
  text-align: left;
  padding: 8px 16px;
}
.choice .mark {
  flex: none;
  width: 1.4em;
  font-size: 28px;
  text-align: center;
}
.choice-text { flex: 1; }
.choice .verdict { flex: none; font-size: 16px; }
.choice.is-correct { color: var(--good); background: var(--good-bg); border-color: var(--good); border-width: 3px; }
.choice.is-wrong { color: var(--try); background: var(--try-bg); border-color: var(--try); border-width: 3px; }
.choice.is-dim { color: var(--ink-sub); }

.feedback {
  min-height: 1.8em;
  margin: 12px 0 0;
  font-size: 22px;
  font-weight: 700;
}
.fb-good { color: var(--good); }
.fb-try { color: var(--try); }

.trivia {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.trivia-label {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-sub);
}
.trivia-text { margin: 0; font-size: 20px; }

/* ---- ④ 市町えらび ---- */
.tiles {
  display: grid;
  gap: 12px;
}
.tile {
  width: 100%;
  min-height: 112px;
  display: grid;
  grid-template-columns: 96px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: start;
  column-gap: 16px;
  padding: 8px 16px 8px 8px;
  text-align: left;
}
.tile-shape {
  position: relative;
  grid-row: 1 / 3;
  width: 96px;
  height: 96px;
}
.shape {
  display: block;
  width: 100%;
  height: 100%;
}
.shape path {
  fill: var(--shape);
  stroke: var(--shape-line);
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.tile-name { font-size: 22px; align-self: end; }
.tiles.is-veteran .tile:not(.is-wrong):not(.is-correct) .tile-name { color: var(--ink-sub); font-size: 18px; }
.tile-verdict { font-size: 18px; align-self: start; min-height: 1.5em; }
.tile-mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 72px;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 4px var(--surface), 0 0 8px var(--surface);
}
.tile.is-wrong { color: var(--try); background: var(--try-bg); border-color: var(--try); border-width: 3px; }
.tile.is-wrong .shape path { fill: #b9c2ca; stroke: #7d8892; }
.tile.is-wrong .tile-mark { color: var(--try); }
.tile.is-correct { color: var(--good); background: var(--good-bg); border-color: var(--good); border-width: 3px; }
.tile.is-correct .tile-mark { color: var(--good); }
.tile.is-dim:not(.is-wrong) { color: var(--ink-sub); }

/* 横に広い画面では 3 つを横にならべて見くらべやすく */
@media (min-width: 520px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    justify-items: center;
    text-align: center;
    padding: 12px 8px;
  }
  .tile-shape { grid-row: auto; width: 100%; height: auto; aspect-ratio: 1; }
  .tile-name, .tile-verdict { align-self: auto; }
}

/* ---- ⑤ 結果 ---- */
.map-wrap {
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
}
.pref-map { display: block; width: 100%; height: auto; }
.pref-map .town {
  fill: var(--map-town);
  stroke: var(--surface);
  stroke-width: 1.5;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.pref-map .town.is-answer {
  fill: var(--map-answer);
  stroke: var(--ink);
  stroke-width: 3;
}
.result-text { margin-top: 24px; font-size: 26px; }
.result-town { font-size: 32px; color: var(--try); }
.result-next { text-align: center; }

/* ---- 隊員えらび ---- */
.rank-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 24px 16px;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-l);
}
.rank-dialog::backdrop { background: rgba(31, 42, 51, 0.55); }
.rank-choices { display: grid; gap: 16px; margin-bottom: 16px; }
.rank-btn {
  width: 100%;
  min-height: 112px;
  flex-direction: column;
  gap: 0;
}
.rank-btn[aria-pressed="true"] { border-color: var(--primary); border-width: 4px; background: var(--good-bg); }
.rank-name { font-size: 28px; }
.rank-sub { font-size: 18px; font-weight: 400; color: var(--ink-sub); }
#rank-cancel { width: 100%; }

/* ---- 下 ---- */
.footer {
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  text-align: center;
}
.sample-note {
  margin: 0;
  font-size: 14px;
  color: var(--ink-sub);
}
.credit {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-sub);
}
.noscript { padding: 24px; font-size: 20px; }

/* ---- 動きを減らす設定 ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* 演出は、ぼかしや暗さを使わない短いフェードに置きかえる */
  .reveal-frame .reveal-cutout,
  .reveal-frame .reveal-photo {
    animation: reveal-fade 300ms ease-out both !important;
  }
}
@keyframes reveal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 隊員えらびの窓が開いている間は、後ろの「じゅんびちゅう…」を見せない */
html:has(.rank-dialog[open]) #screen-loading { visibility: hidden; }
/* 進むボタンを画面に入れる時、下に少し余白を残す */
.actions .btn { scroll-margin-bottom: 16px; }


/* 視覚案: 操作と読みやすさの共通調整 */
rt { font-size: max(0.55em, 11px); }
.rank-badge, .step-label, .trivia-label, .choice .verdict { font-size: 18px; }
.btn-quiet { font-size: 18px; }
.staff-note, .staff-inline, .sample-note { font-size: 16px; }
.topbar { border-bottom-width: 3px; }
.choice, .tile, .rank-btn { box-shadow: 0 4px 0 var(--shadow); }
.btn:active:not([aria-disabled="true"]) { transform: translateY(3px); box-shadow: none; }
.btn-primary { box-shadow: 0 5px 0 var(--shadow); }
.step-label { display: table; padding: 2px 12px; border-radius: 8px; }
.question { padding: 8px 0 12px; }
.reveal-frame, .map-wrap { border-width: 3px; }
.pref-map .town.is-answer { filter: drop-shadow(0 0 5px var(--map-glow)); }
.result-town { color: var(--result-ink); }
.rank-dialog { border-width: 3px; box-shadow: 0 10px 0 var(--shadow); }
.rank-sub { color: var(--ink-sub); }
@media (max-width: 360px) {
  .topbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .btn-quiet { padding-left: 10px; padding-right: 10px; }
  .screens { padding-left: 12px; padding-right: 12px; }
  .tile { grid-template-columns: 100px minmax(0, 1fr); column-gap: 12px; }
  .tile-shape { width: 100px; height: 100px; }
}


/* A: 探検手帳 — 地図の方眼と押印のような札 */
:root { --bg:#e7f2e6; --surface:#fffef4; --ink:#18362e; --ink-sub:#344e44; --line:#426455; --primary:#075a4c; --primary-press:#003e35; --on-primary:#fffef4; --good:#075a4c; --good-bg:#d9f1e7; --try:#8c3208; --try-bg:#fff0df; --shape:#317969; --shape-line:#173d32; --map-town:#b6d3c1; --map-answer:#f6bd23; --shadow:#35594c; --map-glow:#e79a00; --result-ink:#853306; }
body { background-color:var(--bg); background-image:linear-gradient(#b8d8c3 1px, transparent 1px),linear-gradient(90deg,#b8d8c3 1px,transparent 1px); background-size:28px 28px; }
.topbar { background:#fffef4; border-color:#075a4c; }
.progress { color:#075a4c; }
.screen { background:#fffef4; border:2px solid #426455; border-radius:8px 24px 8px 24px; padding:20px 16px 24px; box-shadow:5px 5px 0 #91bba4; }
.step-label { color:#fffef4; background:#075a4c; }
.title, .lead { color:#075a4c; }
.btn { border-radius:8px; border-color:#35594c; }
.btn-primary { border-color:#003e35; }
.reveal-frame { background:#e4f3e5; border-style:dashed; }
.map-wrap { background:#e4f3e5; }
.rank-dialog { background:#fffef4; }


/* ---- 県の地図に色が付いていく（集めた市町・今回の市町） ---- */
/* 集めた市町: A 案の緑より暗い緑。地の色と 3.2:1、今回の黄色と 3.0:1 の明るさの差。色だけに頼らず輪郭も濃くする */
:root { --map-collected: #2f7a5d; --map-collected-line: #123f31; }
.pref-map .town.is-collected {
  fill: var(--map-collected);
  stroke: var(--map-collected-line);
  stroke-width: 2;
}
/* これから集める市町: 紙の色の「空き」。輪郭を濃くして、うすい緑（最初から入っている市町）と見分ける */
:root { --map-todo: #fffef4; --map-todo-line: #426455; }
.pref-map .town.is-todo {
  fill: var(--map-todo);
  stroke: var(--map-todo-line);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}
/* 結果の画面に入った時、今回の市町が空きの色から黄色に変わる */
.pref-map .town.is-answer { animation: town-fill 600ms ease-out 150ms both; }
@keyframes town-fill {
  from { fill: var(--map-todo); }
  to { fill: var(--map-answer); }
}
@media (prefers-reduced-motion: reduce) {
  .pref-map .town.is-answer { animation: none !important; }
}
#message-map { margin-bottom: 16px; }

/* ---- 隊員えらびの窓の上のアプリ名（初回だけ） ---- */
.app-name {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.7;
  text-align: center;
  color: var(--ink-sub);
}

/* 見出しへフォーカスを移した時に、黒い枠を出さない（ボタンの枠は残す） */
.screen [tabindex="-1"]:focus-visible { outline: none; }

/* ---- 答えた後のボタン: 押せないと分かるように、影を消して地を薄くする（文字は 8:1 を保つ） ---- */
.btn[aria-disabled="true"] { box-shadow: none; }
.choice.is-dim,
.tile.is-dim:not(.is-wrong):not(.is-correct) {
  background: #eef2ea;
  border-color: #7f9a8c;
}

/* 選択肢: 「せいかい」「ちがうよ」は文字の下の段に置き、狭い幅でも選択肢の文字を折らせない */
.choice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 8px;
  justify-items: start;
}
.choice .mark { grid-row: 1 / span 2; }
.choice .verdict { grid-column: 2; line-height: 1.3; }
.choice .verdict:empty { display: none; }

/* 市町の名前: 幅 320 でも「山陽小野田市」を 1 行に収める */
.tile-name { font-size: clamp(18px, 5.6vw, 22px); }

/* 上のバー: 「0/6 もん クリア」を 2 行にしない */
.progress { white-space: nowrap; }
@media (max-width: 360px) {
  .progress { font-size: 16px; letter-spacing: -0.02em; }
  .btn-quiet { padding-left: 8px; padding-right: 8px; }
}

/* 背の低い画面: タイルを低くして、3 つ目まで見えやすく（押す高さは 88px） */
@media (max-height: 640px) and (max-width: 519px) {
  .tile { min-height: 88px; grid-template-columns: 72px minmax(0, 1fr); }
  .tile-shape { width: 72px; height: 72px; }
}
