/* The watch room: a dark, calm cinema page. No hover-only behaviour; 44 px touch targets. */
:root {
  --bg: #0b0c0f;
  --surface: #15171c;
  --surface-2: #1d2027;
  --line: #2a2e37;
  --text: #eceef2;
  --muted: #9aa1ad;
  --accent: #e8b65c;
  --accent-text: #1a1206;
  --ok: #8fd19e;
  --warn: #f0b44c;
  --away: #b7a6f2;
  --bad: #f08a7e;
  --focus: #7fb5ff;
  --radius: 14px;
  --gutter: 16px;
  --bar-bg: linear-gradient(to bottom, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0));
  --bar-bg-up: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
  --fade: 240ms;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app { min-height: 100%; background: var(--bg); }
.app[data-view="watch"] { position: fixed; inset: 0; overflow: hidden; background: #000; }
.app:fullscreen { background: #000; }

h1 { font-size: 1.5rem; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.eyebrow { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

/* -- buttons -- */
.btn {
  appearance: none;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.wide { width: 100%; }
.btn.huge { width: 100%; min-height: 64px; font-size: 1.25rem; border-radius: 16px; }
.btn.icon { padding: 10px; display: inline-flex; align-items: center; justify-content: center; }
.btn.icon svg { width: 26px; height: 26px; }

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

/* -- screens -- */
.screen { padding: max(24px, env(safe-area-inset-top)) var(--gutter) max(32px, env(safe-area-inset-bottom)); }
.screen.center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card.message { max-width: 420px; width: 100%; display: grid; gap: 16px; text-align: center; font-size: 1.1rem; }

.signin { width: 100%; max-width: 380px; display: grid; gap: 8px; }
.signin h1 { margin-bottom: 12px; }
.signin label { font-weight: 600; font-size: 0.92rem; margin-top: 6px; }
.signin input {
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 17px; /* 16 px or more keeps iOS from zooming */
}
.signin .btn { margin-top: 14px; }
.error { color: var(--bad); }

.lobby { max-width: 720px; margin: 0 auto; display: grid; gap: 16px; }
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.now-title { font-size: 1.3rem; font-weight: 650; }
.note { text-align: center; color: var(--muted); display: grid; gap: 10px; justify-items: center; }

.people { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.person {
  display: inline-flex; align-items: baseline; gap: 8px;
  padding: 8px 14px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
}
.person.joined { border-color: rgba(232, 182, 92, 0.5); }
.person-name { font-weight: 600; }
.person-tag { color: var(--muted); font-size: 0.85rem; }

/* -- host panel -- */
.host-slot:empty { display: none; }
.host { display: grid; gap: 16px; }
.confirm { display: grid; gap: 12px; border-color: var(--accent); }
.confirm p { font-size: 1.1rem; font-weight: 600; }
.confirm-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.confirm-actions .btn { flex: 1 1 120px; }
.upnext { display: grid; gap: 10px; }
.upnext .eyebrow { margin-bottom: 0; }
.upnext-title { font-weight: 600; }
.picker { display: grid; gap: 10px; }
.picker-head { display: grid; gap: 4px; }
.picker-head .eyebrow { margin-bottom: 0; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; }
.crumbs:empty { display: none; }
.crumb {
  appearance: none; min-height: 44px; padding: 8px 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.crumb + .crumb::before { content: "›"; color: var(--muted); margin-right: 8px; }
.crumb[aria-current="true"] { color: var(--text); }
.picker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.picker-list > li.muted { padding: 10px 4px; }
.row {
  appearance: none; width: 100%; min-height: 52px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-2); color: var(--text); border: 1px solid transparent; border-radius: 12px;
  font: inherit; text-align: left; cursor: pointer; touch-action: manipulation;
}
.row-title { font-weight: 600; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 0.88rem; }
.row-chevron { color: var(--muted); font-size: 1.3rem; line-height: 1; }
.row.selected { border-color: var(--accent); background: rgba(232, 182, 92, 0.12); }
.tag { font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--muted); }
.tag-on { color: var(--accent); }
.tag-watched { color: var(--ok); }
.tag-started { color: var(--warn); }

/* -- watching -- */
.stage { position: absolute; inset: 0; background: #000; overflow: hidden; }
.video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tap { position: absolute; inset: 0; }
.controls-hidden .stage { cursor: none; }

.bar {
  position: absolute; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
  transition: opacity var(--fade) ease;
}
.topbar { top: 0; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 28px; background: var(--bar-bg); }
.controls { bottom: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); padding-top: 32px; background: var(--bar-bg-up); flex-wrap: wrap; }
.controls-hidden .bar { opacity: 0; pointer-events: none; }

.topbar-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.chips { display: flex; gap: 6px; flex: 1 1 auto; justify-content: flex-end; flex-wrap: wrap; min-width: 0; }
.chip {
  font-size: 0.8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.1); color: var(--text); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chip.tone-warn { background: rgba(240, 180, 76, 0.2); color: var(--warn); }
.chip.tone-away { background: rgba(183, 166, 242, 0.18); color: var(--away); }
.chip.tone-idle { color: var(--muted); }

.btn.icon[data-state="playing"] .i-play,
.btn.icon[data-state="paused"] .i-pause,
.btn.icon[data-state="on"] .i-fs-on,
.btn.icon[data-state="off"] .i-fs-off { display: none; }
.controls .btn { background: rgba(255, 255, 255, 0.08); border-color: transparent; color: #fff; }
.controls .btn.ghost { background: transparent; }

.time { font-variant-numeric: tabular-nums; font-size: 0.95rem; white-space: nowrap; }
.quality { font-size: 0.92rem; white-space: nowrap; }
.seek { position: relative; flex: 1 1 160px; min-width: 120px; height: 44px; display: flex; align-items: center; touch-action: none; }
.seek-track { position: relative; width: 100%; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.22); overflow: hidden; }
.seek-buffer, .seek-fill { position: absolute; inset: 0; transform-origin: left center; transform: scaleX(0); }
.seek-buffer { background: rgba(255, 255, 255, 0.28); }
.seek-fill { background: var(--accent); }
.seek-thumb { position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: #fff; display: none; pointer-events: none; }
.seek.can-seek { cursor: pointer; }
.seek.can-seek .seek-thumb { display: block; }

/* Under 560 px the strip wraps: the progress bar takes its own line. */
@media (max-width: 560px) {
  .seek { order: -1; flex-basis: 100%; }
  .time { margin-right: auto; }
  .topbar { flex-wrap: wrap; }
  .chips { order: 3; flex-basis: 100%; justify-content: flex-start; }
}

.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3;
  max-width: min(440px, calc(100% - 2 * var(--gutter)));
  padding: 16px 22px; border-radius: var(--radius);
  background: rgba(14, 15, 19, 0.88); border: 1px solid var(--line);
  display: grid; gap: 12px; justify-items: center; text-align: center; font-size: 1.05rem;
}

.toast {
  position: fixed; left: 50%; bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px)); transform: translateX(-50%); z-index: 6;
  max-width: calc(100% - 2 * var(--gutter)); padding: 10px 16px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 0.95rem; text-align: center;
}

.unlock {
  position: absolute; inset: 0; z-index: 5; background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center; padding: var(--gutter);
}
.unlock .btn { max-width: 360px; }

.debug {
  position: absolute; top: max(64px, calc(env(safe-area-inset-top) + 56px)); left: max(8px, env(safe-area-inset-left)); z-index: 4;
  margin: 0; padding: 10px 12px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.82); color: #fff; border: 1px solid rgba(255, 255, 255, 0.25);
  font: 600 15px/1.35 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre;
  pointer-events: none; max-width: 46vw; overflow: hidden;
}

/* -- sheet -- */
.sheet-wrap { position: absolute; inset: 0; z-index: 7; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.sheet {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 100%);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-left: 1px solid var(--line);
  padding: max(16px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) var(--gutter);
  display: grid; gap: 16px; align-content: start;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 1.25rem; }
.sheet .picker-list { max-height: none; }
.sheet-actions { display: grid; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  :root { --fade: 0ms; }
  * { transition: none !important; animation: none !important; }
  .btn:active { transform: none; }
}
