/* Layout concept: one narrow RPG message window on the page.
   Status strip on top, progress pips, then a single stage that swaps between
   story card, countdown + choices, result and ending. */
:root {
  --bg: #e8ebf6;
  --panel: #fbfcff;
  --ink: #161a37;
  --ink-soft: #505780;
  --line: #b9c0e0;
  --accent: #3a45d1;
  --accent-ink: #ffffff;
  --bad: #b3243d;
  --good: #1d7a52;
  --tile: #dfe4f6;
  --tile-ink: #1b1b2f;
  --bar-bg: #d3d8ee;
  --shadow: #161a37;
  --font-d: 'DotGothic16', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'Noto Sans JP', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1124;
    --panel: #171b3a;
    --ink: #e9ecfb;
    --ink-soft: #98a2d2;
    --line: #2e3566;
    --accent: #f0c050;
    --accent-ink: #17142a;
    --bad: #ff7a8e;
    --good: #6fe0a8;
    --tile: #cfd6ef;
    --bar-bg: #262c58;
    --shadow: #04050e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1124;
  --panel: #171b3a;
  --ink: #e9ecfb;
  --ink-soft: #98a2d2;
  --line: #2e3566;
  --accent: #f0c050;
  --accent-ink: #17142a;
  --bad: #ff7a8e;
  --good: #6fe0a8;
  --tile: #cfd6ef;
  --bar-bg: #262c58;
  --shadow: #04050e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-d);
  font-size: 17px;
  line-height: 1.7;
  padding-block: 8px 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.app { max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }

.top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; line-height: 1.3; }
.brand { margin: 0; font-size: 15px; font-weight: normal; letter-spacing: .04em; }
.brand small { font-size: 11px; color: var(--ink-soft); margin-left: 4px; letter-spacing: 0; }
.collect { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.status { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.stat { background: var(--panel); border: 2px solid var(--line); padding: 2px 4px 1px; text-align: center; line-height: 1.2; }
.stat-l { display: block; font-size: 10px; color: var(--ink-soft); overflow-wrap: anywhere; }
.stat-v { display: block; font-size: 22px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat.neg .stat-v { color: var(--bad); }
.stat.up { animation: bumpUp .7s ease-out; border-color: var(--good); }
.stat.down { animation: bumpDown .7s ease-out; border-color: var(--bad); }
@keyframes bumpUp { 0% { transform: translateY(-6px); } 100% { transform: none; } }
@keyframes bumpDown { 0% { transform: translateY(6px); } 100% { transform: none; } }

.pips { list-style: none; margin: 0; padding: 0; display: flex; gap: 3px; }
.pips li { flex: 1 1 0; max-width: 30px; height: 21px; display: grid; place-items: center; font-size: 11px; line-height: 1; border: 2px solid var(--line); color: var(--ink-soft); }
.pips li.done { background: var(--line); color: var(--ink); }
.pips li.now { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.stage { display: flex; flex-direction: column; gap: 10px; }

.window {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 16px 14px 12px;
  min-height: 96px;
}
.window.tappable { cursor: pointer; }
.plate { position: absolute; top: -15px; left: 12px; background: var(--ink); color: var(--bg); font-size: 14px; padding: 0 10px; line-height: 26px; }
.line { margin: 0; font-size: 18px; line-height: 1.7; white-space: pre-line; text-wrap: pretty; }
.more { position: absolute; right: 12px; bottom: 6px; font-size: 12px; color: var(--ink-soft); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.portrait {
  width: 72px; height: 72px; margin: 2px auto 0;
  display: grid; place-items: center;
  background: var(--tile); color: var(--tile-ink);
  border: 3px solid var(--ink); font-size: 40px; line-height: 1;
}

.clock { display: flex; align-items: center; gap: 12px; }
.clock-num { font-size: 32px; line-height: 1; width: 3.4ch; text-align: right; font-variant-numeric: tabular-nums; }
.clock-bar { flex: 1; height: 14px; border: 3px solid var(--ink); background: var(--bar-bg); overflow: hidden; }
.clock-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left center; transform: scaleX(1); }
.clock-bar i.hot { background: var(--bad); }

.choices { display: grid; gap: 8px; }
.btn {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--shadow);
  padding: 9px 14px; line-height: 1.4; cursor: pointer; text-decoration: none;
  display: inline-flex; justify-content: center; align-items: center; gap: 12px;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--shadow); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--shadow); }
.btn:focus-visible { outline: 3px dashed var(--accent); outline-offset: 3px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: 3px 3px 0 var(--shadow); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.choice { justify-content: flex-start; text-align: left; min-height: 48px; font-size: 17px; }
.key { flex: none; width: 26px; height: 26px; display: grid; place-items: center; background: var(--ink); color: var(--bg); font-size: 14px; }
.txt { min-width: 0; overflow-wrap: anywhere; }
.next { align-self: center; min-width: 160px; }

.deltas { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; min-height: 30px; }
.chip { padding: 2px 12px; border: 2px solid currentColor; font-size: 15px; }
.chip.plus { color: var(--good); }
.chip.minus { color: var(--bad); }

.end { display: grid; gap: 12px; justify-items: center; text-align: center; }
.end-code { margin: 0; font-size: 22px; letter-spacing: .12em; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.new { display: inline-block; margin-left: 10px; padding: 0 8px; font-size: 12px; letter-spacing: .06em; background: var(--accent); color: var(--accent-ink); vertical-align: middle; }
.end-name { margin: 0; font-size: 30px; line-height: 1.35; font-weight: normal; text-wrap: balance; }
.art { width: 172px; padding: 14px; background: var(--tile); border: 3px solid var(--ink); box-shadow: 4px 4px 0 var(--shadow); }
.art svg { display: block; width: 100%; height: auto; }
.end-text { margin: 0; max-width: 34ch; white-space: pre-line; text-wrap: pretty; }
.reason { margin: 0; display: flex; gap: 10px; align-items: baseline; justify-content: center; flex-wrap: wrap; padding: 8px 14px; border: 2px solid var(--bad); }
.reason b { font-weight: normal; background: var(--bad); color: var(--bg); padding: 0 8px; font-size: 13px; }
.end.hidden .end-name, .end.clear .end-name { color: var(--accent); }

.detail { width: 100%; text-align: left; border-top: 2px dashed var(--line); padding-top: 10px; }
.detail summary { cursor: pointer; color: var(--ink-soft); font-size: 14px; }
.detail dl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 10px 0; }
.detail dt { font-size: 11px; color: var(--ink-soft); overflow-wrap: anywhere; }
.detail dd { margin: 0; font-size: 20px; font-variant-numeric: tabular-nums; }
.detail h3 { margin: 12px 0 4px; font-size: 13px; font-weight: normal; color: var(--ink-soft); }
.detail p { margin: 0; font-size: 15px; }
.detail ol { margin: 0; padding-left: 1.6em; font-size: 15px; }
.detail li { margin: 2px 0; }
.h-who { color: var(--ink-soft); margin-right: .6em; }

.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; width: 100%; margin-top: 4px; }
.actions .primary { grid-column: 1 / -1; }

.codex-head { display: flex; align-items: center; gap: 12px; }
.codex-head span { margin-left: auto; }
.codex-head h2 { margin: 0; font-size: 22px; font-weight: normal; }
.codex-head span { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.codex { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }
.codex li { border: 2px solid var(--ink); background: var(--panel); padding: 8px; display: grid; gap: 6px; justify-items: center; text-align: center; min-width: 0; }
.codex li.locked { border: 2px dashed var(--line); color: var(--ink-soft); }
.codex li.locked a:hover .c-hint { color: var(--ink); text-decoration: underline; }
.codex .c-art { width: 56px; background: var(--tile); padding: 6px; border: 2px solid var(--ink); }
.codex li.locked .c-art { background: transparent; border: 2px dashed var(--line); min-height: 56px; display: grid; place-items: center; font-size: 22px; }
.codex .c-art svg { display: block; width: 100%; height: auto; }
.codex .c-code { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.codex .c-name { font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }

@media (max-width: 420px) {
  .stat-l { font-size: 10px; }
  .line { font-size: 17px; }
  .end-name { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  .more { animation: none; }
  .stat.up, .stat.down { animation: none; }
  .btn:hover, .btn:active { transform: none; }
}

/* ---- 複数ページ化で追加した部分 ---- */
.brand-link { color: inherit; text-decoration: none; }
a.collect { text-decoration: none; }
a.collect:hover { color: var(--ink); text-decoration: underline; }

/* エンドへ移る瞬間の演出(暗転は使わず、点滅と揺れで切る) */
.flash { position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: 0; }
body.hit-fail .flash { background: var(--bad); animation: flash .56s ease-out forwards; }
body.hit-ok .flash { background: var(--accent); animation: flash .56s ease-out forwards; }
body.hit-fail .app { animation: shake .56s linear; }
@keyframes flash { 0% { opacity: .7; } 100% { opacity: 0; } }
@keyframes shake { 0%, 100% { transform: none; } 12% { transform: translateX(-7px); } 37% { transform: translateX(7px); } 62% { transform: translateX(-4px); } 85% { transform: translateX(3px); } }

/* エンドのページの到着演出(番号→名前→画像の順に出る) */
.end > *, .reveal > * { animation: stamp .91s cubic-bezier(.2, .9, .3, 1.15) both; animation-delay: calc(var(--i, 4) * .49s); }
.reveal { display: contents; }
@keyframes stamp { 0% { opacity: 0; transform: scale(1.08); } 100% { opacity: 1; transform: none; } }
/* ボタン周りは、動かさない(出る前に動く的を押してしまうのを防ぐ。透明度だけで出す) */
.end > .actions { animation-name: fadeOnly; }
@keyframes fadeOnly { 0% { opacity: 0; } 100% { opacity: 1; } }

.status-line { margin: 0; font-size: 14px; color: var(--ink-soft); }
.codex a { color: inherit; text-decoration: none; display: grid; gap: 6px; justify-items: center; width: 100%; }
@media (prefers-reduced-motion: reduce) {
  .flash, .end > * { animation: none !important; }
  body.hit-fail .app { animation: none; }
}
[hidden] { display: none !important; }

/* ---- 所持金の表示 ---- */
.row2 { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.purse { font-size: 15px; color: var(--ink-soft); white-space: nowrap; }
.purse b { font-weight: normal; font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; margin: 0 2px; }
.purse.up { animation: bumpUp .7s ease-out; }
.purse.down { animation: bumpDown .7s ease-out; }
.purse.up b { color: var(--good); }
.purse.down b { color: var(--bad); }
@media (prefers-reduced-motion: reduce) { .purse.up, .purse.down { animation: none; } }

.row3 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.gear { display: flex; gap: 12px; align-items: center; font-size: 11px; line-height: 1.3; color: var(--ink-soft); min-width: 0; }
.g-eq { display: flex; flex-direction: column; flex: none; }
.g-ally { min-width: 0; overflow-wrap: anywhere; }
.gear b { font-weight: normal; color: var(--ink); }
.purse { font-size: 13px; }
.purse b { font-size: 19px; }
.btn.small { padding: 3px 14px; font-size: 15px; min-height: 0; }

/* ---- 勝利エンドのフェードアウト ---- */
.veil { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; text-align: center;
  background: var(--bg); opacity: 0; transition: opacity 1.8s ease; }
.veil.on { opacity: 1; }
.veil-text { margin: 0; font-size: 22px; line-height: 2; white-space: pre-line; opacity: 0; transition: opacity 1.4s ease 1.9s; }
.veil.on .veil-text { opacity: 1; }

/* ---- キャラクターのアイコン ---- */
.portrait svg { display: block; width: 68px; height: 68px; }

/* ---- 図鑑: 区切りとヒント ---- */
.c-sec { display: grid; gap: 8px; margin-top: 6px; }
.c-phase { margin: 10px 0 0; font-size: 15px; font-weight: normal; display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 2px solid var(--line); padding-bottom: 4px; }
.c-phase span { color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums; }
.codex .c-hint { font-size: 12px; line-height: 1.5; color: var(--ink-soft); overflow-wrap: anywhere; }

/* ---- 未到達のエンド(ヒントだけを見せる) ---- */
.lock { display: grid; gap: 12px; justify-items: center; width: 100%; }
.art-lock { display: grid; place-items: center; height: 172px; font-size: 64px; color: var(--ink-soft); background: transparent; border: 3px dashed var(--line); box-shadow: none; }
.lock-msg { margin: 0; color: var(--ink-soft); }
.hint { width: 100%; text-align: left; border: 2px dashed var(--line); padding: 8px 12px; }
.hint summary { cursor: pointer; color: var(--ink); }
.hint p { margin: 8px 0 2px; font-size: 16px; line-height: 1.7; }

/* エンド画面: 図鑑・共有・📸の並び */
.actions-sub { grid-column: 1 / -1; display: flex; gap: 12px; }
.actions-sub .btn { flex: 1 1 0; }
.actions-sub .btn[hidden] { display: none; }
.actions-sub .btn.cam { flex: 0 0 auto; padding: 8px 14px; font-size: 18px; line-height: 1; }
/* 結果画像のビューア */
.viewer { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(6, 8, 20, .82); }
.viewer-box { width: min(440px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 12px; align-items: center; background: var(--panel); border: 3px solid var(--line); padding: 12px; }
.viewer-box img { width: 100%; height: auto; display: block; image-rendering: auto; }
.viewer-note { margin: 0; font-size: 13px; color: var(--ink-soft); text-align: center; }
.viewer-actions { display: flex; gap: 10px; width: 100%; }
.viewer-actions .btn { flex: 1 1 0; text-align: center; }

/* 横ずれ防止: 演出で横に広がっても、画面の幅を超えて広がらない(スマホで、タップの瞬間に画面がずれる原因) */
html, body { overflow-x: hidden; overflow-x: clip; }
.app { overflow-x: hidden; overflow-x: clip; }
/* タッチ端末では、触れた時にボタンを動かさない(隣のボタンに触れてしまうのを防ぐ) */
@media (hover: none) {
  .btn:hover, .btn:active { transform: none; box-shadow: 3px 3px 0 var(--shadow); }
  .btn:active { filter: brightness(.9); }
}
.actions-sub { margin-top: 6px; gap: 14px; }
.actions-sub .btn { min-height: 48px; }

/* フッターと、規約系ページ */
.foot { margin-top: 18px; padding: 12px 0 6px; border-top: 2px dashed var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.foot nav { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; }
.foot a { color: var(--ink-soft); padding: 4px 2px; }
.foot small { font-size: 12px; }
.doc { display: flex; flex-direction: column; gap: 12px; line-height: 1.85; }
.doc h2 { margin: 0; font-size: 22px; font-weight: normal; }
.doc h3 { margin: 10px 0 0; font-size: 17px; font-weight: normal; border-left: 5px solid var(--accent); padding-left: 10px; }
.doc p, .doc ul { margin: 0; font-size: 15px; }
.doc ul { padding-left: 1.3em; }
.doc a { color: var(--accent); word-break: break-all; }
.doc .upd { color: var(--ink-soft); font-size: 13px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.form .req { color: var(--bad); font-size: 12px; margin-left: 6px; }
.form input[type=text], .form input[type=email], .form select, .form textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--panel); border: 3px solid var(--ink); padding: 8px 10px; border-radius: 0; width: 100%; box-sizing: border-box; }
.form textarea { min-height: 150px; resize: vertical; line-height: 1.6; }
.form .agree { flex-direction: row; align-items: flex-start; gap: 10px; font-size: 14px; }
.form .agree input { margin-top: 4px; width: 20px; height: 20px; flex: none; }
.form .hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-msg { margin: 0; padding: 10px 14px; border: 2px solid var(--line); font-size: 15px; }
.form-msg.ok { border-color: var(--good); }
.form-msg.ng { border-color: var(--bad); }

.about { font-size: 13px; color: var(--ink-soft); margin-top: 8px; }
.about summary { cursor: pointer; padding: 4px 0; }
.about p { margin: 4px 0 0; line-height: 1.8; }
