/* 主役は金銀の会話ウィンドウ(紙に墨の二重線、欠けた角)。ほかは空色の地に平らに置き、影もグラデーションも使わない。
   色: 空(地)・紙(ウィンドウ)・墨(枠と文字)・ボールの赤(進むボタン)・HPの3色(残りで緑→黄→赤) */
:root {
  --sky: #cfe6fb;
  --paper: #f8fbff;
  --ink: #18233a;
  --ink-soft: #4a5872;
  --line: #b8c8dc;
  --ball: #d8343c;
  --hp-hi: #3fae5a;
  --hp-mid: #e8b221;
  --hp-lo: #e04848;
  --ok-bg: #e3f4e6;
  --ng-bg: #fbe4e4;
  --ok: #23803c;
  --ng: #c73232;
  --key-bg: #fff4d1;
  --pixel: "DotGothic16", "MS Gothic", monospace;
  --body: "BIZ UDPGothic", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--sky);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.75;
  -webkit-tap-highlight-color: transparent;
}
.app {
  max-width: 560px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: calc(env(safe-area-inset-top, 0px) + 16px) calc(env(safe-area-inset-bottom, 0px) + 32px);
  display: grid;
  gap: 14px;
}
h1, h2 { font-family: var(--pixel); font-weight: 400; letter-spacing: .04em; text-wrap: balance; margin: 0; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
a { color: var(--ink); }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--ball); outline-offset: 2px; }

/* 会話ウィンドウ(主役) */
.win {
  position: relative; background: var(--paper); padding: 14px 16px;
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px var(--paper), inset 0 0 0 5px var(--ink);
  clip-path: polygon(4px 0, calc(100% - 4px) 0, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 0 calc(100% - 4px), 0 4px);
}
.win p { margin: 0; }

/* ボタン: 進む操作は赤、ほかは紙。どちらも墨の枠 */
.primary, .actions button, .facility-fields button, .settings button, .secondary {
  display: block; width: 100%; text-align: center; text-decoration: none; cursor: pointer;
  border: 3px solid var(--ink); border-radius: 0; padding: 12px 16px;
  background: var(--paper); color: var(--ink); font-family: var(--pixel); font-size: 1rem;
}
.primary, .actions .primary { background: var(--ball); color: var(--paper); }
.danger, .settings .danger { background: var(--ng); color: var(--paper); }
.where { margin: 0; font-family: var(--pixel); font-size: .9rem; }
.where small { font-family: var(--body); font-size: .8rem; color: var(--ink-soft); margin-left: 8px; }

.banner {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; gap: 8px; align-items: center;
  background: var(--key-bg); border-bottom: 3px solid var(--ink); padding: 10px 16px; font-size: .9rem;
}
.banner span { flex: 1; min-width: 0; }
.banner button { border: 2px solid var(--ink); background: var(--paper); padding: 4px 10px; cursor: pointer; font-family: var(--pixel); }

/* 会話 */
.scene { display: grid; gap: 10px; align-content: start; min-height: calc(100dvh - 130px); cursor: pointer; }
/* 場所の絵の下に文字ウィンドウ。画面のどこをタップしても進む */
.stage {
  position: relative; height: auto; aspect-ratio: 9 / 5; min-height: 200px; overflow: hidden; border: 3px solid var(--ink);
  background: var(--sky) center / cover no-repeat; image-rendering: pixelated;
}
.talk .win { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.face { width: 80px; height: 80px; display: grid; place-items: end center; overflow: hidden; }
.portrait { height: 80px; width: auto; max-width: none; image-rendering: pixelated; }
.face-mon .sprite { width: 80px; height: 80px; }
.say { min-width: 0; grid-column: 2; }
.partner-chip {
  display: inline-block; font-family: var(--pixel); color: var(--paper); background: var(--type, var(--ink));
  padding: 1px 10px; font-size: .85rem;
}
.talk { all: unset; display: block; cursor: pointer; }
.talk:focus-visible .win { outline: 3px solid var(--ball); outline-offset: 3px; }
.talk .win { min-height: 112px; }
.talk .name { display: block; font-family: var(--pixel); font-size: .85rem; color: var(--ink-soft); }
.talk .line { margin: 0; white-space: pre-wrap; }
.talk .tapnext { position: absolute; right: 14px; bottom: 8px; font-size: .8rem; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ノート */
.note { background: var(--paper); border: 3px solid var(--ink); padding: 18px 16px; display: grid; gap: 12px; min-width: 0; }
.note .tag { margin: 0; font-family: var(--pixel); font-size: .8rem; color: var(--ink-soft); }
.note p { margin: 0; white-space: pre-wrap; }
.note h3 { font-size: 1rem; margin: 18px 0 0; padding-bottom: 4px; border-bottom: 2px solid var(--ink); }
.note .example { border: 2px solid var(--ink); background: var(--paper); padding: 10px 12px; }
.note .example-q { margin: 0 0 6px; font-weight: 700; }
.note .example-label { display: inline-block; background: var(--ink); color: var(--paper); font-size: .75rem; padding: 1px 6px; margin-right: 8px; }
.note .example ol { margin: 0; padding-left: 1.4em; display: grid; gap: 4px; white-space: pre-wrap; }
.note .example-a { margin: 8px 0 0; font-weight: 700; }
.note .key { background: var(--key-bg); border-left: 5px solid var(--ink); padding: 8px 12px; white-space: pre-wrap; }
.note .exam { border: 2px dashed var(--ink-soft); padding: 10px 12px; }
.note .exam-label { display: block; font-family: var(--pixel); font-size: .8rem; color: var(--ink-soft); }
.note .fig { margin: 0; overflow-x: auto; }
.note .fig svg { display: block; max-width: 100%; height: auto; margin: 0 auto; color: var(--ink); }
.note .fig figcaption { text-align: center; font-size: .8rem; color: var(--ink-soft); }
.table-wrap { overflow-x: auto; }
.note table { border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.note th, .note td { border: 2px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.note th { background: var(--sky); }
.note tr > :first-child { white-space: nowrap; }

/* 問題(バトル) */
.quiz { display: grid; gap: 12px; min-width: 0; }
.quiz-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-family: var(--pixel); }
.quiz-head .count { font-size: .85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.foe { display: flex; align-items: flex-start; gap: 8px; padding-bottom: 10px; border-bottom: 3px solid var(--ink); }
.foe-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.sprite { width: 96px; height: 96px; image-rendering: pixelated; object-fit: contain; flex: none; mix-blend-mode: multiply; }
.foe .foe-sprite { order: 2; }
.quiz .my-sprite { justify-self: start; margin-bottom: -4px; }
.home-head .partner { display: flex; align-items: center; gap: 8px; }
.home-head .partner .sprite { width: 64px; height: 64px; }
.hp { display: flex; align-items: center; gap: 6px; font-family: var(--pixel); font-size: .75rem; }
.hp .lab { background: var(--ink); color: var(--paper); padding: 0 4px; }
.hp-bar { flex: 1; height: 10px; border: 2px solid var(--ink); background: var(--paper); }
.hp-fill { display: block; height: 100%; background: var(--hp-hi); transition: width .5s steps(8); }
.hp-fill.mid { background: var(--hp-mid); }
.hp-fill.lo { background: var(--hp-lo); }
.quiz .q { white-space: pre-wrap; }
.opts { background: var(--paper); border: 3px solid var(--ink); display: grid; }
.opt {
  display: grid; grid-template-columns: 1.4em 1.6em 1fr; align-items: baseline; text-align: left;
  background: transparent; border: 0; border-top: 2px solid var(--line); padding: 10px 12px; cursor: pointer;
}
.opt:first-child { border-top: 0; }
.opt .arrow { font-size: .8rem; visibility: hidden; }
.opt:hover .arrow, .opt:focus-visible .arrow, .opt.picked .arrow { visibility: visible; }
.opt b { font-family: var(--pixel); font-weight: 400; color: var(--ink-soft); }
.opt.ok { background: var(--ok-bg); }
.opt.ng { background: var(--ng-bg); }
.opt:disabled { cursor: default; color: var(--ink); }
.opt:focus-visible { outline: 3px solid var(--ball); outline-offset: -3px; }
.feedback { display: grid; gap: 10px; }
.verdict { font-family: var(--pixel); }
.verdict.ok { color: var(--ok); }
.verdict.ng { color: var(--ng); }
.expl { margin: 0; padding: 0; list-style: none; display: grid; font-size: .92rem; border-top: 2px solid var(--line); }
.expl li { display: grid; grid-template-columns: 1.6em 1fr; padding: 8px 0; border-bottom: 2px solid var(--line); }
.expl li b { font-family: var(--pixel); font-weight: 400; }
.expl li.is-answer { background: var(--ok-bg); }
.note-open { border: 0; background: none; padding: 0; cursor: pointer; justify-self: start; text-decoration: underline; font-family: var(--pixel); }
.note-dialog { border: 3px solid var(--ink); border-radius: 0; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: 85vh; background: var(--sky); }
.note-dialog::backdrop { background: rgba(24, 35, 58, .55); }
.note-dialog .note { border: 0; }

/* 結果 */
.result { display: grid; gap: 12px; }
.result .win { text-align: center; display: grid; gap: 6px; }
.result h2 { font-size: 1.15rem; }
.result .score { font-variant-numeric: tabular-nums; font-weight: 700; }
.actions { display: grid; gap: 8px; }

/* ホーム: トレーナーカード、道でつながった町、スタートメニュー */
.home-head { background: var(--paper); border: 3px solid var(--ink); padding: 14px; display: grid; gap: 10px; }
.home-head .trainer { margin: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.home-head .name { font-family: var(--pixel); font-size: 1.3rem; }
.home-head .partner-chip { border: 2px solid var(--ink); }
.badges { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 0; padding: 0; list-style: none; }
.badges li { aspect-ratio: 1; max-width: 100%; border: 2px solid var(--line); border-radius: 50%; }
.badges li.got { border-color: var(--ink); background: radial-gradient(circle at 35% 35%, #fff6c8 0 20%, var(--hp-mid) 21%); }
.home-head .stats { margin: 0; color: var(--ink-soft); font-size: .88rem; font-variant-numeric: tabular-nums; }
.home-continue { font-size: 1.1rem; padding: 14px; }
.home-wip { margin: 0; }
.map { list-style: none; margin: 0; padding: 0 0 0 30px; position: relative; display: grid; gap: 12px; }
.map::before { content: ""; position: absolute; left: 10px; top: 10px; bottom: 10px; border-left: 3px dotted var(--ink-soft); }
.map li { position: relative; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.map li::before { content: ""; position: absolute; left: -28px; top: 6px; width: 12px; height: 12px; background: var(--paper); border: 3px solid var(--ink); }
.map li[data-status="done"]::before { background: var(--ink); }
.map li[data-status="town"]::before, .map li[data-status="gym"]::before, .map li[data-status="road"]::before { background: var(--ball); }
.map .town { font-family: var(--pixel); }
.map li[data-status="locked"] .town { color: var(--ink-soft); }
.status { font-size: .8rem; color: var(--ink-soft); white-space: nowrap; }
.field-stats { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.field-stats li { display: grid; gap: 4px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.meter { height: 10px; border: 2px solid var(--ink); background: var(--paper); }
.meter i { display: block; height: 100%; background: var(--ink); }
.muted { margin: 0; color: var(--ink-soft); }
.home-nav { background: var(--paper); border: 3px solid var(--ink); display: grid; }
.home-nav a { display: grid; grid-template-columns: 1.4em 1fr; padding: 10px 12px; text-decoration: none; font-family: var(--pixel); border-top: 2px solid var(--line); }
.home-nav a:first-child { border-top: 0; }
.home-nav a::before { content: "▶"; font-size: .8rem; visibility: hidden; }
.home-nav a:hover::before, .home-nav a:focus-visible::before { visibility: visible; }

/* 道路 */
.road { display: grid; gap: 12px; }
.road-progress { margin: 0; font-variant-numeric: tabular-nums; }
.trainer-card { display: flex; align-items: center; gap: 12px; }
.trainer-pic { height: 120px; image-rendering: pixelated; flex: none; }
.trainer-name { font-family: var(--pixel); }

/* ノート帳・バトル施設・設定 */
.list { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 3px solid var(--ink); display: grid; }
.list a { display: grid; grid-template-columns: 1.4em 1fr; padding: 10px 12px; text-decoration: none; border-top: 2px solid var(--line); }
.list li:first-child a { border-top: 0; }
.list a::before { content: "▶"; font-size: .8rem; visibility: hidden; }
.list a:hover::before, .list a:focus-visible::before { visibility: visible; }
.facility-fields { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.settings { display: grid; gap: 16px; }
.settings section { background: var(--paper); border: 3px solid var(--ink); padding: 16px; display: grid; gap: 8px; min-width: 0; }
.settings label { font-family: var(--pixel); }
.settings input, .settings textarea { width: 100%; font: inherit; border: 2px solid var(--ink); border-radius: 0; padding: 8px 10px; background: #fff; }
.settings textarea { font-family: ui-monospace, monospace; font-size: .8rem; }
.settings .msg { margin: 0; font-size: .9rem; color: var(--ink-soft); }
.import-errors { margin: 0; color: var(--ng); font-size: .9rem; }

/* プロローグ */
.form-card { background: var(--paper); border: 3px solid var(--ink); padding: 16px; display: grid; gap: 10px; }
.form-card p { margin: 0; }
.form-card label { font-family: var(--pixel); }
.form-card input { font: inherit; font-size: 1.1rem; border: 2px solid var(--ink); border-radius: 0; padding: 10px 12px; width: 100%; }
.form-error { margin: 0; color: var(--ng); font-size: .9rem; }
.partner-choices { display: grid; border: 3px solid var(--ink); }
.partner-choices button { border: 0; border-top: 2px solid var(--line); padding: 12px; background: var(--paper); cursor: pointer; text-align: left; display: flex; gap: 10px; align-items: center; }
.partner-choices button:has(.sprite) { flex-wrap: wrap; justify-content: center; text-align: center; }
.partner-choices button:has(.sprite)::before { display: none; }
.partner-choices .sprite { width: 96px; height: 96px; flex-basis: 100%; }
.partner-choices button:first-child { border-top: 0; }
.partner-choices button[aria-pressed="true"] { background: var(--ok-bg); }
.partner-choices button[aria-pressed="true"]::before { content: "▶"; font-size: .8rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
