/*
 * 探偵小説誌の組版規律を、札を掲げずに画面へ移す。密度は罫線と表と組版で作り、装飾では作らない。
 * 地は明度を少し落とした白。白いカードと濃紺の帯をコンポーネントごとに塗る。墨のインク、○ は朱、× は墨、関係ないは灰。
 * 本文は明朝（Zen Old Mincho）、見出しはアンチック体（Shippori Antique B1）、記録と操作はゴシック（Zen Kaku Gothic New）。
 * 表の上下は太罫、行間は尺が区切る。確信の帯は 10 目盛の尺の上に置く測定値。核心に触れた質問は傍点。
 * 見た目の決まりの全体は DESIGN.md を見る。
 */
:root {
  color-scheme: light dark;
  --bg: #efefec;
  --panel: #ffffff;
  --fg: #1b1b1a;
  --muted: #5e5e5a;
  --rule: #c9c9c3;
  --band: #ffffff;
  --on-band: #1b1b1a;
  --solid: #1f2b4d;
  --on-solid: #ffffff;
  --yes: #b8382a;
  --no: #1b1b1a;
  --grey: #6a6a64;
  --grey-ink: #85857f;
  --story: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", "Noto Serif JP", serif;
  --display: "Shippori Antique B1", "Zen Old Mincho", "Hiragino Mincho ProN", serif;
  --ui: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", "Yu Gothic", "Noto Sans CJK JP", "Noto Sans JP", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f121b;
    --panel: #222a3c;
    --fg: #e8e6de;
    --muted: #a3a399;
    --rule: #3e465c;
    --band: #222a3c;
    --on-band: #e8e6de;
    --solid: #e8e6de;
    --on-solid: #0f121b;
    --yes: #e8735f;
    --no: #e8e6de;
    --grey: #9a9ca6;
    --grey-ink: #7f818c;
  }
}

* { box-sizing: border-box; }
/* 縦スクロールバーの有無で中央がずれないよう、余白を常に確保する */
html { background: var(--bg); scrollbar-gutter: stable; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  font: 400 15px/1.7 var(--ui); -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
::selection { background: var(--solid); color: var(--on-solid); }
:focus-visible { outline: 2px solid var(--yes); outline-offset: 2px; }
button, input, textarea { font-family: inherit; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 1; padding: 0.5rem 0.8rem; background: var(--solid); color: var(--on-solid); }
.skip:focus { left: 16px; }

/* 柱。濃紺の帯に誌名とタグライン、右に「問題を作る」。下に細罫 */
.hashira { background: var(--band); color: var(--on-band); border-bottom: 1px solid var(--rule); }
.hashira .in {
  max-width: 960px; margin: 0 auto; padding: 0.7rem 20px;
  display: flex; align-items: baseline; gap: 1.4em; font: 400 0.82rem/1.5 var(--ui); letter-spacing: 0.02em;
}
.hashira .mag { font: 700 1.45rem/1.3 var(--story); letter-spacing: 0.05em; text-decoration: none; white-space: nowrap; }
.hashira .mag .shell { vertical-align: -0.22em; margin-right: 0.35em; }
.hashira .tagline { margin: 0; font: 400 0.85rem/1.5 var(--ui); letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
.thinking .shell { vertical-align: -0.2em; margin-right: 0.2em; }
.hashira nav { margin-left: auto; }
main.page { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: 0 20px 3rem; }

/* 見開き。左に問題のカード、右に表と入力欄（閲覧ページはヒントと共有、みんなの質問は集計と表） */
main.spread { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 0 2.4rem; align-items: start; padding-top: 1.6rem; }
/* 中身が短いとき、伸びた main の高さを行が分け合ってカードの下が空くので、上に詰める。出題ページは表と入力欄の配置に使うので除く */
main.spread:not(.play) { align-content: start; }
.problem { position: relative; overflow: hidden; background: var(--panel); padding: 1.4rem 1.5rem 1.6rem; }
/*
 * 見開きはページを画面に収め、カードと右の列がそれぞれの中で動く。柱は留まる。
 * 出題とみんなの質問は表（.history）だけが動き、太罫は表の枠になって行はその間を流れる。閲覧ページは右の列ごと動く。
 * 問題文と真相が長くても、カードの中で送れば全部読める
 */
@media (min-width: 721px) {
  body:has(main.spread) { height: 100dvh; }
  main.spread { min-height: 0; grid-template-rows: minmax(0, 1fr); padding-bottom: 1rem; }
  main.spread .problem { max-height: 100%; overflow-y: auto; }
  main.spread .game, main.spread .questions { display: flex; flex-direction: column; align-self: stretch; min-height: 0; }
  main.spread .owner { max-height: 100%; overflow-y: auto; }
  /* relative は絶対配置の .star（読み上げ用の ★）を枠の中に閉じ込めるため。無いと文書の底へ落ちてページがスクロールする */
  main.spread .history { position: relative; flex: 1; min-height: 0; overflow-y: auto; scrollbar-gutter: stable; border-top: 2px solid var(--fg); border-bottom: 2px solid var(--fg); }
  main.spread .log, main.spread .log-empty { border-top: 0; border-bottom: 0; }
  main.play .result { padding-bottom: 1rem; }
  main.play .controls { position: static; }
}
/* 右上に大きな薄い「？」を切れるほどに置く */
/* 飾りの箱はカードの底までに収め、はみ出す字は切る。低いカードで箱が底を越えると、出題ページではスクロールバーになる */
.problem::before { content: "？"; position: absolute; right: -0.3em; top: -0.12em; bottom: 0; overflow: hidden; font: 400 9rem/1 var(--display); color: var(--fg); opacity: 0.06; pointer-events: none; }
.problem > * { position: relative; }
.problem h1 { margin: 0; font: 400 1.65rem/1.35 var(--display); letter-spacing: 0.05em; text-wrap: balance; overflow-wrap: anywhere; }
.problem .story { margin-top: 1.1rem; }
.story { font: 400 1.0625rem/2 var(--story); letter-spacing: 0.03em; white-space: pre-line; overflow-wrap: anywhere; margin: 0; }

/*
 * ボタンは主（濃紺のベタ）と副（罫囲み）の 2 段。行動のボタンは対象のそばに、移動のボタンは列の底に中央寄せで
 * 出口として置く（.actions）。移動には一律に山形（.go）を添える。文中のリンクは下線つきの文字に山形
 */
button, .button {
  display: inline-block; font: 700 0.92rem/1.2 var(--ui); letter-spacing: 0.12em; text-indent: 0.12em;
  padding: 0.62em 1.05em 0.6em; border: 1.5px solid var(--solid); border-radius: 2px; background: none; color: var(--solid);
  cursor: pointer; text-decoration: none; touch-action: manipulation;
}
button:hover, .button:hover { background: color-mix(in srgb, var(--solid) 8%, transparent); }
.primary { background: var(--solid); color: var(--on-solid); }
.primary:hover { background: color-mix(in srgb, var(--solid) 88%, var(--fg)); }
.small { font-size: 0.82rem; padding: 0.45em 0.9em 0.42em; }
/* 移動の印。罫を 2 辺だけ引いて回した山形。文字色に従うので、ベタでも罫囲みでも文中でも同じに効く */
.go::after {
  content: ""; display: inline-block; width: 0.42em; height: 0.42em; margin-left: 0.45em; vertical-align: 0.12em;
  border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; transform: rotate(45deg);
}
button:disabled { opacity: 0.45; cursor: wait; }

/* 表。上下は太罫、行間に罫は引かず、底の尺が行を区切る。番号、発言、判定印、底に尺 */
.game { margin-top: 0; }
.log { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--fg); border-bottom: 2px solid var(--fg); }
.log:empty { display: none; }
/* まだ問答が無いとき。表の太罫だけ引いて、ここに並ぶことを示す */
.log-empty { margin: 0; padding: 1.2em 0.2em; border-top: 2px solid var(--fg); color: var(--muted); font-size: 0.92rem; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 0.8em; align-items: baseline; padding: 1em 0.2em 0.6em; }
.line.hint .n { font: 400 0.68rem/2.2 var(--ui); letter-spacing: 0; white-space: nowrap; color: var(--muted); }
.q { font-size: 1rem; overflow-wrap: anywhere; color: var(--v, var(--fg)); }
.q.good { text-emphasis: filled sesame currentColor; -webkit-text-emphasis: filled sesame currentColor; text-emphasis-position: over right; }
.star { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.verdict { font-size: 0.92rem; font-weight: 700; line-height: 1.6; white-space: nowrap; letter-spacing: 0.04em; color: var(--v, var(--grey)); }
.verdict .mark { display: inline-block; width: 1.4em; font-size: 1.15em; font-weight: 400; }
.line.hint { grid-template-columns: auto minmax(0, 1fr); }
.line.hint .q { color: var(--muted); font-size: 0.95rem; }
/* 尺。朱=はい 墨=いいえ 灰=関係ない の帯を発言のすぐ下に置き、10 目盛を帯から垂らす。
 * 帯が行の底に沈むと次の発言に寄って見え、目盛が行の罫に接すると罫から生えて見える。どちらも帯にくっつけて行の罫から離す */
.dist {
  grid-column: 1 / -1; display: flex; align-items: flex-start; height: 7px; margin-top: 0.2em;
  background: repeating-linear-gradient(to right, var(--rule) 0 1px, transparent 1px 10%) 0 3px / 100% 4px no-repeat;
}
.dist i { display: block; height: 3px; }
.s-yes { background: var(--yes); } .s-no { background: var(--no); } .s-irr { background: var(--grey-ink); } .s-score { background: var(--v, var(--fg)); }
.line.hint .dist { background: none; height: 0.6em; }
.line.plain .dist { background: none; height: 0.6em; }
.v-yes, .v-correct { --v: var(--yes); }
.v-no, .v-wrong, .v-unclear, .v-close, .v-partial { --v: var(--fg); }
.v-irrelevant, .v-other { --v: var(--grey); }
/* 正解の行。色や面は足さず、組みの強弱で他の行より一段強くする。◎ は線で描き、到着のときに筆順どおりに書く */
.line.v-correct .q { font-weight: 700; font-size: 1.1rem; }
.line.v-correct .verdict { font-size: 1.1rem; }
.line.v-correct .dist { height: 9px; }
.line.v-correct .dist i { height: 5px; }
.ring { width: 1.4em; height: 1em; vertical-align: -0.12em; overflow: visible; }
.ring circle { fill: none; stroke: currentColor; stroke-width: 1.4; }

.notice { margin: 0; padding: 0.6rem 0 0; border-top: 1px solid var(--rule); color: var(--yes); font-weight: 600; font-size: 0.92rem; }

/* 入力欄と送信。カードにはせず、白い欄とボタンだけを地の上に置く。ページごとスクロールするスマホでは画面の下に留まる */
.controls { position: sticky; bottom: 0; margin-top: 1rem; padding: 0.8rem 0 1rem; background: var(--bg); }
.controls input[type="text"] {
  width: 100%; font: 400 1.05rem/1.6 var(--ui); color: var(--fg); background: var(--panel);
  border: 1px solid var(--rule); border-radius: 2px; padding: 0.55em 0.85em; outline: none;
}
.controls input[type="text"]:focus-visible { outline: none; border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.controls .row { display: flex; align-items: stretch; gap: 0.6rem; }
.controls .row .primary { padding-block: 0; }
/* ヒントと降参。表の上に、小さめの副ボタンとして */
.game .tools { display: flex; justify-content: space-between; margin: 0 0 0.6rem; }
.controls .row input[type="text"] { flex: 1; min-width: 0; }
/* 右揃え。主ボタンを DOM の先頭に置いたまま右端に出すために右から並べる */
.buttons { display: flex; flex-direction: row-reverse; align-items: center; gap: 0.5rem; margin-top: 0.8rem; }
.buttons .thinking { margin: 0 0.4rem; }
.thinking { color: var(--muted); font-size: 0.88rem; margin: 0.7rem 0 0; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { transition: opacity 0s linear 250ms; }

/* 真相。正解か降参のあと、破線の下に本文と成績 */
.result { margin-top: 1.8rem; padding-top: 0.8rem; border-top: 1px dashed var(--fg); }
.result .head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.result h2 { margin: 0; font: 700 0.95rem/1.6 var(--ui); letter-spacing: 0.2em; }
.result .truth { margin-top: 0.6rem; background: var(--panel); padding: 1rem 1.2rem 0.9rem; }
.result .truth .story { margin: 0; }
.stats { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; margin: 0; letter-spacing: 0.02em; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.7rem; margin: 2.2rem 0 0; }
.actions .button { text-align: center; }

.lead { margin: 0; font: 400 0.9rem/1.8 var(--ui); color: var(--muted); }

/* 作成フォーム。白い欄を地の上に置き、説明は欄の周りに置かず ? で開く */
.new { display: flex; flex-direction: column; gap: 1.3rem; padding-top: 1.8rem; }
.new h1 { margin: 0 0 0.2rem; font: 400 1.5rem/1.35 var(--display); letter-spacing: 0.05em; }
.field { display: grid; gap: 0.35rem; min-width: 0; }
.field-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.75rem; }
.field-head label { font-weight: 700; }
.note { color: var(--muted); font-size: 0.85rem; margin: 0; }
.field input[type="text"], .field textarea, .share-row input {
  width: 100%; font: 400 1rem/1.6 var(--ui); padding: 0.6rem 0.85rem;
  border: 1px solid var(--rule); border-radius: 2px; background: var(--panel); color: var(--fg);
}
.field input[type="text"]:focus-visible, .field textarea:focus-visible, .share-row input:focus-visible { outline: none; border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); }
input, textarea { caret-color: var(--yes); }
.field textarea { resize: vertical; }
.field input.story-input, .field textarea.story-input { font: 400 1.0625rem/1.9 var(--story); }
.field.invalid input, .field.invalid textarea { border-color: var(--yes); }
.error { margin: 0; color: var(--yes); font-size: 0.9rem; }
.error p { margin: 0; }

/* popover。白いカードに墨の罫 */
.pop {
  width: min(32rem, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  padding: 1.25rem 1.4rem 1.4rem; border: 1px solid var(--fg); border-radius: 2px;
  background: var(--panel); color: var(--fg); box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.pop::backdrop { background: rgb(20 24 38 / 0.15); }
.pop h2 { margin: 0 2rem 0.7rem 0; font: 400 1rem/1.5 var(--display); letter-spacing: 0.2em; }
.pop p { margin: 0 0 0.6rem; font-size: 0.95rem; }
.pop-close {
  position: absolute; top: 0.6rem; right: 0.6rem; width: 2rem; height: 2rem; padding: 0; border: 0;
  border-radius: 50%; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; letter-spacing: 0; text-indent: 0;
}
.pop-close:hover { background: var(--bg); color: var(--fg); }
/* 閲覧ページ。右の列に遊ぶ代わりに、ヒント・共有 URL とみんなの質問への入口を並べる（真相は左のカード） */
.owner { display: grid; gap: 1.6rem; padding-top: 0.4rem; }
.owner h2 { margin: 0 0 0.5rem; font: 700 0.95rem/1.6 var(--ui); letter-spacing: 0.2em; }
.owner .hints { margin: 0; padding-left: 1.6em; font: 400 0.95rem/1.9 var(--story); letter-spacing: 0.03em; }
.owner .share-row { margin-top: 0; }
/* 閲覧ページとみんなの質問の左のカードは問題文の下に破線を引いて真相。みんなの質問の右は見出しの横に集計、判定の select、問答と同じ表 */
.problem-truth { margin-top: 1.4rem; padding-top: 0.8rem; border-top: 1px dashed var(--fg); }
.problem-truth h2 { margin: 0; font: 700 0.95rem/1.6 var(--ui); letter-spacing: 0.2em; }
.problem-truth .story { margin-top: 0.5rem; }
.questions { padding-top: 0.4rem; }
.questions .head { display: flex; align-items: baseline; justify-content: space-between; gap: 0 1rem; flex-wrap: wrap; }
.questions h2 { margin: 0; font: 700 0.95rem/1.6 var(--ui); letter-spacing: 0.2em; }
.filter { display: flex; align-items: center; gap: 0.6rem; margin: 0.6rem 0 1rem; font-size: 0.9rem; }
.filter label { font-weight: 700; }
.filter select { font: 400 0.95rem/1.5 var(--ui); padding: 0.35rem 0.6rem; border: 1px solid var(--rule); border-radius: 2px; background: var(--panel); color: var(--fg); }
.filter select:focus-visible { outline: none; border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); }
.questions .history > .note { margin: 0.5rem 0; }
/* 列の底の出口。遊び終わりの出口（.actions）より上の詰めを狭める */
.actions.exit { margin-top: 0.6rem; }
.questions .actions.exit { margin-top: 1.2rem; }
.share-row { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.share-row input { flex: 1; min-width: 0; }
.share-row button { white-space: nowrap; }

@media (max-width: 720px) {
  main.page, .hashira .in { padding-inline: 16px; }
  .hashira .in { flex-wrap: wrap; gap: 0.2em 1em; }
  .hashira .tagline { order: 2; width: 100%; white-space: normal; margin-top: -0.2em; }
  main.spread { grid-template-columns: 1fr; gap: 0; padding-top: 1rem; }
  .problem { padding: 1.2rem 1.1rem 1.3rem; }
  .problem h1 { font-size: 1.45rem; }
  /* パネルの箱を消して、入力欄の sticky の枠を main にする。問答が少なくて表が短いうちから入力欄が画面の底に留まる */
  .game { display: contents; }
  .tools, input + .history, .owner, .questions { margin-top: 1.4rem; }
  /* 入力欄の下を詰める。頁の底の余白は無くし、考え中の 1 行は入力欄の上に重ねて場所を取らない */
  main.play { padding-bottom: 0; }
  .controls { padding-bottom: 0.6rem; }
  .thinking { position: absolute; left: 0; right: 0; bottom: 100%; margin: 0; background: var(--bg); }
  .verdict { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .game .line:last-child { animation: arrive 240ms ease-out; }
  @keyframes arrive { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
  .result .truth { animation: open 420ms cubic-bezier(0.2, 0.8, 0.2, 1); }
  @keyframes open { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }
  .htmx-request .htmx-indicator, .htmx-request.htmx-indicator { transition: opacity 150ms ease-in 250ms; }
  .game .line.v-correct:last-child .ring circle { stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw 320ms ease-out 200ms forwards; }
  .game .line.v-correct:last-child .ring circle + circle { animation-delay: 440ms; }
  @keyframes draw { to { stroke-dashoffset: 0; } }
  .game .line.v-correct:last-child .verdict .mark + * { animation: show 200ms ease-out 650ms both; }
  @keyframes show { from { opacity: 0; } }
  /* 正解のときは ◎ を書き終えてから真相を開く */
  .result.solved { animation: show 240ms ease-out 900ms both; }
  .result.solved .truth { animation-delay: 900ms; animation-fill-mode: both; }
}
