:root { color-scheme: dark; --ink:#0d1418; --paper:#f2e9d8; --accent:#e0a04a; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #070b0d; overflow: hidden; }
body { display: grid; place-items: center; font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
#stage { position: relative; width: min(100vw, calc(100vh * 16 / 9)); aspect-ratio: 16 / 9; max-height: 100vh; }
#game { width: 100%; height: 100%; display: block; image-rendering: pixelated; background: #0d1418; }
#ui { position: absolute; inset: 0; font-size: calc(var(--ui-scale, 1) * 5px); }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; color: var(--paper); }
.hidden { display: none !important; }
#debug-errors { position: absolute; left: 0; top: 0; max-width: 100%; background: #7a1f1f; color: #fff; font: 12px monospace; padding: 4px; white-space: pre-wrap; z-index: 99; }

#dialogue { align-items: end; justify-items: center; padding: 3% 4% 4%; }
.dlg-panel { width: min(94%, 720px); background: rgba(13, 20, 24, 0.95); border: 2px solid var(--paper); box-shadow: 5px 5px 0 #000; padding: 1em 1.2em 0.8em; }
.dlg-speaker { color: var(--accent); font-weight: 700; font-size: 1.15em; margin-bottom: 0.4em; }
.dlg-text { line-height: 1.65; min-height: 3.2em; white-space: pre-wrap; }
.dlg-choices { display: flex; flex-wrap: wrap; gap: 0.6em; margin-top: 0.6em; }
.dlg-choice { font: inherit; color: var(--paper); background: rgba(224, 160, 74, 0.14); border: 1px solid var(--accent); padding: 0.45em 0.8em; cursor: pointer; }
.dlg-choice:hover, .dlg-choice:focus-visible { background: rgba(224, 160, 74, 0.32); outline: none; }
.dlg-hint { text-align: right; opacity: 0.65; font-size: 0.8em; margin-top: 0.5em; min-height: 1.2em; }

#radio-overlay { align-items: center; justify-items: center; }
.radio-panel { width: min(88%, 640px); background: rgba(10, 16, 20, 0.97); border: 2px solid var(--accent); box-shadow: 6px 6px 0 #000; padding: 1.3em 1.5em; text-align: center; }
.radio-kicker { letter-spacing: 0.18em; opacity: 0.7; font-size: 0.8em; }
.radio-freq { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 2.6em; color: var(--accent); line-height: 1.1; margin: 0.1em 0; }
.radio-track { position: relative; height: 1.1em; margin: 0.7em 0; background: #18262f; border: 1px solid #3b5566; cursor: pointer; touch-action: none; }
.radio-needle { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--paper); transform: translateX(-50%); box-shadow: 0 0 6px rgba(242, 233, 216, 0.7); }
.radio-signal { display: flex; gap: 0.3em; justify-content: center; align-items: flex-end; height: 1.2em; }
.radio-signal span { width: 0.5em; background: #2e4658; transition: background 0.1s; }
.radio-signal span.on { background: var(--accent); }
.radio-name { margin-top: 0.6em; font-weight: 700; font-size: 1.1em; }
.radio-program { min-height: 3em; margin-top: 0.4em; opacity: 0.85; line-height: 1.55; }
.radio-hint { margin-top: 0.8em; opacity: 0.55; font-size: 0.8em; }

/* ---- title ---- */
#title-screen { z-index: 2; background: radial-gradient(ellipse at 50% 42%, rgba(13,20,24,0.35), rgba(7,11,13,0.88) 78%); }
.title-wrap { width: min(90%, 760px); text-align: center; padding: 1em; }
.title-main { margin: 0; font-size: clamp(18px, calc(var(--ui-scale, 1) * 14px), 64px); letter-spacing: 0.22em; font-weight: 700; text-shadow: 4px 4px 0 #000, 0 0 18px rgba(224,160,74,0.35); color: var(--paper); }
.title-sub { margin: 0.9em auto 1.4em; max-width: 34em; font-size: clamp(9px, calc(var(--ui-scale, 1) * 5.5px), 20px); line-height: 1.7; opacity: 0.75; }
.title-menu { display: grid; gap: 0.55em; width: min(100%, 320px); margin: 0 auto; }
.title-menu button { font: inherit; font-size: clamp(9px, calc(var(--ui-scale, 1) * 5.2px), 19px); letter-spacing: 0.12em; color: var(--paper); background: rgba(13,20,24,0.82); border: 2px solid #3b5566; padding: 0.7em 1em; cursor: pointer; transition: background 0.12s, border-color 0.12s; }
.title-menu button:hover:not(:disabled), .title-menu button:focus-visible:not(:disabled) { background: rgba(224,160,74,0.2); border-color: var(--accent); outline: none; }
.title-menu button:disabled { opacity: 0.38; cursor: default; }
.title-note { margin-top: 1.8em; font-size: clamp(7px, calc(var(--ui-scale, 1) * 3.8px), 14px); opacity: 0.45; line-height: 1.5; }

/* ---- HUD ---- */
#hud { position: absolute; left: 0; right: 0; top: 0; display: flex; flex-wrap: wrap; gap: 0.8em; align-items: center; padding: 0.7em 1em; font-size: clamp(7px, calc(var(--ui-scale, 1) * 4.2px), 15px); letter-spacing: 0.06em; color: var(--paper); text-shadow: 1px 1px 0 #000; pointer-events: none; background: linear-gradient(rgba(7,11,13,0.55), rgba(7,11,13,0)); }
#hud .hud-frag { color: var(--accent); }
#hud .hud-hint { margin-left: auto; opacity: 0.5; }

/* ---- panels ---- */
#menu-overlay { z-index: 3; padding: 3%; }
.panel { width: min(96%, 760px); max-height: 100%; display: flex; flex-direction: column; background: rgba(10,16,20,0.97); border: 2px solid var(--paper); box-shadow: 6px 6px 0 #000; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: 0.8em 1.1em; border-bottom: 1px solid #2e4658; }
.panel-title { font-weight: 700; letter-spacing: 0.16em; color: var(--accent); font-size: 1.1em; }
.panel-close { font: inherit; color: var(--paper); background: none; border: 1px solid transparent; font-size: 1.3em; line-height: 1; padding: 0 0.25em; cursor: pointer; }
.panel-close:hover, .panel-close:focus-visible { border-color: var(--paper); outline: none; }
.panel-body { padding: 1em 1.1em 1.2em; overflow-y: auto; display: flex; flex-direction: column; gap: 0.7em; }
.empty { opacity: 0.6; line-height: 1.6; margin: 0.4em 0; }

/* ---- ending ---- */
.ending-open .panel { width: min(92%, 640px); border-color: var(--accent); }
.ending-body { display: flex; flex-direction: column; gap: 0.4em; }
.ending-body p { line-height: 1.9; margin: 0.5em 0; }
.ending-frag { color: var(--accent); letter-spacing: 0.12em; font-size: 0.85em; }
.ending-credit { opacity: 0.55; font-size: 0.82em; line-height: 1.7; border-top: 1px solid #2e4658; padding-top: 0.8em; margin-top: 0.8em; }
.ending-actions { display: flex; gap: 0.6em; flex-wrap: wrap; margin-top: 1.1em; }
.ending-actions .btn { font: inherit; color: var(--paper); background: rgba(24,38,47,0.6); border: 1px solid #33505f; padding: 0.65em 1em; cursor: pointer; }
.ending-actions .btn:hover, .ending-actions .btn:focus-visible { border-color: var(--accent); background: rgba(224,160,74,0.14); outline: none; }

/* ---- touch controls ---- */
#touch-controls { display: none; position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; justify-content: space-between; align-items: end; padding: 0.6em 0.8em calc(0.6em + env(safe-area-inset-bottom, 0px)); pointer-events: none; }
body.touch-device #touch-controls { display: flex; }
#touch-controls button { pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; font: inherit; color: var(--paper); background: rgba(10,16,20,0.72); border: 1px solid rgba(242,233,216,0.55); border-radius: 4px; min-width: 2.6em; min-height: 2.6em; font-size: clamp(10px, calc(var(--ui-scale, 1) * 5.6px), 18px); }
#touch-controls button:active { background: rgba(224,160,74,0.4); }
.touch-dpad { display: grid; grid-template-columns: repeat(3, auto); grid-template-rows: repeat(2, auto); gap: 0.3em; }
.touch-dpad button[data-action="up"] { grid-column: 2; grid-row: 1; }
.touch-dpad button[data-action="left"] { grid-column: 1; grid-row: 2; }
.touch-dpad button[data-action="down"] { grid-column: 2; grid-row: 2; }
.touch-dpad button[data-action="right"] { grid-column: 3; grid-row: 2; }
.touch-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.35em; max-width: 58%; }
.touch-actions button { padding: 0.3em 0.5em; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

.map-list { display: grid; gap: 0.55em; }
.map-card { font: inherit; text-align: left; color: var(--paper); background: rgba(24,38,47,0.6); border: 1px solid #33505f; padding: 0.7em 0.8em; display: grid; grid-template-columns: 2.6em 1fr auto auto; gap: 0.8em; align-items: center; cursor: pointer; }
.map-card:hover, .map-card:focus-visible { border-color: var(--accent); background: rgba(224,160,74,0.14); outline: none; }
.map-card.done { border-color: #5f7f45; }
.map-no { font-family: ui-monospace, "SF Mono", Menlo, monospace; color: var(--accent); opacity: 0.8; }
.map-name { font-weight: 700; }
.map-freq { font-family: ui-monospace, "SF Mono", Menlo, monospace; opacity: 0.8; }
.map-status { font-size: 0.82em; opacity: 0.65; }

.tab-row { display: flex; flex-wrap: wrap; gap: 0.35em; border-bottom: 1px solid #2e4658; padding-bottom: 0.5em; }
.tab { font: inherit; color: var(--paper); background: none; border: 1px solid #33505f; padding: 0.42em 0.85em; cursor: pointer; opacity: 0.75; }
.tab:hover, .tab:focus-visible { border-color: var(--accent); outline: none; opacity: 1; }
.tab.active { background: rgba(224,160,74,0.18); border-color: var(--accent); color: var(--accent); opacity: 1; }
.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6em; }
.journal-card { border: 1px solid #33505f; background: rgba(24,38,47,0.5); padding: 0.7em; display: flex; flex-direction: column; gap: 0.35em; min-height: 5.2em; }
.journal-card.locked { opacity: 0.35; border-style: dashed; }
.journal-icon { width: 24px; height: 24px; image-rendering: pixelated; }
.journal-name { font-weight: 700; color: var(--accent); }
.journal-desc { font-size: 0.85em; line-height: 1.5; opacity: 0.85; }

.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: 0.35em 0; }
.set-row input[type="range"] { flex: 0 1 55%; accent-color: var(--accent); }
.set-row select { font: inherit; color: var(--paper); background: #18262f; border: 1px solid #33505f; padding: 0.3em 0.5em; }
.set-row input[type="checkbox"] { accent-color: var(--accent); width: 1.1em; height: 1.1em; }
.small-btn { font: inherit; color: var(--paper); background: none; border: 1px solid #33505f; padding: 0.35em 0.8em; cursor: pointer; margin-left: 0.35em; }
.small-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(224,160,74,0.15); }
.wide-btn { font: inherit; color: var(--paper); background: rgba(24,38,47,0.6); border: 1px solid #33505f; padding: 0.65em 0.9em; text-align: left; cursor: pointer; }
.wide-btn:hover, .wide-btn:focus-visible { border-color: var(--accent); background: rgba(224,160,74,0.14); outline: none; }
.danger-btn { font: inherit; color: #e07a6a; background: none; border: 1px solid #7a3a32; padding: 0.6em 0.9em; margin-top: 0.6em; cursor: pointer; }
.danger-btn:hover, .danger-btn:focus-visible { background: rgba(224,90,74,0.12); outline: none; }

/* ---- toast ---- */
.toast { position: absolute; left: 50%; top: 2.8em; transform: translate(-50%, -0.8em); background: rgba(10,16,20,0.96); border: 1px solid var(--accent); color: var(--paper); padding: 0.55em 1em; font-size: 0.85em; opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s; z-index: 6; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Playable layers: only the actual controls intercept the world canvas. */
#ui { pointer-events: none; font-size: clamp(14px, calc(var(--ui-scale, 1) * 4.4px), 18px); }
.overlay, #quest-panel, #explore-tools, .scene-marker { pointer-events: auto; }
button, select, input { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
button:focus-visible, [role="slider"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#game { touch-action: none; }
#hud { padding: 16px 22px; font-size: clamp(12px, calc(var(--ui-scale, 1) * 3.8px), 15px); }
#hud .hud-hint { position: absolute; top: calc(var(--scene-top, 0px) + var(--scene-height, 100%) - 38px); left: 50%; width: max-content; max-width: 90vw; transform: translateX(-50%); text-align: center; padding: 5px 12px; background: rgba(7,11,13,.82); border-radius: 3px; opacity: .9; font-size: 12px; }
#explore-tools { position: absolute; top: 12px; right: 18px; display: flex; gap: 6px; }
#explore-tools button { font: inherit; font-size: 13px; color: var(--paper); padding: 8px 12px; border: 1px solid #57605b; background: rgba(13,20,24,.88); cursor: pointer; }
#explore-tools button:hover { border-color: var(--accent); color: var(--accent); }
#quest-panel { position: absolute; top: 68px; left: 22px; width: min(310px, 33%); color: var(--paper); padding: 14px 16px; background: rgba(9,16,20,.91); border: 1px solid #65533b; border-left: 3px solid var(--accent); box-shadow: 3px 3px 0 #0003; }
.quest-head { color: var(--accent); letter-spacing: .12em; font-size: 11px; font-weight: 700; margin-bottom: 8px; text-transform: uppercase; }
#quest-panel p { font-size: 13px; line-height: 1.8; margin: 0 0 10px; opacity: .85; }
.quest-step, .quest-go { display: block; width: 100%; text-align: left; font: inherit; font-size: 13px; line-height: 1.6; color: var(--paper); border: 0; border-top: 1px solid #ffffff12; background: none; padding: 8px 0; cursor: pointer; }
.quest-step:hover, .quest-step:focus-visible { color: var(--accent); }
.quest-step.done { color: #abc393; }
.quest-go { color: var(--accent); margin-top: 5px; font-weight: 600; }
#scene-markers { position: absolute; inset: 0; pointer-events: none; }
.scene-marker { position: absolute; transform: translate(-50%, -100%); display: grid; justify-items: center; width: 32px; height: 32px; padding: 0; border: 0; background: none; cursor: pointer; color: var(--paper); }
.marker-dot { display: grid; place-items: center; align-self: end; width: 22px; height: 22px; font: 700 12px ui-monospace, monospace; border: 1px solid #dacbae99; background: #0d1418e8; box-shadow: 2px 2px 0 #0006; }
.marker-name { display: none; position: absolute; bottom: 30px; width: max-content; max-width: 170px; padding: 5px 8px; font-size: 12px; color: var(--paper); background: #0d1418f5; border: 1px solid #786442; line-height: 1.4; pointer-events: none; }
.scene-marker:hover, .scene-marker:focus-visible, .scene-marker.nearby { z-index: 2; }
.scene-marker:hover .marker-name, .scene-marker:focus-visible .marker-name, .scene-marker.nearby .marker-name { display: block; }
.scene-marker.is-goal .marker-dot { border-color: var(--accent); color: #18130b; background: var(--accent); }
.scene-marker.is-visited:not(.is-goal) .marker-dot { border-color: #94ad7e; color: #abc393; }
#player-label { position: absolute; transform: translate(-50%, -100%); padding: 2px 6px; color: var(--accent); background: #0d1418e8; border: 1px solid #b5904c; font-size: 10px; line-height: 1.3; pointer-events: none; z-index: 1; }
.dlg-panel { padding: 20px 24px 16px; }
.dlg-text { min-height: 3.3em; }
.dlg-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.dlg-hint { margin: 0; text-align: left; }
.dlg-next { font: inherit; color: var(--accent); background: #e0a04a14; border: 1px solid #9b7846; padding: 8px 16px; cursor: pointer; }
.dlg-choice { min-height: 44px; }
.radio-panel { max-height: 94%; overflow-y: auto; padding: 20px 28px; }
.radio-top { display: flex; align-items: center; justify-content: space-between; }
.radio-top .panel-close { min-width: 36px; min-height: 36px; }
.radio-freq { font-size: 46px; letter-spacing: .04em; }
.radio-unit { color: #b5a183; font-size: 11px; letter-spacing: .18em; margin-bottom: 16px; }
.radio-track { min-height: 28px; margin: 0; background: repeating-linear-gradient(90deg, transparent 0 9px, #bdad862b 9px 10px), #18262f; }
.radio-scale { display: flex; justify-content: space-between; font: 10px ui-monospace, monospace; color: #b5a183; margin: 6px 0 12px; }
.radio-name { font-size: 17px; }
.radio-program { min-height: 3.1em; font-size: 14px; }
.radio-actions { display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 8px; margin: 16px 0; }
.radio-actions button, .radio-preset { font: inherit; color: var(--paper); background: #18262f; border: 1px solid #5a665e; cursor: pointer; min-height: 42px; padding: 8px; }
.radio-actions button:disabled { opacity: .5; cursor: default; }
.radio-actions .radio-confirm { color: #17130c; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.radio-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.radio-preset { text-align: left; font-size: 12px; }
.radio-preset.selected { border-color: var(--accent); color: var(--accent); background: #e0a04a12; }
.radio-hint { font-size: 11px; line-height: 1.6; }
.panel-close { min-width: 40px; min-height: 40px; }
.panel-head { padding-block: 8px; }
.panel-body { min-height: 0; overscroll-behavior: contain; }
.toast { max-width: calc(100% - 32px); width: max-content; top: 58px; font-size: 13px; line-height: 1.6; }
body.touch-device #touch-controls { padding: 14px 18px; }
#touch-controls button { min-width: 44px; min-height: 44px; font-size: 15px; }
#touch-controls button.held { background: #e0a04a66; border-color: var(--accent); }
.touch-actions { align-items: end; max-width: 45%; }
.touch-actions button[data-action="confirm"] { min-width: 68px; min-height: 56px; border-color: var(--accent); color: var(--accent); }

@media (max-width: 900px) and (orientation: portrait) {
  body { display: block; }
  #stage { width: 100%; height: 100dvh; max-height: none; aspect-ratio: auto; background: radial-gradient(ellipse at 50% 65%, #1a211f, #090f13 70%); }
  #game { position: absolute; top: calc(90px + env(safe-area-inset-top, 0px)); width: 100%; height: auto; aspect-ratio: 16 / 9; border-block: 1px solid #5c5037; }
  #ui { font-size: 15px; }
  #hud { padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 8px; font-size: 12px; gap: 8px; background: none; }
  #hud .hud-hint { display: none; }
  #explore-tools { top: calc(44px + env(safe-area-inset-top, 0px)); left: 16px; right: 16px; justify-content: space-between; }
  #explore-tools button { flex: 1; min-height: 36px; padding: 6px 8px; font-size: 12px; }
  #quest-panel { top: calc(var(--scene-top) + var(--scene-height) + 18px); left: 16px; width: calc(100% - 32px); max-height: calc(100dvh - var(--scene-top) - var(--scene-height) - 186px); overflow-y: auto; padding: 14px 16px; }
  #quest-panel p, .quest-step, .quest-go { font-size: 14px; }
  .quest-step { padding: 9px 0; }
  .quest-head { font-size: 12px; }
  .scene-marker { width: 36px; height: 36px; }
  .marker-dot { width: 20px; height: 20px; font-size: 11px; }
  .marker-name { max-width: 130px; font-size: 11px; }
  #player-label { font-size: 10px; }
  body.touch-device #touch-controls { bottom: 0; padding: 18px 22px calc(22px + env(safe-area-inset-bottom, 0px)); }
  #touch-controls button { min-width: 48px; min-height: 48px; background: #162127; }
  .touch-dpad { gap: 5px; }
  .touch-actions { flex-direction: column; gap: 8px; }
  .touch-actions button[data-action="confirm"] { min-width: 88px; min-height: 58px; }
  .touch-actions button[data-action="cancel"] { min-width: 88px; }
  #dialogue { align-items: center; padding: 16px; background: #070b0d66; }
  .dlg-panel { width: 100%; padding: 20px; max-height: calc(100dvh - 40px); overflow-y: auto; }
  .dlg-text { min-height: 5em; font-size: 16px; line-height: 1.85; }
  .dlg-speaker { font-size: 16px; }
  .dlg-choices { flex-direction: column; }
  .dlg-hint { font-size: 11px; }
  .dlg-next { min-height: 44px; }
  #radio-overlay { background: #070b0d88; padding: 16px; }
  .radio-panel { width: 100%; padding: 16px; max-height: calc(100dvh - 32px); }
  .radio-freq { font-size: 42px; }
  .radio-program { font-size: 14px; }
  .radio-presets { grid-template-columns: 1fr 1fr; }
  .radio-preset { min-height: 44px; font-size: 12px; }
  #menu-overlay { padding: 16px; background: #070b0d88; }
  .panel { width: 100%; max-height: calc(100dvh - 32px); }
  .panel-head { padding-inline: 16px; }
  .panel-body { padding: 16px; }
  .map-card { grid-template-columns: 1.8em 1fr auto; gap: 8px; font-size: 13px; min-height: 60px; }
  .map-status { grid-column: 2; }
  .map-freq { grid-column: 3; grid-row: 1 / span 2; }
  .journal-grid { grid-template-columns: 1fr 1fr; }
  .journal-desc { font-size: 12px; }
  .title-main { font-size: 34px; }
  .title-sub { font-size: 14px; }
  .title-menu { gap: 10px; }
  .title-menu button { font-size: 16px; min-height: 48px; }
  .title-note { font-size: 11px; }
  .toast { top: calc(var(--scene-top) + var(--scene-height) - 40px); font-size: 12px; text-align: center; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #hud { padding: 8px 12px; font-size: 11px; }
  #explore-tools { top: 6px; right: 10px; }
  #explore-tools button { padding: 5px 8px; font-size: 11px; }
  #quest-panel { top: 42px; left: 12px; padding: 10px 12px; width: 30%; }
  .quest-head { font-size: 10px; margin-bottom: 4px; }
  .quest-step, .quest-go, #quest-panel p { font-size: 11px; padding-block: 4px; }
  .radio-panel { max-height: 94%; padding: 12px 20px; }
  .radio-freq { font-size: 30px; }
  .radio-unit { margin-bottom: 6px; }
  .radio-program { min-height: auto; font-size: 12px; }
  .radio-presets { grid-template-columns: repeat(3, 1fr); }
  .radio-preset { font-size: 11px; }
  .dlg-panel { padding: 12px 18px; }
  .dlg-text { font-size: 13px; }
}

