:root {
  --obsidian: #080A0E;
  --glass: rgba(18, 24, 38, 0.85);
  --glass-soft: rgba(29, 45, 68, 0.35);
  --gold: #D4AF37;
  --gold-soft: rgba(212, 175, 55, 0.25);
  --aqua: #38B000;
  --marble: #F4F1DE;
  --indigo: #1D2D44;
  --coral: #E63946;
  --serif: "Cinzel", Georgia, serif;
  --mono: "Space Grotesk", system-ui, sans-serif;
  --sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --dock-h: 72px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--obsidian); color: var(--marble); font-family: var(--sans); overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(29, 45, 68, 0.55), transparent 60%),
    radial-gradient(80% 50% at 50% 100%, rgba(212, 175, 55, 0.07), transparent 70%),
    var(--obsidian);
}

/* ---------- HUD ---------- */
.hud {
  padding-top: max(14px, env(safe-area-inset-top, 14px));
  padding-left: max(14px, env(safe-area-inset-left, 14px));
  padding-right: max(14px, env(safe-area-inset-right, 14px));
  padding-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, rgba(8, 10, 14, 0.95), rgba(8, 10, 14, 0.6));
  border-bottom: 1px solid var(--gold-soft);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.crest { border-radius: 50%; box-shadow: 0 0 14px rgba(212, 175, 55, 0.45); }
.brand h1 { font-family: var(--serif); font-weight: 700; font-size: 18px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
.brand h1 span { color: var(--marble); font-weight: 500; }
.hud-stats { display: flex; align-items: stretch; gap: 8px; }
.stat {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 4px;
  background: var(--glass-soft);
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 12px;
}
.stat-label { font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase; opacity: 0.6; }
.stat-value { font-family: var(--mono); font-weight: 700; font-size: 16px; color: var(--gold); transition: transform 0.25s, color 0.25s; }
.stat-value.bump { transform: scale(1.22); color: var(--aqua); }
.sound-btn {
  width: 46px; border-radius: 12px; display: grid; place-items: center;
  border: 1px solid rgba(212, 175, 55, 0.35); color: var(--gold); background: var(--glass-soft);
  transition: background 0.2s, transform 0.15s;
}
.sound-btn:active { transform: scale(0.92); }
.sound-btn[aria-pressed="false"] { color: rgba(244, 241, 222, 0.4); border-color: rgba(244, 241, 222, 0.15); }

/* ---------- Views ---------- */
.views { position: relative; flex: 1; min-height: 0; }
.view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none; transform: translateY(12px) scale(0.99);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.view.active { opacity: 1; pointer-events: auto; transform: none; }
.scroll { overflow-y: auto; height: 100%; padding: 18px 16px calc(var(--dock-h) + 30px + env(safe-area-inset-bottom, 0px)); }

.matrix-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px 0; }
.level-chip {
  font-family: var(--serif); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--gold-soft); color: var(--marble); white-space: nowrap;
}
.level-chip b { color: var(--gold); }
.hint { flex: 1; font-size: 11px; line-height: 1.35; opacity: 0.62; }
#matrix-canvas {
  flex: 1; width: 100%; min-height: 0; display: block; touch-action: none;
  margin-bottom: calc(var(--dock-h) + 14px + env(safe-area-inset-bottom, 0px));
}

.ghost-btn {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--gold-soft);
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold);
  transition: background 0.2s, transform 0.15s;
}
.ghost-btn:hover { background: rgba(212, 175, 55, 0.08); }
.ghost-btn:active { transform: scale(0.95); }
.ghost-btn.danger { color: var(--coral); border-color: rgba(230, 57, 70, 0.35); margin-top: 8px; }
.gold-btn {
  padding: 14px 28px; border-radius: 999px; font-family: var(--serif); font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--obsidian); background: linear-gradient(135deg, #F7E7A1, var(--gold) 45%, #8F7420);
  box-shadow: 0 8px 30px rgba(212, 175, 55, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.15s, box-shadow 0.2s;
}
.gold-btn:active { transform: scale(0.96); }

/* ---------- Victory ---------- */
.victory {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle, rgba(8, 10, 14, 0.55), rgba(8, 10, 14, 0.9));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.5s ease;
  z-index: 4;
}
.victory[hidden] { display: none; }
.victory-card {
  width: min(360px, 100%); text-align: center; padding: 28px 22px;
  background: var(--glass); border: 1px solid rgba(212, 175, 55, 0.45); border-radius: 24px;
  box-shadow: 0 0 60px rgba(212, 175, 55, 0.2);
  animation: rise 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.victory-kicker { font-size: 11px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--aqua); }
.victory-card h2 { font-family: var(--serif); font-size: 26px; color: var(--gold); margin: 8px 0 18px; }
.victory-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.victory-grid div { background: var(--glass-soft); border-radius: 12px; padding: 10px; }
.victory-grid dt { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.6; }
.victory-grid dd { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--marble); }

/* ---------- Proof & Lab ---------- */
.section-title { font-family: var(--serif); font-size: 24px; color: var(--gold); letter-spacing: 0.08em; }
.section-sub { font-size: 13px; opacity: 0.65; margin: 6px 0 18px; line-height: 1.5; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.card, .lab-readout > div {
  background: var(--glass); border: 1px solid rgba(212, 175, 55, 0.18); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.card-label { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; opacity: 0.6; }
.card-value { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--gold); }
.panel {
  background: var(--glass); border: 1px solid rgba(212, 175, 55, 0.14); border-radius: 18px; padding: 16px; margin-bottom: 14px;
  box-shadow: inset 0 1px 0 rgba(244, 241, 222, 0.04);
}
.panel h3 { font-family: var(--serif); font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--marble); margin-bottom: 12px; }
.panel canvas { width: 100%; display: block; }
.ledger { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.ledger li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: rgba(8, 10, 14, 0.5); border-left: 3px solid var(--gold);
  animation: rise 0.4s ease both;
}
.ledger .num { font-family: var(--serif); color: var(--gold); font-size: 15px; }
.ledger .meta { font-size: 12px; opacity: 0.75; line-height: 1.4; }
.ledger .seq { font-family: var(--mono); font-size: 11px; color: var(--aqua); letter-spacing: 0.04em; }
.ledger .score { font-family: var(--mono); font-weight: 700; color: var(--marble); }
.empty { font-size: 13px; opacity: 0.55; line-height: 1.5; }

.lab-stage { padding: 0; overflow: hidden; }
#lab-canvas { height: 220px; touch-action: none; cursor: pointer; }
.lab-readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px; }
.lab-readout .card-value { font-size: 15px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--aqua), var(--gold)); outline: none; margin: 8px 0 16px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF3C4, var(--gold) 60%, #6E5713); box-shadow: 0 0 14px rgba(212, 175, 55, 0.6);
}
input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border: 0; border-radius: 50%; background: var(--gold); }
.scale { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.scale button {
  padding: 10px 4px; border-radius: 12px; border: 1px solid rgba(212, 175, 55, 0.22); background: rgba(8, 10, 14, 0.5);
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: all 0.2s;
}
.scale button b { font-family: var(--mono); color: var(--gold); font-size: 14px; }
.scale button small { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; }
.scale button.active { background: rgba(56, 176, 0, 0.15); border-color: var(--aqua); box-shadow: 0 0 16px rgba(56, 176, 0, 0.3); }
.toggles { display: flex; flex-direction: column; gap: 14px; }
.toggle { display: flex; align-items: center; gap: 12px; font-size: 14px; cursor: pointer; }
.toggle input { display: none; }
.toggle span { width: 44px; height: 24px; border-radius: 12px; background: rgba(244, 241, 222, 0.15); position: relative; transition: background 0.25s; flex-shrink: 0; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--marble); transition: transform 0.25s; }
.toggle input:checked + span { background: var(--gold); }
.toggle input:checked + span::after { transform: translateX(20px); background: var(--obsidian); }

/* ---------- Dock ---------- */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  width: min(420px, calc(100% - 24px)); height: var(--dock-h);
  display: flex; padding: 6px; gap: 6px;
  background: var(--glass); border: 1px solid rgba(212, 175, 55, 0.28); border-radius: 24px;
  backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  z-index: 10;
}
.dock-btn {
  flex: 1; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-family: var(--serif); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(244, 241, 222, 0.55);
  transition: background 0.25s, color 0.25s, transform 0.15s;
}
.dock-btn svg { width: 22px; height: 22px; fill: currentColor; }
.dock-btn.active { color: var(--gold); background: linear-gradient(180deg, rgba(212, 175, 55, 0.18), rgba(212, 175, 55, 0.04)); box-shadow: inset 0 0 0 1px rgba(212, 175, 55, 0.35); }
.dock-btn:active { transform: scale(0.94); }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.96); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media (min-width: 720px) {
  .hud { flex-direction: row; align-items: center; justify-content: space-between; }
  .hud-stats { width: 460px; }
  .scroll { max-width: 640px; margin: 0 auto; }
  .cards { grid-template-columns: repeat(4, 1fr); }
}
