/* War in the Void — design system. Dark 90s-sci-fi, N64-era flavor: near-black blue/violet surfaces,
   one saturated violet accent, chunky slightly-rounded controls with hard 2px borders and a
   subtle bevel (inset highlight/shadow), pixel-crisp edges. System fonts only for now. */

:root {
  /* Void surfaces — near-black with a blue/violet cast */
  --bg: #08080f;
  --bg-elev: #10101c;
  --bg-elev-2: #181829;
  --bg-elev-3: #222238;
  --line: #2e2e4d;
  --line-soft: #1e1e33;

  /* Text */
  --text: #f2f1fa;
  --text-dim: #b0aecb;
  --text-mute: #75748f;

  /* Accent — saturated violet, used everywhere an accent is needed */
  --accent: #7c5cff;
  --accent-bright: #9d85ff;
  --accent-tint: rgba(124, 92, 255, 0.16);
  --accent-line: rgba(124, 92, 255, 0.5);
  --danger: #ff4d5e;
  --good: #3ec46d;
  --warn: #e8b13c;

  /* Bevel — the N64-cartridge plastic look: hard top highlight, hard bottom shade */
  --bevel-up: inset 0 2px 0 rgba(255, 255, 255, 0.12), inset 0 -2px 0 rgba(0, 0, 0, 0.45);
  --bevel-down: inset 0 2px 0 rgba(0, 0, 0, 0.45), inset 0 -2px 0 rgba(255, 255, 255, 0.06);

  /* Geometry — chunky, slightly rounded, never pill-shaped */
  --radius: 6px;
  --radius-sm: 3px;
  --border-w: 2px;

  --topbar-h: 52px;
  --bottombar-h: 64px;

  --shadow-1: 0 2px 0 rgba(0, 0, 0, 0.6);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.55);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

/* ---- Reset basics ---- */
* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  min-height: 100vh; min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* This is a game, not a document: kill text selection and the iOS long-press
     callout/loupe everywhere. Without these, holding a finger (radial menu,
     control-group assign) starts OS text selection and breaks tap handling. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Form fields are the one place selection must still work. */
input, textarea { -webkit-user-select: text; user-select: text; }
a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; color: inherit; font-size: inherit; }
img, canvas { display: block; max-width: 100%; }
/* pixel-crisp scaled sprites/canvases */
.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }

/* Tabular numbers for resource counters / timers */
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--bg-elev-3) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elev-3); border-radius: 4px; border: 2px solid var(--bg); }

/* ---- Orientation contract ----
   Boot code stamps :root[data-orient="portrait"|"landscape"] (from matchMedia) so views can
   restructure without JS layout math. Example rule: */
:root[data-orient="landscape"] .bottombar { padding-left: var(--safe-left); padding-right: var(--safe-right); }

/* ---- Fixed bars ---- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg-elev);
  border-bottom: var(--border-w) solid var(--line);
  box-shadow: var(--shadow-1);
}
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--bottombar-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  display: flex;
  background: var(--bg-elev);
  border-top: var(--border-w) solid var(--line);
}
/* content pages sit between the bars */
body.has-bars { padding-top: calc(var(--topbar-h) + var(--safe-top)); padding-bottom: calc(var(--bottombar-h) + var(--safe-bot)); }

.bar-item {
  position: relative; flex: 1; min-width: 44px; background: none; border: 0; cursor: pointer;
  color: var(--text-mute);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  transition: color 0.15s;
}
.bar-item .bar-ico { font-size: 18px; line-height: 1; }
.bar-item.is-active { color: var(--accent-bright); }
.bar-item.is-active::before {
  content: ""; position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
  width: 38px; height: 3px; background: var(--accent);
}
.bar-item:active { color: var(--text); }

/* ---- Buttons — chunky, hard 2px border, bevelled plastic ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: var(--radius); border: var(--border-w) solid var(--line);
  background: var(--bg-elev-2); color: var(--text);
  box-shadow: var(--bevel-up);
  font-size: 13px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  cursor: pointer; user-select: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.08s, transform 0.08s;
}
.btn:active { box-shadow: var(--bevel-down); transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent-bright); color: #fff; }
.btn-primary:active { background: #6a4de6; }
.btn-ghost { background: var(--bg-elev); color: var(--text-dim); }
.btn-ghost:active { background: var(--bg-elev-2); }
.btn-danger { background: var(--bg-elev); border-color: var(--danger); color: var(--danger); }
.btn-danger:active { background: rgba(255, 77, 94, 0.14); }
.btn-block { width: 100%; }
.btn:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

.icon-btn {
  width: 44px; height: 44px; flex: 0 0 auto;
  border-radius: var(--radius); border: var(--border-w) solid var(--line);
  background: var(--bg-elev-2); color: var(--text-mute); box-shadow: var(--bevel-up);
  font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: color 0.12s, border-color 0.12s, box-shadow 0.08s;
}
.icon-btn:active { box-shadow: var(--bevel-down); }
.icon-btn.danger:active { color: var(--danger); border-color: var(--danger); }

/* ---- Section header ---- */
.section-head { position: relative; margin: 4px 0 18px; padding-left: 14px; }
.section-head::before {
  content: ""; position: absolute; left: 0; top: 3px; bottom: 4px; width: 5px;
  background: var(--accent);
}
.section-head h1 {
  margin: 0; font-size: 24px; font-weight: 900; line-height: 1.02;
  letter-spacing: 0.03em; text-transform: uppercase;
}
.section-head p {
  margin: 5px 0 0; color: var(--text-dim); font-size: 12px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
}

/* ---- Cards / tiles ---- */
.card {
  background: var(--bg-elev); border: var(--border-w) solid var(--line);
  border-radius: var(--radius); box-shadow: var(--bevel-up);
  padding: 14px;
}
.card-grid { display: flex; flex-direction: column; gap: 10px; }

.tile {
  display: flex; align-items: stretch; gap: 12px;
  background: var(--bg-elev); border: var(--border-w) solid var(--line); border-radius: var(--radius);
  box-shadow: var(--bevel-up);
  padding: 12px 12px 12px 0; overflow: hidden;
  transition: border-color 0.12s, box-shadow 0.08s;
}
.tile .tile-main { flex: 1; min-width: 0; padding: 3px 0 3px 12px; }
/* Tappable row: a stretched transparent button is the hit target + keyboard focus; real buttons sit above it. */
.tile.is-tappable { position: relative; cursor: pointer; }
.tile-open { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer; }
.tile.is-tappable:active { box-shadow: var(--bevel-down); }
.tile.is-tappable:focus-within { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
.tile-open:focus { outline: none; }
/* decorative children must not swallow taps; only the open layer + real buttons stay live */
.tile.is-tappable > * { pointer-events: none; }
.tile.is-tappable > .tile-open, .tile.is-tappable > .icon-btn { pointer-events: auto; }
.tile.is-tappable > .icon-btn { position: relative; z-index: 1; }
.tile.is-tappable .icon-btn.danger { background: transparent; border-color: transparent; box-shadow: none; }
.tile-chev {
  position: relative; align-self: center; flex: 0 0 auto; padding-right: 8px;
  color: var(--accent-bright); font-size: 22px; font-weight: 700; line-height: 1;
}
.tile-title { font-weight: 800; font-size: 15px; letter-spacing: 0.03em; text-transform: uppercase; }
.tile-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; font-weight: 600; letter-spacing: 0.02em; }

/* Empty state */
.empty {
  text-align: center; color: var(--text-mute); font-size: 13px; line-height: 1.6;
  padding: 36px 22px; border: var(--border-w) dashed var(--line); border-radius: var(--radius);
  background: var(--bg-elev);
}

.muted { color: var(--text-dim); font-size: 13px; line-height: 1.55; }

/* ---- Stat bars (resources, HP, progress) ---- */
.statbar { margin-bottom: 10px; }
.statbar-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.statbar-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.statbar-val { font-size: 12px; font-weight: 800; }
.statbar-track { height: 8px; background: var(--bg-elev-2); border: 1px solid var(--line-soft); border-radius: 2px; overflow: hidden; }
.statbar-fill { height: 100%; background: var(--accent); }

/* ---- Fields ---- */
.field { margin-bottom: 14px; }
.field-label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 6px;
}
.field-input, .select {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border-radius: var(--radius); background: var(--bg);
  border: var(--border-w) solid var(--line); color: var(--text); font-size: 15px;
  box-shadow: var(--bevel-down);
}
.field-input:focus, .select:focus { outline: none; border-color: var(--accent); }
.form-section-title { font-size: 13px; font-weight: 900; letter-spacing: 0.06em; text-transform: uppercase; margin: 18px 0 4px; }
.form-section-sub { font-size: 12px; color: var(--text-mute); margin-bottom: 10px; }

/* ---- Sliders (volume settings) ---- */
.slider-row { margin-bottom: 16px; }
.slider-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.slider-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.slider-val { font-size: 13px; font-weight: 800; color: var(--accent-bright); }
.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 10px; border-radius: 2px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  cursor: pointer; padding: 0; margin: 8px 0; /* margin grows the vertical hit area */
}
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--bg-elev-3); border: var(--border-w) solid var(--accent);
  box-shadow: var(--bevel-up); cursor: pointer;
}
.range::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--bg-elev-3); border: var(--border-w) solid var(--accent);
  box-shadow: var(--bevel-up); cursor: pointer;
}

/* ---- Toggles ---- */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; margin-bottom: 6px;
}
.toggle-label { font-size: 13px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-dim); }
.toggle {
  position: relative; width: 60px; height: 32px; flex: 0 0 auto;
  border-radius: var(--radius); border: var(--border-w) solid var(--line);
  background: var(--bg-elev-2); box-shadow: var(--bevel-down);
  cursor: pointer; padding: 0;
  transition: background 0.15s, border-color 0.15s;
}
.toggle-knob {
  position: absolute; top: 2px; left: 2px; width: 24px; height: 24px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-3); border: 1px solid var(--line);
  box-shadow: var(--bevel-up);
  transition: left 0.15s ease, background 0.15s;
}
.toggle.is-on { background: var(--accent-tint); border-color: var(--accent); }
.toggle.is-on .toggle-knob { left: 30px; background: var(--accent); border-color: var(--accent-bright); }
.toggle:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }

/* ---- Segmented control ---- */
.segmented {
  display: flex; gap: 0; border: var(--border-w) solid var(--line); border-radius: var(--radius);
  background: var(--bg-elev); overflow: hidden;
}
.segmented button {
  flex: 1; min-height: 44px; border: 0; background: transparent; cursor: pointer;
  color: var(--text-mute); font-size: 12px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase;
}
.segmented button + button { border-left: var(--border-w) solid var(--line); }
.segmented button.is-active { background: var(--accent-tint); color: var(--accent-bright); box-shadow: var(--bevel-up); }

/* ---- Toasts ---- */
.toast-host {
  position: fixed; left: 0; right: 0; bottom: calc(var(--bottombar-h) + var(--safe-bot) + 14px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 600; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 90vw;
  padding: 11px 18px 11px 14px; border-radius: var(--radius);
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--bg-elev-2); color: var(--text);
  border: var(--border-w) solid var(--line); border-left: 4px solid var(--text-mute);
  box-shadow: var(--bevel-up), var(--shadow-2);
  opacity: 0; transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-in { opacity: 1; transform: translateY(0); }
.toast.is-out { opacity: 0; transform: translateY(8px); }
.toast-success { border-left-color: var(--good); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--accent); }

/* ---- Modal (bottom sheet on phones, centered card on wide screens) ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 700;
  background: rgba(3, 3, 9, 0.7);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity 0.18s ease;
}
.modal-overlay.is-in { opacity: 1; }
.modal-card {
  width: 100%; max-width: 480px;
  background: var(--bg-elev); border: var(--border-w) solid var(--line); border-bottom: 0;
  border-top: 3px solid var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 18px calc(18px + var(--safe-bot));
  box-shadow: var(--bevel-up), var(--shadow-2);
  transform: translateY(16px); transition: transform 0.2s cubic-bezier(0.22, 0.91, 0.36, 1);
}
.modal-overlay.is-in .modal-card { transform: translateY(0); }
@media (min-width: 560px) {
  .modal-overlay { align-items: center; }
  .modal-card { border-bottom: var(--border-w) solid var(--line); border-radius: var(--radius); padding-bottom: 18px; }
}
.modal-title { font-size: 17px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px; }
.modal-body { font-size: 14px; color: var(--text); }
.modal-message { color: var(--text); font-size: 14px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* ---- View transitions (used by VOID.transitions.swap) ---- */
.view {
  min-height: calc(100dvh - var(--topbar-h) - var(--bottombar-h));
  padding: 16px; max-width: 760px; margin: 0 auto;
  transition: opacity 0.19s ease;
}
.view.is-leaving { opacity: 0; }
.view.is-entering { opacity: 0; }

/* ---- Motion + breakpoint conventions ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Convention: <=640px is the single-column phone layout; wider gets breathing room.
   Add per-view overrides under this query, not new breakpoints. */
@media (max-width: 640px) {
  .section-head h1 { font-size: 21px; }
  .view { padding: 14px 12px; }
}
