:root {
  --mono: "Cascadia Mono", Consolas, "Roboto Mono", "DejaVu Sans Mono", "Courier New", monospace;
  --bg: #05070a;
  --panel: rgba(6, 12, 10, 0.88);
  --line: rgba(150, 230, 170, 0.28);
  --acc: #9dffb2;
  --acc-dim: #5fbf7a;
  --txt: #d7e7dc;
  --dim: #8aa093;
  --warn: #ffb02e;
  --bad: #ff6a4d;
}

* { box-sizing: border-box; }

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

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}
body.playing #game { cursor: none; }
#view {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}
#game { z-index: 1; background: transparent; }
#loading {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 40;
  transform: translate(-50%, -50%);
  max-width: 90vw;
  color: var(--acc);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-align: center;
}
body.ready #loading { display: none; }

button { font-family: var(--mono); cursor: pointer; }

/* ---------- menus ---------- */
#ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.15), rgba(0, 0, 0, 0.6));
  pointer-events: auto;
}
.screen.on { display: flex; }

.panel {
  position: relative;
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 20px 60px rgba(0, 0, 0, 0.6);
}
.panel::before, .panel::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--acc);
  pointer-events: none;
}
.panel::before { left: 6px; top: 6px; border-right: 0; border-bottom: 0; }
.panel::after { right: 6px; bottom: 6px; border-left: 0; border-top: 0; }
.panel.wide { width: min(860px, 100%); }
.panel.narrow { width: min(360px, 100%); text-align: center; }

.menu-panel { text-align: center; width: min(420px, 100%); }
#emblem { width: 112px; height: 112px; display: block; margin: 0 auto 6px; }
h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0.14em;
  color: var(--acc);
  text-shadow: 0 0 18px rgba(157, 255, 178, 0.35);
}
h2 { margin: 0 0 12px; font-size: 22px; letter-spacing: 0.08em; color: var(--acc); }
h3 { margin: 14px 0 8px; font-size: 14px; color: var(--txt); letter-spacing: 0.06em; }
p { line-height: 1.5; font-size: 14px; }
.sub { margin: 6px 0 18px; color: var(--dim); font-size: 13px; }
.kicker { margin: 0 0 4px; color: var(--dim); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; }
.pts { color: var(--dim); font-size: 13px; margin: 14px 0 0; }
.pts b { color: var(--warn); }

.menu-btns { display: flex; flex-direction: column; gap: 10px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.btn {
  min-height: 42px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(157, 255, 178, 0.06);
  color: var(--txt);
  font-size: 15px;
  letter-spacing: 0.05em;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover, .btn:focus-visible { background: rgba(157, 255, 178, 0.16); border-color: var(--acc); color: #fff; outline: none; }
.btn.primary { background: var(--acc); color: #04140a; border-color: var(--acc); font-weight: 700; }
.btn.primary:hover, .btn.primary:focus-visible { background: #c6ffd2; color: #04140a; }
.btn.ghost { background: transparent; color: var(--dim); }
.btn[disabled] { opacity: 0.4; cursor: default; }

.phead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.phead .pts { margin: 0; }

/* mission cards */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card {
  position: relative;
  text-align: left;
  padding: 14px;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--txt);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card:hover:not([disabled]), .card:focus-visible { border-color: var(--acc); background: rgba(157, 255, 178, 0.08); outline: none; }
.card .num { color: var(--acc); font-size: 12px; letter-spacing: 0.12em; }
.card .name { font-size: 16px; font-weight: 700; }
.card .meta { color: var(--dim); font-size: 12px; }
.card .best { margin-top: auto; color: var(--warn); font-size: 12px; }
.card[disabled] { opacity: 0.45; cursor: default; }
.card .lock { position: absolute; right: 12px; top: 12px; font-size: 11px; color: var(--dim); }

.facts { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; font-size: 13px; }
.facts li { padding: 8px 10px; border-left: 2px solid var(--acc-dim); background: rgba(157, 255, 178, 0.05); }
.facts b { color: var(--acc); font-weight: 600; }

/* shop */
.shop { display: grid; gap: 10px; }
.up {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 14px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
}
.up .t { font-weight: 700; font-size: 15px; }
.up .d { color: var(--dim); font-size: 12px; }
.up .pips { display: flex; gap: 4px; margin-top: 4px; }
.up .pips i { width: 22px; height: 6px; border: 1px solid var(--acc-dim); }
.up .pips i.on { background: var(--acc); }
.up .btn { grid-row: span 3; white-space: nowrap; font-size: 13px; min-width: 120px; }

/* help */
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 26px; }
.keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 13px; color: var(--txt); }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--acc-dim);
  border-radius: 4px;
  color: var(--acc);
  font: inherit;
  font-size: 12px;
  text-align: center;
}

/* debrief */
.stats { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.stats td { padding: 7px 4px; border-bottom: 1px solid rgba(150, 230, 170, 0.12); }
.stats td:last-child { text-align: right; color: var(--acc); }
.stats tr.total td { color: var(--warn); font-weight: 700; border-bottom: 0; }
.win { color: var(--acc) !important; }
.fail { color: var(--bad) !important; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; z-index: 5; pointer-events: none; display: none; }
body.touch.playing #touch { display: block; }
#touch button { pointer-events: auto; touch-action: none; -webkit-user-select: none; user-select: none; }
.tb {
  position: relative;
  min-width: 58px;
  height: 46px;
  padding: 0 8px;
  overflow: hidden;
  border: 1px solid rgba(200, 255, 205, 0.45);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #dfffe3;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.tb b { font-size: 16px; }
.tb small { display: block; font-size: 10px; font-weight: 400; opacity: 0.8; }
.chip::after, .chip-ab::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: calc(var(--v, 0) * 100%);
  background: currentColor;
  opacity: 0.85;
}
.chip { min-width: 62px; }
.chip.sel { background: rgba(157, 255, 178, 0.28); border-color: #d2ffd9; }
.chip.hot { color: var(--warn); }
.chip-ab { color: #8f9f94; min-width: 76px; }
.chip-ab.ready { color: #dfffe3; border-color: var(--acc); }
.t-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); }
.t-top .tb { min-width: 48px; height: 38px; font-size: 14px; }
.t-left {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.t-row { display: flex; gap: 8px; }
.t-right {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 12px;
}
#t-decoy { align-self: flex-end; height: 52px; }
#t-decoy.alarm { color: #fff; border-color: #ff3b30; background: rgba(255, 59, 48, 0.35); animation: decoyBlink 0.3s steps(2) infinite; }
@keyframes decoyBlink { 50% { background: rgba(255, 59, 48, 0.1); } }
.t-zoom { display: flex; flex-direction: column; gap: 8px; }
.t-zoom .tb { width: 52px; min-width: 0; font-size: 22px; }
#t-fire {
  width: 98px;
  height: 98px;
  border-radius: 50%;
  border: 2px solid rgba(255, 205, 185, 0.75);
  background: rgba(130, 24, 10, 0.38);
  color: #fff3ea;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
#t-fire.on { background: rgba(225, 70, 35, 0.6); }

/* ---------- rotate hint ---------- */
#rotate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(3, 6, 5, 0.92);
}
#rotate.on { display: flex; }

@media (max-width: 760px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .help-cols { grid-template-columns: 1fr; }
}
@media (max-height: 520px) {
  .panel { padding: 14px 18px; }
  #emblem { width: 64px; height: 64px; }
  h1 { font-size: 24px; }
  .sub { margin: 2px 0 10px; }
  .menu-btns { gap: 6px; }
  .btn { min-height: 36px; padding: 6px 14px; font-size: 14px; }
  .card { min-height: 96px; padding: 10px; }
  .row-btns { margin-top: 10px; }
  .pts { margin-top: 8px; }
}
@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
  .up { grid-template-columns: 1fr; }
  .up .btn { grid-row: auto; }
}

/* stars, challenges, best shot */
.stars { color: var(--warn); font-style: normal; letter-spacing: 0.08em; }
.stars.big { font-size: 26px; margin: 4px 0 2px; }
.ch-head { margin: 18px 0 8px; font-size: 14px; letter-spacing: 0.1em; color: var(--acc); }
.chl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ch { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: rgba(0, 0, 0, 0.3); font-size: 12px; }
.ch b { font-size: 13px; }
.ch span { grid-column: 1; color: var(--dim); }
.ch em { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-style: normal; color: var(--warn); white-space: nowrap; }
.ch.done { opacity: 0.6; }
.ch.done em { color: var(--acc); }
#deb-shot { margin: 10px 0; }
#deb-shot img { display: block; width: 100%; max-height: 32vh; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; }
#deb-shot figcaption { margin-top: 4px; font-size: 12px; color: var(--warn); }
#deb-shot[hidden] { display: none; }
@media (max-width: 640px) { .chl { grid-template-columns: 1fr; } }

/* ---------- free play ---------- */
.card.free { grid-column: 1 / -1; border-style: dashed; }
.facts li:has(.opts) { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { padding: 5px 10px; font-size: 12px; background: transparent; color: var(--dim); border: 1px solid var(--line); }
.opt:hover, .opt:focus-visible { color: #fff; border-color: var(--acc); outline: none; }
.opt.on { background: var(--acc); color: #04140a; border-color: var(--acc); font-weight: 700; }
