/* NIGHT ECHO — UI shell
   Two builds share one stylesheet:
     body.desktop  fixed 960x544 frame, keyboard + mouse HUD
     body.mobile   canvas matches the device aspect, touch controls
   Everything inside #stage is authored in canvas pixels; the stage itself is
   transform-scaled to fill the window, so both builds stay pixel-consistent. */

:root {
  --bg: #05070c;
  --ink: #cfe3dc;
  --dim: #6d8079;
  --green: #59ff9e;
  --green-dim: #2a8f59;
  --amber: #ffc14d;
  --red: #ff5468;
  --panel: rgba(8, 16, 18, 0.72);
  --edge: rgba(89, 255, 158, 0.22);
  --mono: "SF Mono", "JetBrains Mono", "Consolas", ui-monospace, monospace;
  --pad-h: 190px;   /* height reserved for the touch controls */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #0b1220 0%, #05070c 60%, #020306 100%);
}

/* The stage is anchored top-left and positioned entirely by JS: grid/flex
   centering refuses to produce negative offsets, which pushes an oversized
   stage (and its touch controls) off-screen on phones. */
#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 960px;
  height: 544px;
  transform-origin: 0 0;
  box-shadow: 0 0 0 1px rgba(89,255,158,.14), 0 40px 120px rgba(0,0,0,.9);
  background: #04060a;
  overflow: hidden;
}
body.mobile #stage { box-shadow: none; }

#game { display: block; width: 100%; height: 100%; }

.hidden { display: none !important; }

/* ---------------------------------------------------------- HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 12px;
  letter-spacing: .06em;
}

.hud-top, .hud-bottom {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px;
  gap: 12px;
}
.hud-top { top: 0; }
.hud-bottom { bottom: 0; align-items: flex-end; }

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  padding: 8px 10px;
  backdrop-filter: blur(3px);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
}

.panel-title {
  color: var(--green);
  font-size: 10px;
  opacity: .85;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.objectives { min-width: 210px; }
.objectives ul { list-style: none; margin: 0; padding: 0; }
.objectives li {
  display: flex; gap: 6px; align-items: baseline;
  color: var(--dim); font-size: 11px; line-height: 1.55;
}
.objectives li::before { content: "□"; color: var(--dim); }
.objectives li.done { color: var(--green-dim); text-decoration: line-through; }
.objectives li.done::before { content: "▣"; color: var(--green); }
.objectives li.active { color: var(--ink); }
.objectives li.active::before { color: var(--amber); }

.alarm { text-align: right; min-width: 120px; }
.alarm-pips { display: flex; gap: 5px; justify-content: flex-end; }
.pip {
  width: 26px; height: 7px;
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.16);
  display: block;
}
.pip.on { background: var(--red); border-color: var(--red); box-shadow: 0 0 10px var(--red); }
.stat-line { margin-top: 6px; font-size: 14px; color: var(--ink); opacity: .85; }

.icon-btn {
  display: none;
  pointer-events: auto;
  width: 42px; height: 42px;
  background: var(--panel); border: 1px solid var(--edge);
  color: var(--green); font-family: var(--mono); font-size: 13px;
  border-radius: 4px;
}

.meters { min-width: 210px; }
.meter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.meter-row label { width: 46px; font-size: 9px; color: var(--dim); }
.meter {
  position: relative; flex: 1; height: 8px;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  overflow: hidden;
}
.bar { position: absolute; inset: 0 auto 0 0; width: 0%; transition: width .08s linear; }
.bar.light  { background: linear-gradient(90deg, #1d4d3a, var(--green) 55%, #f4ffa8); }
.bar.sound  { background: linear-gradient(90deg, #2b3f66, #7fb2ff 60%, #d9ecff); }
.bar.health { background: linear-gradient(90deg, #6a1f2a, var(--red)); }
.stance-line { margin-top: 6px; font-size: 10px; color: var(--dim); }
.stance-line b { color: var(--green); }

.gear { display: flex; gap: 14px; }
.gear-item { text-align: center; line-height: 1.2; }
.gear-item .gi { display: block; font-size: 15px; color: var(--green); }
.gear-item b { display: block; font-size: 16px; }
.gear-item small { display: block; font-size: 8px; color: var(--dim); }

.prompt {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(6,12,14,.85);
  border: 1px solid var(--edge);
  padding: 6px 14px; font-size: 12px; color: var(--ink);
  animation: pulse 1.6s ease-in-out infinite;
  white-space: nowrap;
}
.prompt b { color: var(--green); }
@keyframes pulse { 50% { opacity: .6; } }

.hack {
  position: absolute; left: 50%; top: 58%; transform: translateX(-50%);
  width: 260px; max-width: 76%; text-align: center;
}
.hack-label { font-size: 10px; color: var(--green); margin-bottom: 4px; }
.hack-bar { height: 10px; border: 1px solid var(--edge); background: rgba(0,0,0,.6); }
.hack-bar div { height: 100%; width: 0%; background: var(--green); box-shadow: 0 0 12px var(--green); }

.toast {
  position: absolute; left: 50%; top: 74px; transform: translateX(-50%);
  font-size: 13px; color: var(--amber); text-shadow: 0 0 12px rgba(0,0,0,.9);
  opacity: 0; transition: opacity .25s;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

#minimap {
  position: absolute; right: 12px; bottom: 92px;
  width: 180px; height: 130px;
  border: 1px solid var(--edge);
  background: rgba(4,8,10,.72);
  opacity: .9;
}

#detectFlash {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 120px rgba(255,84,104,0);
  transition: box-shadow .18s;
}
#detectFlash.on { box-shadow: inset 0 0 90px rgba(255,84,104,.42); }

/* ---------------------------------------------------------- Screens */
.screen {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(90% 70% at 50% 40%, rgba(5,12,14,.86), rgba(2,4,7,.97));
  backdrop-filter: blur(2px);
  z-index: 5;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen-inner { width: 100%; max-width: 620px; text-align: center; }

.logo .goggles { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.logo .goggles i {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #b6ffd6, var(--green) 45%, #06301c 75%);
  box-shadow: 0 0 22px rgba(89,255,158,.75);
  animation: flicker 4s infinite;
}
@keyframes flicker { 0%,92%,100% { opacity: 1 } 94% { opacity: .35 } 96% { opacity: .9 } }

h1 {
  margin: 0; font-size: 46px; letter-spacing: .34em;
  color: #eafff3; text-shadow: 0 0 30px rgba(89,255,158,.45);
}
h2 { margin: 0 0 10px; font-size: 22px; letter-spacing: .2em; color: #eafff3; }
.tagline { margin: 6px 0 22px; font-size: 11px; color: var(--dim); letter-spacing: .22em; }

.mission-select { display: grid; gap: 8px; margin-bottom: 20px; }
.mcard {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px;
  padding: 11px 14px; text-align: left;
  background: rgba(10,20,22,.7); border: 1px solid var(--edge); color: var(--ink);
  font-family: var(--mono); font-size: 13px; cursor: pointer;
  transition: background .15s, transform .15s, border-color .15s;
}
.mcard:hover:not(:disabled) { background: rgba(20,45,42,.85); transform: translateX(3px); border-color: var(--green); }
.mcard:disabled { opacity: .38; cursor: not-allowed; }
.mcard .num { color: var(--green); font-size: 18px; }
.mcard .sub { display: block; font-size: 10px; color: var(--dim); margin-top: 2px; }
.mcard .best { font-size: 10px; color: var(--amber); text-align: right; }

.controls-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px;
  font-size: 11px; color: var(--dim); text-align: left;
  border-top: 1px solid rgba(89,255,158,.14); padding-top: 14px;
}
.controls-grid.for-mobile { display: none; grid-template-columns: 1fr; }
body.mobile .controls-grid.for-desktop { display: none; }
body.mobile .controls-grid.for-mobile { display: grid; }
kbd {
  background: rgba(89,255,158,.1); border: 1px solid var(--edge);
  padding: 1px 6px; color: var(--green); font-family: var(--mono); font-size: 10px;
}
.hint { font-size: 10px; color: var(--green-dim); margin-top: 16px; }

.brief { text-align: left; }
.brief-tag { font-size: 10px; color: var(--amber); letter-spacing: .3em; margin-bottom: 6px; }
.brief p { font-size: 12px; line-height: 1.8; color: var(--dim); }
.brief ul { font-size: 12px; line-height: 1.9; color: var(--ink); padding-left: 18px; }
.brief-rules { display: flex; gap: 18px; font-size: 10px; color: var(--red); margin: 14px 0 20px; }

.btn {
  display: inline-block; margin: 5px 4px 0;
  padding: 10px 22px; font-family: var(--mono); font-size: 12px; letter-spacing: .16em;
  background: rgba(12,26,26,.9); color: var(--ink);
  border: 1px solid var(--edge); cursor: pointer;
  transition: background .15s, color .15s;
}
.btn:hover { background: rgba(89,255,158,.18); color: #fff; }
.btn.primary { background: rgba(89,255,158,.16); color: var(--green); border-color: var(--green); }
.btn.primary:hover { background: var(--green); color: #04120b; }
.btn.ghost { border-color: rgba(255,255,255,.14); color: var(--dim); }
.btn.small { padding: 7px 14px; font-size: 10px; }

/* settings */
.setting { margin: 0 auto 22px; max-width: 420px; text-align: left; }
.setting-label { font-size: 10px; color: var(--green); letter-spacing: .2em; margin-bottom: 8px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button {
  padding: 12px 6px; font-family: var(--mono); font-size: 12px;
  background: rgba(10,20,22,.8); border: 1px solid var(--edge); color: var(--dim);
  cursor: pointer;
}
.seg button.on { background: rgba(89,255,158,.18); color: var(--green); border-color: var(--green); }
.setting-hint { font-size: 10px; color: var(--dim); line-height: 1.7; margin: 10px 0 0; }

.score-grid {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 20px;
  font-size: 12px; margin: 18px auto; max-width: 340px; text-align: left;
  color: var(--dim);
}
.score-grid b { color: var(--ink); font-weight: 400; }
.rank { font-size: 12px; color: var(--dim); margin-bottom: 14px; letter-spacing: .2em; }
.rank b { font-size: 40px; color: var(--green); text-shadow: 0 0 24px rgba(89,255,158,.6); vertical-align: middle; margin-left: 10px; }
#endTitle.fail { color: var(--red); text-shadow: 0 0 26px rgba(255,84,104,.5); }

/* ---------------------------------------------------------- Touch build */
#touch { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

.stick-zone {
  position: absolute;
  left: 0; bottom: 0;
  width: 52%; height: var(--pad-h);
  pointer-events: auto;
  background:
    radial-gradient(70% 90% at 30% 80%, rgba(89,255,158,.05), transparent 70%);
}
.stick {
  position: absolute;            /* placed at the touch point, in stage px */
  width: 128px; height: 128px; margin: -64px 0 0 -64px;
  border-radius: 50%;
  border: 1px solid rgba(89,255,158,.3);
  background: rgba(10,20,22,.28);
  opacity: 0; transition: opacity .12s;
  pointer-events: none;
}
.stick.live { opacity: 1; }
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(89,255,158,.3); border: 1px solid var(--green);
  box-shadow: 0 0 18px rgba(89,255,158,.35);
}
.stick-hint {
  position: absolute; left: 14px; bottom: 10px;
  font-size: 9px; color: rgba(120,180,160,.45); letter-spacing: .1em;
}

.pad {
  position: absolute; right: 10px; bottom: 10px;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
  justify-items: center; align-items: end;
  pointer-events: auto;
}
.tbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 66px; height: 66px; border-radius: 50%;
  background: rgba(10,24,24,.62); border: 1px solid var(--edge); color: var(--green);
  font-family: var(--mono); font-size: 12px; line-height: 1.2;
  backdrop-filter: blur(2px);
  transition: background .08s, transform .08s;
}
.tbtn small { font-size: 8px; color: var(--dim); margin-top: 2px; }
.tbtn.on, .tbtn:active { background: rgba(89,255,158,.32); color: #eafff3; transform: scale(.95); }
.tbtn.on small { color: #bfeed8; }
.tbtn.tiny { width: 50px; height: 50px; font-size: 11px; }
.tbtn.tiny small { font-size: 7px; }
.tbtn.fire {
  width: 88px; height: 88px;
  border-color: var(--green); background: rgba(89,255,158,.16);
  font-size: 14px; letter-spacing: .08em;
}
.tbtn.latch { border-style: dashed; }

/* ---------------------------------------------------------- Mobile HUD */
body.mobile #hud { font-size: 11px; }
body.mobile .hud-top { padding: 8px; gap: 8px; align-items: flex-start; }
body.mobile .panel { padding: 6px 8px; }
body.mobile .objectives { min-width: 0; max-width: 54%; }
body.mobile .objectives li { font-size: 10px; line-height: 1.45; }
body.mobile .alarm { min-width: 0; margin-left: auto; }
body.mobile .pip { width: 18px; height: 6px; }
body.mobile .stat-line { font-size: 12px; margin-top: 4px; }
body.mobile .icon-btn { display: block; }

/* meters + gear float above the control pad instead of sitting on the edge */
body.mobile .hud-bottom {
  display: block; padding: 0; inset: 0;
}
body.mobile .meters {
  position: absolute; left: 8px; bottom: calc(var(--pad-h) + 40px);
  min-width: 0; width: 46%;
}
body.mobile .meter-row label { width: 34px; font-size: 8px; }
body.mobile .meter { height: 6px; }
body.mobile .stance-line { font-size: 9px; margin-top: 4px; }
body.mobile .gear {
  position: absolute; right: 8px; bottom: calc(var(--pad-h) + 40px);
  gap: 10px;
}
body.mobile .gear-item b { font-size: 14px; }
body.mobile #minimap {
  width: 116px; height: 84px;
  right: 8px; bottom: auto; top: 96px;
}
body.mobile .prompt {
  bottom: calc(var(--pad-h) + 76px);
  font-size: 11px; padding: 6px 12px;
}
body.mobile .hack { top: 40%; }
body.mobile .toast { top: 62px; font-size: 11px; }

/* Mobile screens: tighter type, full-width buttons */
body.mobile h1 { font-size: 28px; letter-spacing: .22em; }
body.mobile h2 { font-size: 18px; }
body.mobile .tagline { font-size: 9px; margin-bottom: 14px; }
body.mobile .screen { padding: 14px; align-items: start; }
body.mobile .screen-inner { padding: 12px 0 28px; }
body.mobile .logo .goggles i { width: 20px; height: 20px; }
body.mobile .mcard { font-size: 12px; padding: 12px; grid-template-columns: 28px 1fr auto; }
body.mobile .controls-grid { font-size: 10px; }
body.mobile .btn { display: block; width: 100%; margin: 8px 0 0; padding: 13px; }
body.mobile .btn.small { width: auto; display: inline-block; }
body.mobile .brief p { font-size: 11px; line-height: 1.7; }
body.mobile .brief-rules { flex-direction: column; gap: 4px; }
body.mobile .score-grid { font-size: 11px; }

/* Portrait phones: shorter control block, stack the meters row */
body.mobile.portrait { --pad-h: 210px; }
body.mobile:not(.portrait) { --pad-h: 150px; }
body.mobile:not(.portrait) .stick-zone { width: 42%; }
/* Landscape has no room above the pad, so the readouts tuck into the corners
   the thumbs never cover. */
body.mobile:not(.portrait) .meters {
  top: 96px; bottom: auto; left: 8px; width: 208px;
}
body.mobile:not(.portrait) .gear {
  bottom: 14px; right: 250px;
}
body.mobile:not(.portrait) .tbtn { width: 58px; height: 58px; }
body.mobile:not(.portrait) .tbtn.tiny { width: 44px; height: 44px; }
body.mobile:not(.portrait) .tbtn.fire { width: 74px; height: 74px; }
body.mobile:not(.portrait) #minimap { width: 96px; height: 70px; top: 88px; }

@media (max-width: 700px) {
  body.desktop h1 { font-size: 30px; }
  body.desktop .controls-grid { grid-template-columns: 1fr; }
}
