:root {
  color-scheme: dark;
  --bg: #0c1714;
  --panel: #172722;
  --line: #2a4038;
  --text: #f1f5ef;
  --muted: #b6c5bc;
  --accent: #a8efc4;
  --danger: #ffd29a;
  font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: radial-gradient(ellipse at 15% 0, #1c3a2d 0, transparent 42%), var(--bg);
  touch-action: pan-y;
}
.app {
  display: grid;
  gap: 14px;
  width: min(100%, 560px);
  margin: auto;
  padding: calc(22px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
body:not(.paired) .app { gap: 10px; padding: calc(12px + env(safe-area-inset-top)) 16px calc(10px + env(safe-area-inset-bottom)); }
header { display: flex; align-items: center; gap: 12px; padding: 4px 2px 6px; text-align: left; }
body:not(.paired) header { padding: 0 2px 2px; }
.brand-icon { width: 56px; height: 56px; flex: 0 0 auto; border-radius: 16px; }
h1, h2, p { margin-top: 0; }
h1 { margin: 0; font-size: clamp(27px, 8vw, 36px); line-height: 1.08; letter-spacing: -.04em; }
.component-name { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
h2 { margin-bottom: 5px; font-size: 19px; letter-spacing: -.02em; }
.card {
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
}
body:not(.paired) .card { padding: 15px; }
.card > p { margin-bottom: 14px; color: var(--muted); }
body:not(.paired) .connect-card > p { margin-bottom: 10px; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 650; }
.join-row { display: flex; gap: 9px; }
input, button { font: inherit; }
input {
  min-width: 0;
  flex: 1;
  padding: 12px 13px;
  border: 1px solid #496257;
  border-radius: 12px;
  color: var(--text);
  background: #0b1512;
  text-transform: uppercase;
  letter-spacing: .08em;
}
button {
  min-height: 46px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  color: #10251b;
  background: var(--accent);
  font-weight: 750;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .55; cursor: not-allowed; }
.status { margin: 10px 0 0 !important; color: var(--muted) !important; font-size: 13px !important; }
.status[data-state="connected"] { color: var(--accent) !important; }
.status[data-state="error"] { color: var(--danger) !important; }
.primary { width: 100%; }
.gesture-output {
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d1915;
  font-size: 16px;
  font-weight: 680;
  text-align: center;
}
.dictation-notice {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #6b8d78;
  border-radius: 10px;
  color: var(--accent);
  background: #172722;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
#dictation-notice[hidden] { display: none; }
.controls .dictation-status { margin: 0 0 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.controls .dictation-status[hidden] { display: none; }
.quiet {
  width: 100%;
  min-height: 36px;
  margin: 8px 0;
  border: 1px solid #597165;
  color: var(--text);
  background: transparent;
}
.scan-button { margin: 0 0 8px; }
.manual-label { margin: 0 0 8px !important; font-size: 12px; }
.scanner { margin: 0 0 14px; }
.scanner video { display: block; width: 100%; max-height: 48dvh; border-radius: 12px; background: #050907; object-fit: cover; }
.scanner p { margin: 8px 0; color: var(--muted); font-size: 13px; }
.scanner .quiet { margin-bottom: 0; }
.reference summary { font-size: 16px; font-weight: 720; cursor: pointer; }
.reference ul { margin: 0; padding: 5px 0 0; list-style: none; }
.reference li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.reference li span { color: var(--muted); text-align: right; }
.reference .muted { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.motion-diagnostics { margin-top: 12px; }
.motion-diagnostics summary { color: var(--muted); font-size: 12px; cursor: pointer; }
.motion-diagnostics #motion-readout { margin: 8px 0 0; font: 11px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.unpair { margin: 14px 0 0; }
.reference .unpair-help { margin-top: 6px; }
footer { padding: 0 8px 4px; color: var(--muted); font-size: 12px; line-height: 1.4; text-align: center; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid #d3ffe1; outline-offset: 2px; }
body:not(.paired) .controls { display: none; }
body:not(.paired):not(.has-saved-room) .unpair,
body:not(.paired):not(.has-saved-room) .unpair-help { display: none; }
body.paired .app { gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 14px calc(8px + env(safe-area-inset-bottom)); }
body.paired:not(.permission-error) .app:has(.reference[open]) {
  min-height: 100dvh;
  grid-template-rows: auto auto minmax(0, 1fr);
}
body.paired .home-help { display: none; }
body.paired header { gap: 10px; padding: 0 2px 2px; }
body.paired .brand-icon { width: 42px; height: 42px; border-radius: 12px; }
body.paired h1 { font-size: 20px; line-height: 1.1; }
body.paired .component-name { margin-top: 1px; font-size: 11px; }
body.paired:not(.pair-error) #scan-qr,
body.paired:not(.pair-error) .manual-label { display: none; }
body.paired:not(.pair-error) .connect-card { display: none; }
body.permission-error .connect-card { display: block; }
body.permission-error .connect-card h2,
body.permission-error .connect-card > p:not(.status),
body.permission-error #room-entry { display: none; }
body.pair-error .connect-card { padding: 14px; }
body.paired .controls { padding: 11px 12px; border-radius: 15px; }
body.paired:not(.motion-enabled) .controls .quiet,
body.paired:not(.motion-enabled) .controls .gesture-output { display: none; }
body.motion-enabled .controls .quiet, body.motion-enabled .controls .gesture-output { display: block; }
body.paired .reference { padding: 9px 12px; border-radius: 13px; }
body.paired .reference[open] { min-height: 0; max-height: none; overflow-y: auto; overscroll-behavior: contain; }
@media (prefers-reduced-motion: no-preference) {
  button { transition: filter .15s ease, transform .15s ease; }
  button:active { transform: scale(.98); }
}
@media (display-mode: standalone) { .home-help { display: none; } }
