/* ===========================================================================
   Descent Protocol - full-bleed viewport with a classic status bar.
   Design tokens live here; nothing downstream hardcodes a colour.
   =========================================================================== */

:root {
  --iron-900: #07080a;
  --iron-800: #0c0e12;
  --iron-700: #14161b;
  --iron-600: #1d2027;
  --iron-500: #2a2e36;
  --bone: #d8cfc0;
  --bone-dim: #8d8577;
  --ember: #e0a340;
  --rust: #b4361f;
  --blood: #6e0f0f;
  --toxic: #57d06a;
  --cobalt: #4aa3e0;
  --coolant: #4fd6c4;

  --display: 'Big Shoulders Display', 'Arial Narrow', sans-serif;
  --mono: 'Share Tech Mono', ui-monospace, 'Courier New', monospace;

  --rule: 1px solid #23262e;
  --bar-height: clamp(84px, 11vh, 124px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--iron-900);
  color: var(--bone);
  font-family: var(--mono);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  user-select: none;
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  border: 1px solid currentColor;
  padding: 0 3px;
  opacity: 0.75;
}

/* ------------------------------- viewport --------------------------------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: crosshair;
}

/* --------------------------------- chrome --------------------------------- */

.topline {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4, 5, 7, 0.78), transparent);
}

.sector {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--bone-dim);
  text-shadow: 0 2px 4px #000;
}
.sector b {
  display: block;
  font-family: var(--display);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--bone);
}

.topline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--iron-900);
  background: var(--ember);
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  transition: filter 120ms linear, transform 120ms linear;
}
.btn:hover { filter: brightness(1.14); }
.btn:active { transform: translateY(1px); }
.btn[aria-pressed='true'] {
  background: var(--toxic);
  box-shadow: 0 0 18px rgba(87, 208, 106, 0.4);
}

.btn-ghost {
  background: rgba(10, 12, 15, 0.72);
  color: var(--bone-dim);
  border: var(--rule);
  clip-path: none;
}
.btn-ghost:hover { color: var(--bone); }

.readout {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--bone-dim);
  text-shadow: 0 2px 4px #000;
}
.readout span { color: var(--toxic); }

/* ------------------------------- messages --------------------------------- */

.messages {
  position: absolute;
  left: 18px;
  top: 74px;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.95);
  z-index: 2;
}
.messages li {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--bone);
  animation: slide-in 180ms ease-out;
}
.messages li[data-kind='kill'] { color: var(--ember); }
.messages li[data-kind='warn'] { color: var(--rust); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------- map panel -------------------------------- */

.map-panel {
  position: absolute;
  right: 14px;
  bottom: 14px;
  background: rgba(7, 8, 10, 0.8);
  border: var(--rule);
  padding: 8px;
  transition: transform 160ms ease-out;
  transform-origin: bottom right;
  pointer-events: none;
}
.map-panel[hidden] { display: none; }
.map-panel h2 {
  margin: 0 0 6px;
  font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--bone-dim);
  font-weight: 400;
  font-family: var(--mono);
}
#minimap {
  display: block;
  width: 210px;
  height: 140px;
  image-rendering: pixelated;
}
.stage[data-map='expanded'] .map-panel { transform: scale(1.75); }

/* ------------------------------ agent readout ------------------------------ */

.agent-readout {
  position: absolute;
  left: 16px;
  bottom: 14px;
  min-width: 210px;
  padding: 9px 12px;
  background: rgba(7, 8, 10, 0.78);
  border: var(--rule);
  border-left: 2px solid var(--iron-500);
  pointer-events: none;
}
.agent-readout[data-active='true'] {
  border-left-color: var(--toxic);
  box-shadow: inset 0 0 40px rgba(87, 208, 106, 0.09);
}
.agent-label { margin: 0; font-size: 9px; letter-spacing: 0.24em; color: var(--bone-dim); }
.agent-mode {
  margin: 2px 0 0;
  font-family: var(--display);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--iron-500);
  line-height: 1;
}
.agent-readout[data-active='true'] .agent-mode { color: var(--toxic); }
.agent-goal { margin: 3px 0 0; font-size: 11px; color: var(--bone-dim); min-height: 1.2em; }
.agent-stats { margin: 6px 0 0; font-size: 9px; color: #5d6b5f; letter-spacing: 0.06em; }

/* -------------------------------- overlay --------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(90% 90% at 50% 40%, rgba(10, 4, 6, 0.88), rgba(4, 4, 6, 0.97));
  backdrop-filter: blur(2px);
  z-index: 5;
  cursor: pointer;
  padding: 20px;
}
.overlay[hidden] { display: none; }

.overlay-card {
  max-width: 620px;
  text-align: center;
  border: 1px solid #2c2119;
  background: linear-gradient(180deg, rgba(22, 15, 13, 0.97), rgba(8, 8, 10, 0.97));
  padding: 32px 36px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.75);
}
.overlay-card h2 {
  font-family: var(--display);
  font-size: clamp(36px, 7vw, 68px);
  font-weight: 900;
  letter-spacing: 0.1em;
  margin: 0 0 12px;
  color: var(--bone);
  text-shadow: 0 0 30px rgba(180, 54, 31, 0.65);
}
.tagline { color: var(--bone-dim); margin: 0 0 16px; }
.difficulty-note { margin: 14px 0 0; font-size: 11px; color: var(--bone-dim); letter-spacing: 0.1em; }
.difficulty-note b { color: var(--ember); }
.overlay-action {
  margin: 20px 0 0;
  font-size: 12px;
  letter-spacing: 0.24em;
  color: var(--ember);
  animation: pulse 1.6s ease-in-out infinite;
}
.overlay-note { margin: 10px 0 0; color: var(--rust); font-size: 12px; }

@keyframes pulse { 50% { opacity: 0.45; } }

.keys {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 6px 14px;
  font-size: 12px;
  color: var(--bone-dim);
}
.keys b { color: var(--bone); }

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px 18px;
  margin: 8px 0 0;
  text-align: left;
}
.scoreboard div { border-left: 2px solid var(--rust); padding-left: 10px; }
.scoreboard dt { font-size: 10px; letter-spacing: 0.2em; color: var(--bone-dim); }
.scoreboard dd {
  margin: 2px 0 0;
  font-family: var(--display);
  font-size: 26px;
  font-weight: 700;
  color: var(--ember);
}

/* ------------------------------- settings --------------------------------- */

.settings-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 5, 7, 0.86);
  backdrop-filter: blur(3px);
  z-index: 6;
  padding: 20px;
}
.settings-panel[hidden] { display: none; }

.settings-card {
  width: min(460px, 100%);
  border: 1px solid #2c2119;
  background: linear-gradient(180deg, rgba(20, 14, 12, 0.98), rgba(8, 8, 10, 0.98));
  padding: 24px 26px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.75);
}
.settings-card h2 {
  font-family: var(--display);
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.14em;
  margin: 0 0 18px;
  color: var(--bone);
}

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.2em;
  color: var(--bone-dim);
  margin-bottom: 6px;
}
.field output { color: var(--ember); }

.field input[type='range'] {
  width: 100%;
  appearance: none;
  height: 6px;
  background: #1b1d22;
  outline: none;
}
.field input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 20px;
  background: var(--ember);
  cursor: pointer;
}
.field input[type='range']::-moz-range-thumb {
  width: 14px;
  height: 20px;
  border: none;
  background: var(--ember);
  cursor: pointer;
}

.field select {
  width: 100%;
  background: #12151a;
  color: var(--bone);
  border: var(--rule);
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px;
}

.field-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--bone-dim);
  cursor: pointer;
}
.check input { accent-color: var(--ember); }

.settings-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ------------------------------- status bar -------------------------------- */

.statusbar {
  flex: none;
  height: var(--bar-height);
  display: grid;
  grid-template-columns: 1.4fr 0.8fr auto 0.8fr 1.9fr 1fr;
  gap: 1px;
  background: #23262e;
  border-top: 2px solid #33261a;
}

.status-block {
  background: linear-gradient(180deg, #14120f, #090a0c);
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.status-label {
  margin: 0 0 2px;
  font-size: 9px;
  letter-spacing: 0.26em;
  color: var(--bone-dim);
}

.status-value {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(30px, 4.6vh, 48px);
  font-weight: 900;
  line-height: 0.9;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
}
.status-value small { font-size: 0.4em; color: var(--bone-dim); margin-left: 2px; }
.status-amber { color: var(--ember); }
.status-blue { color: var(--cobalt); }

#health-block[data-critical='true'] .status-value { color: var(--rust); }
#health-block[data-critical='true'] { animation: critical 1s steps(2) infinite; }
@keyframes critical { 50% { background: linear-gradient(180deg, #26100e, #090a0c); } }

#ammo-block[data-empty='true'] .status-value { color: var(--rust); }

.pools { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }
.pool {
  display: flex;
  align-items: baseline;
  gap: 3px;
  font-size: 9px;
  letter-spacing: 0.1em;
  color: #5e5749;
}
.pool b { color: var(--bone-dim); font-size: 11px; }
.pool i { font-style: normal; opacity: 0.5; }
.pool[data-active='true'] { color: var(--ember); }
.pool[data-active='true'] b { color: var(--ember); }

.status-portrait {
  background: linear-gradient(180deg, #14120f, #090a0c);
  display: grid;
  place-items: center;
  padding: 6px 12px;
}
#portrait {
  height: calc(var(--bar-height) - 22px);
  width: calc(var(--bar-height) - 22px);
  image-rendering: pixelated;
  border: 1px solid #2c3039;
}

.slots {
  list-style: none;
  display: flex;
  gap: 5px;
  margin: 2px 0 0;
  padding: 0;
}
.slot {
  flex: 1;
  border: var(--rule);
  padding: 4px 3px;
  text-align: center;
  font-size: 8px;
  letter-spacing: 0.08em;
  color: #4a453d;
  min-width: 0;
}
.slot b { display: block; font-size: 12px; color: var(--iron-500); }
.slot span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot[data-state='owned'] { color: var(--bone-dim); }
.slot[data-state='owned'] b { color: var(--bone-dim); }
.slot[data-state='active'] {
  border-color: var(--ember);
  color: var(--iron-900);
  background: var(--ember);
}
.slot[data-state='active'] b { color: #4a300c; }

.status-tally {
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.status-tally span { font-size: 9px; letter-spacing: 0.18em; color: var(--bone-dim); }
.status-tally b {
  font-family: var(--display);
  font-size: 20px;
  font-weight: 700;
  color: var(--bone);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------- touch controls ----------------------------- */

.touchpad { display: none; }

@media (pointer: coarse) {
  .touchpad {
    display: flex;
    position: absolute;
    inset: auto 0 0 0;
    justify-content: space-between;
    padding: 10px 14px 16px;
    pointer-events: none;
    z-index: 3;
  }
  .pad { display: grid; gap: 6px; pointer-events: auto; }
  .pad-left { grid-template-columns: repeat(3, 46px); grid-template-areas: '. up .' 'left down right'; }
  .pad-left .tbtn:nth-child(1) { grid-area: up; }
  .pad-left .tbtn:nth-child(2) { grid-area: left; }
  .pad-left .tbtn:nth-child(3) { grid-area: down; }
  .pad-left .tbtn:nth-child(4) { grid-area: right; }
  .pad-right { grid-auto-flow: column; align-items: end; }
  .tbtn {
    width: 46px;
    height: 46px;
    background: rgba(12, 14, 18, 0.75);
    border: 1px solid #2c3039;
    color: var(--bone);
    font-family: var(--mono);
    font-size: 15px;
  }
  .tbtn-fire { width: 74px; height: 74px; border-color: var(--rust); color: var(--ember); }
  .agent-readout { display: none; }
}

/* ------------------------------- responsive ------------------------------- */

@media (max-width: 900px) {
  .statusbar { grid-template-columns: 1fr auto 1fr; grid-auto-rows: auto; height: auto; }
  .status-wide { grid-column: 1 / -1; }
  .map-panel { display: none; }
  .agent-readout { min-width: 0; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
