:root {
  --ink: #181d2c;
  --ink-soft: #2a3046;
  --cream: #f3ebde;
  --cream-dim: rgba(243, 235, 222, 0.68);
  --cream-faint: rgba(243, 235, 222, 0.18);
  --bone: #e8decf;
  --coral: #ff7a62;
  --gold: #e0b070;
  --mint: #8ec7ad;
  --rose: #e8a8a0;
  --shadow-lg: 0 24px 60px -22px rgba(15, 10, 25, 0.55);
  --shadow-sm: 0 6px 20px -8px rgba(15, 10, 25, 0.4);
  --glass: rgba(24, 29, 44, 0.55);
  --glass-strong: rgba(24, 29, 44, 0.7);
  --glass-blur: blur(24px) saturate(1.45);
  --hairline: 1px solid rgba(243, 235, 222, 0.08);
  --hairline-strong: 1px solid rgba(243, 235, 222, 0.14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: 'Geist', system-ui, -apple-system, sans-serif;
  font-weight: 400;
  color: var(--cream);
  background: #1a1426;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  cursor: default;
}

#stage { position: fixed; inset: 0; display: block; z-index: 0; }

/* Subtle grain overlay for cinematic feel */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ------------------- TOP HUD ------------------- */
.hud-top {
  position: fixed;
  top: 18px; left: 18px; right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 22px;
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--hairline);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 8px;
}
.brand-mark {
  font-size: 30px;
  line-height: 1;
  color: var(--coral);
  filter: drop-shadow(0 0 10px rgba(255, 122, 98, 0.4));
  transform: translateY(1px);
}
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name {
  font-family: 'Fraunces', 'Times New Roman', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 30px;
  letter-spacing: -0.025em;
  color: var(--cream);
}
.brand-sub {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 11px;
  color: var(--cream-dim);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-top: 4px;
}

.stats {
  display: flex;
  gap: 0;
  flex-wrap: nowrap;
}
.stat {
  padding: 4px 22px;
  border-left: var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 92px;
}
.stat:first-child { border-left: 0; padding-left: 18px; }
.stat:last-child { padding-right: 6px; }
.stat-label {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cream-dim);
  font-weight: 500;
}
.stat-value {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 19px;
  font-weight: 500;
  color: var(--cream);
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}
.stat[data-stat="money"] .stat-value { color: var(--gold); }
.stat[data-stat="happiness"] .stat-value { color: var(--mint); }
.stat[data-stat="power"] .stat-value.warn { color: var(--coral); }

.stat .pulse {
  animation: pulseFlash 0.6s ease-out;
}
@keyframes pulseFlash {
  0% { transform: scale(1); }
  30% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ------------------- BOTTOM PALETTE ------------------- */
.hud-bottom {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.palette {
  display: flex;
  gap: 6px;
  padding: 10px;
  background: var(--glass-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--hairline);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
}

.tool {
  position: relative;
  width: 70px;
  height: 70px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--cream-dim);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  font-family: 'Geist', sans-serif;
}
.tool:hover {
  background: rgba(243, 235, 222, 0.06);
  color: var(--cream);
  transform: translateY(-3px);
}
.tool.active {
  background: var(--cream);
  color: var(--ink);
  border-color: var(--cream);
  box-shadow: 0 8px 28px -6px rgba(243, 235, 222, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transform: translateY(-3px);
}
.tool .tool-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool .tool-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.tool .tool-name {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}
.tool .tool-cost {
  position: absolute;
  top: 5px;
  right: 7px;
  font-family: 'Geist Mono', monospace;
  font-size: 9px;
  color: var(--gold);
  opacity: 0.85;
}
.tool.active .tool-cost { color: rgba(24, 29, 44, 0.65); }
.tool.danger.active {
  background: var(--coral);
  color: var(--cream);
  border-color: var(--coral);
  box-shadow: 0 8px 28px -6px rgba(255, 122, 98, 0.55);
}
.tool.danger.active .tool-cost { color: rgba(255, 255, 255, 0.7); }

.palette-info {
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--hairline);
  border-radius: 14px;
  padding: 9px 22px;
  max-width: 540px;
  text-align: center;
}
.info-name {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 19px;
  color: var(--cream);
  margin-bottom: 2px;
  letter-spacing: -0.01em;
}
.info-desc {
  font-size: 12px;
  color: var(--cream-dim);
  line-height: 1.5;
}

/* ------------------- LOG ------------------- */
.hud-log {
  position: fixed;
  right: 18px;
  top: 110px;
  width: 270px;
  max-height: 50vh;
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--hairline);
  border-radius: 16px;
  padding: 14px 16px;
  z-index: 9;
  overflow: hidden;
}
.log-head {
  font-size: 10px;
  letter-spacing: 0.32em;
  color: var(--cream-dim);
  margin-bottom: 10px;
  font-weight: 500;
}
.log-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 42vh;
  overflow: hidden;
}
.log-list li {
  font-size: 12px;
  color: var(--cream);
  line-height: 1.5;
  padding-left: 10px;
  border-left: 1px solid var(--gold);
  opacity: 0;
  animation: logIn 0.5s ease forwards;
}
.log-list li.warn { border-left-color: var(--coral); color: var(--rose); }
.log-list li.good { border-left-color: var(--mint); }
@keyframes logIn {
  from { opacity: 0; transform: translateX(8px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ------------------- INSPECTOR ------------------- */
.hud-inspect {
  position: fixed;
  left: 18px;
  top: 110px;
  width: 250px;
  background: var(--glass-strong);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--hairline);
  border-radius: 16px;
  padding: 18px 20px;
  z-index: 9;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.hud-inspect.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
}
.inspect-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: 0;
  color: var(--cream-dim);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
}
.inspect-close:hover { color: var(--cream); }
.inspect-name {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 26px;
  color: var(--cream);
  margin-bottom: 14px;
  letter-spacing: -0.015em;
}
.inspect-stats {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12px;
}
.inspect-stats .row {
  display: flex;
  justify-content: space-between;
  color: var(--cream-dim);
  border-top: 1px dotted rgba(243, 235, 222, 0.1);
  padding-top: 7px;
}
.inspect-stats .row:first-child {
  border-top: 0;
  padding-top: 0;
}
.inspect-stats .row .v {
  font-family: 'Geist Mono', monospace;
  color: var(--cream);
  letter-spacing: -0.01em;
}

/* ------------------- HINT ------------------- */
.hint {
  position: fixed;
  bottom: 18px;
  left: 18px;
  font-family: 'Geist', sans-serif;
  font-size: 11px;
  color: var(--cream-dim);
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: var(--hairline);
  border-radius: 999px;
  padding: 8px 14px;
  z-index: 8;
  letter-spacing: 0.04em;
}
.hint kbd {
  font-family: 'Geist Mono', monospace;
  font-size: 10px;
  color: var(--cream);
  background: rgba(243, 235, 222, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(243, 235, 222, 0.1);
}

/* ------------------- FLOATING TEXT ------------------- */
.float {
  position: fixed;
  pointer-events: none;
  font-family: 'Geist Mono', monospace;
  font-size: 17px;
  font-weight: 500;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
  animation: float 1.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  z-index: 20;
  letter-spacing: -0.015em;
}
.float.gain { color: var(--gold); }
.float.loss { color: var(--coral); }
@keyframes float {
  0%   { transform: translateY(0) scale(0.92); opacity: 0; }
  20%  { transform: translateY(-8px) scale(1); opacity: 1; }
  100% { transform: translateY(-50px) scale(1); opacity: 0; }
}

/* ------------------- LOADER ------------------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(ellipse at 50% 60%, #2a1f3a 0%, #1a1426 60%, #0d0a16 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease;
}
#loader.gone { opacity: 0; pointer-events: none; }
.loader-mark {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 88px;
  color: var(--cream);
  letter-spacing: -0.04em;
  text-shadow: 0 0 60px rgba(255, 122, 98, 0.3);
}
.loader-sub {
  font-size: 11px;
  letter-spacing: 0.5em;
  color: var(--cream-dim);
  margin-top: 6px;
  font-weight: 500;
}
.loader-bar {
  width: 240px;
  height: 1px;
  background: rgba(243, 235, 222, 0.1);
  margin-top: 36px;
  position: relative;
  overflow: hidden;
}
.loader-bar::after {
  content: '';
  position: absolute;
  top: 0;
  height: 100%;
  width: 30%;
  background: var(--coral);
  animation: load 1.4s ease-in-out infinite;
  box-shadow: 0 0 12px var(--coral);
}
@keyframes load {
  0% { left: -30%; }
  100% { left: 100%; }
}

/* Responsive trims */
@media (max-width: 920px) {
  .hud-log { display: none; }
  .stat:not(:nth-child(-n+3)) { display: none; }
  .brand-sub { display: none; }
  .hint { display: none; }
}
