/* 紙と墨。シルエットが主役なので、色は正解の深緑と不正解の朱だけに絞ってある。 */

:root {
  --paper: #f7f3ea;
  --surface: #fffdf7;
  --ink: #1f2933;
  --muted: #58606a;
  --line: #ddd4c2;
  --faint: #c9c2b4;
  --correct: #1f7a4d;
  --correct-bg: #e4f1e8;
  --wrong: #c0392b;
  --wrong-bg: #fae7e4;
  --focus: #1d4ed8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); }
body {
  min-width: 0;
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
h1, h2, p, ol, ul { margin-top: 0; }
p { text-wrap: pretty; }
/* 日本語は文節で折る。対応していないブラウザは今までどおり */
.site-description, .mode__sub, .hint__text, .reveal__sub, .wiki__extract, .result__list li, .sources p { word-break: auto-phrase; }
button, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-head, #app, .sources { width: min(100% - 32px, 1080px); margin-inline: auto; }
.site-head { padding: 20px 0 12px; }
.site-head h1 { margin: 0; font-size: clamp(1.8rem, 5vw, 2.7rem); letter-spacing: -.04em; line-height: 1.12; }
.site-head__text { min-width: 0; }
.site-description { margin: 6px 0 0; color: var(--muted); font-size: .95rem; }
/* 遊んでいる間の主役はシルエット。説明文と例は最初の画面にだけ置く。
   見出しは <header> にあって #app の外なので、body 側から状態を見る */
body:has(#app:not([data-state="start"])) .site-description,
body:has(#app:not([data-state="start"])) #start-samples { display: none; }

/* 「シルエット」が何なのかを言葉ではなく形で見せる（形が届くまでは hidden のまま） */
.samples { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; margin-top: 12px; }
.samples__shapes { display: flex; gap: 12px; margin: 0; padding: 0; list-style: none; }
.samples__shape { display: block; width: 56px; height: auto; aspect-ratio: 1; }
.samples__shape path { fill: var(--ink); }
.samples__caption { margin: 0; color: var(--muted); font-size: .8rem; }
.eyebrow, .kicker {
  margin-bottom: 3px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .14em;
}
#app { margin-bottom: 28px; }

/* ---------------------------------------------------------------- 画面の出し分け */
.panel { display: none; }
#app[data-state="start"] #start,
#app[data-state="loading"] #loading,
#app[data-state="playing"] #question,
#app[data-state="reveal"] #question,
#app[data-state="result"] #result,
#app[data-state="error"] #load-error { display: block; }
#reveal { display: none; }
#app[data-state="reveal"] #reveal { display: block; }
/* 正解を見たあとに、重ねた地図と押せるボタンは要らない（同じ絵が正解表示に出る）。
   ただし .hint-row の高さは残す。ここが畳まれると4択が上へ跳ねる。
   文字は残して行を埋める（空の帯のままだと読み込みに失敗した画面に見える） */
#app[data-state="reveal"] #hint,
#app[data-state="reveal"] #hint-button { display: none; }

/* ---------------------------------------------------------------- 共通の部品 */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  min-width: 44px;
  padding: 10px 18px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
.button--primary { width: 100%; border-color: var(--ink); background: var(--ink); color: #fff9ee; }
.button--primary:hover { background: #101820; }
.button:hover:not(.button--primary) { background: #efe8d8; }
.text-button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: .92rem;
  font-weight: 700;
}
.text-button:hover { background: #efe8d8; }
/* 「やめる」は逃げ道であって主役ではない。地に対して 5.7:1 の墨灰は保ったまま、
   背景と枠を弱めて主役から降ろす（文字を細くすると読めなくなるので太さは戻した） */
.text-button--quiet { border-color: var(--line); background: transparent; color: var(--muted); }
.text-button--quiet:hover { background: #efe8d8; color: var(--ink); }
.notice {
  margin: 0 0 14px;
  padding: 10px 14px;
  border: 1px solid #8a5a1c;
  border-radius: 10px;
  background: #fdf1da;
  color: #6a4211;
  font-weight: 700;
}

/* ---------------------------------------------------------------- start */
.modes { display: grid; gap: 14px; padding: 0; margin: 0; list-style: none; }
.mode {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
/* 最初に押すものを1つに絞る。塗りは「都道府県ではじめる」だけ、残り2つは枠線 */
.mode .button { width: 100%; }
.mode__label { color: var(--muted); font-size: .85rem; font-weight: 700; }
#pref-select {
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.mode__sub { margin: 0; color: var(--muted); font-size: .88rem; }
.mode__best { margin: 0; color: var(--ink); font-size: .92rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- loading */
.loading__text { color: var(--muted); }
.skeleton { border-radius: 12px; background: linear-gradient(90deg, #ece5d6, #f4eee1, #ece5d6); animation: pulse 1.2s ease-in-out infinite; }
.skeleton--shape { width: min(100%, 480px); max-height: 46vh; margin-inline: auto; aspect-ratio: 1; }
.skeleton-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.skeleton--choice { height: 56px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------------------------------------------------------------- playing */
/* シルエットのカードと4択・ヒント行を同じ幅の箱に入れる。
   カードだけ高さ基準（46vh）で幅を詰めると、4択より内側へ寄って揃えの線が切れる */
.play-grid { display: grid; gap: 14px; align-items: start; max-width: 480px; margin-inline: auto; }
.play-head { display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: center; margin-bottom: 6px; }
.progress { margin: 0; color: var(--muted); font-size: .9rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .06em; }
/* いまの得点。進み具合より読ませたいので墨色にする */
.progress--score { color: var(--ink); }
#quit-button { margin-left: auto; }
.shape-bed {
  position: relative;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
/* 縦の短い画面では高さだけ上限を掛ける。カードは4択と同じ幅のままなので、
   図は preserveAspectRatio="xMidYMid meet" で横長の枠の中央に置かれる（左右が余白になる） */
#shape { display: block; width: 100%; height: auto; max-height: 46vh; aspect-ratio: 1; }
#shape-path { fill: var(--ink); }
#shape.appear { animation: shape-in 240ms ease-out both; }
@keyframes shape-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

/* ボタンと同じ高さを常に確保する。ヒントを出しても回答しても、この行の高さは変わらない */
.hint-row { display: flex; min-height: 44px; align-items: center; justify-content: flex-start; }
/* 県内の位置はシルエットのカードの左下に重ねる。行が増えないので下の4択が動かない。
   カードの幅に合わせて縮める（小さい端末で主役のシルエットを隠しすぎないため） */
.hint {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: clamp(56px, 22%, 90px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
#hint-map { width: 100%; }
.hint__text { margin: 0; color: var(--ink); font-size: .92rem; font-weight: 700; }
/* ヒントを使わなかった問の控えめな記録。行の高さは変えず、色と太さだけ下げる */
.hint__text[data-tone="quiet"] { color: var(--muted); font-weight: 400; }
.mini-map { display: block; flex: none; width: 76px; height: auto; aspect-ratio: 1; }
/* 薄墨の塗りだけだと地に溶ける（1.74:1）。縁取りで輪郭を立てる。
   non-scaling-stroke なので viewBox の倍率が変わっても線の太さは同じ */
.mini-map__pref { fill: var(--faint); stroke: #8a8070; stroke-width: 1.25px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.mini-map__town { fill: var(--wrong); }

.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.choice {
  min-height: 60px;
  padding: 10px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.3;
}
.choice:hover:not(:disabled) { background: #efe8d8; }
.choice:disabled { opacity: 1; color: var(--muted); border-color: var(--line); }
.choice[data-result="correct"]:disabled { border-color: var(--correct); background: var(--correct-bg); color: var(--correct); }
.choice[data-result="wrong"]:disabled { border-color: var(--wrong); background: var(--wrong-bg); color: var(--wrong); }
/* 色だけに頼らず、正誤は記号でも伝える */
.choice .mark { margin-right: .35em; font-weight: 800; }
/* ヒントで消した選択肢。塗ると生き残りより目立つので、薄くするだけにする。
   取り消し線も引かない（押せないことは破線の枠と薄さで分かる） */
.choice[data-eliminated="true"] { border-style: dashed; border-color: var(--line); background: var(--surface); color: var(--muted); opacity: .45; }

/* 10問ぶんの丸。未回答は薄墨の枠、正解は深緑の塗り、ヒント正解は半分、不正解は朱の✕ */
.tracker {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 24px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.tracker li {
  position: relative;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--faint);
  border-radius: 999px;
}
.tracker li[data-mark="correct"] { border-color: var(--correct); background: var(--correct); }
.tracker li[data-mark="hint"] {
  border-color: var(--correct);
  background: linear-gradient(90deg, var(--correct) 0 50%, transparent 50% 100%);
}
.tracker li[data-mark="wrong"] { border-color: var(--wrong); }
.tracker li[data-mark="wrong"]::before {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--wrong);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* ---------------------------------------------------------------- reveal */
#reveal {
  margin-top: 14px;
  padding: 14px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  animation: reveal-in 220ms ease-out both;
}
/* スマホは自動スクロールで上の「3 / 10」が画面から出るので、ここにも進み具合を出す */
.reveal__progress { margin: 0 0 2px; color: var(--muted); font-size: .82rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.reveal__result { margin: 0; font-size: 1.1rem; font-weight: 800; }
#reveal[data-correct="true"] .reveal__result { color: var(--correct); }
#reveal[data-correct="false"] .reveal__result { color: var(--wrong); }
.reveal__name { margin: 2px 0 0; font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.25; }
.reveal__sub { margin: 2px 0 10px; color: var(--muted); font-size: .92rem; }
#reveal-map { margin: 0 0 12px; width: 96px; }
.reveal__note { margin: 0 0 12px; color: var(--muted); font-size: .92rem; }
.wiki {
  display: grid;
  /* 写真の無い記事では本文が全幅を使う（2列のままだとリンクと帰属が右へ潰れてはみ出す） */
  grid-template-columns: minmax(0, 1fr);
  gap: 10px 12px;
  align-content: start;
  /* 本文3行（＝写真の高さ）＋リンク行ぶんを先に確保する。
     要約が遅れて届いても、写真が付いても付かなくても「次へ」の位置は動かない。
     実測 130.05px にわずかに足りていなかった（0.05px でも丸めで1px動く）ので 132px にした */
  min-height: 132px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.wiki[data-thumb="true"] { grid-template-columns: auto minmax(0, 1fr); }
/* 本文3行と同じ高さにしておく。写真の有無で枠の高さが変わらない */
.wiki__thumb { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; }
.wiki__extract {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  margin: 0;
  color: var(--ink);
  font-size: .92rem;
}
/* 読み込み中と、取れなかったときの1行 */
.wiki:not([data-status="ready"]) .wiki__extract { color: var(--muted); }
/* リンクと帰属は写真の下ではなく枠の全幅に置く。狭い画面で2行に折れて高さが増えるのを防ぐ */
.wiki__foot { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; grid-column: 1 / -1; margin: 0; }
/* 紙と墨に青は混ぜない。リンクだと分かればよいので下線で示す */
.wiki__link { color: var(--ink); font-size: .9rem; font-weight: 700; text-decoration: underline; }
.wiki__link:hover { color: var(--muted); }
.wiki__license { color: var(--muted); font-size: .78rem; }
#next-button { margin-top: 4px; }

/* ---------------------------------------------------------------- result */
.result__score { margin: 0; font-size: clamp(2.6rem, 12vw, 4rem); font-weight: 800; letter-spacing: -.04em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.result__score:focus-visible { outline-offset: 6px; }
.result__mode { margin: 2px 0 0; color: var(--muted); }
.result__best { min-height: 1.6em; margin: 6px 0 12px; color: var(--correct); font-weight: 700; }
.result__head { min-width: 0; }
/* 朱は記号だけに使う。行ごと赤くすると、外した回数が画面の主役になってしまう */
.result__list { display: grid; gap: 4px; margin: 0 0 16px; padding-left: 1.6em; }
.result__list li { color: var(--ink); font-size: .95rem; }
.result__list li[data-mark="correct"] { font-weight: 700; }
.result__list .mark--correct { color: var(--correct); font-weight: 700; }
.result__list .mark--wrong { color: var(--wrong); font-weight: 700; }
.result__list .note { color: var(--muted); }
.result__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.copy-note { min-height: 1.5em; margin: 0 0 8px; color: var(--muted); font-size: .88rem; }
.error__text { font-size: 1.15rem; font-weight: 700; }

/* ---------------------------------------------------------------- 出典 */
.sources { padding: 14px 0 36px; border-top: 1px solid var(--line); color: var(--muted); font-size: .76rem; }
.sources p { margin: 0 0 6px; overflow-wrap: anywhere; }
.sources a { color: var(--ink); text-decoration: underline; }
.sources a:hover { color: var(--muted); }

@keyframes reveal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 899px) and (max-height: 700px) {
  /* 360×640 のような縦の短い端末でも、4択の下段まで画面に入れる。
     ヒントは重ねて出すので、開いても縮め直す必要はない */
  #shape, .skeleton--shape { max-height: 34vh; }
  .hint { bottom: 8px; left: 8px; padding: 5px; }
}

@media (min-width: 900px) {
  .modes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .play-grid { grid-template-columns: minmax(0, 440px) minmax(300px, 1fr); max-width: none; }
  .shape-bed { width: min(100%, 440px, 62vh); }
  /* 2カラムなので縦は詰めない。カードは正方形に戻る */
  #shape { max-height: none; }
  .skeleton--shape { width: min(100%, 440px, 62vh); max-height: none; }
  .choices { margin-top: 10px; }
  /* 見出しの横に例を置く。狭い画面では下に回る（.site-head は既定で縦積み） */
  .site-head { display: flex; gap: 32px; align-items: flex-end; justify-content: space-between; }
  .samples { margin-top: 0; }
  .samples__shape { width: 72px; }
  /* 点数と操作を左、10問の一覧を右に置く（1列のままだと右半分が空く）。
     出し分けの #app[data-state] より弱い指定だと display:block に負けるので、同じ前置きで書く */
  #app[data-state="result"] #result {
    display: grid;
    grid-template-areas: "head list" "foot list";
    grid-template-columns: minmax(280px, 1fr) minmax(0, 1.1fr);
    gap: 0 40px;
    align-items: start;
  }
  .result__head { grid-area: head; }
  #result-list { grid-area: list; margin-top: 6px; }
  .result__foot { grid-area: foot; }
}

@media (max-width: 480px) {
  .site-head, #app, .sources { width: min(100% - 24px, 1080px); }
  .site-head { padding-top: 14px; }
  .result__actions { grid-template-columns: 1fr; }
  /* 320px 級ではリンクと帰属が2行に折れる。その1行ぶんも先に確保しておく（実測 154.02px） */
  .wiki { min-height: 156px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
