@font-face {
  font-family: "Mona Sans";
  src: url("./assets/fonts/MonaSans.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Mona Sans Mono";
  src: url("./assets/fonts/MonaSansMono.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}
:root {
  color-scheme: light;
  --bg: #e9edec;
  --panel: #f3f5f4;
  --panel-elevated: #e1e6e3;
  --border: #bdc7c0;
  --text: #343d37;
  --muted: #57615b;
  --primary: #5fed83;
  --primary-strong: #1a7f37;
  --danger: #c32222;
  --mono: "Mona Sans Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Mona Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: var(--mono);
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; letter-spacing: -0.04em; }
.button-row { display: flex; align-items: center; gap: 0.7rem; }
.button-row.wrap { flex-wrap: wrap; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 0.55rem 0.85rem;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}
.button.primary { background: var(--primary); border-color: var(--primary); color: #000; }
.button.secondary { background: var(--panel-elevated); }
.button.danger { background: #fbe7e7; border-color: #c32222; color: #a51d1d; }
.button:hover:not(:disabled) { border-color: var(--primary-strong); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--primary-strong); outline-offset: 4px; }
[hidden] { display: none !important; }

.landing-page { display: grid; min-height: 100vh; place-items: center; padding: 2rem; }
.landing-card {
  width: min(640px, 100%);
  border: 1px solid var(--border);
  border-radius: 0;
  background: linear-gradient(135deg, var(--panel), var(--bg));
  padding: 2rem;
  box-shadow: 0 0 60px #5fed8314;
}
.landing-card h1 { margin-bottom: 1rem; font-size: clamp(2.3rem, 8vw, 4rem); }
.landing-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.landing-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }

.audience-page {
  min-height: 100vh;
  overflow-x: hidden;
  display: grid;
  align-items: center;
}
.audience-shell { width: min(2100px, 100%); margin: auto; padding: clamp(12px, 3.8vw, 80px); }
.arcade-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 3.12fr) minmax(0, 1fr);
  background: var(--bg);
  box-shadow: 0 0 35px #5fed8326, 0 0 90px #1a7f371a;
}
.audience-side {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.side-camera {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  opacity: 0.25;
  pointer-events: none;
}
.side-visual { position: relative; flex: 1; min-height: 0; }
.side-visual canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.side-label {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font: 0.58rem var(--mono);
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.side-instructions {
  border-top: 1px solid var(--border);
  padding: clamp(8px, 0.8vw, 16px);
  color: var(--muted);
  font: clamp(8px, 0.7vw, 13px)/1.5 var(--mono);
}
.side-instructions p { margin: 0; }
.side-instructions p + p { margin-top: 1em; }
.stage-shell {
  position: relative;
  overflow: hidden;
  border: 1px solid #8b9e91;
  border-bottom-color: var(--danger);
  background: var(--bg);
  align-self: start;
}
#gameCanvas { position: relative; z-index: 2; display: block; width: 100%; height: auto; }
#webcam {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.stage-message {
  margin: 0;
  color: var(--muted);
  font: inherit;
  text-align: right;
}
.audience-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 20px;
  color: var(--muted);
  font: 0.65rem/1.7 var(--mono);
}
.audience-footer > div { flex: 1; }
.play-state {
  display: inline-block;
  margin-right: 1rem;
  color: var(--primary-strong);
  text-transform: uppercase;
}
.play-state::before { content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 7px 2px 0; background: currentColor; }
.power-status { color: #583af7; margin-right: 1rem; }
.startup-panel {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: min(380px, calc(100% - 24px));
  transform: translate(-50%, -50%);
  border: 1px solid var(--primary-strong);
  background: #f3f5f4f5;
  padding: clamp(12px, 1.5vw, 24px);
  box-shadow: 0 8px 40px #57615b33;
}
.startup-panel h2 { margin-bottom: 0.5rem; font-size: clamp(1.1rem, 2vw, 1.6rem); font-weight: 550; }
.startup-panel .button-row { flex-wrap: wrap; gap: 0.5rem; }
.startup-panel .button { font-size: 0.78rem; min-height: 36px; }
.startup-panel.hidden { display: none; }
.camera-select {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem 0 1rem;
  font: 0.75rem var(--mono);
}
.camera-select select {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border-radius: 2px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: inherit;
}

.operator-page { padding: 22px; }
.operator-topbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  align-items: center;
  gap: 1rem;
  margin: 0 auto 1rem;
  max-width: 1500px;
}
.connection-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--panel);
  padding: 0.65rem 0.85rem;
}
.connection-card strong, .connection-card small { display: block; }
.connection-card small { margin-top: 0.18rem; color: var(--muted); }
.status-dot { width: 8px; height: 8px; background: #bba00a; }
.status-dot.connected { background: var(--primary-strong); box-shadow: 0 0 10px #5fed8366; }
.operator-layout { width: min(1500px, 100%); margin: auto; }
.telemetry-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}
.telemetry-panel div {
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--panel);
  padding: 0.7rem;
}
.telemetry-panel span, .telemetry-panel strong { display: block; }
.telemetry-panel span { margin-bottom: 0.3rem; color: var(--muted); font: 0.65rem var(--mono); text-transform: uppercase; }
.telemetry-panel strong { font-family: var(--mono); color: var(--primary-strong); font-weight: 500; }
.command-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--panel);
  padding: 0.8rem;
  margin-bottom: 0.75rem;
}
.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  align-items: start;
  gap: 0.75rem;
}
.control-stack {
  display: grid;
  min-width: 0;
  gap: 0.75rem;
}
fieldset {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--panel);
  padding: 1rem;
}
legend { padding: 0 0.4rem; font-weight: 550; }
fieldset > label {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.75rem;
  color: var(--text);
  font-size: 0.86rem;
}
fieldset > label.is-disabled {
  opacity: 0.5;
}
fieldset > label input[type="text"], fieldset > label select, fieldset > label > input[type="range"] {
  grid-column: 1 / -1;
}
input[type="text"], select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #ffffff;
  padding: 0.55rem;
  color: var(--text);
}
input[type="range"] { width: 100%; accent-color: var(--primary-strong); }
input[type="checkbox"] { accent-color: var(--primary-strong); }
input[type="color"] { width: 46px; height: 32px; border: 0; background: transparent; }
output { color: var(--primary-strong); font-family: var(--mono); font-variant-numeric: tabular-nums; }
fieldset > small { display: block; color: var(--muted); line-height: 1.5; margin-bottom: 0.8rem; }
.toggle { grid-template-columns: auto 1fr; justify-content: start; }
.range-with-number {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 1fr 5.5rem;
  gap: 0.6rem;
  align-items: center;
}
.range-with-number input[type="number"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #ffffff;
  padding: 0.4rem 0.5rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.toggle input { grid-column: auto; }
.file-button input { display: none; }
.form-message { min-height: 1.3em; margin: 0.7rem 0 0; color: var(--primary-strong); }
.form-message.error { color: var(--danger); }

@media (max-width: 1050px) {
  .operator-topbar { grid-template-columns: 1fr 1fr; }
  .operator-topbar > .button-row { grid-column: 1 / -1; }
  .control-grid { grid-template-columns: repeat(2, minmax(250px, 1fr)); }
}
@media (max-width: 720px) {
  .operator-page { padding: 12px; }
  .operator-topbar, .control-grid { grid-template-columns: 1fr; }
  .operator-topbar > .button-row { grid-column: auto; }
  .telemetry-panel { grid-template-columns: repeat(2, 1fr); }
  .arcade-stage { grid-template-columns: 1fr 1fr; }
  .stage-shell { grid-column: 1 / -1; grid-row: 1; }
  .audience-side { flex-direction: row; min-height: 150px; }
  .side-left { border-right: 1px solid var(--border); }
  .side-visual { flex: 1; min-width: 0; }
  .side-label { bottom: 5px; left: 8px; font-size: 7px; }
  .side-instructions { flex: 1; border-top: 0; border-left: 1px solid var(--border); font-size: 8px; }
  .audience-footer { flex-direction: column; gap: 0.5rem; font-size: 0.6rem; }
  .stage-message { text-align: left; }
  .startup-panel { position: relative; top: auto; left: auto; transform: none; width: 100%; border: 0; border-top: 1px solid var(--border); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
