:root {
  --bg: #0e0c0a;
  --panel: rgba(28, 23, 18, 0.94);
  --panel-solid: #1c1712;
  --line: rgba(201, 162, 74, 0.35);
  --gold: #c9a24a;
  --gold-hi: #e8c979;
  --text: #efe6d2;
  --muted: #a99c84;
  --danger: #c0533a;
  --radius: 10px;
  --font: "Yu Gothic", "YuGothic", "Hiragino Sans", "Noto Sans JP", "Meiryo", sans-serif;
  --serif: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- ボタン ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-size: 15px; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: rgba(201,162,74,0.12); border-color: var(--gold); }
.btn.primary { background: linear-gradient(#b8903c, #8e6a25); border-color: #e2c27a; color: #1a1408; font-weight: bold; }
.btn.primary:hover { background: linear-gradient(#cfa54b, #9f7a2c); }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* ---------- タイトル ---------- */
.title-screen {
  position: absolute; inset: 0; overflow-y: auto; padding: 32px 16px 48px;
  background: radial-gradient(ellipse at top, #2a2015 0%, #0e0c0a 70%);
}
.title-head { text-align: center; max-width: 900px; margin: 0 auto 28px; }
.title-logo { display: flex; align-items: center; justify-content: center; gap: 12px; }
.title-key { font-size: 36px; filter: drop-shadow(0 0 8px rgba(232,201,121,.5)); }
.title-head h1 { font-family: var(--serif); font-size: clamp(26px, 5vw, 42px); margin: 0; letter-spacing: .12em; color: var(--gold-hi); }
.title-sub { color: var(--muted); margin: 10px 0 16px; letter-spacing: .1em; }
.title-tools { display: flex; gap: 8px; justify-content: center; }
.scenario-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; max-width: 980px; margin: 0 auto; }
.scenario-card { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.card-band { height: 96px; position: relative; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), #1c1712); }
.card-emoji { font-size: 48px; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); }
.card-cleared { position: absolute; top: 10px; right: 10px; background: var(--gold); color: #1a1408; font-weight: bold; font-size: 12px; padding: 3px 8px; border-radius: 4px; letter-spacing: .1em; }
.card-main { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-main h2 { margin: 0; font-family: var(--serif); font-size: 21px; color: var(--gold-hi); }
.card-subtitle { color: var(--muted); font-size: 13px; }
.card-desc { margin: 4px 0; font-size: 14px; line-height: 1.7; flex: 1; }
.card-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.card-buttons { display: flex; gap: 8px; margin-top: 6px; }
.title-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.title-screen .modal-layer { position: fixed; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 12px; }
.link-btn:hover { color: var(--gold-hi); }
.credits p { white-space: pre-wrap; font-size: 14px; }
.credits h3 { color: var(--gold-hi); font-size: 15px; margin: 14px 0 2px; }
.credits-url { color: var(--muted); font-size: 12px; }
.credits pre { white-space: pre-wrap; font-size: 11px; background: rgba(255,255,255,.04); padding: 10px; border-radius: 6px; max-height: 240px; overflow-y: auto; }

/* ---------- ゲーム画面 ---------- */
.game { position: absolute; inset: 0; }
.game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }

.hud-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: linear-gradient(rgba(0,0,0,.6), rgba(0,0,0,0)); pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.hud-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: rgba(20,16,12,.7); color: var(--text); font-size: 18px; cursor: pointer; }
.hud-btn:hover { border-color: var(--gold); }
.hud-btn.map-btn { width: auto; border-radius: 21px; padding: 0 12px 0 10px; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--gold-hi); }
.hud-btn.map-btn svg { flex: 0 0 auto; }
.hud-names { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hud-title { font-family: var(--serif); font-size: 16px; color: var(--gold-hi); text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-room { font-size: 12px; color: var(--text); text-shadow: 0 1px 3px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-banner { position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%); font-family: var(--serif); font-size: clamp(22px, 4vw, 34px); color: var(--gold-hi);
  letter-spacing: .3em; padding: 10px 34px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .5s; z-index: 15; white-space: nowrap; }
.room-banner.show { opacity: 1; }
.hud-timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; text-shadow: 0 1px 3px #000; }

.nav { position: absolute; border: 1px solid var(--line); background: rgba(20,16,12,.6); color: var(--gold-hi); cursor: pointer; font-size: 22px; transition: background .15s; }
.nav:hover { background: rgba(201,162,74,.25); }
.nav-left, .nav-right { top: 45%; width: 46px; height: 72px; border-radius: 10px; transform: translateY(-50%); }
.nav-left { left: 10px; }
.nav-right { right: 10px; }
.nav-back { left: 50%; transform: translateX(-50%); bottom: 112px; padding: 8px 22px; border-radius: 20px; font-size: 15px; }

.inventory { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 10px 10px; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.75) 30%); }
.inv-head { display: flex; align-items: center; gap: 10px; min-height: 28px; padding: 0 4px; }
.inv-label { font-size: 12px; color: var(--muted); letter-spacing: .1em; }
.inv-selname { font-size: 13px; color: var(--gold-hi); flex: 1; }
.inv-slots { display: flex; gap: 8px; overflow-x: auto; padding: 4px; scrollbar-width: thin; }
.inv-slot { flex: 0 0 auto; width: 64px; height: 64px; border-radius: 8px; border: 1px solid var(--line); background: rgba(40,32,24,.85); padding: 2px; cursor: pointer; }
.inv-slot img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.inv-slot.selected { border: 2px solid var(--gold-hi); box-shadow: 0 0 12px rgba(232,201,121,.6); background: rgba(90,70,30,.9); }
.inv-slot.combine-target { border-style: dashed; border-color: var(--gold); animation: pulse-border 1.2s infinite; }
@keyframes pulse-border { 50% { box-shadow: 0 0 10px rgba(232,201,121,.5); } }
.inv-selname.combine { color: #ffd890; }
.inv-empty { color: var(--muted); font-size: 13px; padding: 20px 6px; }

/* メッセージ */
.msg-layer { position: absolute; inset: 0; display: none; z-index: 20; cursor: pointer; }
.msg-layer.show { display: block; }
.msgbox { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(760px, calc(100% - 24px)); min-height: 110px;
  background: var(--panel); border: 1px solid var(--gold); border-radius: var(--radius); padding: 18px 22px 22px; display: flex; gap: 16px; align-items: flex-start;
  box-shadow: 0 8px 30px rgba(0,0,0,.6); }
.msg-icon { width: 72px; height: 72px; object-fit: contain; flex: 0 0 auto; background: rgba(255,255,255,.04); border-radius: 8px; }
.msg-text { font-size: 17px; line-height: 1.8; white-space: pre-wrap; flex: 1; font-family: var(--serif); }
.msg-next { position: absolute; right: 16px; bottom: 6px; color: var(--gold); font-size: 13px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.toast { position: absolute; top: 64px; left: 50%; transform: translate(-50%, -10px); background: var(--panel); border: 1px solid var(--line); padding: 8px 18px; border-radius: 20px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; z-index: 30; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fade { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .4s; z-index: 40; }
.fade.show { opacity: 1; }

/* ---------- モーダル ---------- */
.modal-layer { position: absolute; inset: 0; pointer-events: none; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; transition: opacity .18s; pointer-events: auto; }
.modal-backdrop.show { opacity: 1; }
.modal-panel { position: relative; background: var(--panel-solid); border: 1px solid var(--gold); border-radius: 14px; padding: 20px 22px; width: min(440px, 100%); max-height: calc(100% - 16px); overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,.7); }
.modal-panel.wide { width: min(640px, 100%); }
.modal-title { font-family: var(--serif); font-size: 19px; color: var(--gold-hi); margin: 0 30px 14px 0; }
.modal-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { line-height: 1.7; }
.modal-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.menu-body { display: flex; flex-direction: column; gap: 10px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* 謎UI */
.puzzle-text { margin: 0 0 14px; color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.dial-row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.dial { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dial-btn { width: 54px; height: 34px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--gold-hi); cursor: pointer; font-size: 14px; }
.dial-btn:hover { background: rgba(201,162,74,.2); }
.dial-face { width: 54px; height: 64px; border-radius: 8px; background: linear-gradient(#3b3125, #1f1912 50%, #3b3125); border: 2px solid #8e6a25;
  display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: bold; font-family: var(--serif); color: #f5e6c0; user-select: none; }
.dial-color { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); }
.keypad-display { font-family: monospace; font-size: 28px; text-align: center; letter-spacing: .2em; background: #0b120c; color: #8dff9c; padding: 10px; border-radius: 6px; margin-bottom: 12px; }
.keypad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { height: 50px; font-size: 20px; border-radius: 8px; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--text); cursor: pointer; }
.key.primary { background: #8e6a25; color: #fff; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.btn.choice { text-align: left; padding: 12px 16px; font-size: 16px; }
.text-answer { width: 100%; font-size: 18px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: #0f0c09; color: var(--text); }

/* アイテム詳細 */
.item-view { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.item-canvas-wrap { position: relative; width: 100%; display: flex; justify-content: center; background: radial-gradient(#3a3024, #15110d); border-radius: 10px; }
.item-canvas { touch-action: none; cursor: grab; display: block; }
.item-hint { position: absolute; bottom: 6px; right: 10px; font-size: 11px; color: var(--muted); pointer-events: none; }
.item-desc { white-space: pre-wrap; line-height: 1.8; font-family: var(--serif); width: 100%; }

/* ヒント・ヘルプ・エンディング */
.hint-list { padding-left: 20px; margin: 0 0 12px; line-height: 1.8; }
.hint-list li.answer { color: var(--gold-hi); }
.help h3 { color: var(--gold-hi); font-size: 15px; margin: 14px 0 6px; font-family: var(--serif); }
.help h3:first-child { margin-top: 0; }
.help table { width: 100%; border-collapse: collapse; font-size: 14px; }
.help th { text-align: left; white-space: nowrap; color: var(--gold); padding: 5px 12px 5px 0; vertical-align: top; font-weight: normal; }
.help td { padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.ending .modal-title { text-align: center; font-size: 26px; margin-right: 0; }
.ending-text { white-space: pre-wrap; font-family: var(--serif); line-height: 1.9; margin-bottom: 16px; }
.ending-stats { display: flex; flex-direction: column; gap: 4px; background: rgba(255,255,255,.04); padding: 12px 14px; border-radius: 8px; font-size: 14px; }
.ending-stats b { color: var(--gold-hi); }
.ending-kind { text-align: center; font-size: 13px; letter-spacing: .3em; margin: -6px 0 12px; color: var(--gold); }
.ending-kind.bad { color: #e07a64; }
.ending-kind.true { color: #ffe9a8; text-shadow: 0 0 8px rgba(255,220,140,.6); }
.ending.bad { border-color: #7a3a2e; }
.ending.bad .modal-title { color: #e07a64; }
.ending-note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

/* マップ */
.map-grid { display: grid; gap: 10px; }
.map-room { appearance: none; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text); border-radius: 10px; padding: 14px 4px; font-family: inherit; min-height: 74px; min-width: 0; }
.map-room.can { cursor: pointer; }
.map-room.can:hover { background: rgba(201,162,74,.18); border-color: var(--gold); }
.map-room.here { border: 2px solid var(--gold-hi); background: rgba(90,70,30,.6); }
.map-room.unknown { opacity: .45; border-style: dashed; }
.map-room:disabled { cursor: default; }
.map-name { font-family: var(--serif); font-size: clamp(12px, 3.4vw, 16px); color: var(--gold-hi); word-break: keep-all; overflow-wrap: anywhere; }
.map-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.map-note { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.card-meta .diff { color: var(--gold-hi); }
.card-endings { color: var(--muted); }

/* デバッグ */
.debug-panel { position: absolute; top: 60px; right: 10px; width: 260px; background: rgba(0,0,0,.8); border: 1px solid #4a4; color: #9f9; font-size: 11px; padding: 8px; z-index: 45; border-radius: 6px; }
.debug-panel pre { white-space: pre-wrap; word-break: break-all; margin: 4px 0; font-size: 11px; }
.debug-panel select, .debug-panel input { width: 140px; font-size: 11px; }
.debug-panel button { font-size: 11px; }
.debug-title { font-weight: bold; }

@media (max-width: 640px) {
  .nav-left, .nav-right { width: 38px; height: 60px; font-size: 18px; }
  .nav-left { left: 4px; } .nav-right { right: 4px; }
  .nav-back { bottom: 104px; }
  .inv-slot { width: 56px; height: 56px; }
  .msgbox { bottom: 12px; padding: 14px 16px 20px; }
  .msg-text { font-size: 15px; }
  .msg-icon { width: 52px; height: 52px; }
  .hud-title { font-size: 14px; }
}
