:root {
  --bg: #120e0c;
  --bg-elevated: #1c1613;
  --ink: #f4ebe1;
  --muted: #b7a99a;
  --brass: #d4a25a;
  --brass-hot: #f0c57a;
  --rim: #3a8f88;
  --danger: #c45c3a;
  --line: rgba(244, 235, 225, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font-display: "Unbounded", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 18px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
}

body {
  position: relative;
  overflow-x: hidden;
}

.stage-glow {
  position: fixed;
  inset: -20% -10% auto;
  height: 55vh;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(212, 162, 90, 0.22), transparent 55%),
    radial-gradient(ellipse at 75% 20%, rgba(58, 143, 136, 0.16), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.stage-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.top-bar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem 0.5rem;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--brass-hot);
}

.brand {
  text-align: center;
}

.brand-kicker {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brass);
}

.brand h1 {
  margin: 0.15rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.4vw, 1.55rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-pill {
  justify-self: end;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(28, 22, 19, 0.75);
  font-size: 0.78rem;
  color: var(--muted);
  backdrop-filter: blur(8px);
}

.status-pill[data-state="live"] {
  color: #9fe7d8;
  border-color: rgba(58, 143, 136, 0.45);
  box-shadow: 0 0 0 1px rgba(58, 143, 136, 0.15);
}

.status-pill[data-state="error"] {
  color: #ffb4a2;
  border-color: rgba(196, 92, 58, 0.5);
}

.stage {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 1rem;
  padding: 0.75rem 1.25rem 1.25rem;
  min-height: calc(100vh - 4.5rem);
}

.viewport {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #070504;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  min-height: 62vh;
  isolation: isolate;
}

#camera,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#camera {
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0.88;
  filter: saturate(0.85) contrast(1.05);
}

#overlay {
  z-index: 2;
  pointer-events: auto;
  cursor: crosshair;
}

.gate {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    linear-gradient(160deg, rgba(18, 14, 12, 0.55), rgba(18, 14, 12, 0.82)),
    radial-gradient(circle at 50% 30%, rgba(212, 162, 90, 0.18), transparent 55%);
  backdrop-filter: blur(4px);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.gate.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.gate-card {
  max-width: 28rem;
  padding: 1.75rem 1.6rem;
  border-radius: 22px;
  border: 1px solid rgba(212, 162, 90, 0.28);
  background: rgba(28, 22, 19, 0.88);
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise-in 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.gate-eyebrow {
  margin: 0;
  color: var(--brass);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
}

.gate-card h2 {
  margin: 0.55rem 0 0.7rem;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.gate-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.cta {
  margin-top: 1.25rem;
  appearance: none;
  border: 0;
  cursor: pointer;
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brass-hot), var(--brass));
  color: #1a120c;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  box-shadow: 0 10px 30px rgba(212, 162, 90, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 36px rgba(212, 162, 90, 0.45);
}

.cta:active {
  transform: translateY(0);
}

.gate-note {
  margin-top: 0.9rem !important;
  font-size: 0.78rem;
  opacity: 0.85;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 3;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background: rgba(18, 14, 12, 0.72);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.hint.visible {
  opacity: 1;
}

.console {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: rgba(28, 22, 19, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.console section h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brass);
}

.switch-row,
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  flex-wrap: wrap;
}

.field label {
  flex: 1 1 100%;
}

.field input[type="range"] {
  flex: 1;
  accent-color: var(--brass);
}

.field output {
  min-width: 3.2rem;
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.chip-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font: inherit;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.chip.active {
  background: rgba(212, 162, 90, 0.16);
  border-color: rgba(212, 162, 90, 0.45);
  color: var(--brass-hot);
}

.help {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.hit-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 8rem;
}

.hit-log li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  animation: hit-flash 0.45s ease;
}

.hit-log li span:last-child {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.console-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.72rem;
}

.ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.75rem;
}

.ghost:hover {
  color: var(--ink);
  border-color: rgba(244, 235, 225, 0.28);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes hit-flash {
  from {
    background: rgba(212, 162, 90, 0.22);
  }
  to {
    background: rgba(255, 255, 255, 0.03);
  }
}

@media (max-width: 960px) {
  .top-bar {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .brand {
    text-align: left;
  }

  .status-pill {
    justify-self: start;
  }

  .stage {
    grid-template-columns: 1fr;
  }

  .viewport {
    min-height: 58vh;
  }

  .console {
    min-height: auto;
  }
}
