/* APORIA — base: tokens, reset, typography, pixel panels, buttons, chips, meters. */

:root {
  --bg0: #060a14;
  --bg1: #0d1426;
  --bg2: #141d36;
  --bg3: #1c2848;
  --bg4: #24345c;
  --line: #2a3a63;
  --line-hi: #3e5590;
  --outline: #010309;
  --ink: #e8eef9;
  --ink-dim: #9aa9c8;
  --ink-faint: #5f6d8f;
  --cyan: #3ee6ff;
  --cyan-2: #18a7c8;
  --cyan-3: #0b5b6e;
  --cyan-ink: #03141b;
  --yellow: #ffd23f;
  --yellow-2: #c79a00;
  --yellow-ink: #1d1500;
  --red: #ff4d5e;
  --red-2: #a3202f;
  --green: #45e08a;
  --green-2: #1b8a4e;
  --orange: #ff9a3c;
  --purple: #b48cff;
  --font: ui-monospace, "SFMono-Regular", "SF Mono", "Cascadia Mono", "Cascadia Code", "Segoe UI Mono", "Roboto Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
  /* notched 3px pixel outline (corners left empty) */
  --notch: -3px 0 0 0 var(--outline), 3px 0 0 0 var(--outline), 0 -3px 0 0 var(--outline), 0 3px 0 0 var(--outline);
  --notch2: -2px 0 0 0 var(--outline), 2px 0 0 0 var(--outline), 0 -2px 0 0 var(--outline), 0 2px 0 0 var(--outline);
  --drop: 6px 8px 0 0 rgba(0, 0, 0, .5);
  --scan: repeating-linear-gradient(0deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 4px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body { touch-action: manipulation; }

img, canvas, svg { image-rendering: pixelated; }

button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--cyan); color: var(--cyan-ink); }

h1, h2, h3, h4 { margin: 0; font-weight: 800; }
p { margin: 0 0 .7em; }
p:last-child { margin-bottom: 0; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.dim { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }
.small { font-size: 13px; }
.mono { font-family: var(--font); }
[hidden] { display: none !important; }

/* Emoji glyphs (icons, portraits) */
.btn-icon, .modal-icon, .toast-icon, .stat-icon, .tab-icon, .lab-icon, .locker-icon, .note-icon,
.dlg-portrait, .ev-photo, .custody-icon, .touch-glyph, .report-portrait, .viewer-icon {
  font-family: var(--emoji);
  font-style: normal;
  line-height: 1;
}

/* Focus ring: chunky dashed yellow, always visible for keyboard users */
:focus-visible {
  outline: 3px dashed var(--yellow);
  outline-offset: 3px;
}
:focus:not(:focus-visible) { outline: none; }

/* ── layout roots ─────────────────────────────────────────────────────── */
#world {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse at 50% 40%, #16224a 0%, #070b18 70%);
  image-rendering: pixelated;
}
#world canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

#ui {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen-layer, .dialogue-host { position: absolute; inset: 0; pointer-events: none; }

/* ── pixel panel ──────────────────────────────────────────────────────── */
.panel {
  position: relative;
  background-color: var(--bg1);
  background-image: var(--scan);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line), inset 0 4px 0 0 rgba(255, 255, 255, .03), var(--notch), var(--drop);
}
.panel-inset {
  background: rgba(3, 6, 14, .55);
  box-shadow: inset 0 0 0 2px var(--line), inset 0 4px 0 0 rgba(0, 0, 0, .35);
  padding: 14px;
}
.panel-heading {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--cyan);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-heading::before {
  content: "";
  width: 8px; height: 8px;
  background: var(--cyan);
  box-shadow: 2px 2px 0 var(--cyan-3);
  flex: none;
}
.screen-heading {
  font-size: clamp(22px, 3.2vw, 32px);
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink);
  text-shadow: 3px 3px 0 var(--outline), 0 3px 0 var(--cyan-3);
}

/* ── buttons ──────────────────────────────────────────────────────────── */
.btn {
  --b: var(--cyan);
  --bt: var(--cyan-ink);
  --bs: var(--cyan-2);
  --bh: rgba(255, 255, 255, .45);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55em;
  min-height: 42px;
  padding: 9px 16px 13px;
  border: 0;
  border-radius: 0;
  background: var(--b);
  color: var(--bt);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  line-height: 1.1;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: inset 0 -4px 0 0 var(--bs), inset 0 2px 0 0 var(--bh), var(--notch2), 4px 5px 0 0 rgba(0, 0, 0, .5);
}
.btn:hover:not(:disabled) { background: color-mix(in srgb, var(--b) 82%, white); }
.btn:active:not(:disabled) {
  transform: translate(2px, 3px);
  padding: 12px 16px 10px;
  box-shadow: inset 0 3px 0 0 var(--bs), var(--notch2), 1px 1px 0 0 rgba(0, 0, 0, .5);
}
.btn:focus-visible { outline-offset: 5px; }
.btn:disabled { cursor: not-allowed; opacity: .42; filter: grayscale(.7); }
.btn-ghost { --b: var(--bg3); --bt: var(--ink); --bs: #0b1222; --bh: rgba(255, 255, 255, .08); }
.btn-ghost:hover:not(:disabled) { background: var(--bg4); }
.btn-danger { --b: var(--red); --bt: #1b0306; --bs: var(--red-2); }
.btn-warn { --b: var(--yellow); --bt: var(--yellow-ink); --bs: var(--yellow-2); }
.btn-good { --b: var(--green); --bt: #021a0c; --bs: var(--green-2); }
.btn-sm { min-height: 34px; padding: 6px 11px 9px; font-size: 13px; }
.btn-sm:active:not(:disabled) { padding: 8px 11px 7px; }
.btn-lg { min-height: 54px; padding: 13px 26px 17px; font-size: 18px; }
.btn-lg:active:not(:disabled) { padding: 16px 26px 14px; }
.btn-icon { font-size: 1.1em; }
.btn .keycap {
  background: rgba(0, 0, 0, .22);
  color: inherit;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .25), 0 0 0 1px rgba(0, 0, 0, .3);
  opacity: .85;
}

.link-btn {
  background: none;
  border: 0;
  padding: 2px 4px;
  color: var(--cyan);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  cursor: pointer;
  pointer-events: auto;
  font-size: 13px;
}

.keycap {
  display: inline-block;
  min-width: 1.7em;
  padding: 3px 5px 4px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  color: var(--ink);
  background: #0a1020;
  box-shadow: inset 0 -2px 0 0 #000, 0 0 0 1px var(--line-hi);
  vertical-align: 1px;
}

/* ── chips / tags ─────────────────────────────────────────────────────── */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px;
  padding: 3px 7px;
  color: var(--cyan);
  background: rgba(62, 230, 255, .08);
  box-shadow: inset 0 0 0 1px rgba(62, 230, 255, .35);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.ev-tag {
  display: inline-block;
  padding: 3px 8px 4px 14px;
  background: var(--yellow);
  color: var(--yellow-ink);
  font-weight: 900;
  letter-spacing: .08em;
  font-size: 14px;
  position: relative;
  box-shadow: inset 0 -3px 0 var(--yellow-2), var(--notch2);
  white-space: nowrap;
}
.ev-tag::before { /* punched hole */
  content: "";
  position: absolute;
  left: 4px; top: 50%;
  width: 4px; height: 4px;
  margin-top: -3px;
  background: var(--bg1);
  box-shadow: 0 0 0 1px var(--yellow-2);
}
.ev-tag.is-small { font-size: 12px; padding: 1px 6px 2px 12px; }
.ev-tag.is-small::before { left: 3px; }

.status-chip, .points-chip {
  display: inline-block;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: inset 0 0 0 2px currentColor;
}
.status-chip.is-new { color: var(--cyan); animation: blink 1.2s steps(2) infinite; }
.status-chip.is-warn { color: var(--yellow); }
.status-chip.is-done, .points-chip.is-good { color: var(--green); }
.status-chip.is-fail, .points-chip.is-bad { color: var(--red); }

.rank-chip {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  font-weight: 900;
  font-size: 15px;
  color: var(--outline);
  background: var(--ink-dim);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .3), var(--notch2);
}
.rank-chip[data-rank="S"] { background: var(--yellow); }
.rank-chip[data-rank="A"] { background: var(--cyan); }
.rank-chip[data-rank="B"] { background: var(--green); }
.rank-chip[data-rank="C"] { background: var(--orange); }
.rank-chip[data-rank="D"] { background: var(--red); }

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 0;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  background: rgba(0, 0, 0, .45);
  box-shadow: inset 0 0 0 2px currentColor;
  pointer-events: auto;
}
.mode-badge:hover { background: rgba(255, 255, 255, .06); }
.mode-badge:focus-visible { outline: 2px solid var(--yellow); outline-offset: 3px; }
.mode-badge.is-device { color: var(--cyan); }
.mode-badge.is-online { color: var(--green); }
.mode-badge.is-temporary, .mode-badge.is-offline { color: var(--yellow); }
.mode-dot { width: 8px; height: 8px; flex: none; background: currentColor; }
.mode-badge.is-temporary .mode-dot { animation: blink 1.6s steps(2) infinite; }
.mode-short { display: none; }
@media (max-width: 700px) {
  .mode-long { display: none; }
  .mode-short { display: inline; }
}
.save-info { display: grid; gap: 10px; }
.save-info p { margin: 0; }

/* ── meters ───────────────────────────────────────────────────────────── */
.meter {
  position: relative;
  height: 12px;
  background: #040812;
  box-shadow: 0 0 0 2px var(--outline), inset 0 0 0 1px var(--line);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: var(--cyan);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .28), inset 0 2px 0 rgba(255, 255, 255, .35);
  transition: width .45s steps(6);
}
.meter::after { /* segment ticks */
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 10px, rgba(1, 3, 9, .55) 10px 12px);
  pointer-events: none;
}
.meter[data-level="good"] .meter-fill { background: var(--green); }
.meter[data-level="warn"] .meter-fill { background: var(--yellow); }
.meter[data-level="bad"] .meter-fill { background: var(--red); }
.meter.hit { animation: meter-hit .6s steps(2) 3; }

/* ── generic note cards / feedback ────────────────────────────────────── */
.note-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 12px;
  padding: 12px 14px;
  background: rgba(255, 210, 63, .07);
  box-shadow: inset 4px 0 0 var(--yellow), inset 0 0 0 1px rgba(255, 210, 63, .25);
  text-align: left;
  width: 100%;
  border: 0;
  color: var(--ink);
}
.note-icon { font-size: 22px; }
.note-kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--yellow);
  margin-bottom: 3px;
}
.concept-card { background: rgba(180, 140, 255, .08); box-shadow: inset 4px 0 0 var(--purple), inset 0 0 0 1px rgba(180, 140, 255, .3); cursor: pointer; }
.concept-card .note-kicker { color: var(--purple); }
.concept-card:hover { background: rgba(180, 140, 255, .14); }

.feedback {
  margin-top: 12px;
  padding: 12px 14px;
  animation: pop-in .22s steps(3);
}
.feedback.is-bad { background: rgba(255, 77, 94, .1); box-shadow: inset 4px 0 0 var(--red), inset 0 0 0 1px rgba(255, 77, 94, .35); }
.feedback.is-good { background: rgba(69, 224, 138, .09); box-shadow: inset 4px 0 0 var(--green), inset 0 0 0 1px rgba(69, 224, 138, .35); }
.feedback-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 6px;
}
.feedback.is-bad .feedback-head { color: var(--red); }
.feedback.is-good .feedback-head { color: var(--green); }
.penalty-chip {
  display: inline-block;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 900;
  color: #fff;
  background: var(--red);
  box-shadow: inset 0 -2px 0 var(--red-2);
  letter-spacing: .04em;
  white-space: nowrap;
}

.empty {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 36px 16px;
  text-align: center;
  color: var(--ink-dim);
}
.empty > span { font-family: var(--emoji); font-size: 40px; filter: grayscale(.5); opacity: .7; }

/* ── keyframes (stepped for a pixel feel) ─────────────────────────────── */
@keyframes blink { 50% { opacity: 0; } }
@keyframes pop-in { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@keyframes meter-hit { 50% { box-shadow: 0 0 0 2px var(--red), inset 0 0 0 1px var(--red); } }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.shake { animation: shake .32s steps(4); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ── boot / fatal ─────────────────────────────────────────────────────── */
.boot {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: var(--bg0);
  color: var(--cyan);
  letter-spacing: .3em;
  font-weight: 800;
}
.boot-bar { width: 180px; height: 12px; box-shadow: 0 0 0 2px var(--line); position: relative; overflow: hidden; }
.boot-bar::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--cyan); animation: boot-bar 1.2s steps(10) infinite; }
@keyframes boot-bar { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

.fatal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg0);
}
.fatal-box { max-width: 560px; padding: 24px; }
.fatal-box h1 { color: var(--red); font-size: 22px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 12px; }
.fatal-box p { color: var(--ink-dim); }
.fatal-detail { font-size: 13px; color: var(--ink-faint); word-break: break-word; }

/* ── Sound controls (js/ui/audio-ui.js) ─────────────────────────────────── */
.sound-dock { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; z-index: 25; pointer-events: auto; }
html[data-phase="play"] .sound-dock,
html[data-phase="briefing"] .sound-dock,
html[data-phase="boot"] .sound-dock { display: none; }
.sound-dock .btn-label, .btn-hud-sound .btn-label { display: none; }
.sound-toggle .btn-icon { font-family: var(--emoji); }
.sound-toggle.is-muted { color: var(--ink-faint); }
.sound-toggle.is-muted .btn-icon { opacity: .7; }

.audio-settings { display: grid; gap: 16px; }
.audio-mute { display: flex; align-items: center; gap: 12px; }
.audio-mute .sound-toggle .btn-label { display: inline; }
.vol-row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr 52px; align-items: center; gap: 12px; }
.vol-label { display: flex; flex-direction: column; gap: 2px; font-weight: 800; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; }
.vol-hint { font-weight: 400; font-size: 12px; letter-spacing: 0; text-transform: none; color: var(--ink-dim); }
.vol-val { text-align: right; color: var(--cyan); font-variant-numeric: tabular-nums; }
.vol-range { -webkit-appearance: none; appearance: none; width: 100%; height: 12px; margin: 0; background: var(--bg1); box-shadow: inset 0 0 0 2px var(--line-hi); cursor: pointer; }
.vol-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 24px; border: 0; border-radius: 0; background: var(--cyan); box-shadow: inset -3px -3px 0 var(--cyan-2), 2px 2px 0 rgba(0, 0, 0, .55); }
.vol-range::-moz-range-thumb { width: 14px; height: 24px; border: 0; border-radius: 0; background: var(--cyan); box-shadow: inset -3px -3px 0 var(--cyan-2), 2px 2px 0 rgba(0, 0, 0, .55); }
.vol-range::-moz-range-track { height: 12px; background: transparent; }
.vol-range:focus-visible { outline: 2px solid var(--yellow); outline-offset: 4px; }
.audio-note { margin: 0; }
@media (max-width: 520px) {
  .vol-row { grid-template-columns: 1fr 52px; }
  .vol-row .vol-range { grid-column: 1 / -1; grid-row: 2; }
}
