:root {
  --bg: #171a2b;
  --bg2: #20243a;
  --panel: #262b45;
  --text: #f2f3f8;
  --muted: #a7acc6;
  --accent: #ffd166;
  --win: #36b37e;
  --lose: #e0525a;
  --boss: #9b5de5;
  --stone: #3a4063;
  --stone-dark: #2c3150;
  --room: #1c2036;
  --bridge: #a0764a;
  --fragile: #c9893a;
  --rope: #7fc4e8;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px env(safe-area-inset-bottom); min-height: 100dvh; display: flex; flex-direction: column; }
.screen { display: flex; flex-direction: column; flex: 1; }

/* タイトル */
#screen-title { align-items: center; padding-top: 6vh; gap: 12px; }
.logo { font-size: clamp(36px, 10vw, 56px); margin: 0; letter-spacing: 0.08em; color: var(--accent); text-shadow: 0 4px 0 #8a5a00; }
.tagline { margin: 0 0 12px; color: var(--muted); text-align: center; }
.level-list { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px; }
.level-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel); border: 2px solid transparent; border-radius: 14px; padding: 12px 14px;
}
.level-card:hover, .level-card:focus-visible { border-color: var(--accent); outline: none; }
.level-card .lv-name { font-weight: 700; font-size: 18px; min-width: 3.5em; }
.level-card .lv-title { flex: 1; color: var(--muted); }
.level-card .lv-best { font-size: 13px; color: var(--win); white-space: nowrap; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 8px; }

/* ゲーム */
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 0 4px; }
.topbar .stage { flex: 1; text-align: center; font-weight: 700; font-size: 18px; }
.topbar .stage small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: none; background: var(--panel); font-size: 20px; }
.hud { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 4px 6px; }
.hud-power { font-size: 18px; }
.hud-power b { font-size: 30px; color: var(--accent); margin-left: 4px; }
.hud-moves { color: var(--muted); }
.hud-moves b { color: var(--text); font-size: 20px; margin-left: 4px; }
/* ゲーム画面は1画面に固定し、盤面が残りの高さを使う（案内欄が伸びると盤面が縮む） */
body.in-game #app { height: 100dvh; min-height: 0; overflow: hidden; }
body.in-game #screen-game { flex: 1 1 0; min-height: 0; }
#board-wrap { flex: 1 1 0; min-height: 0; display: flex; justify-content: center; }
#board { width: 100%; height: 100%; min-height: 200px; user-select: none; -webkit-user-select: none; }
.info { min-height: 3em; padding: 8px 10px; margin: 6px 0; background: var(--bg2); border-radius: 10px; font-size: 15px; line-height: 1.4; }
.info .win { color: var(--win); font-weight: 700; }
.info .lose { color: var(--lose); font-weight: 700; }
.info .warn, .modal-box .warn { color: #f0a94a; }
.controls { display: flex; gap: 10px; padding-bottom: 12px; }
.controls button { flex: 1; min-height: 48px; border-radius: 12px; border: none; background: var(--panel); font-size: 16px; }
.controls button:disabled { opacity: 0.4; cursor: default; }
.controls button.pulse { animation: pulse 1s ease-in-out infinite; background: #4a3f1a; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.6); } }

/* 盤面 SVG */
.room-g { cursor: pointer; }
.room-g .room-bg { fill: var(--room); stroke: #000; stroke-opacity: 0.25; stroke-width: 2; }
.room-g.adj .room-bg { stroke: var(--accent); stroke-opacity: 1; stroke-width: 4; }
.room-g.adj.danger .room-bg { stroke: var(--lose); stroke-dasharray: 8 6; }
.room-g:hover .room-bg { fill: #283052; }
.num { font-weight: 800; text-anchor: middle; dominant-baseline: central; fill: #fff; paint-order: stroke; stroke: rgba(0,0,0,0.45); stroke-width: 4px; }
.bridge-label { font-size: 13px; font-weight: 700; text-anchor: middle; fill: var(--fragile); }
.sign-text { font-size: 14px; font-weight: 800; text-anchor: middle; dominant-baseline: central; fill: #e8f6ff; }
.badge-text { font-weight: 700; text-anchor: middle; dominant-baseline: central; fill: #fff; font-size: 15px; }
.trail { fill: none; stroke: var(--accent); stroke-width: 5; stroke-dasharray: 2 9; stroke-linecap: round; opacity: 0; animation: trail 0.9s ease-out; pointer-events: none; }
@keyframes trail { from { opacity: 0.9; } to { opacity: 0; } }
.float-text { font-weight: 800; text-anchor: middle; fill: var(--accent); font-size: 26px; animation: floatup 0.9s ease-out forwards; pointer-events: none; }
@keyframes floatup { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-40px); } }
.player-g { animation: pop 0.25s ease-out; }
@keyframes pop { from { transform: scale(0.85); } to { transform: scale(1); } }
.player-g, .trail { fill: none; stroke: var(--accent); stroke-width: 5; stroke-dasharray: 2 9; stroke-linecap: round; opacity: 0; animation: trail 0.9s ease-out; pointer-events: none; }
@keyframes trail { from { opacity: 0.9; } to { opacity: 0; } }
.float-text { transform-box: fill-box; transform-origin: center; }

/* モーダル */
.modal { position: fixed; inset: 0; background: rgba(5, 6, 15, 0.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-box { background: var(--panel); border-radius: 16px; padding: 20px; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); }
.modal-box h2 { margin: 0 0 10px; font-size: 22px; }
.modal-box p { margin: 6px 0; line-height: 1.5; }
.modal-box ul { padding-left: 1.2em; margin: 6px 0; line-height: 1.6; }
.modal-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.modal-buttons button { flex: 1 1 40%; min-height: 46px; border-radius: 12px; border: none; background: var(--stone); font-size: 16px; }
.modal-buttons button.primary { background: var(--accent); color: #2a1f00; font-weight: 700; }
.modal-buttons button.danger { background: var(--lose); }
.swatch { display: inline-block; width: 0.9em; height: 0.9em; border-radius: 50%; vertical-align: -0.1em; margin-right: 2px; }

.finish-line { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.finish-line span { flex: 1 1 12em; }
.finish-line button { border: none; border-radius: 10px; background: var(--accent); color: #2a1f00; font-weight: 700; padding: 8px 12px; min-height: 40px; }

.star { color: var(--accent); }
.nomiss { font-weight: 700; }
.teach-pic { width: 100%; max-width: 260px; display: block; margin: 0 auto 6px; }
.progress { margin: -6px 0 4px; color: var(--muted); min-height: 1.2em; }
.complete-sum { font-size: 20px; font-weight: 700; }
.complete-list { list-style: none; padding-left: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 8px; font-size: 15px; }
