/* =============================================================================
 *  BACKROOMS // style.css
 *  Full-screen canvas + overlay UI (menus, HUD, screens). Deliberately grimy,
 *  monospaced and low-contrast to suit the liminal horror vibe. Layout is
 *  responsive: panels scroll on small screens and the HUD scales down.
 * ========================================================================== */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  color: #d7d2b8;
  font-family: "Courier New", ui-monospace, monospace;
  cursor: default;
  user-select: none;
}

#game-canvas { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------------------
 *  Overlays: full-screen fade + damage vignette
 * ------------------------------------------------------------------------- */
#fade {
  position: fixed; inset: 0; background: #000; opacity: 0;
  pointer-events: none; z-index: 50; transition: opacity 0.8s ease;
}
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 20; opacity: 0;
  background: radial-gradient(ellipse at center, rgba(120,0,0,0) 35%, rgba(120,0,0,0.55) 90%, rgba(90,0,0,0.85) 100%);
  transition: opacity 0.15s linear;
}

/* ---------------------------------------------------------------------------
 *  Menu / state screens
 * ------------------------------------------------------------------------- */
.screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at center, rgba(20,18,8,0.55), rgba(0,0,0,0.92)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.015) 0 1px, transparent 1px 3px);
  padding: 24px; overflow-y: auto;
}
.vignette-bg {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(150,140,60,0.07), transparent 60%);
}

.panel {
  position: relative;
  max-width: 640px; width: 100%;
  background: rgba(10,10,8,0.82);
  border: 1px solid rgba(180,170,90,0.25);
  box-shadow: 0 0 60px rgba(0,0,0,0.8), inset 0 0 40px rgba(0,0,0,0.6);
  padding: 38px 40px;
  backdrop-filter: blur(2px);
}
.panel.center { text-align: center; }

h1 {
  font-size: 30px; letter-spacing: 4px; margin-bottom: 14px;
  color: #e9e2bc; text-shadow: 0 0 18px rgba(200,190,90,0.35);
}
.title {
  font-size: clamp(34px, 7vw, 62px); letter-spacing: 8px;
  color: #d9cf7a; text-shadow: 0 0 30px rgba(190,175,60,0.5);
  animation: flickerTitle 6s infinite;
}
@keyframes flickerTitle {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.4; } 98% { opacity: 0.9; } 99% { opacity: 0.3; }
}
.subtitle { color: #9a9472; margin-bottom: 28px; font-size: 14px; letter-spacing: 1px; }
.credit { margin-top: 26px; font-size: 11px; color: #6b6750; letter-spacing: 1px; }
.lore { color: #b3ad8b; line-height: 1.7; font-size: 14px; margin: 10px 0 18px; }
.tiny { font-size: 11px; color: #777150; margin-top: 12px; letter-spacing: 2px; }

.died { color: #c0392b; letter-spacing: 10px; font-size: clamp(34px, 8vw, 64px);
  text-shadow: 0 0 26px rgba(180,30,20,0.7); animation: flickerTitle 4s infinite; }
.escaped { color: #2ecc71; letter-spacing: 8px; font-size: clamp(30px, 7vw, 56px);
  text-shadow: 0 0 26px rgba(40,200,110,0.6); }

/* buttons */
.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.btn {
  font-family: inherit; font-size: 16px; letter-spacing: 2px;
  color: #d7d2b8; background: rgba(40,38,22,0.6);
  border: 1px solid rgba(180,170,90,0.35); padding: 13px 20px;
  cursor: pointer; transition: all 0.15s ease; text-transform: uppercase;
}
.btn:hover { background: rgba(120,110,50,0.35); color: #fff; border-color: rgba(220,210,120,0.7);
  box-shadow: 0 0 18px rgba(180,170,90,0.25); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: rgba(120,110,50,0.4); border-color: rgba(220,210,120,0.6); }
.btn.disabled, .btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.disabled:hover, .btn:disabled:hover { background: rgba(40,38,22,0.6); color: #d7d2b8; box-shadow: none; }

/* loading */
.loading-track { height: 8px; background: rgba(255,255,255,0.08); border: 1px solid rgba(180,170,90,0.3); margin-top: 16px; }
#loading-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #8a7f30, #e9e2bc); transition: width 0.3s ease; }

/* how-to controls */
.controls-grid {
  display: grid; grid-template-columns: 140px 1fr; gap: 10px 16px;
  margin: 18px 0; font-size: 14px; text-align: left;
}
.controls-grid .key {
  background: rgba(60,56,30,0.7); border: 1px solid rgba(180,170,90,0.4);
  padding: 4px 8px; text-align: center; color: #e9e2bc; font-weight: bold;
}

/* settings */
.settings-grid {
  display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 16px 14px;
  align-items: center; margin: 16px 0 26px; text-align: left; font-size: 14px;
}
.settings-grid label { color: #b8b290; }
.settings-grid input[type=range] { width: 100%; accent-color: #b3a23e; }
.settings-grid input[type=checkbox] { width: 20px; height: 20px; accent-color: #b3a23e; }
.settings-grid .val { color: #e9e2bc; min-width: 56px; text-align: right; font-size: 13px; }

/* ---------------------------------------------------------------------------
 *  HUD
 * ------------------------------------------------------------------------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

#level-indicator {
  position: absolute; top: 18px; left: 20px; line-height: 1.3;
  text-shadow: 0 1px 4px #000;
}
#level-indicator b { display: block; font-size: 17px; letter-spacing: 3px; color: #e9e2bc; }
#level-indicator span { font-size: 12px; color: #9a9472; letter-spacing: 1px; }
#level-indicator #dim-tag { display: block; font-size: 11px; letter-spacing: 2px; margin-top: 2px; }
#anomaly { position: absolute; bottom: 54px; left: 50%; transform: translateX(-50%); font-size: 13px; letter-spacing: 2px; font-weight: bold; text-shadow: 0 0 10px #000; animation: pulseAlert 1s infinite; pointer-events: none; }

#objective-wrap { position: absolute; top: 18px; right: 20px; text-align: right; max-width: 42vw; text-shadow: 0 1px 4px #000; }
#objective { font-size: 14px; color: #e4dca8; letter-spacing: 0.5px; }
#progress { font-size: 13px; color: #b3ad8b; margin-top: 4px; }

#alert {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: 16px; letter-spacing: 3px; font-weight: bold; text-shadow: 0 0 10px #000;
}
#alert.alert-on.warn { color: #f1c40f; }
#alert.alert-on.danger { color: #ff3b30; animation: pulseAlert 0.5s infinite; }
@keyframes pulseAlert { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* crosshair */
#crosshair {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 16px; height: 16px; opacity: 0.7;
}
#crosshair span {
  position: absolute; background: rgba(235,230,200,0.85); box-shadow: 0 0 2px #000;
}
#crosshair span:nth-child(1) { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair span:nth-child(2) { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }

#prompt {
  position: absolute; top: 58%; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.55); border: 1px solid rgba(180,170,90,0.4);
  padding: 7px 14px; font-size: 14px; color: #e9e2bc; letter-spacing: 1px; white-space: nowrap;
}
#message {
  position: absolute; bottom: 17%; left: 50%; transform: translateX(-50%);
  font-size: 15px; color: #e4dca8; text-shadow: 0 0 8px #000; opacity: 0;
  transition: opacity 0.4s ease; text-align: center; max-width: 80vw;
}
#message.show { opacity: 1; }

/* survival bars */
#bars { position: absolute; bottom: 20px; left: 20px; width: 230px; max-width: 45vw; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.bar-label { width: 30px; font-size: 12px; color: #b8b290; text-shadow: 0 1px 3px #000; text-align: center; }
#flashlight-icon { filter: grayscale(1) brightness(0.6); transition: filter 0.2s; font-size: 15px; }
#flashlight-icon.on { filter: none; text-shadow: 0 0 8px #ffec80; }
.bar {
  flex: 1; height: 12px; background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.25); overflow: hidden;
}
.bar-fill { height: 100%; width: 100%; transition: width 0.18s linear, background 0.3s; }
#battery-text { font-size: 11px; color: #c9c39a; width: 36px; text-align: right; }
.bar-row.mini { gap: 5px; }
.bar-row.mini .bar-label { width: 16px; font-size: 12px; }
.bar.sm { height: 8px; }

/* ---------------------------------------------------------------------------
 *  Meta-game: accent variable, panels, cards, tabs
 * ------------------------------------------------------------------------- */
:root { --accent: #d9cf7a; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-grid .primary { grid-column: 1 / -1; }

.panel.wide { max-width: 880px; }
.panel-screen .panel { max-height: 88vh; display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; border-bottom: 1px solid rgba(180,170,90,0.25); padding-bottom: 12px; }
.panel-head h1 { margin: 0; font-size: 22px; }
.panel-head .head-right { display: flex; align-items: center; gap: 12px; }
.panel-body { overflow-y: auto; padding-right: 6px; }
.money-pill { background: rgba(180,160,60,0.18); border: 1px solid var(--accent); color: var(--accent); padding: 4px 10px; font-size: 13px; border-radius: 2px; }

.btn.small { font-size: 12px; padding: 7px 12px; letter-spacing: 1px; }
.btn.back { font-size: 12px; padding: 7px 14px; }

.tab-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tab { font-family: inherit; font-size: 12px; letter-spacing: 1px; color: #b8b290; background: rgba(40,38,22,0.5); border: 1px solid rgba(180,170,90,0.3); padding: 6px 12px; cursor: pointer; text-transform: uppercase; }
.tab.active { background: var(--accent); color: #1a160a; border-color: var(--accent); }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: rgba(20,20,16,0.7); border: 1px solid rgba(180,170,90,0.25); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.card-rarity { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; }
.card-name { font-size: 15px; color: #ece4be; }
.card-desc { font-size: 12px; color: #9a9472; line-height: 1.5; flex: 1; }
.card-action { margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.card.lvl.locked { opacity: 0.5; }
.owned-tag { color: #4caf50; font-size: 12px; margin-left: 8px; }
.dim { color: #777150; font-size: 12px; }

.inv-grid, .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; margin: 8px 0 18px; font-size: 13px; color: #b8b290; }
.stat-grid.wide { grid-template-columns: 1fr 1fr 1fr; }
.inv-grid div, .stat-grid div { display: flex; justify-content: space-between; border-bottom: 1px dotted rgba(180,170,90,0.2); padding: 4px 0; }
.inv-grid b, .stat-grid b { color: #ece4be; }
.panel-body h3 { font-size: 14px; color: var(--accent); margin: 16px 0 8px; letter-spacing: 1px; }
.inv-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inv-list { display: flex; flex-direction: column; gap: 4px; }
.inv-row { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 10px; background: rgba(255,255,255,0.03); }

.char-head { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.char-badge { font-size: 42px; }
.char-title { font-size: 22px; color: var(--accent); letter-spacing: 2px; }
.xp-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.xp-track { flex: 1; height: 12px; background: rgba(0,0,0,0.5); border: 1px solid rgba(180,170,90,0.3); }
.xp-track-fill { height: 100%; background: linear-gradient(90deg, #6a5f20, var(--accent)); }

.skills-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.skill-cat h3 { margin-top: 0; }
.skill-node { background: rgba(20,20,16,0.6); border: 1px solid rgba(180,170,90,0.2); padding: 10px; margin-bottom: 8px; }
.skill-name { font-size: 14px; }
.skill-desc { font-size: 12px; color: #9a9472; margin: 4px 0 8px; line-height: 1.5; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.ach { background: rgba(20,20,16,0.5); border: 1px solid rgba(120,120,120,0.2); padding: 10px; opacity: 0.55; }
.ach.got { opacity: 1; border-color: var(--accent); background: rgba(120,100,40,0.18); }
.ach-name { font-size: 13px; color: #ece4be; }
.ach-desc { font-size: 11px; color: #9a9472; margin-top: 3px; line-height: 1.4; }

/* ---------------------------------------------------------------------------
 *  Extra HUD widgets
 * ------------------------------------------------------------------------- */
#money-hud { position: absolute; top: 82px; left: 20px; color: var(--accent); font-size: 16px; text-shadow: 0 1px 4px #000; }
#xp-hud { position: absolute; top: 106px; left: 20px; width: 150px; }
#xp-hud #xp-level { font-size: 11px; color: #b8b290; }
#xp-bar { height: 6px; background: rgba(0,0,0,0.5); border: 1px solid rgba(180,170,90,0.3); margin-top: 3px; }
#xp-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.3s; }

#quests { position: absolute; top: 74px; right: 20px; text-align: right; max-width: 40vw; }
.quest { font-size: 12px; color: #b3ad8b; text-shadow: 0 1px 3px #000; margin-bottom: 3px; }
.quest.done { color: #4caf50; text-decoration: line-through; opacity: 0.8; }

#compass { position: absolute; top: 44px; left: 50%; transform: translateX(-50%); font-size: 12px; letter-spacing: 2px; color: var(--accent); text-shadow: 0 1px 4px #000; }
#compass-arrow { display: inline-block; font-size: 16px; }

#minimap { position: absolute; bottom: 20px; right: 20px; border: 1px solid rgba(180,170,90,0.4); background: rgba(0,0,0,0.4); image-rendering: pixelated; }
#scanner-readout { position: absolute; bottom: 200px; right: 20px; width: 168px; font-size: 11px; color: #ff8866; text-align: center; text-shadow: 0 1px 3px #000; }
#vision-mode { position: absolute; top: 128px; left: 20px; font-size: 11px; color: #44ff88; letter-spacing: 2px; text-shadow: 0 0 6px #000; }

#consumables { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.cons-slot { background: rgba(0,0,0,0.5); border: 1px solid rgba(180,170,90,0.3); padding: 5px 9px; font-size: 11px; color: #d7d2b8; display: flex; align-items: center; gap: 6px; }
.cons-key { background: var(--accent); color: #1a160a; padding: 0 5px; font-weight: bold; }
.cons-x { color: #9a9472; }

#toasts { position: absolute; top: 120px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: rgba(15,15,10,0.92); border: 1px solid var(--accent); padding: 10px 18px; min-width: 220px; text-align: center; opacity: 0; transform: translateY(-12px); transition: all 0.4s ease; box-shadow: 0 0 24px rgba(0,0,0,0.7); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ach { border-color: #f1c40f; }
.toast.level { border-color: #4caf50; }
.toast-title { font-size: 14px; color: #ece4be; letter-spacing: 1px; }
.toast-sub { font-size: 11px; color: #9a9472; margin-top: 3px; }

/* film grain + vision overlays */
#grain { position: fixed; inset: -120px; z-index: 5; pointer-events: none; opacity: 0.5; display: none;
  animation: grainShift 0.55s steps(2) infinite; }
@keyframes grainShift {
  0% { transform: translate(0, 0); } 25% { transform: translate(-28px, 12px); }
  50% { transform: translate(22px, -18px); } 75% { transform: translate(-12px, 16px); } 100% { transform: translate(0, 0); }
}
#vision-overlay { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#vision-overlay.night { background: rgba(20,255,90,0.10); box-shadow: inset 0 0 220px rgba(0,90,0,0.6); }
#vision-overlay.thermal { background: linear-gradient(rgba(30,0,50,0.28), rgba(0,30,70,0.28)); box-shadow: inset 0 0 200px rgba(0,0,40,0.7); }

/* =============================================================================
 *  Week 8 — Factions panel
 * ========================================================================== */
.faction-intro { padding: 0 0 18px; font-size: 12px; line-height: 1.6; border-bottom: 1px solid rgba(180,170,90,0.2); margin-bottom: 16px; }
.faction-card  { background: rgba(15,14,8,0.55); border: 1px solid rgba(180,170,90,0.15); padding: 14px 16px; margin-bottom: 10px; }
.faction-head  { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.faction-icon  { font-size: 18px; }
.faction-name  { font-size: 14px; font-weight: bold; letter-spacing: 1px; flex: 1; }
.faction-tier  { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; }
.faction-rep   { font-size: 12px; width: 40px; text-align: right; }
.faction-desc  { font-size: 11px; line-height: 1.55; margin-bottom: 10px; }
.faction-bar-wrap { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.faction-bar   { flex: 1; height: 6px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; }
.faction-bar-fill { height: 100%; border-radius: 2px; transition: width 0.4s ease; }
.faction-bar-label { font-size: 10px; white-space: nowrap; }
.faction-item  { font-size: 11px; padding: 6px 10px; border-radius: 2px; }
.faction-item.locked   { color: #666; border: 1px solid rgba(100,100,100,0.2); }
.faction-item.unlocked { color: #44dd88; border: 1px solid rgba(68,221,136,0.3); }

/* =============================================================================
 *  Week 6 — Codex panel
 * ========================================================================== */
.codex-grid { display: flex; flex-direction: column; gap: 12px; }
.codex-entry { background: rgba(20,18,10,0.6); border: 1px solid rgba(180,170,90,0.2); padding: 14px 16px; }
.codex-meta { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 10px; letter-spacing: 2px; }
.codex-type { font-weight: bold; text-transform: uppercase; }
.codex-loc  { color: #6a6450; }
.codex-title { font-size: 14px; color: #e4dca8; margin-bottom: 8px; }
.codex-text  { font-size: 12px; color: #9a9472; line-height: 1.65; font-style: italic; }
#codex-filters { display: flex; gap: 6px; flex-wrap: wrap; }
#codex-filters .tab { font-size: 11px; padding: 4px 10px; }

/* =============================================================================
 *  Week 7 — Research panel
 * ========================================================================== */
.research-bestiary { padding: 0 0 16px; font-size: 13px; border-bottom: 1px solid rgba(180,170,90,0.2); margin-bottom: 18px; }
.research-cat { margin-bottom: 22px; }
.research-cat h3 { margin: 0 0 10px; font-size: 14px; letter-spacing: 2px; }
.research-node { background: rgba(15,15,10,0.5); border: 1px solid rgba(180,170,90,0.15); padding: 12px 14px; margin-bottom: 8px; }
.research-node.done      { border-color: rgba(68,221,136,0.3); background: rgba(20,40,25,0.4); }
.research-node.available { border-color: rgba(180,170,90,0.35); }
.research-node.locked    { opacity: 0.5; }
.rn-name { font-size: 13px; margin-bottom: 5px; }
.rn-desc { font-size: 11px; line-height: 1.5; margin-bottom: 6px; }
.rn-req  { font-size: 10px; color: #aa7744; margin-bottom: 5px; }
.rn-cost { font-size: 12px; color: #e4dca8; }

/* =============================================================================
 *  Week 4: Reactive HUD — per-dimension theming + Reality Stability glitch
 * ========================================================================== */

/* HUD CSS variables (defaults = prime/amber) */
#hud {
  --hud-accent:  #d9cf7a;
  --hud-glow:    rgba(217,207,122,0.18);
  --hud-text:    #e9e2bc;
  --hud-dim:     #9a9472;
  --hud-bar-bg:  rgba(0,0,0,0.55);
  --hud-border:  rgba(180,170,90,0.3);
}

/* Propagate to hud children that use explicit colours */
#hud #level-indicator b      { color: var(--hud-text); }
#hud #level-indicator span   { color: var(--hud-dim); }
#hud #objective              { color: var(--hud-text); }
#hud #progress               { color: var(--hud-dim); }
#hud .bar                    { background: var(--hud-bar-bg); border-color: var(--hud-border); }
#hud #prompt                 { border-color: var(--hud-border); color: var(--hud-text); }
#hud #compass                { color: var(--hud-accent); }
#hud .cons-key               { background: var(--hud-accent); }
#hud .cons-slot              { border-color: var(--hud-border); }
#hud #minimap                { border-color: var(--hud-border); }

/* Crosshair reacts to theme */
#crosshair span { background: var(--hud-accent); box-shadow: 0 0 3px var(--hud-glow); }

/* ---- dimension theme classes -------------------------------------------- */
/* dream: lavender/purple — hazy, soft */
#hud.hud-dream {
  --hud-accent:  #c4a0f0; --hud-glow: rgba(196,160,240,0.22);
  --hud-text:    #e8ddff;  --hud-dim:  #9988bb;
  --hud-bar-bg:  rgba(18,10,28,0.72); --hud-border: rgba(196,160,240,0.28);
}
#hud.hud-dream #bars { filter: blur(0.4px) saturate(1.3); }

/* corrupted: sickly green — biological, dripping */
#hud.hud-corrupted {
  --hud-accent:  #6fde4a; --hud-glow: rgba(111,222,74,0.22);
  --hud-text:    #d8f5c8;  --hud-dim:  #7aaa62;
  --hud-bar-bg:  rgba(8,20,5,0.78); --hud-border: rgba(111,222,74,0.28);
}
#hud.hud-corrupted .bar-fill { filter: saturate(1.6); }

/* machine: cyan/steel — digital, cold */
#hud.hud-machine {
  --hud-accent:  #4ac8e8; --hud-glow: rgba(74,200,232,0.22);
  --hud-text:    #c8f0ff;  --hud-dim:  #6aaccc;
  --hud-bar-bg:  rgba(5,15,22,0.82); --hud-border: rgba(74,200,232,0.28);
}
#hud.hud-machine #bars { font-family: monospace; letter-spacing: 0.5px; }
#hud.hud-machine .bar { border-radius: 0; }

/* void: deep violet — oppressive, minimal */
#hud.hud-void {
  --hud-accent:  #8855ee; --hud-glow: rgba(136,85,238,0.20);
  --hud-text:    #ccc0ee;  --hud-dim:  #7766aa;
  --hud-bar-bg:  rgba(5,3,14,0.88); --hud-border: rgba(100,60,200,0.22);
}
#hud.hud-void { opacity: 0.82; }
#hud.hud-void #crosshair { transform: translate(-50%,-50%) scale(0.7); opacity: 0.55; }

/* cosmic: aurora pink — alien, pulsing */
#hud.hud-cosmic {
  --hud-accent:  #ff88dd; --hud-glow: rgba(255,136,221,0.25);
  --hud-text:    #ffddff;  --hud-dim:  #cc88bb;
  --hud-bar-bg:  rgba(15,5,20,0.80); --hud-border: rgba(255,136,221,0.30);
}
@keyframes cosmicPulse { 0%,100%{opacity:0.85} 50%{opacity:1} }
#hud.hud-cosmic #bars { animation: cosmicPulse 2.5s ease-in-out infinite; }

/* mirror: silver/ice — eerie, slightly wrong */
#hud.hud-mirror {
  --hud-accent:  #c8ceee; --hud-glow: rgba(200,206,238,0.18);
  --hud-text:    #eeeeff;  --hud-dim:  #9999bb;
  --hud-bar-bg:  rgba(18,18,24,0.78); --hud-border: rgba(200,206,238,0.25);
}
#hud.hud-mirror #level-indicator { transform: scaleX(-1) translateX(-100%); left: auto; right: 20px; text-align: right; }

/* ancient: ochre/rust — crumbling, warm decay */
#hud.hud-ancient {
  --hud-accent:  #c87a38; --hud-glow: rgba(200,122,56,0.22);
  --hud-text:    #f0ddc0;  --hud-dim:  #aa8860;
  --hud-bar-bg:  rgba(20,12,5,0.78); --hud-border: rgba(200,122,56,0.28);
}
#hud.hud-ancient .bar-fill { filter: sepia(0.4); }

/* ---- crosshair variants ------------------------------------------------- */
/* default (+) crosshair uses the two spans — keep as-is for prime */
#crosshair.cross-circle span:nth-child(1) { width: 14px; height: 14px; top: 1px; left: 1px; border-radius: 50%; background: transparent; border: 2px solid var(--hud-accent); }
#crosshair.cross-circle span:nth-child(2) { display: none; }
#crosshair.cross-dot span:nth-child(1) { width: 4px; height: 4px; top: 6px; left: 6px; border-radius: 50%; }
#crosshair.cross-dot span:nth-child(2) { display: none; }
#crosshair.cross-diamond { transform: translate(-50%,-50%) rotate(45deg); }
#crosshair.cross-ring { width: 20px; height: 20px; }
#crosshair.cross-ring span:nth-child(1) { width: 20px; height: 20px; top: 0; left: 0; border-radius: 50%; background: transparent; border: 1px solid var(--hud-accent); box-shadow: 0 0 4px var(--hud-glow); }
#crosshair.cross-ring span:nth-child(2) { display: none; }

/* ---- Reality Stability readout ------------------------------------------ */
#stability-readout {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  font-size: 11px; letter-spacing: 3px; text-transform: uppercase;
  color: var(--hud-accent); text-shadow: 0 0 8px currentColor;
  transition: color 0.6s, opacity 0.3s;
  pointer-events: none;
}
#stability-readout.stab-warn     { color: #ffaa44; }
#stability-readout.stab-critical { color: #ff4444; animation: pulseAlert 0.6s infinite; }

/* ---- Reality Stability glitch animations --------------------------------- */
@keyframes hudGlitch {
  0%,75%,100% { transform: none; filter: none; }
  80%  { transform: translateX(-3px) skewX(-1.5deg); filter: hue-rotate(18deg); }
  88%  { transform: translateX(2px); filter: brightness(1.15); }
  94%  { transform: translateX(-1px) skewX(0.8deg); filter: hue-rotate(-12deg); }
}
@keyframes hudGlitchSevere {
  0%,55%,100% { transform: none; filter: none; }
  60%  { transform: translateX(-5px) skewX(-2.5deg); filter: hue-rotate(30deg) brightness(1.25); }
  68%  { transform: translateX(4px) skewX(1.5deg); filter: hue-rotate(-20deg); }
  76%  { transform: translateX(-3px); filter: brightness(0.75) saturate(1.8); }
  84%  { transform: translateX(2px) skewX(-0.8deg); filter: hue-rotate(10deg); }
  92%  { transform: translateX(-1px); filter: brightness(1.1); }
}
@keyframes hudGlitchCritical {
  0%   { transform: none; filter: none; }
  20%  { transform: translateX(-7px) skewX(-3deg); filter: hue-rotate(50deg) brightness(1.4); }
  40%  { transform: translateX(6px) skewX(2.5deg); filter: hue-rotate(-35deg) saturate(2.2); }
  60%  { transform: translateX(-4px) skewX(-1deg); filter: brightness(0.55); }
  80%  { transform: translateX(3px); filter: hue-rotate(22deg) brightness(1.3); }
  100% { transform: none; filter: none; }
}

#hud.hud-glitch-mild     { animation: hudGlitch 6s steps(2) infinite; }
#hud.hud-glitch-severe   { animation: hudGlitchSevere 1.2s steps(3) infinite; }
#hud.hud-glitch-critical { animation: hudGlitchCritical 0.18s steps(4) infinite; }

/* small screens */
@media (max-width: 560px) {
  .panel { padding: 26px 22px; }
  .controls-grid { grid-template-columns: 110px 1fr; }
  .settings-grid { grid-template-columns: 1fr auto; }
  .settings-grid .val { grid-column: 2; }
  #objective-wrap { max-width: 50vw; }
}

/* =============================================================================
 *  Mobile HUD & UI scaling (phones in landscape)
 * ========================================================================== */
@media (max-width: 900px) and (pointer: coarse) {

  /* ── HUD text & indicators ── */
  #level-indicator { font-size: 9px; top: 8px; left: 8px; }
  #level-indicator b { font-size: 12px; letter-spacing: 1px; }
  #level-indicator span { font-size: 9px; }
  #level-indicator #dim-tag { font-size: 8px; }

  #alert { font-size: 11px; letter-spacing: 1px; top: 8px; }

  #objective-wrap { top: 8px; right: 8px; max-width: 44vw; }
  #objective { font-size: 10px; }
  #progress  { font-size: 9px; margin-top: 2px; }

  #quests { top: 52px; right: 8px; max-width: 44vw; }
  .quest  { font-size: 9px; margin-bottom: 2px; }

  #money-hud { font-size: 11px; top: 56px; left: 8px; }
  #xp-hud    { top: 72px; left: 8px; width: 110px; }
  #xp-hud #xp-level { font-size: 9px; }

  /* ── survival bars (bottom-left) ── */
  #bars { bottom: 12px; left: 8px; width: 160px; }
  .bar-row  { gap: 5px; margin-bottom: 4px; }
  .bar-label { font-size: 9px; width: 22px; }
  .bar      { height: 5px; }
  #battery-text { font-size: 9px; width: 28px; }
  .bar-row.mini .bar-label { width: 12px; font-size: 10px; }
  .bar-row.mini .bar.sm { height: 4px; }

  /* ── crosshair ── */
  #crosshair { transform: translate(-50%, -50%) scale(0.75); }

  /* ── compass / scanner ── */
  #compass        { font-size: 9px; top: 32px; }
  #compass-arrow  { font-size: 11px; }
  #scanner-readout { font-size: 9px; width: 120px; right: 8px; bottom: 140px; }
  #stability-readout { font-size: 9px; }
  #anomaly { font-size: 10px; bottom: 40px; }
  #vision-mode { font-size: 9px; top: 90px; left: 8px; }

  /* ── message / toasts ── */
  #message { font-size: 12px; padding: 5px 12px; }
  #prompt  { font-size: 11px; padding: 4px 10px; }
  .toast   { font-size: 11px; padding: 6px 10px; }
  .toast-title { font-size: 11px; }
  .toast-sub   { font-size: 9px; }

  /* ── minimap ── */
  #minimap { width: 110px !important; height: 110px !important; bottom: 12px; right: 8px; }

  /* ── consumables ── */
  .cons-slot { font-size: 9px; padding: 3px 6px; }

  /* ── menus & panels ── */
  .panel      { padding: 18px 16px; }
  .panel.wide { max-width: 100%; }
  .panel-head h1   { font-size: 16px; }
  .panel-head      { margin-bottom: 10px; padding-bottom: 8px; }
  .panel-body      { font-size: 12px; }

  .title    { font-size: clamp(22px, 8vw, 40px) !important; letter-spacing: 3px !important; }
  .subtitle { font-size: 11px; margin-bottom: 16px; }

  .btn { font-size: 12px; padding: 10px 14px; letter-spacing: 1px; }
  .btn.back  { font-size: 11px; padding: 6px 10px; }
  .btn.small { font-size: 11px; padding: 6px 10px; }
  .money-pill { font-size: 10px; padding: 3px 7px; }

  /* ── main menu grid ── */
  .menu-grid { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* ── achievements ── */
  .ach-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .ach-card { padding: 8px 10px; }
  .ach-name { font-size: 10px; }
  .ach-desc { font-size: 9px; }

  /* ── shop / inventory cards ── */
  .grid-cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card-name  { font-size: 12px; }
  .card-desc  { font-size: 10px; }
  .card-rarity{ font-size: 9px; }

  /* ── skills ── */
  .skills-grid   { grid-template-columns: 1fr; gap: 8px; }
  .skill-name    { font-size: 12px; }
  .skill-desc    { font-size: 10px; }

  /* ── stats ── */
  .stat-grid { grid-template-columns: 1fr; font-size: 11px; }
  .inv-grid  { grid-template-columns: 1fr; font-size: 11px; }

  /* ── factions ── */
  .faction-card { padding: 10px 12px; margin-bottom: 8px; }
  .faction-name { font-size: 12px; }
  .faction-icon { font-size: 14px; }
  .faction-tier { font-size: 9px; }
  .faction-desc { font-size: 10px; }
  .faction-rep  { font-size: 10px; }
  .faction-item { font-size: 9px; padding: 4px 8px; }

  /* ── codex ── */
  .codex-entry { padding: 10px 12px; }
  .codex-title { font-size: 12px; }
  .codex-text  { font-size: 10px; }
  .codex-meta  { font-size: 9px; }

  /* ── research ── */
  .research-node { padding: 8px 10px; margin-bottom: 6px; }
  .rn-name { font-size: 11px; }
  .rn-desc { font-size: 9px; }
  .research-cat h3 { font-size: 12px; }

  /* ── tabs ── */
  .tab      { font-size: 9px; padding: 4px 8px; }
  .tab-row  { gap: 4px; flex-wrap: wrap; }

  /* ── menu & panel compactness ── */
  .screen { padding: 10px; }
  .panel  { padding: 14px 12px; max-height: 96vh; }
  .panel.wide { max-width: 100%; }
  .panel-head { margin-bottom: 8px; padding-bottom: 6px; }
  .panel-head h1 { font-size: 14px; letter-spacing: 1px; }
  .panel-body { padding-right: 2px; font-size: 11px; }

  /* main menu tighter */
  .title    { font-size: clamp(18px, 6vw, 32px) !important; letter-spacing: 2px !important; margin-bottom: 6px !important; }
  .subtitle { font-size: 10px; margin-bottom: 10px; }
  .menu-buttons { gap: 6px; }
  .menu-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .btn { font-size: 11px; padding: 8px 10px; letter-spacing: 0.5px; }
  .btn.back  { font-size: 10px; padding: 5px 8px; }
  .credit { font-size: 9px; margin-top: 10px; }

  /* pause / death / victory screens */
  .died    { font-size: clamp(22px, 7vw, 44px) !important; }
  .escaped { font-size: clamp(18px, 6vw, 36px) !important; }
  .lore    { font-size: 11px; margin: 6px 0 10px; }

  /* settings compact */
  .settings-grid { gap: 6px 10px; font-size: 11px; }
  .settings-grid input[type=range] { width: 100px; }

  /* how to play compact */
  .controls-grid { grid-template-columns: 90px 1fr; gap: 5px 10px; font-size: 11px; }
  .key { font-size: 10px; padding: 3px 5px; }
}
