@font-face {
  font-family: "Bebas Neue";
  src: url("assets/BebasNeue-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #08090b;
  --panel: rgba(9, 10, 12, 0.88);
  --paper: #e6e1d4;
  --muted: #98958d;
  --gold: #d0cbc1;
  --acid: #f1f1ee;
  --line: rgba(230, 225, 212, 0.28);
  --stage-width: min(100vw, calc(100vh * 16 / 9));
  --stage-height: min(100vh, calc(100vw * 9 / 16));
}

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

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--ink);
}

body {
  overflow: hidden;
  color: var(--paper);
  font-family: "Noto Sans SC", system-ui, sans-serif;
}

button,
output {
  font: inherit;
}

button {
  color: inherit;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.game-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #030405;
}

#game-stage {
  position: relative;
  container-type: inline-size;
  width: var(--stage-width);
  height: var(--stage-height);
  overflow: hidden;
  background: var(--ink);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.9);
}

#game-stage canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.start-artwork {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.start-artwork[hidden],
.start-tagline[hidden] {
  display: none;
}

.start-artwork img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(1);
}

.start-artwork::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(13, 13, 13, 0.68), transparent 25%, transparent 67%, rgba(13, 13, 13, 0.88));
  content: "";
}

.site-header {
  position: fixed;
  z-index: 20;
  top: 1.5rem;
  left: max(1.5rem, calc((100vw - var(--stage-width)) / 2 + 1.5rem));
  pointer-events: none;
  opacity: 0;
}

.site-header h1 {
  margin: 0;
  font-size: 0.75rem;
}

.site-header p {
  margin: 0.2rem 0 0;
}

.scene-nav {
  position: fixed;
  z-index: 30;
  top: 1rem;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem;
  border: 1px solid transparent;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 180ms ease, border-color 180ms ease, background 180ms ease;
}

body:hover .scene-nav,
.scene-nav:focus-within {
  border-color: var(--line);
  background: rgba(6, 7, 9, 0.8);
  opacity: 1;
}

.scene-nav button {
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.scene-nav output {
  min-width: 5.4rem;
  color: var(--muted);
  font-family: "Bebas Neue", sans-serif;
  font-size: 1rem;
  letter-spacing: 0.1em;
  text-align: center;
}

.start-panel {
  position: absolute;
  z-index: 2;
  top: 17.59%;
  left: 21.875%;
  display: flex;
  width: 56.25%;
  height: 57.41%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9375cqw;
  text-align: center;
}

.start-panel[hidden] {
  display: none;
}

.start-title {
  display: flex;
  flex-direction: column;
  gap: 0.9375cqw;
  margin: 0;
  color: var(--paper);
  font-family: "Bebas Neue", Impact, sans-serif;
  font-size: 5.94cqw;
  font-weight: 400;
  line-height: 1;
}

.start-subtitle {
  margin: 0;
  color: var(--gold);
  font-family: "Noto Serif SC", serif;
  font-size: 2.08cqw;
  font-weight: 700;
  line-height: 1.25;
}

.start-panel button {
  width: 18.75cqw;
  height: 4.48cqw;
  border: 0.15625cqw solid var(--paper);
  background: var(--gold);
  color: var(--ink);
  font-size: 1.51cqw;
  font-weight: 700;
  cursor: pointer;
  transition: filter 160ms ease, transform 160ms ease;
}

.start-panel button:hover {
  filter: brightness(1.12);
  transform: translateY(-2px);
}

.start-panel button:focus-visible,
.scene-nav button:focus-visible {
  outline: 3px solid var(--acid);
  outline-offset: 3px;
}

.start-help {
  margin: 0;
  color: var(--muted);
  font-size: 1.09cqw;
}

.start-tagline {
  position: absolute;
  z-index: 2;
  top: 93.52%;
  left: 50%;
  margin: 0;
  color: var(--muted);
  font-family: "Bebas Neue", Impact, sans-serif;
  font-size: 1.145cqw;
  line-height: 1;
  transform: translateX(-50%);
}

.sensor-panel,
.fallback-controls {
  position: fixed;
  z-index: 24;
  right: max(1rem, calc((100vw - var(--stage-width)) / 2 + 1rem));
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  opacity: 0;
  transform: translateX(0.5rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

body:hover .sensor-panel,
body:hover .fallback-controls,
.sensor-panel:focus-within,
.fallback-controls:focus-within {
  opacity: 1;
  transform: translateX(0);
}

.sensor-panel {
  top: 5rem;
  width: 12.5rem;
  padding: 0.8rem;
}

.sensor-panel h2,
.fallback-controls h2 {
  margin: 0 0 0.55rem;
  color: var(--gold);
  font-family: "Bebas Neue", sans-serif;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
}

.sensor-panel ul {
  display: grid;
  gap: 0.35rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.sensor-panel li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.sensor-panel li[data-state="active"] output {
  color: var(--acid);
}

.sensor-panel li[data-state="error"] output {
  color: #df806e;
}

.camera-preview {
  position: fixed;
  z-index: 35;
  right: max(1rem, calc((100vw - var(--stage-width)) / 2 + 1rem));
  bottom: 5rem;
  width: min(16rem, 38vw);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}

.camera-preview[hidden],
.camera-preview__content[hidden] {
  display: none;
}

.camera-preview__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
}

.camera-preview__header h2 {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
}

.camera-preview__header button {
  border: 1px solid var(--line);
  background: #1d2025;
  cursor: pointer;
  font-size: 0.68rem;
}

.camera-preview__header button:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 2px;
}

.camera-preview__frame {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #111;
}

.camera-preview__frame video,
.camera-preview__frame canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
}

.camera-preview__frame video {
  filter: grayscale(1);
  object-fit: cover;
}

.camera-preview__frame canvas {
  pointer-events: none;
}

.camera-preview__content p {
  min-height: 2em;
  margin: 0;
  padding: 0.4rem 0.55rem;
  color: var(--paper);
  font-size: 0.65rem;
  line-height: 1.3;
}

.neural-controls {
  position: fixed;
  z-index: 24;
  bottom: 1rem;
  left: max(1rem, calc((100vw - var(--stage-width)) / 2 + 1rem));
  width: min(24rem, calc(100vw - 2rem));
  padding: 0.9rem;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
}

.neural-controls[hidden] {
  display: none;
}

.neural-controls h2 {
  margin: 0 0 0.35rem;
  color: var(--gold);
  font-size: 0.9rem;
}

.neural-controls p,
.neural-controls output {
  margin: 0.35rem 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.neural-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  margin: 0.6rem 0;
}

.neural-actions button {
  min-height: 2rem;
  border: 1px solid var(--line);
  background: #1d2025;
  cursor: pointer;
  font-size: 0.72rem;
}

.neural-actions button:hover,
.neural-actions button:focus-visible {
  border-color: var(--gold);
}

.fallback-controls {
  bottom: 1rem;
  width: min(28rem, calc(100vw - 2rem));
  padding: 0.7rem 0.9rem;
}

.fallback-controls p {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

kbd {
  padding: 0.05rem 0.3rem;
  border: 1px solid var(--line);
  background: #16181c;
  color: var(--paper);
}

.site-footer {
  position: fixed;
  z-index: 22;
  right: 50%;
  bottom: 1.25rem;
  transform: translateX(50%);
  pointer-events: none;
  opacity: 0;
}

.site-footer p {
  margin: 0;
  color: rgba(230, 225, 212, 0.72);
  font-family: "Bebas Neue", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
}

@media (max-width: 720px), (max-height: 560px) {
  .camera-preview {
    right: 0.5rem;
    bottom: 3.2rem;
    width: min(11rem, 42vw);
  }

  .sensor-panel {
    display: none;
  }

  .neural-controls {
    bottom: 0.5rem;
    left: 0.5rem;
    width: min(18rem, 48vw);
    padding: 0.5rem;
  }

  .fallback-controls {
    right: 0.5rem;
    bottom: 0.5rem;
    width: auto;
    padding: 0.45rem;
  }

  .fallback-controls h2,
  .fallback-controls p {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
