/* ===========================================================================
   HOLLOW VEIL — design system
   Owned by: nobody (shared). HUD / Keel / Lobby each own their own stylesheet
   and must build on these tokens and primitives rather than redefining them.

   Visual language: a cold, failing industrial station lit by a dying red dwarf.
   Interiors are desaturated blue-grey. The star is amber. The Hollows are void
   black with violet lattice. Everything is thin lines, hard angles, and light
   that looks like it costs power to produce.
   =========================================================================== */

:root {
  /* --- surfaces (station interior) */
  --v-void:        #05070a;
  --v-bg:          #090c11;
  --v-panel:       #0d1117;
  --v-panel-2:     #121822;
  --v-panel-3:     #18202c;
  --v-line:        #1e2836;
  --v-line-hot:    #2b3a4d;

  /* --- text */
  --v-text:        #c8d4e0;
  --v-text-dim:    #7d8b9b;
  --v-text-faint:  #4c5866;
  --v-text-hot:    #eef4fa;

  /* --- the star */
  --v-star:        #ff6a3a;
  --v-star-dim:    #b8442099;
  --v-star-bright: #ffa06a;
  --v-flare:       #ffd08a;

  /* --- the hollows */
  --v-hollow:      #8b5cff;
  --v-hollow-dim:  #5b2fd6;
  --v-hollow-glow: #b98cff;

  /* --- semantic */
  --v-ok:          #4ade80;
  --v-warn:        #fbbf24;
  --v-bad:         #f43f5e;
  --v-info:        #38bdf8;
  --v-shield:      #4aa8ff;
  --v-health:      #e2e8f0;
  --v-stam:        #63ffd0;
  --v-anchor:      #63e8ff;
  --v-echo:        #c9a4ff;

  /* --- rarity (matches RARITY_COLOR in shared/constants.js) */
  --r-common:      #9fb0bd;
  --r-uncommon:    #54d99a;
  --r-rare:        #4aa8ff;
  --r-exotic:      #c06bff;
  --r-veiled:      #ffb03a;

  /* --- type */
  --f-ui: ui-sans-serif, "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, monospace;
  --f-display: var(--f-mono);

  --t-xs: 10px; --t-sm: 11px; --t-md: 13px; --t-lg: 16px; --t-xl: 22px; --t-2xl: 34px; --t-3xl: 56px;

  /* --- geometry */
  --gap: 8px;
  --radius: 2px;
  --cut: 10px;               /* corner chamfer for panels */
  --bord: 1px solid var(--v-line);
  --bord-hot: 1px solid var(--v-line-hot);

  --z-hud: 10;
  --z-screen: 40;
  --z-modal: 60;
  --z-toast: 80;
  --z-cursor: 95;

  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-in: cubic-bezier(.55,.06,.68,.19);
  --ease-snap: cubic-bezier(.16,1,.3,1);
}

/* --------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--v-void); color: var(--v-text);
  font-family: var(--f-ui); font-size: var(--t-md);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overscroll-behavior: none; touch-action: none;
}
body { user-select: none; -webkit-user-select: none; cursor: default; }
canvas#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; z-index: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--v-void); }
::-webkit-scrollbar-thumb { background: var(--v-line); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--v-line-hot); }

/* ------------------------------------------------------------ scaffold */
#ui-root { position: fixed; inset: 0; z-index: var(--z-hud); pointer-events: none; }
#ui-root > .screen { position: absolute; inset: 0; display: none; }
#ui-root > .screen.active { display: block; }
#ui-root > .screen:not(.hud) { pointer-events: auto; overflow: hidden; }
#hud-root { pointer-events: none; z-index: var(--z-hud); }

/* The screens layer stays mounted for the whole raid (death/extract/results all
   live in it) but is EMPTY most of that time. Left interactive it becomes a
   full-viewport invisible click-catcher over the game: clicks meant for the
   world hit it instead, so pointer lock is never requested and the player
   cannot look around. Only the actual screens inside it take input. */
#screens-root { pointer-events: none; }
#screens-root > * { pointer-events: auto; }
#lobby-root, #keel-root, #screens-root { z-index: var(--z-screen); }
/* Bottom-left, stacking upward. Toasts used to sit top-centre where they
   covered the lobby header in menus and the anchor strip + veil timer in a
   raid — and critical alerts already own top-centre (#hv-banners). Toasts are
   the secondary feed (sector names, resonance, flavour); they live with the
   other ambient info, clear of every interactive surface. */
#toast-root {
  position: absolute; left: 18px; bottom: 148px;
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: 6px;
  align-items: flex-start; justify-content: flex-end; pointer-events: none;
  width: min(420px, 40vw);
}
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-family: var(--f-mono); }

/* --------------------------------------------------------- map overlay (M) */
#hv-map-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center;
  background: rgba(4, 6, 9, .78); backdrop-filter: blur(2px);
  font-family: var(--f-mono);
}
#hv-map-overlay[hidden] { display: none; }
.hvmap-panel {
  background: linear-gradient(180deg, rgba(14,18,24,.98), rgba(9,12,17,.98));
  border: 1px solid var(--v-line-hot); border-top: 2px solid var(--v-anchor);
  padding: 14px 16px 12px;
}
.hvmap-title {
  display: flex; justify-content: space-between; gap: 24px; align-items: baseline;
  font-size: var(--t-sm); letter-spacing: .24em; color: var(--v-text-hot);
  margin-bottom: 8px;
}
.hvmap-title .esc { font-size: 10px; letter-spacing: .14em; color: var(--v-text-faint); }
#hv-map-canvas { display: block; background: #05070b; border: 1px solid var(--v-line); }
.hvmap-legend {
  display: flex; gap: 18px; margin-top: 8px;
  font-size: 10px; letter-spacing: .12em; color: var(--v-text-dim);
}
.hvmap-legend b { color: var(--v-text); font-weight: 400; }

/* --------------------------------------------------- controls overlay (F1) */
#hv-controls-overlay {
  position: fixed; inset: 0; z-index: calc(var(--z-modal) + 1);
  display: grid; place-items: center;
  background: rgba(4, 6, 9, .82); backdrop-filter: blur(3px);
  font-family: var(--f-mono);
}
#hv-controls-overlay[hidden] { display: none; }
.hvco-panel {
  width: min(880px, 94vw); max-height: 86vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(16,20,27,.98), rgba(10,13,18,.98));
  border: 1px solid var(--v-line-hot); border-top: 2px solid var(--v-star);
  padding: 22px 28px 26px;
}
.hvco-title {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: var(--t-lg); letter-spacing: .3em; color: var(--v-text-hot);
  margin-bottom: 4px;
}
.hvco-title .esc { font-size: var(--t-xs); letter-spacing: .14em; color: var(--v-text-faint); }
.hvco-sub { font-size: var(--t-xs); letter-spacing: .14em; color: var(--v-text-dim); margin-bottom: 16px; }
.hvco-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 2px 0 18px; }
.hvco-act {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--f-mono); font-size: var(--t-sm); letter-spacing: .1em;
  color: var(--v-text-hot); background: rgba(255,255,255,.045);
  border: 1px solid var(--v-line-hot); border-left: 2px solid var(--v-star);
  padding: 8px 14px; cursor: pointer;
}
.hvco-act:hover:not(:disabled) { background: rgba(255,255,255,.09); }
.hvco-act:disabled { opacity: .35; cursor: default; }
.hvco-act .k {
  color: var(--v-text-hot); background: rgba(255,255,255,.05);
  border: 1px solid var(--v-line-hot); padding: 0 7px; letter-spacing: .08em;
}
.hvco-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 6px 34px; }
.hvco-group { margin-bottom: 12px; }
.hvco-h {
  font-size: 10px; letter-spacing: .34em; color: var(--v-star);
  border-bottom: 1px solid var(--v-line); padding-bottom: 3px; margin-bottom: 6px;
}
.hvco-row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: var(--t-sm); padding: 2px 0; color: var(--v-text);
}
.hvco-row .k {
  color: var(--v-text-hot); background: rgba(255,255,255,.05);
  border: 1px solid var(--v-line-hot); padding: 0 7px; min-width: 34px;
  text-align: center; letter-spacing: .08em; white-space: nowrap;
}
.hvco-row .k + .k { margin-left: 4px; }

/* -------------------------------------------------------- primitives */
.v-panel {
  background:
    linear-gradient(180deg, rgba(255,255,255,.022), rgba(0,0,0,.18)),
    var(--v-panel);
  border: var(--bord);
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  position: relative;
}
.v-panel::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.14) 3px 4px);
  opacity: .5;
}
.v-panel--flat { clip-path: none; }

.v-hdr {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: var(--bord);
  font-family: var(--f-mono); font-size: var(--t-xs);
  letter-spacing: .22em; text-transform: uppercase; color: var(--v-text-dim);
}
.v-hdr::before {
  content: ''; width: 3px; height: 12px; background: var(--v-star);
  box-shadow: 0 0 8px var(--v-star);
}
.v-hdr .spacer { flex: 1; }

.v-btn {
  --btn-accent: var(--v-star);
  appearance: none; background: var(--v-panel-2); border: var(--bord-hot);
  color: var(--v-text); padding: 9px 18px; cursor: pointer;
  font-family: var(--f-mono); font-size: var(--t-sm);
  letter-spacing: .16em; text-transform: uppercase;
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  transition: background .12s var(--ease), color .12s var(--ease), box-shadow .18s var(--ease);
  position: relative; white-space: nowrap;
}
.v-btn:hover:not(:disabled) {
  background: var(--v-panel-3); color: var(--v-text-hot);
  box-shadow: inset 0 0 0 1px var(--btn-accent), 0 0 18px -6px var(--btn-accent);
}
.v-btn:active:not(:disabled) { transform: translateY(1px); }
.v-btn:disabled { opacity: .32; cursor: not-allowed; }
.v-btn--primary {
  background: linear-gradient(180deg, #2a1409, #1a0d06);
  border-color: var(--v-star-dim); color: var(--v-star-bright);
}
.v-btn--primary:hover:not(:disabled) { background: linear-gradient(180deg, #3c1d0d, #24120a); }
.v-btn--ghost { background: transparent; border-color: var(--v-line); }
.v-btn--danger { --btn-accent: var(--v-bad); color: #ffc3cd; border-color: #4a1a25; }
.v-btn--sm { padding: 5px 11px; font-size: var(--t-xs); }
.v-btn--block { width: 100%; justify-content: center; }

.v-input {
  background: var(--v-void); border: var(--bord); color: var(--v-text-hot);
  padding: 8px 11px; font-family: var(--f-mono); font-size: var(--t-sm);
  letter-spacing: .08em; outline: none; width: 100%;
}
.v-input:focus { border-color: var(--v-star-dim); box-shadow: 0 0 0 1px var(--v-star-dim); }
.v-input::placeholder { color: var(--v-text-faint); }

.v-bar { height: 4px; background: rgba(255,255,255,.06); overflow: hidden; position: relative; }
.v-bar > i { display: block; height: 100%; width: 0; background: var(--v-star); transition: width .16s linear; }
.v-bar--thick { height: 8px; }

.v-tag {
  display: inline-block; padding: 2px 7px; font-family: var(--f-mono);
  font-size: var(--t-xs); letter-spacing: .14em; text-transform: uppercase;
  border: 1px solid currentColor; opacity: .9;
}
.v-kbd {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px;
  border: 1px solid var(--v-line-hot); background: var(--v-panel-2);
  font-family: var(--f-mono); font-size: var(--t-xs); color: var(--v-text-dim);
}

.r0, .rarity-0 { color: var(--r-common); }
.r1, .rarity-1 { color: var(--r-uncommon); }
.r2, .rarity-2 { color: var(--r-rare); }
.r3, .rarity-3 { color: var(--r-exotic); }
.r4, .rarity-4 { color: var(--r-veiled); }

.mono { font-family: var(--f-mono); }
.dim { color: var(--v-text-dim); }
.faint { color: var(--v-text-faint); }
.hot { color: var(--v-text-hot); }
.up { text-transform: uppercase; letter-spacing: .18em; }
.tabnum { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- effects */
@keyframes v-scan { to { transform: translateY(100vh); } }
@keyframes v-flicker {
  0%, 100% { opacity: 1; } 42% { opacity: 1; } 43% { opacity: .55; }
  45% { opacity: 1; } 61% { opacity: 1; } 62% { opacity: .78; } 64% { opacity: 1; }
}
@keyframes v-pulse { 0%,100% { opacity: .45; } 50% { opacity: 1; } }
@keyframes v-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes v-glitch-x {
  0%,100% { transform: none; } 20% { transform: translateX(-2px); }
  22% { transform: translateX(3px); } 24% { transform: none; }
  70% { transform: translateX(1px); } 72% { transform: none; }
}
.v-flicker { animation: v-flicker 6s infinite steps(1); }
.v-rise { animation: v-rise .32s var(--ease-snap) both; }

/* Global CRT/scanline veneer — toggled by the HUD during Solar Flares. */
#ui-root::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.12) 2px 3px);
  mix-blend-mode: multiply; opacity: .35; z-index: 1;
}
body.flare #ui-root { animation: v-glitch-x .9s infinite steps(2); }
body.flare { --v-text: #d8c2a8; --v-line: #3a2418; --v-line-hot: #5a3a22; }
body.flare #ui-root::after { opacity: .7; background:
  repeating-linear-gradient(0deg, rgba(255,120,40,.05) 0 2px, rgba(0,0,0,.2) 2px 3px); }

/* ------------------------------------------------------------ boot screen */
#boot { display: none; place-items: center; background: radial-gradient(ellipse at 50% 62%, #14100e 0%, #05070a 62%); }
/* Two ids on purpose: the generic `#ui-root > .screen.active { display:block }`
   rule outranks a bare `#boot.active`, which forced the boot screen to block
   layout — place-items never applied and the logo pinned to the top of the
   page until the lobby replaced it. */
#ui-root > #boot.active { display: grid; }
.boot-inner { text-align: center; width: min(520px, 88vw); }
.logo { font-family: var(--f-display); font-size: var(--t-3xl); letter-spacing: .12em; line-height: 1; display: flex; justify-content: center; gap: .28em; }
.logo-hollow { color: var(--v-text-hot); font-weight: 200; }
.logo-veil { color: var(--v-star); font-weight: 700; text-shadow: 0 0 34px var(--v-star-dim); }
.boot-sub { margin-top: 14px; font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: .42em; color: var(--v-text-faint); text-transform: uppercase; }
.boot-bar { margin: 34px auto 10px; width: 100%; height: 2px; background: var(--v-line); }
.boot-bar > i { display: block; height: 100%; width: 0; background: var(--v-star); box-shadow: 0 0 12px var(--v-star); transition: width .3s var(--ease); }
.boot-status { font-family: var(--f-mono); font-size: var(--t-xs); color: var(--v-text-dim); letter-spacing: .16em; min-height: 1.4em; }

/* -------------------------------------------------------- pointer hint */
#pointer-hint {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: var(--z-modal);
  font-family: var(--f-mono); font-size: var(--t-lg); letter-spacing: .4em;
  color: var(--v-text-hot); background: rgba(5,7,10,.55); backdrop-filter: blur(2px);
  pointer-events: none; animation: v-pulse 2.2s infinite ease-in-out;
}
#pointer-hint[hidden] { display: none; }

/* ----------------------------------------------------------- toasts */
.v-toast {
  pointer-events: none; width: 100%;
  background: linear-gradient(90deg, rgba(13,17,23,.96), rgba(13,17,23,.78));
  border-left: 2px solid var(--v-star); padding: 8px 14px;
  font-family: var(--f-mono); font-size: var(--t-sm); color: var(--v-text);
  letter-spacing: .06em; animation: v-rise .26s var(--ease-snap) both;
  display: flex; gap: 10px; align-items: baseline;
}
.v-toast .tk { color: var(--v-text-faint); font-size: var(--t-xs); letter-spacing: .2em; }
.v-toast--warn { border-color: var(--v-warn); }
.v-toast--bad { border-color: var(--v-bad); }
.v-toast--hollow { border-color: var(--v-hollow); }
.v-toast--anchor { border-color: var(--v-anchor); }
.v-toast--echo { border-color: var(--v-echo); }
.v-toast.out { opacity: 0; transform: translateY(-6px); transition: .3s var(--ease-in); }

/* ------------------------------------------------------ responsive-ish */
@media (max-width: 900px) {
  :root { --t-3xl: 40px; --t-2xl: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
