:root{
  --bg: #03070d;
  --panel: rgba(6, 16, 28, 0.82);
  --panel-border: rgba(40, 120, 150, 0.35);
  --cyan: #3fe0d0;
  --cyan-dim: #1a8a80;
  --teal: #14b8a6;
  --amber: #f5b942;
  --red: #ff4d5e;
  --green: #6df29a;
  --violet: #9d7bff;
  --text: #cfeef5;
  --dim: #6d94a0;
  --font-head: 'Press Start 2P', monospace;
  --font-body: 'VT323', monospace;
}

*{ box-sizing:border-box; margin:0; padding:0; }
html,body{ height:100%; }
html{ -webkit-text-size-adjust:100%; }
body{
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 20px;
  line-height: 1.35;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: none;
  height:100vh; height:100dvh;
}
button, .btn{ touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* CRT scanlines + vignette */
.scanlines{
  position: fixed; inset: 0; pointer-events: none; z-index: 999;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.16) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
body::after{
  content:''; position: fixed; inset:0; pointer-events:none; z-index:998;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
}

#app{ position:relative; height:100vh; height:100dvh; overflow:hidden; }

.screen{ display:none; position:relative; height:100vh; height:100dvh; }
.screen.active{ display:block; }
#screen-title.active,
#screen-game.active,
#screen-end.active{ display:flex; }
.screen.overlay{ position:fixed; z-index:50; inset:0; display:none; overflow-y:auto; }
.screen.overlay.active{ display:flex; align-items:center; justify-content:center; }

.bg-canvas{ position:absolute; inset:0; width:100%; height:100%; z-index:0; }

/* ---------- generic ---------- */
.btn{
  font-family: var(--font-head);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--cyan);
  background: rgba(10, 40, 50, 0.6);
  border: 2px solid var(--cyan-dim);
  padding: 10px 18px;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform .05s, background .1s, box-shadow .1s;
  user-select: none;
}
.btn:hover{ background: rgba(20, 70, 90, 0.7); box-shadow: 0 0 12px rgba(63,224,208,0.35); }
.btn:active{ transform: translateY(1px); }
.btn.primary{
  color: #04151a; background: var(--cyan);
  border-color: #c6fff7;
  text-shadow: 0 1px 0 rgba(255,255,255,0.2);
}
.btn.primary:hover{ background:#5ff5e6; box-shadow: 0 0 18px rgba(63,224,208,0.65); }
.btn.ghost{ background: rgba(6,16,28,0.5); }
.btn.big{ font-size: 14px; padding: 16px 26px; }
.btn.tiny{ font-size: 10px; padding: 6px 10px; background:transparent; }
@media (pointer: coarse){
  .btn.tiny{ font-size: 12px; padding: 10px 14px; }
}
.btn:disabled{ opacity: .4; cursor: not-allowed; }
.dim{ color: var(--dim); }

.panel{
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}

/* ---------- TITLE ---------- */
#screen-title{ overflow-y:auto; padding: 16px 12px; }
.title-inner{ position:relative; z-index:2; text-align:center; padding: 32px 20px; max-width: 760px; width:100%; margin:auto; }
.eyebrow{ font-family:var(--font-head); font-size: 10px; letter-spacing: 3px; color: var(--cyan-dim); margin-bottom: 18px; }
.game-title{
  font-family: var(--font-head);
  font-size: clamp(40px, 9vw, 78px);
  line-height: 1.05;
  color: var(--cyan);
  text-shadow: 0 0 24px rgba(63,224,208,0.55), 0 0 3px #9ff;
  margin-bottom: 18px;
}
.tagline{ color: var(--text); font-size: 24px; margin-bottom: 26px; }
.tagline em{ color: var(--dim); }

.roster-box{
  margin: 0 auto 20px; max-width: 560px;
  border: 1px solid var(--panel-border);
  background: rgba(4, 12, 20, 0.6);
  padding: 14px 18px 18px;
}
.roster-head{ font-family: var(--font-head); font-size: 10px; letter-spacing: 2px; color: var(--violet); text-align:left; margin-bottom: 12px; }
.roster-head .dim{ color: var(--dim); font-size: 8px; float: right; }
.roster{ display:flex; flex-wrap:wrap; gap: 8px 18px; justify-content:center; text-align:left; }
.roster .mate{ font-size: 18px; color: var(--text); white-space: nowrap; }
.roster .mate .glyph{ color: var(--cyan); margin-right: 5px; }
.roster .mate .role{ color: var(--dim); font-size: 15px; }
.roster-actions{ margin-top: 12px; }

.title-actions{ margin-bottom: 14px; }
.fineprint{ font-size: 15px; color: var(--dim); max-width: 540px; margin: 0 auto; }

/* ---------- HUD ---------- */
#screen-game{ flex-direction:column; overflow:hidden; }
.hud{
  position: relative; z-index: 3; flex: 0 0 auto;
  display:flex; align-items:center; gap: 18px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: rgba(4, 12, 20, 0.88);
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
}
.hud-item{ display:flex; align-items:baseline; gap: 6px; }
.hud-item .label{ font-family: var(--font-head); font-size: 8px; color: var(--dim); letter-spacing: 2px; }
.hud-item .value{ font-family: var(--font-head); font-size: 20px; color: var(--cyan); }
.hud-item .unit{ color: var(--dim); font-size: 14px; }
.hud-item.zone .value{ font-size: 13px; color: var(--violet); }
.gauges{ display:flex; gap: 14px; flex:1; flex-wrap:wrap; min-width: 0; }
.gauge{ min-width: 84px; flex: 1 1 90px; }
.gauge .g-label{ font-family: var(--font-head); font-size: 7px; color: var(--dim); letter-spacing: 1px; display:flex; justify-content:space-between; }
.gauge .g-label b{ color: var(--text); }
.gauge .g-track{ height: 8px; background: #041018; border: 1px solid #143648; margin-top: 3px; }
.gauge .g-fill{ height: 100%; transition: width .25s, background .25s; }
.hud-actions{ display:flex; gap: 8px; }

/* ---------- game body ---------- */
.game-body{
  position: relative; z-index: 2;
  display:grid; grid-template-columns: 250px minmax(0,1fr);
  grid-template-rows: minmax(0,1fr);
  gap: 12px; padding: 12px 16px;
  flex: 1 1 auto; min-height: 0;
}
.crew-panel{ padding: 12px; overflow-y:auto; min-height:0; min-width:0; }
.panel-title{ font-family: var(--font-head); font-size: 10px; color: var(--violet); letter-spacing: 2px; margin-bottom: 12px; }
.crew-list{ display:flex; flex-direction:column; gap: 12px; }
.mate{ border-bottom: 1px dashed rgba(40,120,150,0.25); padding-bottom: 8px; }
.mate:last-child{ border-bottom:none; }
.mate .m-top{ display:flex; justify-content:space-between; font-size: 18px; color: var(--text); }
.mate .m-role{ color: var(--dim); font-size: 15px; }
.mate.dead .m-top{ color: var(--red); text-decoration: line-through; }
.mate.dead{ opacity: .55; }
.mate .m-hp{ height: 6px; background:#041018; border:1px solid #143648; margin-top: 4px; }
.mate .m-hp .bar{ height:100%; background: var(--green); transition: width .25s; }

.center-col{ display:flex; flex-direction:column; gap: 12px; min-width: 0; min-height: 0; }
.dive-log{ flex:1; padding: 12px 16px; overflow-y:auto; min-height: 0; font-size: 18px; }
.dive-log .line{ margin-bottom: 5px; }
.dive-log .line.sys{ color: var(--dim); }
.dive-log .line.good{ color: var(--green); }
.dive-log .line.bad{ color: var(--red); }
.dive-log .line.warn{ color: var(--amber); }
.dive-log .line.ev{ color: var(--violet); }

.controls{ padding: 12px 16px; flex: 0 0 auto; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.pace-row{ display:flex; align-items:center; gap: 14px; margin-bottom: 10px; flex-wrap:wrap; }
.pace-row .label{ font-family: var(--font-head); font-size: 8px; color: var(--dim); letter-spacing: 2px; }
.pace-btns{ display:flex; gap: 8px; flex:1; }
.pace-btn{
  flex:1; font-family: var(--font-head); font-size: 9px; color: var(--text);
  background: rgba(6,20,30,0.6); border: 2px solid #1c4a5c; padding: 9px 6px; cursor:pointer;
  display:flex; flex-direction:column; gap:4px; align-items:center;
}
.pace-btn .sub{ font-family: var(--font-body); font-size: 13px; color: var(--dim); }
.pace-btn.active{ border-color: var(--cyan); color: var(--cyan); box-shadow: 0 0 10px rgba(63,224,208,0.4); }
.pace-btn:hover{ background: rgba(12,40,55,0.7); }
.action-row{ display:flex; gap: 10px; align-items:center; }
.action-row .btn.primary{ flex:1; }

/* ---------- EVENT ---------- */
.event-card{ max-width: 640px; width:100%; padding: 28px 30px; margin:auto; }
.event-stamp{ font-family: var(--font-head); font-size: 9px; letter-spacing: 3px; color: var(--amber); margin-bottom: 14px; }
.event-title{ font-family: var(--font-head); font-size: 18px; color: var(--cyan); line-height: 1.4; margin-bottom: 14px; }
.event-body{ font-size: 21px; color: var(--text); margin-bottom: 22px; white-space: pre-line; }
.event-choices{ display:flex; flex-direction:column; gap: 10px; }
.event-choices .btn{ width:100%; text-align:left; font-size: 11px; line-height: 1.5; }
.event-choices .btn:hover{ box-shadow: 0 0 12px rgba(157,123,255,0.4); }

/* ---------- MINIGAME ---------- */
.mini-card{ padding: 18px 22px; margin:auto; text-align:center; width:100%; max-width: 820px; }
.mini-head{ display:flex; justify-content:space-between; align-items:center; margin-bottom: 10px; }
.mini-title{ font-family: var(--font-head); font-size: 13px; color: var(--cyan); }
.mini-status{ font-family: var(--font-head); font-size: 11px; color: var(--amber); }
#mini-canvas{ width: 100%; max-width: 760px; height: auto; background: #041018; border: 1px solid var(--panel-border); cursor: crosshair; image-rendering: pixelated; }
.mini-hint{ margin-top: 10px; font-size: 18px; color: var(--dim); min-height: 1.4em; }

/* ---------- END ---------- */
#screen-end{ overflow-y:auto; padding: 16px 12px; }
.end-inner{ position:relative; z-index:2; text-align:center; padding: 28px 16px; max-width: 720px; width:100%; margin:auto; }
.end-badge{ font-size: 60px; margin-bottom: 8px; }
.end-title{ font-family: var(--font-head); font-size: 26px; color: var(--cyan); line-height: 1.3; margin-bottom: 12px; text-shadow: 0 0 18px rgba(63,224,208,0.5); }
.end-sub{ font-size: 22px; color: var(--text); margin-bottom: 20px; }
.end-summary{ display:flex; gap: 12px; justify-content:center; flex-wrap:wrap; margin-bottom: 18px; }
.end-stat{ border: 1px solid var(--panel-border); background: rgba(4,12,20,0.6); padding: 12px 16px; min-width: 84px; }
.end-stat .k{ font-family: var(--font-head); font-size: 8px; color: var(--dim); letter-spacing: 2px; }
.end-stat .v{ font-family: var(--font-head); font-size: 18px; color: var(--cyan); margin-top: 6px; }
.end-log{ max-height: 200px; overflow-y:auto; text-align:left; font-size: 16px; padding: 12px 16px; margin-bottom: 20px; }
.end-log .line{ margin-bottom: 4px; }
.end-actions{ display:flex; gap: 12px; justify-content:center; flex-wrap:wrap; }
.end-actions .btn{ flex: 1 1 200px; max-width: 320px; }

.glyph{ filter: drop-shadow(0 0 3px var(--cyan)); }

/* ================= MOBILE ================= */
@media (max-width: 860px){
  body{ font-size: 18px; }
  .game-title{ font-size: clamp(32px, 12vw, 56px); }
  .tagline{ font-size: 19px; margin-bottom: 20px; }
  .eyebrow{ font-size: 9px; margin-bottom: 12px; }
  .roster-box{ padding: 10px 12px 14px; margin-bottom: 16px; }
  .roster .mate{ font-size: 16px; }
  .roster .mate .role{ font-size: 13px; }
  .fineprint{ font-size: 13px; }
  .title-inner{ padding: 16px 12px; }

  .hud{ gap: 10px; padding: 8px 10px; }
  .hud-item.depth{ order: 1; }
  .hud-item.zone{ order: 2; }
  .hud-actions{ order: 3; margin-left: auto; }
  .gauges{ order: 4; flex: 1 1 100%; gap: 8px; }
  .hud-item .value{ font-size: 16px; }
  .hud-item.zone .value{ font-size: 11px; }
  .hud-item .unit{ font-size: 12px; }
  .gauge{ min-width: 0; flex: 1 1 0; }
  .gauge .g-track{ height: 6px; }
  .gauge .g-label{ font-size: 6px; letter-spacing: 0; }

  .game-body{
    grid-template-columns: minmax(0,1fr);
    grid-template-rows: auto minmax(0,1fr) auto;
    gap: 8px; padding: 8px;
  }
  .crew-panel{ order:1; overflow-y:visible; padding: 6px 8px; min-width:0; }
  .panel-title{ margin-bottom: 6px; font-size: 9px; }
  .crew-list{ flex-direction: row; gap: 8px; overflow-x:auto; padding-bottom: 4px; }
  .crew-list .mate{ min-width: 96px; flex: 0 0 auto; border-bottom:none; border-right:1px dashed rgba(40,120,150,0.3); padding: 0 8px 2px 0; }
  .crew-list .mate:last-child{ border-right:none; }
  .mate .m-top{ font-size: 15px; }
  .mate .m-role{ font-size: 12px; }

  .center-col{ order:2; min-height:0; gap: 8px; }
  .dive-log{ order:1; font-size: 16px; padding: 10px 12px; }

  .controls{ order:2; padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .pace-row{ gap: 8px; margin-bottom: 8px; }
  .pace-row .label{ font-size: 7px; }
  .pace-btns{ gap: 6px; }
  .pace-btn{ font-size: 8px; padding: 10px 4px; min-height: 48px; }
  .pace-btn .sub{ font-size: 11px; }
  .action-row .btn.big{ font-size: 13px; padding: 14px 10px; min-height: 52px; }
  .action-row .btn.ghost{ font-size: 9px; padding: 11px 10px; min-height: 48px; }

  .event-card{ padding: 22px 16px; }
  .event-title{ font-size: 15px; }
  .event-body{ font-size: 18px; }

  .mini-card{ padding: 12px 10px; }
  .mini-title{ font-size: 10px; }
  .mini-status{ font-size: 9px; }
  .mini-hint{ font-size: 15px; }

  .end-title{ font-size: 20px; }
  .end-sub{ font-size: 18px; }
  .end-badge{ font-size: 46px; }
  .end-stat{ min-width: 64px; padding: 10px 12px; }
}