:root {
  --font: "Trebuchet MS", "Segoe UI", sans-serif;
  --amber: #ffc66b;
  --cyan: #5fe9ff;
  --navy: #0a1030;
  --ink: #050818;
  --gold: #ffd36a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #03050f; color: #eef3ff;
  font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; }
#bg { position: fixed; inset: 0; background: #050a1e url(../assets/space-bg.webp) center / cover no-repeat; transition: opacity .4s; }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.screen { position: fixed; inset: 0; display: none; pointer-events: none; }
.screen.on { display: block; }
.screen.on > * { pointer-events: auto; }
button { font-family: var(--font); }

/* text style */
.h-title { font-weight: 900; font-size: 22px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--amber);
  text-shadow: 0 0 2px #000, 2px 2px 0 #1a0f00, -1px -1px 0 #1a0f00, 1px -1px 0 #1a0f00, -1px 1px 0 #1a0f00, 0 3px 0 #1a0f00; }
.h-title.center { text-align: center; }
.h-title.big { font-size: 26px; }
.h-sub { font-weight: 800; font-size: 15px; color: #cfe8ff; text-shadow: 0 1px 0 #000, 0 0 4px #000, 1px 1px 0 #000; margin-top: 2px; }
.hud-tl { position: absolute; left: calc(12px + env(safe-area-inset-left, 0px)); top: calc(10px + var(--sat)); right: 72px; pointer-events: none !important; }

/* 9-slice art */
.panel { border: 18px solid transparent; border-image: url(../assets/ui-panel.webp) 22% fill / 18px stretch; }
.plate { border: 12px solid transparent; border-image: url(../assets/ui-button.webp) 30% fill / 12px stretch; }

.btn { cursor: pointer; color: #fff; font-weight: 900; font-size: 16px; letter-spacing: .5px; background: none; padding: 0;
  text-shadow: 0 2px 0 #1a0f00, 0 0 3px #000; transition: transform .12s cubic-bezier(.3,1.6,.5,1), filter .12s; outline: none; }
.btn:hover, .btn.focus { filter: brightness(1.25) drop-shadow(0 0 6px rgba(95,233,255,.7)); transform: scale(1.04); }
.btn:active { transform: scale(.92); }
.btn[disabled] { filter: grayscale(.8) brightness(.6); }
.row { display: flex; gap: 8px; justify-content: center; }
.wide { min-width: 140px; height: 54px; padding: 0 10px; }

/* title */
#title .title-art { position: absolute; inset: 0; background: #050a1e url(../assets/cover-bg.webp) center / cover no-repeat; }
.title-logo { position: absolute; left: 50%; top: 11%; width: 80%; max-height: 30%; object-fit: contain; transform: translateX(-50%);
  animation: logoIn .7s cubic-bezier(.3,1.5,.5,1) both, logoFloat 4s 0.7s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(0,0,0,.6)); pointer-events: none !important; }
@keyframes logoIn { from { transform: translateX(-50%) scale(.4) translateY(-40px); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes logoFloat { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-6px); } }
.title-prompt { position: absolute; left: 8%; right: 8%; bottom: calc(8% + var(--sab)); padding: 12px 0; text-align: center; font-weight: 900; font-size: 20px;
  color: #fff; text-shadow: 0 2px 0 #10183a, 0 0 10px rgba(95,233,255,.8); animation: pulse 1.6s ease-in-out infinite; pointer-events: none !important; }
@keyframes pulse { 0%,100% { opacity: .55; transform: scale(.97); } 50% { opacity: 1; transform: scale(1.03); } }
.corner-btn { position: absolute; left: calc(10px + env(safe-area-inset-left, 0px)); top: calc(10px + var(--sat)); min-height: 44px; padding: 0 14px;
  font-size: 14px; border-radius: 22px; background: rgba(10,16,48,.55); border: 1px solid rgba(255,198,107,.5); color: #ffe6b8; }

/* intro */
#intro { background: #000 url(../assets/cover-bg.webp) center / cover no-repeat; }
#introVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none !important; }
.skip-btn { position: absolute; right: calc(12px + env(safe-area-inset-right, 0px)); top: calc(12px + var(--sat)); height: 48px; min-width: 96px; padding: 0 10px; }

/* map */
#map { background: #050a1e url(../assets/station-bg.webp) center / cover no-repeat; }
#map::before { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(3,6,20,.55), rgba(3,6,20,.35) 40%, rgba(3,6,20,.75)); pointer-events: none; }
.gold-pill { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 3px 12px 3px 4px; border-radius: 20px;
  background: rgba(5,8,24,.7); border: 1px solid rgba(95,233,255,.45); font-weight: 900; font-size: 17px; color: #fff; text-shadow: 0 1px 0 #000; }
.gold-ico { width: 28px; height: 28px; object-fit: contain; }
.map-nodes { position: absolute; left: 6%; right: 6%; top: 18%; bottom: 25%; }
#mapLines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.node { position: absolute; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 900; background: radial-gradient(circle at 40% 35%, #2b3a78, #0c1438 70%); border: 3px solid #4a5a99; color: #9fb0e0; }
.node.solved { border-color: var(--gold); color: #fff; background: radial-gradient(circle at 40% 35%, #5a4a20, #1e1606 75%); box-shadow: 0 0 10px rgba(255,211,106,.5); }
.node.open { border-color: var(--cyan); color: #fff; box-shadow: 0 0 16px rgba(95,233,255,.8); animation: nodePulse 1.4s ease-in-out infinite; }
.node.locked { opacity: .55; cursor: default; }
.node .star { position: absolute; top: -8px; right: -6px; font-size: 16px; color: var(--gold); text-shadow: 0 1px 0 #000; }
.node .lockico { position: absolute; bottom: -6px; right: -4px; width: 18px; height: 18px; }
@keyframes nodePulse { 0%,100% { box-shadow: 0 0 8px rgba(95,233,255,.5); } 50% { box-shadow: 0 0 22px rgba(95,233,255,1); } }
.map-bottom { position: absolute; left: 10px; right: 10px; bottom: calc(14px + var(--sab)); display: flex; flex-direction: column; gap: 8px; }
.bag { min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 0 4px; overflow: hidden; }
.bag .bag-label { font-weight: 900; font-size: 13px; color: var(--amber); text-transform: uppercase; text-shadow: 0 1px 0 #000; margin-right: 2px; }
.bag-item { position: relative; display: flex; align-items: center; gap: 4px; min-width: 44px; min-height: 44px; padding: 2px 6px; border-radius: 12px; background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12); font-weight: 900; font-size: 15px; color: #fff; text-shadow: 0 1px 0 #000; }
.bag-item img { width: 34px; height: 34px; object-fit: contain; }
.bag-item.off { opacity: .45; }
.bag-item small { font-size: 12px; color: #bfe; }

/* puzzle */
.fragment { position: absolute; left: 8px; right: 8px; top: calc(62px + var(--sat)); min-height: 74px; padding: 0 4px; }
.frag-label { font-size: 12px; font-weight: 900; color: var(--cyan); letter-spacing: 1px; text-transform: uppercase; text-shadow: 0 1px 0 #000; }
.frag-text { font-size: 15px; line-height: 1.35; font-weight: 700; color: #e8eeff; text-shadow: 0 1px 0 #000; margin-top: 2px; }
.frag-text .blank { letter-spacing: 1px; color: #6f7fb8; font-family: monospace; font-weight: 900; }
.frag-text .w { color: var(--gold); font-weight: 900; }
.frag-text .w small { font-size: 11px; margin-left: 2px; color: #ffe9b0; opacity: .85; }
.readout { position: absolute; left: 8px; right: 8px; display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; pointer-events: none !important; }
.beam-group { display: flex; align-items: center; gap: 3px; padding: 4px 6px; border-radius: 10px; background: rgba(5,8,24,.7); border: 2px solid var(--bc, #5fe9ff); transition: transform .2s; }
.beam-group.lit { border-color: var(--gold); box-shadow: 0 0 12px rgba(255,211,106,.7); animation: litPop .35s cubic-bezier(.3,1.8,.5,1); }
@keyframes litPop { from { transform: scale(1.25); } to { transform: scale(1); } }
.cell { width: 22px; height: 26px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 17px;
  background: rgba(255,255,255,.08); color: #fff; text-shadow: 0 1px 0 #000; }
.beam-group.lit .cell { background: rgba(255,211,106,.25); color: #fff6d8; }
.subtitle { position: absolute; left: 10%; right: 10%; bottom: 168px; text-align: center; font-size: 15px; font-weight: 800; color: #fff; opacity: 0; transition: opacity .25s;
  text-shadow: 0 1px 0 #000, 0 0 6px #000; pointer-events: none !important; }
.subtitle.on { opacity: 1; }
.subtitle b { color: var(--cyan); }
.pz-bottom { position: absolute; left: 8px; right: 8px; bottom: calc(12px + var(--sab)); display: flex; flex-direction: column; gap: 8px; }
.ring-chips { display: flex; justify-content: center; gap: 8px; align-items: center; }
.chip { position: relative; width: 48px; height: 44px; border-radius: 12px; background: rgba(8,14,40,.8); border: 2px solid #3d4c86; color: #cdd8ff; font-weight: 900; font-size: 17px;
  display: flex; align-items: center; justify-content: center; }
.chip.sel { border-color: var(--cyan); color: #fff; box-shadow: 0 0 12px rgba(95,233,255,.8); }
.chip.nb { border-color: #ff9a3d; }
.chip.locked { border-color: #a03a3a; color: #ff9a9a; }
.chip .arr { position: absolute; top: -13px; left: 50%; transform: translateX(-50%); font-size: 13px; color: #ff9a3d; text-shadow: 0 1px 0 #000; }
.chip.sel .arr { color: var(--cyan); }
.ctl-row { gap: 6px; }
.arrow { width: 74px; height: 60px; display: flex; align-items: center; justify-content: center; }
.arrow svg { width: 30px; height: 30px; fill: none; stroke: #fff; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 2px 0 #000); }
.tool { position: relative; flex: 1; max-width: 76px; height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; font-size: 12px; }
.tool svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1px 0 #000); }
.tool img { width: 26px; height: 26px; object-fit: contain; }
.badge { position: absolute; top: -10px; right: -10px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: #1fb36b; color: #fff;
  font-size: 12px; line-height: 22px; text-shadow: 0 1px 0 #000; border: 2px solid #0a2a18; }
.badge:empty { display: none; }

/* log */
#log { background: #050a1e url(../assets/station-bg.webp) center / cover no-repeat; }
.log-panel { position: absolute; left: 10px; right: 10px; top: calc(62px + var(--sat)); bottom: calc(86px + var(--sab)); display: flex; flex-direction: column; }
.log-list { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; padding: 6px 2px; touch-action: pan-y; }
.log-list::-webkit-scrollbar { display: none; }
.log-entry { margin: 0 0 12px; animation: slideIn .3s ease-out both; }
.log-entry .lh { font-size: 12px; font-weight: 900; color: var(--cyan); letter-spacing: 1px; text-shadow: 0 1px 0 #000; }
.log-entry .lt { font-size: 15px; line-height: 1.4; color: #eef3ff; text-shadow: 0 1px 0 #000; }
.log-entry .lt .w { color: var(--gold); font-weight: 900; }
.log-entry .lt .w small { font-size: 11px; margin-left: 2px; color: #ffe9b0; opacity: .85; }
.log-entry.missing .lt { color: #5d6a9a; font-family: monospace; }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.bottom-center { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(18px + var(--sab)); }
.bottom-center:hover, .bottom-center.focus { transform: translateX(-50%) scale(1.04); }
.bottom-center:active { transform: translateX(-50%) scale(.92); }

/* ending */
#ending { background: #050a1e url(../assets/ending-bg.webp) center / cover no-repeat; }
.ending-text { position: absolute; left: 12px; right: 12px; top: calc(40px + var(--sat)); padding: 2px 6px; animation: dropIn .8s cubic-bezier(.3,1.4,.5,1) both; }
.ending-text p { font-size: 16px; line-height: 1.45; color: #eef3ff; text-shadow: 0 1px 0 #000; margin: 8px 0; }
.ending-text .thanks { color: var(--gold); font-weight: 900; }
.end-row { position: absolute; left: 10px; right: 10px; bottom: calc(22px + var(--sab)); }
@keyframes dropIn { from { opacity: 0; transform: translateY(-30px) scale(.95); } to { opacity: 1; transform: none; } }

/* overlay dialog */
.overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(2,4,14,.55); z-index: 20; }
.overlay.on { display: flex; }
.dialog { width: min(92vw, 380px); padding: 4px 6px 6px; text-align: center; animation: popIn .26s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes popIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.dialog .h-title { margin-bottom: 6px; }
.dialog p { font-size: 15px; line-height: 1.4; margin: 6px 0 10px; color: #eef3ff; text-shadow: 0 1px 0 #000; }
.dialog .who { font-size: 12px; font-weight: 900; letter-spacing: 1px; color: var(--cyan); text-transform: uppercase; }
.dialog .row { margin-top: 8px; flex-wrap: wrap; }
.dialog .stats { display: flex; justify-content: center; gap: 14px; font-weight: 900; font-size: 16px; margin: 6px 0; text-shadow: 0 1px 0 #000; }
.dialog .stats .gain { color: #8ff7ff; display: inline-flex; align-items: center; gap: 4px; }
.dialog .stats img { width: 24px; height: 24px; }
.dialog .bonus { color: var(--gold); font-size: 13px; font-weight: 900; }
.dialog .logline { font-size: 15px; min-height: 3.6em; text-align: left; padding: 6px 8px; border-radius: 8px; background: rgba(0,0,0,.3); }
.dialog .logline .w { color: var(--gold); font-weight: 900; }
.dialog .logline .w small { font-size: 11px; margin-left: 2px; color: #ffe9b0; }
.dialog .item-ico { width: 64px; height: 64px; object-fit: contain; }
.dialog .btn .gold-ico { width: 22px; height: 22px; vertical-align: middle; }
.ch { opacity: 0; animation: chIn .05s forwards; }
@keyframes chIn { to { opacity: 1; } }
.flash { position: fixed; inset: 0; background: radial-gradient(circle, rgba(255,230,160,.7), rgba(255,211,106,0) 70%); opacity: 0; pointer-events: none; z-index: 15; transition: opacity .5s; }
.fade { position: fixed; inset: 0; background: #02040c; opacity: 0; pointer-events: none; z-index: 30; transition: opacity .25s; }
.fade.on { opacity: 1; }
