/* tesla-tube — Tesla Model Y Juniper center screen is ~1920x1200.
   Everything is big and tap-friendly; the player hides chrome.          */

:root {
  color-scheme: dark;
  --bg: #000;
  --surface: #111214;
  --surface-2: #1b1d20;
  --fg: #f3f5f7;
  --muted: #a7adb4;
  --accent: #e60017;
  --border: #26292d;
  --radius: 14px;
  --tap: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 20px/1.3 -apple-system, "Helvetica Neue", Arial, sans-serif;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

main {
  position: fixed;
  top: 76px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  overflow: auto;
}

.topbar {
  position: fixed;
  z-index: 10;
  top: 0; left: 0; right: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.95), rgba(0,0,0,0.75));
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.back {
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 32px;
  cursor: pointer;
}

.searchform {
  flex: 1;
  display: flex;
  gap: 10px;
}
.searchform input {
  flex: 1;
  height: var(--tap);
  padding: 0 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--radius);
  font-size: 22px;
  outline: none;
}
.searchform input:focus { border-color: var(--accent); }
.searchform button {
  height: var(--tap);
  padding: 0 24px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
  padding: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 60ms ease, border-color 120ms ease;
}
.card:active { transform: scale(0.98); border-color: var(--accent); }
.card .thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000 center/cover no-repeat;
  position: relative;
}
.card .thumb .dur {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.75);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 16px;
}
.card .meta { padding: 10px 12px 14px; }
.card .title {
  font-size: 20px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
}
.card .channel { color: var(--muted); margin-top: 6px; font-size: 16px; }

.hint {
  padding: 40px 20px;
  color: var(--muted);
  text-align: center;
}

/* ---- Player ---- */
#playerView { background: #000; }
.stage {
  position: absolute;
  inset: 0;
  background: #000;
}
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
/* hidden video is kept on-screen but transparent; some Chromium builds
   won't decode frames for an element with display:none. */
#hiddenVideo {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  pointer-events: none;
  top: 0; left: 0;
}
.overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 22px 26px;
  background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0));
  color: #fff;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}
.stage.show-overlay .overlay { opacity: 1; pointer-events: auto; }
.overlay .title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.overlay .row {
  display: flex;
  gap: 14px;
  align-items: center;
}
.overlay button {
  min-width: var(--tap);
  height: var(--tap);
  border: 0;
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-radius: var(--radius);
  font-size: 22px;
  cursor: pointer;
}
.overlay button:active { background: rgba(255,255,255,0.2); }
.overlay input[type="range"] {
  flex: 1;
  height: var(--tap);
  accent-color: var(--accent);
}
.overlay #volBar { flex: 0 0 160px; }
.overlay #timeLabel { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 140px; text-align: center; }

.loading, .error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 22px;
  background: rgba(0,0,0,0.5);
  padding: 20px;
  text-align: center;
}
.error { color: #ffb3b3; background: rgba(60,0,0,0.6); }
.loading[hidden], .error[hidden] { display: none; }

/* ---- Role gate ---- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #141518 0%, #000 70%);
  padding: 24px;
}
/* HTML `hidden` normally resolves to display:none, but a later display:flex
   wins specificity, so the gate stays visible after the role is picked.
   Force hidden to win. */
.gate[hidden] { display: none !important; }
.gate-card {
  width: min(820px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px 36px;
  text-align: center;
}
.gate-title {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}
.gate-sub {
  color: var(--muted);
  font-size: 20px;
  margin-bottom: 32px;
  line-height: 1.4;
}
.gate-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.gate-buttons:has(> :only-child) { grid-template-columns: 1fr; }
.gate-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
  transition: transform 80ms ease, border-color 120ms ease, background 120ms ease;
}
.gate-btn:active { transform: scale(0.98); }
.gate-btn.passenger:hover { border-color: #2bbf6a; background: rgba(43,191,106,0.08); }
.gate-btn.driver:hover { border-color: var(--accent); background: rgba(230,0,23,0.06); }
.gate-btn .emoji { font-size: 48px; line-height: 1; }
.gate-btn .label { font-size: 22px; font-weight: 600; }
.gate-btn .hint { font-size: 16px; color: var(--muted); }
