/* 犯人はこの中にいる — 見た目
 *   夜の捜査ボード。地は墨色、事件はクラフト紙のファイル。
 *   札の色で進み具合が見える: 容疑者は暗い札 → 無実は白い紙 → 犯人は赤い札。解くほど盤が明るくなる。
 *   «無実»«犯人» はゴム印。数字（人数・時間・日付）は等幅。
 *   骨格はルート AGENTS.md のとおり（普通にスクロールするページ。fixed は使わない）
 */
[hidden] { display: none !important; }
/* 言語は <html lang> で片方を伏せる（src/lang.js が描く前に決める） */
html[lang="ja"] [lang="en"], html[lang="en"] [lang="ja"] { display: none !important; }

:root {
  --bg: #121417;
  --surface: #1a1d22;
  --surface2: #22262c;
  --line: rgba(255, 255, 255, .08);
  --text: #ebe6dd;
  --sub: #948f86;
  --kraft: #c9ad78;
  --kraft-ink: #2a2116;
  --paper: #f4f0e7;
  --paper-ink: #1c1b19;
  --paper-sub: #77716a;
  --suspect: #2a2e35;
  --suspect-ink: #c9c4bb;
  --culprit: #3b1714;
  --red: #e2483b;
  --green: #3f8f5f;
  --amber: #f0b13a;
  --blue: #66a3e8;
  --teal: #3fc4ae;
  --sans: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --serif: "Shippori Mincho B1", "Yu Mincho", "Hiragino Mincho ProN", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  font-weight: 500;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.red { color: var(--red) !important; }

#app { padding: 0 16px 48px; }
#site-header, #main, #guide-section, .related-apps, #ad-section, #site-footer { max-width: 760px; margin-left: auto; margin-right: auto; }

/* ── ヘッダ ───────────────────────────── */
#site-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.apps-link { color: var(--sub); text-decoration: none; font-size: 12px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; white-space: nowrap; }
.apps-link:hover { color: var(--text); }
.header-logo { margin: 0; flex: 1; min-width: 0; font-family: var(--serif); font-weight: 800; font-size: 19px; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-logo a { color: inherit; text-decoration: none; }
.langsw { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.langsw button { font-size: 12px; padding: 3px 9px; border: 0; background: none; color: var(--sub); cursor: pointer; }
.langsw button[aria-pressed="true"] { background: var(--surface2); color: var(--text); font-weight: 700; }

.topbar { display: flex; align-items: center; gap: 10px; margin: 10px 0 8px; }
.sub { margin: 0; flex: 1; min-width: 0; font-size: 12px; color: var(--sub); }
#themes {
  display: flex;
  flex: none;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
#themes a {
  font-size: 12px;
  color: var(--sub);
  text-decoration: none;
  padding: 3px 12px;
  border-radius: 5px;
}
#themes a.on { background: var(--surface2); color: var(--text); }

/* ── 事件ファイル ───────────────────────── */
#case { margin: 4px 0 14px; }
.file-tab {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px 4px;
  background: var(--kraft);
  color: var(--kraft-ink);
  border-radius: 8px 8px 0 0;
  font-size: 12px;
  letter-spacing: .04em;
}
.file-tab b { font-weight: 600; }
#case-lv { letter-spacing: .1em; }
.file-body {
  position: relative;
  padding: 14px 16px 16px;
  background: var(--kraft);
  color: var(--kraft-ink);
  border-radius: 0 10px 10px 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
#case-tag {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  color: #8a2a1e;
}
#case-title { margin: 0 0 6px; font-family: var(--serif); font-weight: 800; font-size: 24px; line-height: 1.35; }
#case-what { margin: 0 0 10px; font-size: 14px; }
.case-k {
  display: inline-block;
  margin: 0;
  padding: 3px 10px;
  border: 1.5px solid #8a2a1e;
  border-radius: 4px;
  color: #8a2a1e;
  font-size: 13px;
  font-weight: 700;
}
.case-k b { font-family: var(--mono); font-size: 16px; margin: 0 2px; }

/* ── 状況 ─────────────────────────────── */
#status {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  align-items: stretch;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.metric { background: var(--surface); padding: 6px 10px; display: flex; flex-direction: column; }
.metric span { font-size: 10px; color: var(--sub); letter-spacing: .06em; }
.metric b { font-size: 18px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
#hint {
  background: var(--surface);
  border: 0;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal);
  cursor: pointer;
}
#hint:hover { background: var(--surface2); }

/* 知らせの行は高さを固定する（出るたびに盤が下にずれないように） */
#msg {
  min-height: 3.2em;
  margin: 8px 0;
  padding-left: 10px;
  border-left: 2px solid var(--amber);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  display: flex;
  align-items: center;
}
#msg:empty { border-left-color: transparent; }
#msg.bad { border-left-color: var(--red); color: #ff8a7e; font-weight: 700; }

/* ── 教室（捜査ボード） ───────────────────── */
#board-wrap {
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px 12px 6px;
}
.front {
  margin: 0 0 12px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sub);
  font-size: 11px;
  letter-spacing: .3em;
}
.front::before, .front::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#board {
  display: grid;
  grid-template-columns: 22px repeat(4, minmax(0, 1fr));
  gap: 7px;
}
.lab { color: var(--sub); font-size: 10px; text-align: center; align-self: center; font-family: var(--mono); }
.lab.row { writing-mode: vertical-rl; letter-spacing: .08em; }

.card {
  position: relative;
  min-height: 116px;
  padding: 7px 7px 8px;
  border-radius: 8px;
  text-align: left;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
  transition: transform .08s, background .2s;
}
.card:active { transform: scale(.97); }
.card.unknown { background: var(--suspect); color: var(--suspect-ink); }
.card.innocent { background: var(--paper); color: var(--paper-ink); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.card.culprit { background: var(--culprit); color: #f3d6d2; }
.card.sel { outline: 2px solid var(--red); outline-offset: 2px; }
.card.hl-a { box-shadow: 0 0 0 3px var(--amber); }
.card.hl-b { box-shadow: 0 0 0 3px var(--blue); }
.card.hint { box-shadow: 0 0 0 3px var(--teal); }

.seat { display: flex; align-items: baseline; gap: 5px; font-size: 10.5px; line-height: 1.3; white-space: nowrap; overflow: hidden; }
.seat .no { font-family: var(--mono); font-weight: 600; opacity: .6; }
.seat .job { opacity: .7; }
.icon { font-size: 19px; line-height: 1.2; margin-top: 2px; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.name { font-family: var(--serif); font-weight: 700; font-size: 17px; line-height: 1.3; margin-top: 1px; white-space: nowrap; letter-spacing: -.02em; }
.say { position: relative; z-index: 1; font-size: 11.5px; line-height: 1.45; margin-top: 5px; }
.say.spent { opacity: .32; }
.card.culprit .say { color: #f0b8b0; }
.q { margin: auto auto 0; font-family: var(--mono); font-size: 20px; opacity: .25; }

/* ゴム印。無実は薄い透かし、犯人ははっきり押す */
.stamp {
  position: absolute;
  z-index: 0;
  right: 4px;
  bottom: 10px;
  padding: 2px 6px;
  border: 2px solid currentColor;
  border-radius: 4px;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: .08em;
  transform: rotate(-12deg);
  pointer-events: none;
}
.card.innocent .stamp { color: var(--green); opacity: .2; }
/* 犯人の印も札の下に押し、白状の一言はその上に収める（上に置くと名前に重なった） */
.card.culprit .stamp { color: var(--red); opacity: .95; bottom: 6px; }
.card.culprit .say { padding-bottom: 24px; }
.card.flip .stamp { animation: stamp .35s .15s both cubic-bezier(.3, 1.6, .5, 1); }
@keyframes stamp {
  from { transform: rotate(-12deg) scale(2.2); opacity: 0; }
}

.pick { display: flex; flex-direction: column; gap: 4px; margin-top: auto; padding-top: 6px; }
.pick-btn {
  padding: 6px 0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
}
.pick-btn.innocent { background: transparent; color: var(--paper); border: 1.5px solid rgba(244, 240, 231, .5); }
.pick-btn.culprit { background: var(--red); color: #fff; border: 1.5px solid var(--red); }

.shake { animation: shake .35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}
/* 正体が分かった札はめくれる */
.flip { animation: flip .4s ease-out; }
@keyframes flip {
  0% { transform: perspective(500px) rotateY(90deg); }
  100% { transform: perspective(500px) rotateY(0); }
}

/* ── 解決 ─────────────────────────────── */
#result {
  position: relative;
  margin-top: 16px;
  padding: 18px 16px 16px;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 12px;
  overflow: hidden;
}
.closed {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 3px 8px;
  border: 2.5px solid var(--red);
  border-radius: 4px;
  color: var(--red);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .12em;
  transform: rotate(8deg);
  animation: stamp-closed .4s both cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes stamp-closed { from { transform: rotate(8deg) scale(2.4); opacity: 0; } }
/* 印は 1 行目（事件名の行）の右に置き、見出しは幅いっぱいに使う（見出しの右を空けると変な所で折れた） */
.solved { margin: 0; padding-right: 120px; min-height: 38px; font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--paper-sub); }
#result h2 { margin: 4px 0 8px; font-family: var(--serif); font-weight: 800; font-size: 22px; line-height: 1.4; }
#result h2 b { color: var(--red); }
.confess { margin: 0 0 14px; padding: 0; list-style: none; font-size: 14px; }
.confess li { padding: 6px 0; border-top: 1px dashed rgba(0, 0, 0, .15); }
.confess li span { font-weight: 700; margin-right: 6px; }
.share {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: #ebe5d9;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  /* pre でも折り返す（«今日の事件 No.○「事件名」解決！» はスマホの幅を超える） */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.share-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px; }
.share-btn {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1.5px solid rgba(0, 0, 0, .14);
  background: #fff;
  color: var(--paper-ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.share-btn.x { background: #111; color: #fff; border-color: #111; }
.share-btn.line { background: #06c755; color: #fff; border-color: #06c755; }
.share-msg { min-height: 1.4em; margin: 6px 0 0; font-size: 13px; color: var(--green); }
.next-in { margin: 10px 0 0; font-size: 13px; color: var(--paper-sub); }
.next-in b { color: var(--paper-ink); font-family: var(--mono); font-size: 16px; }
.next-case {
  display: block;
  margin-top: 10px;
  padding: 11px;
  border-radius: 8px;
  background: var(--paper-ink);
  color: var(--paper);
  text-align: center;
  text-decoration: none;
  font-weight: 700;
}

/* ── 捜査記録・事件ファイル ─────────────────── */
#stats, #archive { margin-top: 28px; }
/* «#main h2» と書くと事件名（#case-title）と解決の見出しまで上書きするので、見出しを名指しする */
#stats h2, #archive h2, #guide-section h2, .related-apps-title {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .06em;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.stat-grid div { background: var(--surface); padding: 10px 4px; text-align: center; }
.stat-grid b { display: block; font-size: 22px; font-weight: 600; line-height: 1.2; }
.stat-grid span { font-size: 11px; color: var(--sub); }
.note { margin: 8px 0; font-size: 12px; color: var(--sub); }
#archive-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}
.arch {
  display: grid;
  grid-template-columns: 7.2em 3em 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.arch:first-child { border-top: 0; }
.arch:hover { background: var(--surface2); }
.arch.on { box-shadow: inset 3px 0 0 var(--red); }
.arch-date { font-family: var(--mono); font-weight: 600; font-size: 12px; }
.arch-lv { color: var(--amber); font-size: 11px; letter-spacing: .05em; }
.arch-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arch-done { font-size: 11px; font-weight: 700; color: var(--teal); }

/* ── 遊び方・足元 ───────────────────────── */
#guide-section { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }
#guide-section h3 { margin: 18px 0 6px; font-size: 14px; font-weight: 700; color: var(--kraft); letter-spacing: .04em; }
#guide-section p { margin: 0 0 10px; }
#guide-section ol, #guide-section ul { margin: 0 0 12px; padding-left: 1.4em; }
#guide-section li { margin-bottom: 4px; }
.terms { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 10px; padding: 12px 14px; background: var(--surface); border-radius: 10px; font-size: 13px; }
.terms dt { font-weight: 700; color: var(--amber); }
.terms dd { margin: 0; color: var(--text); }
/* 関連アプリ（画像つきのカード。文字だけのリンクは押されない） */
.related-apps { margin-top: 32px; }
.related-apps-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(180px, calc(50% - 5px)), 1fr)); gap: 10px; }
.related-app-link.ra-card { display: flex; flex-direction: column; overflow: hidden; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; transition: transform .15s, border-color .15s; }
.related-app-link.ra-card:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, .2); }
.ra-card .ra-thumb { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; }
.ra-card .ra-name { display: block; padding: 8px 12px 10px; font-size: 13px; font-weight: 700; line-height: 1.4; }
#ad-section { margin-top: 28px; }

#site-footer { margin-top: 28px; padding: 14px 0 0; border-top: 1px solid var(--line); text-align: center; font-size: 12px; color: var(--sub); }
#site-footer a { color: var(--sub); text-decoration: none; }
#site-footer a:hover { color: var(--text); }
.footer-sep { margin: 0 8px; opacity: .5; }
.footer-copy { margin: 8px 0 0; }
.reset { margin-left: 8px; border: 1px solid var(--line); background: none; color: var(--sub); border-radius: 6px; padding: 2px 10px; font-size: 12px; cursor: pointer; }

@media (max-width: 480px) {
  #case-title { font-size: 21px; }
  #status { grid-template-columns: repeat(4, 1fr); }
  #hint { grid-column: 1 / -1; padding: 7px; }
  .metric { padding: 5px 8px; }
  .card { min-height: 112px; padding: 6px 5px 7px; }
  .name { font-size: 14px; }
  .say { font-size: 10.5px; }
  .stamp { font-size: 14px; padding: 1px 4px; }
  .arch { grid-template-columns: 1fr 2.6em auto; }
  .arch-date { grid-row: 1; grid-column: 1; }
  .arch-lv { grid-row: 1; grid-column: 2; }
  .arch-done { grid-row: 1; grid-column: 3; }
  .arch-title { grid-row: 2; grid-column: 1 / -1; }
  /* 英語の印（CLEAR / GUILTY）は文字が多いので小さく押す */
  html[lang="en"] .stamp { font-size: 11px; letter-spacing: .02em; }
  .header-logo { font-size: 16px; }
  .sub { font-size: 11px; }
}
