/* =====================================================================
   LANCER TERMINAL — styles
   Colours are variables, so a new colour scheme is a few lines here.
   Effects are controlled by body[data-fx="off|low|high"] and are
   always disabled for "prefers-reduced-motion".
   ===================================================================== */

:root {
  --fg: #ffb000;          /* phosphor */
  --fg-bright: #ffd27a;
  --fg-dim: #a8741a;
  --bg: #0b0906;
  --bg-panel: #15110a;
  --line: #4a3410;
  --alert: #ff4a3d;
  --ok: #ffd27a;
  --glow: rgba(255, 176, 0, 0.45);
  --font: "Cascadia Mono", "IBM Plex Mono", Consolas, "DejaVu Sans Mono", "Menlo", monospace;
  color-scheme: dark;
}

body[data-theme="green"] {
  --fg: #33ff66;
  --fg-bright: #a6ffbf;
  --fg-dim: #1f9e46;
  --bg: #040a05;
  --bg-panel: #08140a;
  --line: #124d22;
  --ok: #a6ffbf;
  --glow: rgba(51, 255, 102, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

::selection { background: var(--fg); color: var(--bg); }

/* --- Layout: header / title / scrolling main / footer -------------------- */

#screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 1000px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
}

#header {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  font-size: 12px;
  letter-spacing: 0.05em;
}
.brand { font-weight: bold; color: var(--fg-bright); }
#campaign-label { color: var(--fg-dim); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status[data-kind="warn"] { color: var(--fg-bright); animation: blink-soft 2s steps(2) infinite; }
#status[data-kind="error"] { color: var(--alert); }
#status[data-kind="dim"] { color: var(--fg-dim); }

#title {
  font-size: 16px;
  margin: 10px 0 6px;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}
#title::before { content: "// "; color: var(--fg-dim); }

#main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 2px 12px;
  outline: none;
  overscroll-behavior: contain;
}

#footer {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

/* --- Menu: wrapping row on desktop, big 2-column buttons on phones ------ */

#menu {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.menu-item {
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line);
  padding: 6px 10px;
  cursor: pointer;
  text-align: left;
  letter-spacing: 0.04em;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--fg); color: var(--bg); outline: none; }
.menu-item:hover .key, .menu-item:focus-visible .key { color: var(--bg); }
.menu-item .key { color: var(--fg-dim); }
.menu-gm { border-style: dashed; }

@media (max-width: 640px) {
  #menu { display: grid; grid-template-columns: 1fr 1fr; }
  .menu-item { padding: 11px 10px; min-height: 44px; }
  .hint-desktop { display: none; }
}

/* --- Log + command line ---------------------------------------------------- */

#log {
  max-height: 4.6em;
  overflow-y: auto;
  font-size: 13px;
}
.log-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-echo { color: var(--fg-dim); }
.log-ok { color: var(--ok); }
.log-warn { color: var(--fg-bright); }
.log-error { color: var(--alert); }

#cmd-form {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.prompt { color: var(--fg-bright); }
#cmd-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
  color: var(--fg);
  background: transparent;
  border: none;
  outline: none;
  padding: 2px 0;
  caret-color: var(--fg);
}
/* Blinking block cursor, shown while the command line is empty. */
.cursor {
  position: absolute;
  left: calc(1ch + 8px);
  width: 0.6em;
  height: 1.1em;
  background: var(--fg);
  pointer-events: none;
  animation: blink 1s steps(2) infinite;
}
#cmd-input:placeholder-shown { caret-color: transparent; }
#cmd-input:not(:placeholder-shown) + .cursor { display: none; }
#cmd-input:not(:focus) + .cursor { opacity: 0.35; animation: none; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes blink-soft { 50% { opacity: 0.55; } }

/* --- Content building blocks -------------------------------------------------- */

h2, h3 { letter-spacing: 0.06em; margin: 14px 0 6px; }
h2 { font-size: 18px; color: var(--fg-bright); }
h3 { font-size: 14px; color: var(--fg-bright); }
h3::before { content: "> "; color: var(--fg-dim); }
p { margin: 6px 0; }
.dim { color: var(--fg-dim); }
.warn { color: var(--alert); }
kbd { border: 1px solid var(--line); padding: 0 4px; font: inherit; }
a { color: var(--fg-bright); }

.panel {
  border: 1px solid var(--line);
  background: var(--bg-panel);
  padding: 8px 12px;
  margin: 6px 0 12px;
}
.panel h2:first-child { margin-top: 2px; }

.kv { border-collapse: collapse; width: 100%; }
.kv th {
  text-align: left;
  font-weight: normal;
  color: var(--fg-dim);
  padding: 2px 14px 2px 0;
  vertical-align: top;
  white-space: nowrap;
  width: 1%;
}
.kv td { padding: 2px 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .kv th { white-space: normal; width: 38%; }
}

.text-block { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }

ul.list { list-style: none; padding: 0; margin: 6px 0; }
ul.list li { margin: 0 0 4px; }
ul.plain { padding-left: 1.4em; margin: 4px 0; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid transparent;
  border-left: 2px solid var(--line);
  padding: 6px 10px;
  text-align: left;
  cursor: pointer;
}
.row:hover, .row:focus-visible { border-color: var(--fg); outline: none; background: var(--bg-panel); }
.row.static { cursor: default; }
.row-main { color: var(--fg-bright); }

.btn {
  font: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--fg-dim);
  padding: 6px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover, .btn:focus-visible, .btn.active { background: var(--fg); color: var(--bg); outline: none; }
.btn-small { padding: 2px 8px; font-size: 12px; }
.btn-danger { border-color: var(--alert); color: var(--alert); margin-top: 18px; }
.btn-danger:hover { background: var(--alert); color: var(--bg); }
.link { font: inherit; color: var(--fg-bright); background: none; border: none; padding: 0; text-decoration: underline; cursor: pointer; text-align: left; }

.tag { border: 1px solid var(--fg-dim); padding: 0 5px; font-size: 11px; color: var(--fg-dim); }
.code { letter-spacing: 0.2em; color: var(--fg-bright); }

.banner {
  border: 1px solid var(--fg);
  padding: 8px 12px;
  margin: 4px 0 12px;
}
.banner-alert { border-color: var(--alert); color: var(--fg-bright); box-shadow: inset 0 0 12px rgba(255, 74, 61, 0.2); }
.banner-alert strong { color: var(--alert); }
.banner-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* --- Forms ------------------------------------------------------------------------ */

.form { display: flex; flex-direction: column; gap: 10px; margin: 8px 0; max-width: 680px; }
.form label { display: flex; flex-direction: column; gap: 3px; color: var(--fg-dim); }
.form-inline { flex-direction: row; max-width: none; }
.form-inline input { flex: 1; min-width: 0; }
input, textarea, select {
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  padding: 7px 9px;
  border-radius: 0;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--fg); }
textarea { resize: vertical; min-height: 8em; }
.form .btn { align-self: flex-start; }

/* --- Notes, AAR, dossier, contracts --------------------------------------------- */

.note { border-left: 2px solid var(--line); padding: 4px 10px; margin: 8px 0; }
.note-private { border-left-style: dashed; }
.note-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--fg-dim); font-size: 13px; }

.aar-entry { margin-top: 10px; }

.raw { margin-top: 18px; color: var(--fg-dim); }
.raw summary { cursor: pointer; }
.raw pre { max-height: 300px; overflow: auto; font-size: 12px; border: 1px solid var(--line); padding: 8px; }

.briefing { border: 1px solid var(--line); padding: 10px 12px; background: var(--bg-panel); }
.redacted { background: var(--fg-dim); color: var(--fg-dim); user-select: none; letter-spacing: -0.1em; }
.secret { color: var(--alert); }
.revealed { color: var(--fg-bright); text-shadow: 0 0 6px var(--glow); }

.boot { white-space: pre-wrap; }
.drop-target { outline: 1px dashed var(--fg); outline-offset: -4px; }

/* --- Dossier service record + info pop-ups ------------------------------------------------ */

.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.chips li { display: inline-flex; align-items: center; gap: 5px; }
.info-btn {
  font: inherit;
  font-size: 10px;
  line-height: 1;
  width: 15px;
  height: 15px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--fg-dim);
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  font-style: italic;
  font-weight: bold;
}
.info-btn:hover, .info-btn:focus-visible, .info-btn[aria-expanded="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); outline: none; }
@media (pointer: coarse) { .info-btn { width: 22px; height: 22px; font-size: 12px; } } /* bigger tap target on phones */

.info-pop {
  position: fixed;
  z-index: 70; /* above the CRT layer so it stays crisp */
  width: min(420px, calc(100vw - 16px));
  max-height: min(60vh, 460px);
  overflow-y: auto;
  background: var(--bg-panel);
  color: var(--fg);
  border: 1px solid var(--fg);
  box-shadow: 0 0 0 1px var(--bg), 0 8px 24px rgba(0, 0, 0, 0.6);
  padding: 8px 12px 10px;
  font-size: 13px;
  text-shadow: none;
}
.info-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 6px; color: var(--fg-bright); }
.info-close { font: inherit; background: none; border: none; color: var(--fg-dim); cursor: pointer; padding: 2px 4px; }
.info-close:hover, .info-close:focus-visible { color: var(--fg-bright); outline: 1px solid var(--fg); }
.info-rank { border-left: 2px solid var(--fg); padding: 2px 0 2px 8px; margin: 8px 0; }
.info-rank.locked { border-left-color: var(--line); opacity: 0.6; }
.info-rank-name { color: var(--fg-bright); font-size: 12px; letter-spacing: 0.05em; }
.info-source { font-size: 11px; margin-top: 8px; }
@media (max-width: 640px) {
  .info-pop { left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); top: auto; width: auto; }
}

/* --- Logistics ------------------------------------------------------------------------- */

.row-body { flex-basis: 100%; white-space: pre-wrap; color: var(--fg); }
li.used .row { opacity: 0.55; }
li.used .row-main { text-decoration: line-through; }

/* --- Printable ID card (85.6 x 54 mm, credit-card size) ---------------------------------- */

.print-area { margin: 12px 0; }
.id-card {
  width: 85.6mm;
  height: 54mm;
  max-width: 100%;
  border: 1px solid var(--fg);
  border-radius: 3mm;
  padding: 2.5mm 3mm;
  display: flex;
  flex-direction: column;
  gap: 1.5mm;
  background: var(--bg-panel);
  font-size: 9pt;
  line-height: 1.25;
  overflow: hidden;
}
.id-head, .id-foot {
  display: flex;
  justify-content: space-between;
  gap: 2mm;
  font-size: 6.5pt;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
}
.id-head { border-bottom: 1px solid var(--line); padding-bottom: 1mm; }
.id-body { flex: 1; display: flex; gap: 3mm; min-height: 0; }
.id-fields { flex: 1; min-width: 0; }
.id-callsign { font-size: 15pt; font-weight: bold; color: var(--fg-bright); letter-spacing: 0.06em; }
.id-name { margin-bottom: 1.5mm; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.id-card dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3mm 2mm; margin: 0; font-size: 7.5pt; }
.id-card dt { color: var(--fg-dim); }
.id-card dd { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.id-qr { width: 25mm; flex-shrink: 0; align-self: center; background: #fff; padding: 1.2mm; }
.id-qr svg { display: block; width: 100%; height: auto; }

@media print {
  @page { margin: 12mm; }
  html, body { height: auto; overflow: visible; background: #fff !important; color: #000 !important; text-shadow: none !important; }
  #header, #title, #footer, #crt, #nhp-overlay, .no-print { display: none !important; }
  #screen { display: block; height: auto; padding: 0; max-width: none; }
  #main { overflow: visible; }
  #main > :not(.print-area) { display: none !important; }
  .id-card { background: #fff; color: #000; border-color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .id-callsign, .id-name, .id-card dd { color: #000; }
  .id-head, .id-foot, .id-card dt { color: #444; }
  .id-head { border-color: #999; }
}

/* --- CRT effects -------------------------------------------------------------------- */

#crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

body[data-fx="low"] { text-shadow: 0 0 2px var(--glow); }
body[data-fx="low"] #crt {
  background:
    radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.45) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.12) 0 1px, transparent 1px 3px);
}

body[data-fx="high"] { text-shadow: 0 0 4px var(--glow), 0 0 1px var(--fg); }
body[data-fx="high"] #crt {
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.6) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.7);
  border-radius: 18px;
  animation: flicker 6s infinite;
}
@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.85; }
  98% { opacity: 1; }
  99% { opacity: 0.9; }
}

/* A brief glitch: jump sideways with a colour split. */
#screen.glitch {
  animation: glitch 0.18s steps(3) 1;
  text-shadow: 2px 0 rgba(255, 0, 60, 0.7), -2px 0 rgba(0, 200, 255, 0.6);
}
@keyframes glitch {
  0% { transform: translate(0); clip-path: inset(0 0 0 0); }
  33% { transform: translate(-3px, 1px); clip-path: inset(10% 0 40% 0); }
  66% { transform: translate(3px, -1px); clip-path: inset(50% 0 5% 0); }
  100% { transform: translate(0); clip-path: inset(0 0 0 0); }
}

/* --- NHP mode ------------------------------------------------------------------------- */

body.nhp { --fg: #ff6a4d; --fg-bright: #ffb3a3; --fg-dim: #a8402e; --line: #5a1d14; --glow: rgba(255, 74, 61, 0.5); }

#nhp-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none; /* never blocks the app */
  box-shadow: inset 0 0 120px rgba(255, 40, 20, 0.35);
  background: repeating-linear-gradient(to bottom, rgba(255, 40, 20, 0.05) 0 2px, transparent 2px 4px);
  animation: nhp-roll 0.6s linear infinite;
}
#nhp-overlay[hidden] { display: none; }
@keyframes nhp-roll { to { background-position: 0 4px; } }

#nhp-text {
  position: absolute;
  left: 10%;
  top: 30%;
  max-width: 80%;
  font-size: clamp(18px, 5vw, 34px);
  color: #ff6a4d;
  letter-spacing: 0.12em;
  text-shadow: 0 0 10px rgba(255, 74, 61, 0.9), 3px 0 rgba(0, 200, 255, 0.4);
}
#nhp-mute {
  position: absolute;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  pointer-events: auto;
  background: var(--bg);
}

/* --- Accessibility: reduced motion / effects off ----------------------------------------- */

body[data-fx="off"] #crt { display: none; }
body[data-fx="off"] *, body[data-fx="off"] *::before, body[data-fx="off"] *::after { animation: none !important; }
body[data-fx="off"] #nhp-overlay { animation: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #screen.glitch { text-shadow: none; }
}
