:root {
  --bg: #121315;
  --bg-2: #1a1c1f;
  --bg-3: #212428;
  --ink: #ebe7dc;
  --muted: #8f8b80;
  --line: #2d3034;
  --case: #3b3f37;
  --case-dark: #262923;
  --face: #23262a;
  --face-2: #2d3136;
  --hazard: #e8b72a;
  --danger: #ff3b2f;
  --ok: #3ee07a;
  --ice: #7cd6ff;
  --lcd-bg: #1a0705;
  --lcd: #ff3a24;
  --paper: #efe7d2;
  --paper-ink: #2a2620;
  --paper-line: #cdbf9b;
  --gold: #f2c94c;

  --red: #d8392f;
  --blue: #2f6ee0;
  --yellow: #f2c230;
  --white: #ece8dc;
  --black: #151515;

  --font-ui: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic UI', sans-serif;
  --font-pixel: 'DotGothic16', var(--font-ui);
  --font-mono: 'Share Tech Mono', ui-monospace, 'SFMono-Regular', monospace;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
input { font: inherit; }
:focus-visible { outline: 2px solid var(--hazard); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- 共通部品 ---------- */
.app-screen { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.btn-primary, .btn-ghost {
  border-radius: 10px; padding: 12px 18px; font-weight: 700; border: 1px solid transparent; min-height: 46px;
  transition: transform .06s, filter .15s;
}
.btn-primary { background: var(--hazard); color: #1a1505; box-shadow: 0 3px 0 #8d6c12; }
.btn-primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #8d6c12; }
.btn-primary:disabled { filter: grayscale(.7) brightness(.7); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-block { width: 100%; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.seg-btn.active { background: var(--face-2); color: var(--ink); }
.chips-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--bg-3); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-family: var(--font-mono); }
.chip.active { border-color: var(--hazard); color: var(--hazard); }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card-kicker { font-family: var(--font-mono); font-size: 12px; letter-spacing: .12em; color: var(--hazard); }
.card-title { font-family: var(--font-pixel); font-size: 17px; }
.card-title.big { font-size: 24px; }
.card-alert { border-color: var(--danger); background: #2a1514; }
.stack { display: flex; flex-direction: column; gap: 12px; padding: 16px; max-width: 720px; margin: 0 auto; }
.section-title { font-family: var(--font-pixel); font-weight: normal; font-size: 16px; margin: 8px 2px 0; color: var(--muted); letter-spacing: .1em; }
.specs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; margin: 0; }
.specs dt { font-size: 12px; color: var(--muted); }
.specs dd { margin: -4px 0 4px; font-size: 18px; }
.coins { display: inline-flex; align-items: center; gap: 6px; font-size: 16px; color: var(--gold); }
.coin-icon { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff3b0, var(--gold) 50%, #a37a12); box-shadow: inset 0 0 0 2px rgba(0,0,0,.15); display: inline-block; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--bg-3); border-radius: 10px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-value { font-size: 22px; }
.stat-label { font-size: 11px; color: var(--muted); }
.loading { height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); padding: 16px; text-align: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--hazard); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 下部タブ */
.tabbar {
  display: flex; flex: none; background: rgba(18, 19, 21, .97); border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + var(--safe-b));
}
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; border-radius: 10px; position: relative; min-height: 52px; }
.tab-icon { font-size: 20px; line-height: 1; filter: grayscale(1) opacity(.7); }
.tab.active { color: var(--hazard); }
.tab.active .tab-icon { filter: none; }
.tab-badge:not(:empty) { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; display: grid; place-items: center; padding: 0 5px; }

/* 階級章 */
.insignia {
  flex: none; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 28px; height: 32px; border-radius: 6px 6px 14px 14px;
  background: linear-gradient(160deg, #3d4a37, #263021); box-shadow: inset 0 0 0 1.5px #6b7a55;
}
.insignia-lg { width: 48px; height: 56px; gap: 3px; border-radius: 8px 8px 24px 24px; }
.ins-chevron { width: 60%; height: 4px; background: var(--gold); clip-path: polygon(0 100%, 50% 0, 100% 100%, 85% 100%, 50% 30%, 15% 100%); height: 6px; }
.insignia-lg .ins-chevron { height: 8px; }
.ins-dot { width: 6px; height: 6px; border-radius: 50%; background: #8a957a; }
.ins-star { color: var(--gold); font-size: 16px; text-shadow: 0 0 8px rgba(242, 201, 76, .6); }
.insignia-lg .ins-star { font-size: 28px; }
.insignia.r6 { background: linear-gradient(160deg, #5a4718, #2c220a); box-shadow: inset 0 0 0 1.5px var(--gold), 0 0 14px rgba(242, 201, 76, .35); }

/* 経験値 */
.xp { display: flex; flex-direction: column; gap: 6px; }
.xp-label { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.xp.ready .xp-label span:first-child { color: var(--hazard); font-weight: 700; }
.xp-track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.xp-fill { height: 100%; background: linear-gradient(90deg, #8d6c12, var(--hazard)); border-radius: 4px; transition: width .6s; }
.xp.ready .xp-fill { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { filter: brightness(1.4); } }

/* ---------- ログイン ---------- */
.auth-screen { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px calc(32px + var(--safe-b)); gap: 8px; text-align: center; }
.hazard { height: 10px; width: min(320px, 80%); margin-bottom: 24px; background: repeating-linear-gradient(-45deg, var(--hazard) 0 14px, #111 14px 28px); border-radius: 2px; }
.logo { margin: 0; display: grid; gap: 6px; }
.logo-en { font-family: var(--font-mono); font-size: clamp(42px, 13vw, 84px); letter-spacing: .06em; color: var(--lcd); text-shadow: 0 0 18px rgba(255, 58, 36, .55), 0 0 2px #ff9a8a; line-height: 1; }
.logo-ja { font-family: var(--font-pixel); font-size: 22px; letter-spacing: .5em; padding-left: .5em; }
.tagline { color: var(--muted); margin: 10px 0 20px; }
.auth-form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field input { padding: 13px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--ink); font-size: 16px; }
.field input:focus { border-color: var(--hazard); outline: none; }
.auth-note { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- 本部 ---------- */
.hq-top { flex: none; padding: calc(14px + var(--safe-t)) 16px 14px; background: linear-gradient(180deg, #1d2019, var(--bg)); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.hq-top > * { width: 100%; max-width: 688px; margin: 0 auto; }
.profile { display: flex; align-items: center; gap: 12px; }
.profile-main { flex: 1; min-width: 0; }
.profile-rank { display: flex; flex-direction: column; }
.rank-en { font-family: var(--font-mono); font-size: 11px; letter-spacing: .2em; color: var(--hazard); }
.rank-name { font-family: var(--font-pixel); font-size: 18px; }
.profile-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hq-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.exam-card.ready { border-color: var(--hazard); background: linear-gradient(160deg, #2a2512, var(--bg-2)); box-shadow: 0 0 0 1px rgba(232, 183, 42, .2), 0 8px 30px rgba(232, 183, 42, .08); }
.exam-card:not(.ready) { opacity: .8; padding: 12px 14px; }
.exam-head { display: flex; align-items: center; gap: 12px; }
.mission {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 64px;
}
.mission:active:not(:disabled) { background: var(--bg-3); }
.mission.locked { opacity: .45; }
.mission-lv { flex: none; width: 46px; height: 46px; border-radius: 10px; background: var(--face); display: grid; place-content: center; text-align: center; font-family: var(--font-mono); font-size: 20px; line-height: 1; color: var(--hazard); }
.mission-lv small { font-size: 9px; color: var(--muted); display: block; }
.mission-main { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.mission-name { font-family: var(--font-pixel); font-size: 16px; }
.mission-meta { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.mission-best { flex: none; font-size: 13px; }
.back { align-self: flex-start; border: 0; background: transparent; color: var(--hazard); padding: 4px 0; font-size: 15px; }
.type-list { display: flex; flex-wrap: wrap; gap: 6px; }
.type-tag { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--face-2); }
.item-chips { display: flex; flex-direction: column; gap: 8px; }
.item-chip { display: flex; align-items: center; gap: 12px; text-align: left; background: var(--bg-3); border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.item-chip.on { border-color: var(--hazard); background: #2a2512; }
.item-chip:disabled { opacity: .4; }
.item-chip-main { flex: 1; display: flex; flex-direction: column; }
.item-icon { font-size: 22px; flex: none; }
.item-icon.big { font-size: 30px; }
.item-name { font-weight: 700; }
.item-desc { font-size: 12px; color: var(--muted); }
.item-count { color: var(--muted); }
.btn-go { font-size: 18px; letter-spacing: .3em; padding: 16px; position: sticky; bottom: 12px; }
.shop-head { display: flex; justify-content: space-between; align-items: center; }
.shop-item { flex-direction: row; align-items: center; gap: 14px; }
.shop-main { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.btn-buy { flex: none; display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; border: 1px solid #6b5a1c; background: #2a2512; color: var(--gold); padding: 10px 14px; font-family: var(--font-mono); font-size: 16px; min-height: 44px; }
.btn-buy:disabled { opacity: .4; }
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rank-list li { display: flex; align-items: center; gap: 10px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.rank-list li.me { border-color: var(--hazard); background: #2a2512; }
.rank-no { width: 26px; text-align: center; font-family: var(--font-mono); font-size: 18px; color: var(--muted); }
.rank-no.top1 { color: var(--gold); } .rank-no.top2 { color: #cfd4da; } .rank-no.top3 { color: #d39060; }
.rank-player { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rank-player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-size: 16px; }
.badge-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.badge { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 10px; opacity: .45; }
.badge.got { opacity: 1; border-color: #5c4d1e; background: linear-gradient(160deg, #262013, var(--bg-2)); }
.badge-icon { font-size: 30px; }
.badge:not(.got) .badge-icon { font-family: var(--font-mono); color: var(--muted); }
.badge-name { font-family: var(--font-pixel); }
.badge-desc { font-size: 11px; color: var(--muted); }
.rank-ladder { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 4px; }
.rank-ladder li { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 10px; opacity: .5; }
.rank-ladder li.done { opacity: .85; }
.rank-ladder li.current { opacity: 1; background: #2a2512; border: 1px solid var(--hazard); }
.ladder-name { flex: 1; font-family: var(--font-pixel); }
.account { flex-direction: row; align-items: center; justify-content: space-between; }

/* ---------- ゲーム画面 ---------- */
.g-hud {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-t)) 10px 8px; background: #0d0e10; border-bottom: 1px solid var(--line);
}
.g-hud.hit { animation: hud-hit .5s; }
@keyframes hud-hit { 20% { background: #4a0f0b; } }
.g-timer { position: relative; flex: none; background: var(--lcd-bg); border-radius: 6px; padding: 4px 10px; box-shadow: inset 0 2px 8px rgba(0,0,0,.9), 0 0 0 2px #000; font-family: var(--font-mono); font-size: 36px; line-height: 1; }
.g-timer-ghost { color: rgba(255, 58, 36, .08); }
.g-timer-digits { position: absolute; inset: 4px 10px; text-align: right; color: var(--lcd); text-shadow: 0 0 10px rgba(255, 58, 36, .7); }
.g-timer-digits.urgent { animation: urgent 1s steps(2) infinite; }
.g-timer-digits.frozen { color: var(--ice); text-shadow: 0 0 10px rgba(124, 214, 255, .8); }
@keyframes urgent { 50% { color: #ff9a8a; text-shadow: 0 0 20px rgba(255, 80, 60, 1); } }
.g-hud-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.g-strikes { display: flex; gap: 4px; }
.g-strike { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 4px; background: var(--lcd-bg); color: rgba(255, 58, 36, .15); font-size: 12px; font-weight: 700; }
.g-strike.on { color: var(--lcd); text-shadow: 0 0 6px var(--lcd); }
.g-bombinfo { display: flex; gap: 8px; align-items: center; font-family: var(--font-mono); font-size: 15px; white-space: nowrap; }
.g-serial { background: #f3f0e6; color: #1c1c1c; border-radius: 3px; padding: 1px 6px; letter-spacing: .12em; }
.g-serial small { font-size: 9px; opacity: .6; margin-right: 4px; letter-spacing: 0; }
.g-battery { display: inline-flex; align-items: center; gap: 3px; color: var(--gold); }
.battery-icon { width: 8px; height: 14px; border-radius: 2px; background: linear-gradient(90deg, #b88a1d, #f0c040 45%, #a57a13); position: relative; }
.battery-icon::before { content: ''; position: absolute; top: -2px; left: 2px; width: 4px; height: 2px; background: #999; }
.g-hud-right { display: flex; align-items: center; gap: 4px; }
.g-status { display: flex; gap: 2px; font-size: 18px; }
.g-flag.freeze { animation: glow 1s infinite; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-3); display: grid; place-items: center; font-size: 15px; }

.g-main { flex: 1; min-height: 0; position: relative; }
.pane { display: none; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.game[data-pane='bomb'] .pane-bomb,
.game[data-pane='manual'] .pane-manual,
.game[data-pane='items'] .pane-items { display: flex; flex-direction: column; }

/* 爆弾ペイン（スマホ：選択中のモジュールを大きく1つ表示） */
.pane-bomb { background: radial-gradient(ellipse at 50% 0%, #2a2d27, var(--bg) 70%); }
.module-chips { flex: none; display: flex; gap: 6px; overflow-x: auto; padding: 10px 10px 4px; scrollbar-width: none; }
.module-chips::-webkit-scrollbar { display: none; }
.module-chip { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg-2); border-radius: 99px; padding: 8px 12px; font-size: 13px; min-height: 38px; }
.module-chip.active { border-color: var(--hazard); background: #2a2512; }
.module-chip.strike { animation: chip-strike .6s; }
@keyframes chip-strike { 30% { border-color: var(--danger); background: #4a0f0b; } }
.module-grid { flex: 1; display: flex; flex-direction: column; padding: 8px 10px 16px; }
.module-grid .module:not(.selected) { display: none; }

.module {
  background: linear-gradient(180deg, var(--face-2), var(--face));
  border-radius: 14px;
  border: 1px solid #15171a;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 3px 0 rgba(0,0,0,.35), 0 0 0 5px var(--case), 0 0 0 7px var(--case-dark);
  margin: 7px;
  padding: 10px 12px 18px;
  display: flex; flex-direction: column;
  position: relative;
  flex: 1;
  min-height: 320px;
}
.module::after {
  content: ''; position: absolute; inset: 6px; pointer-events: none;
  background:
    radial-gradient(circle, #6d7178 0 2px, transparent 3px) left top / 10px 10px no-repeat,
    radial-gradient(circle, #6d7178 0 2px, transparent 3px) right top / 10px 10px no-repeat,
    radial-gradient(circle, #6d7178 0 2px, transparent 3px) left bottom / 10px 10px no-repeat,
    radial-gradient(circle, #6d7178 0 2px, transparent 3px) right bottom / 10px 10px no-repeat;
}
.module-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 12px 6px; }
.module-title { font-family: var(--font-pixel); font-size: 14px; color: var(--muted); letter-spacing: .1em; }
.led { width: 12px; height: 12px; border-radius: 50%; background: #3a1714; box-shadow: inset 0 1px 2px rgba(0,0,0,.6); transition: background .2s, box-shadow .2s; flex: none; }
.module-chip .led { width: 9px; height: 9px; }
.solved .led { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.module.strike { animation: strike .6s; }
.module.strike .led { animation: led-strike .6s; }
.module.blocked { animation: blocked .8s; }
@keyframes strike {
  0%, 100% { transform: none; }
  15% { transform: translateX(-6px); box-shadow: 0 0 0 3px var(--danger), 0 0 30px rgba(255,59,47,.5); }
  30% { transform: translateX(5px); } 45% { transform: translateX(-3px); } 60% { transform: translateX(2px); }
}
@keyframes led-strike { 0%, 70% { background: var(--danger); box-shadow: 0 0 12px var(--danger); } }
@keyframes blocked { 30% { box-shadow: 0 0 0 4px var(--ice), 0 0 30px rgba(124,214,255,.6); } }
.module-body { flex: 1; display: flex; align-items: center; justify-content: center; }
.hint-tag { font-size: 14px; color: var(--ice); background: rgba(124, 214, 255, .1); border: 1px solid rgba(124, 214, 255, .4); border-radius: 99px; padding: 4px 12px; text-align: center; }

/* ワイヤー */
.wires { width: 100%; max-width: 420px; }
.wires-svg { width: 100%; height: auto; display: block; overflow: visible; }
.wire { cursor: pointer; outline: none; }
.wire-num { fill: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.terminal { fill: #8b8f95; stroke: #2a2c30; }
.wire path { fill: none; stroke-linecap: round; }
.wire-shadow { stroke: #050505; stroke-width: 10; }
.wire-core { stroke-width: 7; transition: stroke-width .1s; }
.wire-shine { stroke: rgba(255,255,255,.28); stroke-width: 1.6; transform: translateY(-1.5px); }
.wire-hit { stroke: transparent; stroke-width: 28; }
.wire:focus-visible .wire-shadow { stroke: var(--hazard); }
.wire.hinted .wire-shadow { stroke: var(--ice); stroke-width: 14; filter: drop-shadow(0 0 6px var(--ice)); }
.wire-red .wire-core { stroke: var(--red); }
.wire-blue .wire-core { stroke: var(--blue); }
.wire-yellow .wire-core { stroke: var(--yellow); }
.wire-white .wire-core { stroke: var(--white); }
.wire-black .wire-core { stroke: var(--black); }
.wire-black .wire-shadow { stroke: #5e6268; }
.wire.cut { cursor: default; }
.wire.cut path:not(.wire-hit) { stroke-dasharray: 44 12 44; }
.wire.cut .wire-shine { opacity: .2; }

/* ボタン */
.button-module { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.button-row { display: flex; align-items: center; gap: 26px; }
.big-button {
  width: 150px; height: 150px; border-radius: 50%; border: none; position: relative;
  box-shadow: 0 8px 0 rgba(0,0,0,.55), inset 0 -6px 14px rgba(0,0,0,.35), inset 0 6px 10px rgba(255,255,255,.3), 0 0 0 9px #16181b;
  transition: transform .05s, box-shadow .05s;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.big-button.pressed { transform: translateY(6px); box-shadow: 0 2px 0 rgba(0,0,0,.55), inset 0 -3px 10px rgba(0,0,0,.4), inset 0 4px 8px rgba(255,255,255,.2), 0 0 0 9px #16181b; }
.big-button-label { font-family: var(--font-pixel); font-size: 26px; pointer-events: none; }
.btn-red { background: radial-gradient(circle at 40% 35%, #f0574c, var(--red) 60%, #8f2018); color: #fff; }
.btn-blue { background: radial-gradient(circle at 40% 35%, #5a8ff2, var(--blue) 60%, #173f8f); color: #fff; }
.btn-yellow { background: radial-gradient(circle at 40% 35%, #ffe07a, var(--yellow) 60%, #a07c10); color: #1d1a10; }
.btn-white { background: radial-gradient(circle at 40% 35%, #fff, var(--white) 60%, #a19d92); color: #1d1d1d; }
.big-button:disabled { filter: saturate(.5) brightness(.75); }
.strip { width: 24px; height: 150px; border-radius: 4px; background: #0d0e10; padding: 4px; box-shadow: inset 0 1px 4px rgba(0,0,0,.9); }
.strip-light { width: 100%; height: 100%; border-radius: 2px; background: #1c1e21; }
.strip[data-color='red'] .strip-light { background: var(--red); box-shadow: 0 0 14px var(--red); }
.strip[data-color='blue'] .strip-light { background: var(--blue); box-shadow: 0 0 14px var(--blue); }
.strip[data-color='yellow'] .strip-light { background: var(--yellow); box-shadow: 0 0 14px var(--yellow); }
.strip[data-color='white'] .strip-light { background: var(--white); box-shadow: 0 0 14px var(--white); }

/* キーパッド */
.keypad { display: grid; grid-template-columns: repeat(2, 88px); gap: 14px; }
.key {
  height: 88px; border-radius: 10px; border: none; position: relative;
  background: linear-gradient(180deg, #ece6d4, #cfc7b0); color: #1c1b17;
  box-shadow: 0 5px 0 #6d6656, inset 0 1px 0 #fff;
  transition: transform .05s, box-shadow .05s;
}
.key:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #6d6656; }
.key-symbol { font-size: 36px; line-height: 1; }
.key-led { position: absolute; top: 7px; left: 50%; translate: -50% 0; width: 24px; height: 5px; border-radius: 2px; background: #3a3730; }
.key.done .key-led { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.key.hinted { box-shadow: 0 5px 0 #6d6656, 0 0 0 3px var(--ice), 0 0 20px rgba(124,214,255,.7); }

/* パスワード */
.password { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pw-display { display: flex; gap: 6px; background: #0e1a10; padding: 8px; border-radius: 8px; box-shadow: inset 0 2px 8px rgba(0,0,0,.9), 0 0 0 3px #111; }
.pw-col { display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 6px; }
.pw-col.hinted { box-shadow: 0 0 0 2px var(--ice); }
.pw-letter { width: 46px; height: 54px; display: grid; place-items: center; font-family: var(--font-mono); font-size: 38px; color: #7dff9a; text-shadow: 0 0 10px rgba(125,255,154,.6); background: #0a140c; border-radius: 3px; }
.pw-arrow { width: 46px; height: 36px; border: none; border-radius: 4px; background: #3a3e44; color: #cfd2d6; font-size: 12px; }
.pw-arrow:active:not(:disabled) { background: #555a62; }
.pw-submit { padding: 12px 40px; border: none; border-radius: 8px; background: #c9c3b1; color: #1c1b17; font-family: var(--font-pixel); font-size: 18px; box-shadow: 0 4px 0 #6d6656; }
.pw-submit:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #6d6656; }
.solved .pw-letter { color: var(--ok); }

/* メモリー */
.memory { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.mem-top { display: flex; align-items: center; gap: 14px; }
.mem-display { width: 120px; height: 84px; display: grid; place-items: center; background: #0a140c; border-radius: 8px; box-shadow: inset 0 2px 8px rgba(0,0,0,.9), 0 0 0 3px #111; font-family: var(--font-mono); font-size: 60px; color: #7dff9a; text-shadow: 0 0 12px rgba(125,255,154,.6); }
.mem-stages { display: flex; flex-direction: column-reverse; gap: 6px; }
.mem-stage { width: 14px; height: 18px; border-radius: 3px; background: #2a2d31; box-shadow: inset 0 1px 3px rgba(0,0,0,.7); }
.mem-stage.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.mem-buttons { display: grid; grid-template-columns: repeat(4, 62px); gap: 10px; }
.mem-btn { height: 80px; border: none; border-radius: 8px; background: linear-gradient(180deg, #ece6d4, #cfc7b0); color: #1c1b17; font-family: var(--font-mono); font-size: 32px; box-shadow: 0 5px 0 #6d6656; }
.mem-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #6d6656; }
.mem-btn.hinted { box-shadow: 0 5px 0 #6d6656, 0 0 0 3px var(--ice), 0 0 20px rgba(124,214,255,.7); }

/* マニュアルペイン */
.pane-manual { background: var(--paper); color: var(--paper-ink); }
.manual { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.manual-nav { flex: none; display: flex; gap: 6px; padding: 8px 10px; overflow-x: auto; background: #e1d6b8; border-bottom: 1px solid var(--paper-line); scrollbar-width: none; }
.manual-nav button { flex: none; border: 1px solid #b9a97f; background: var(--paper); color: var(--paper-ink); border-radius: 99px; padding: 6px 12px; font-size: 13px; }
.manual-nav button.active { background: var(--paper-ink); color: var(--paper); border-color: var(--paper-ink); }
.manual-scroll { flex: 1; overflow-y: auto; position: relative; -webkit-overflow-scrolling: touch; }
.manual-content { padding: 16px 18px 120px; font-size: 15px; line-height: 1.7; }
.manual-content h2 { font-family: var(--font-pixel); font-weight: normal; font-size: 20px; margin: 0 0 8px; border-bottom: 3px double var(--paper-ink); padding-bottom: 6px; }
.manual-section { padding-top: 10px; }
.manual-content h3 { font-family: var(--font-pixel); font-weight: normal; font-size: 18px; margin: 18px 0 6px; padding: 2px 10px; background: var(--paper-ink); color: var(--paper); display: inline-block; }
.manual-content h4 { margin: 12px 0 2px; font-size: 14px; }
.manual-content p { margin: 6px 0; }
.manual-content .lead { font-size: 13px; }
.rules { margin: 4px 0; padding-left: 1.4em; }
.rules li { padding: 4px 0; border-bottom: 1px dashed var(--paper-line); }
.rules .cond::after { content: ' → '; color: #8a7d5c; }
.rules .act { font-weight: bold; }
.strip-table { border-collapse: collapse; margin: 6px 0; }
.strip-table th, .strip-table td { border: 1px solid var(--paper-line); padding: 5px 12px; text-align: left; }
.swatch { display: inline-block; padding: 0 8px; border-radius: 3px; border: 1px solid rgba(0,0,0,.3); font-size: 13px; }
.sw-red { background: var(--red); color: #fff; } .sw-blue { background: var(--blue); color: #fff; } .sw-yellow { background: var(--yellow); } .sw-white { background: #fff; }
.keypad-table { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-top: 6px; }
.kp-col { display: flex; flex-direction: column; border: 1px solid var(--paper-line); background: #f6f0e0; }
.kp-head { text-align: center; font-size: 11px; background: #e1d6b8; }
.kp-cell { text-align: center; font-size: 24px; line-height: 1.55; border-top: 1px solid var(--paper-line); }
.word-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 2px 8px; font-family: var(--font-mono); font-size: 16px; margin-top: 6px; }

/* アイテムペイン */
.pane-items { padding: 12px; }
.items-list { display: flex; flex-direction: column; gap: 10px; max-width: 560px; width: 100%; margin: 0 auto; }
.item-row { display: flex; align-items: center; gap: 12px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.item-row.used { opacity: .45; }
.item-row-main { flex: 1; min-width: 0; }
.item-target { font-size: 12px; color: var(--ice); margin-top: 2px; }
.btn-use { flex: none; min-width: 72px; min-height: 44px; border-radius: 10px; border: 0; background: var(--hazard); color: #1a1505; font-weight: 700; }
.btn-use:disabled { background: var(--face-2); color: var(--muted); }
.empty { text-align: center; padding: 24px 8px; }

body.boom::after { content: ''; position: fixed; inset: 0; background: #fff; z-index: 50; pointer-events: none; animation: flash 1.1s forwards; }
body.boom .g-main { animation: shake .9s; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes shake {
  0%, 100% { transform: none; }
  10% { transform: translate(-12px, 6px) rotate(-1deg); } 20% { transform: translate(10px, -8px) rotate(1deg); }
  35% { transform: translate(-8px, 4px); } 50% { transform: translate(6px, -3px); } 70% { transform: translate(-3px, 2px); }
}

/* ---------- 結果 ---------- */
.result { background: var(--bg); }
.result.exploded { background: radial-gradient(circle at 50% 25%, #4a120b, var(--bg) 70%); }
.result.cleared { background: radial-gradient(circle at 50% 20%, #12301d, var(--bg) 70%); }
.result-body { flex: 1; overflow-y: auto; padding: calc(32px + var(--safe-t)) 18px 20px; display: flex; flex-direction: column; gap: 16px; max-width: 520px; width: 100%; margin: 0 auto; text-align: center; }
.result-title { font-family: var(--font-pixel); font-size: 48px; letter-spacing: .15em; animation: pop .4s cubic-bezier(.2, 1.4, .4, 1); }
.cleared .result-title { color: var(--ok); text-shadow: 0 0 22px rgba(62, 224, 122, .5); }
.exploded .result-title { color: var(--danger); font-family: var(--font-mono); font-size: 72px; text-shadow: 0 0 30px rgba(255, 59, 47, .8); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.result-sub { color: var(--muted); margin-top: -10px; }
.result-cause { font-size: 18px; margin: 0; }
.rewards { display: flex; gap: 8px; }
.reward { flex: 1; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.reward-label { font-size: 12px; color: var(--muted); }
.reward-value { font-size: 24px; color: var(--hazard); }
.reward .coins { font-size: 24px; }
.new-best { color: var(--hazard); font-family: var(--font-pixel); font-size: 17px; }
.new-badges { display: flex; flex-direction: column; gap: 8px; }
.new-badges .badge { flex-direction: row; text-align: left; padding: 10px 14px; gap: 12px; }
.new-badges .badge-name { min-width: 5em; }
.rankup { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 20px; border-radius: 16px; border: 1px solid var(--gold); background: linear-gradient(160deg, #3a2f10, #1a160a); box-shadow: 0 0 40px rgba(242, 201, 76, .25); animation: pop .6s .2s both cubic-bezier(.2, 1.4, .4, 1); }
.rankup-kicker { font-family: var(--font-mono); letter-spacing: .4em; color: var(--gold); }
.rankup-name { font-family: var(--font-pixel); font-size: 24px; }
.rankup-note { margin: 0; color: var(--gold); }
.result-actions { flex: none; display: flex; gap: 10px; padding: 12px 18px calc(12px + var(--safe-b)); max-width: 520px; width: 100%; margin: 0 auto; }
.result-actions > * { flex: 1; }
.result .xp { text-align: left; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + var(--safe-b)); translate: -50% 10px; z-index: 60; max-width: calc(100% - 32px); width: max-content;
  background: #2b2e33; border: 1px solid #444; padding: 10px 16px; border-radius: 10px; font-size: 14px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; translate: -50% 0; }

/* ---------- 小さいスマホ ---------- */
@media (max-width: 370px) {
  .g-timer { font-size: 30px; }
  .big-button { width: 130px; height: 130px; }
  .strip { height: 130px; }
  .pw-letter { width: 40px; font-size: 32px; }
  .pw-arrow { width: 40px; }
  .mem-buttons { grid-template-columns: repeat(4, 54px); }
  .g-bombinfo { font-size: 13px; }
}
@media (max-height: 640px) {
  .module { min-height: 260px; }
}

/* ---------- PC：爆弾とマニュアルを並べて表示 ---------- */
@media (min-width: 1000px) {
  .game .tabbar, .module-chips { display: none; }
  .g-hud { padding: 10px 20px; gap: 18px; }
  .g-timer { font-size: 44px; }
  .g-hud-mid { flex-direction: row; align-items: center; gap: 18px; }
  .g-main { display: grid; grid-template-columns: 1fr minmax(360px, 440px); grid-template-rows: auto 1fr; grid-template-areas: 'items manual' 'bomb manual'; }
  .game .pane { display: flex; flex-direction: column; }
  .pane-items { grid-area: items; padding: 12px 16px 0; overflow: visible; height: auto; }
  .pane-items .items-list { flex-direction: row; flex-wrap: wrap; max-width: none; }
  .pane-items .item-row { flex: 1 1 260px; padding: 8px 12px; }
  .pane-items .empty { padding: 4px; text-align: left; }
  .pane-bomb { grid-area: bomb; min-height: 0; }
  .pane-manual { grid-area: manual; border-left: 1px solid #000; min-height: 0; }
  .module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-content: start; gap: 6px; padding: 16px; }
  .module-grid .module:not(.selected) { display: flex; }
  .module { min-height: 280px; cursor: default; }
  .module.selected { box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 3px 0 rgba(0,0,0,.35), 0 0 0 5px var(--case), 0 0 0 7px var(--hazard); }
  .stack { padding: 24px; }
  .badge-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
