:root {
  --bg: #0F2A2E;
  --surface: #173A3F;
  --surface-2: #1E474D;
  --text: #EAF4F1;
  --muted: #8FB1AC;
  --dial: #F2B134;
  --dial-ink: #2A1C00;
  --danger: #E5484D;
  --line: rgba(234, 244, 241, 0.12);
  --radius-video: 18px;
  --radius-ctl: 999px;
  --display: "Bricolage Grotesque", "Arial Narrow", system-ui, sans-serif;
  --ui: "Atkinson Hyperlegible", system-ui, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #E4EFEC;
    --surface: #FFFFFF;
    --surface-2: #F1F7F5;
    --text: #0F2A2E;
    --muted: #4C6B67;
    --line: rgba(15, 42, 46, 0.14);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--ui);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
}

button, input { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--dial);
  outline-offset: 3px;
}

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

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 20px 10px;
}
.wordmark {
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 75%;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
  line-height: 1;
}
.online { color: var(--muted); font-size: 0.9rem; }

/* ---------- Stage ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  padding: 0 20px;
  min-height: 0;
}

.stranger {
  position: relative;
  background: #071618;
  border-radius: var(--radius-video);
  overflow: hidden;
  min-height: 0;
}
.stranger video,
.stranger .static {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.stranger video { object-fit: cover; opacity: 0; transition: opacity 0.25s; }
.stranger.live video { opacity: 1; }
.static { image-rendering: pixelated; opacity: 0.55; }
.stranger.live .static { visibility: hidden; }

.status {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 16px;
  border-radius: var(--radius-ctl);
  background: rgba(7, 22, 24, 0.78);
  color: #EAF4F1;
  font-size: 0.95rem;
  max-width: calc(100% - 32px);
  text-align: center;
}
.stranger.live .status { display: none; }

/* ---------- Side column ---------- */
.side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  min-width: 0;
}

.self {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface);
  border-radius: var(--radius-video);
  overflow: hidden;
}
.self video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror yourself, like a mirror */
}

.chat {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  background: var(--surface);
  border-radius: 14px;
  min-height: 0;
}
.log {
  list-style: none;
  margin: 0;
  padding: 14px 14px 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.95rem;
}
.log li { max-width: 85%; padding: 6px 11px; border-radius: 14px; overflow-wrap: anywhere; }
.log .them { background: var(--surface-2); align-self: flex-start; }
.log .me { background: var(--dial); color: var(--dial-ink); align-self: flex-end; }
.log .sys { color: var(--muted); align-self: center; font-size: 0.85rem; padding: 2px 0; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}
.chat-form input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}
.chat-form button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
.chat-form :disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Controls ---------- */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px 20px max(16px, env(safe-area-inset-bottom));
  position: relative;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-ctl);
  padding: 12px 22px;
  font-weight: 700;
  cursor: pointer;
}
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* The Next "dial": the one loud thing on the page. */
.dial {
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 85%;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  min-width: 190px;
  padding: 14px 34px;
  border: 0;
  border-radius: var(--radius-ctl);
  background: var(--dial);
  color: var(--dial-ink);
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgba(42, 28, 0, 0.25);
  transition: transform 0.08s;
}
.dial:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(42, 28, 0, 0.25); }
.dial:disabled { opacity: 0.5; cursor: not-allowed; }

.hint {
  position: absolute;
  right: 20px;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Dialogs ---------- */
.sheet {
  border: 0;
  border-radius: 20px;
  padding: 28px;
  max-width: min(460px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgba(4, 14, 16, 0.72); }
.sheet h1, .sheet h2 {
  font-family: var(--display);
  font-weight: 800;
  font-stretch: 80%;
  font-size: 1.9rem;
  line-height: 1.05;
  margin: 0 0 10px;
}
.sheet h2 { font-size: 1.5rem; }
.sheet p { margin: 0 0 14px; color: var(--muted); }
.rules { margin: 0 0 18px; padding-left: 1.1em; }
.rules li { margin-bottom: 4px; }
.check, .radio { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; cursor: pointer; }
.check input, .radio input { margin-top: 4px; accent-color: var(--dial); }
.check { margin-bottom: 20px; }
.sheet .dial { width: 100%; }
.sheet fieldset { border: 0; padding: 0; margin: 0 0 18px; }
.row { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { padding: 12px 16px 8px; }
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 190px;
    padding: 0 16px;
    gap: 10px;
    position: relative;
  }
  .stranger { min-height: 46dvh; }
  .side { display: contents; }
  .self {
    position: absolute;
    z-index: 2;
    width: 28vw;
    max-width: 140px;
    top: 10px;
    right: 26px;
    border-radius: 12px;
    box-shadow: 0 0 0 2px var(--bg);
  }
  .controls { gap: 10px; padding-left: 16px; padding-right: 16px; }
  .dial { min-width: 0; flex: 1; font-size: 1.3rem; padding: 12px 18px; }
  .btn { padding: 11px 16px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
