/* Tesla in-car browser: landscape, glossy, fingers only.
   Every interactive target is at least --touch tall, text never below 18px. */

:root {
  --touch: 64px;
  --touch-lg: 84px;
  --bg: #0b0d10;
  --bg-raised: #15181d;
  --bg-raised-2: #1d2127;
  --line: #2b3037;
  --fg: #f2f5f8;
  --fg-dim: #a3adb8;
  --accent: #4da3ff;
  --accent-ink: #04121f;
  --danger: #ff6b6b;
  --radius: 14px;
  --gap: 16px;
  /* The Tesla browser renders inside a card whose insets change between
     software versions, so lean on the safe-area vars rather than fixed padding. */
  --pad-t: max(14px, env(safe-area-inset-top));
  --pad-r: max(18px, env(safe-area-inset-right));
  --pad-b: max(14px, env(safe-area-inset-bottom));
  --pad-l: max(18px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

/* Any author `display` rule beats the UA stylesheet's `[hidden] { display: none }`,
   so every component below that sets a display value would otherwise ignore the
   attribute entirely — including the views themselves and the inline SVG icons,
   which Chrome does not hide from `hidden` at all. One reset covers the lot. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 400 20px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  /* dvh keeps the layout correct when the browser chrome resizes. */
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.view { display: none; height: 100dvh; }
.view:not([hidden]) { display: flex; flex-direction: column; }

/* ── controls ─────────────────────────────────────────────────────────── */

.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.btn:active { background: var(--bg-raised-2); transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-icon { padding: 0 16px; }
.btn-lg { min-height: var(--touch-lg); min-width: var(--touch-lg); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.btn svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn-lg svg { width: 38px; height: 38px; }
.btn svg .filled { fill: currentColor; stroke: none; }
.glyph { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }

.field {
  min-height: var(--touch);
  padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--fg);
  font: inherit;
  outline: none;
}
.field:focus { border-color: var(--accent); }
.field-grow { flex: 1 1 auto; min-width: 0; }

.muted { color: var(--fg-dim); }
.error { color: var(--danger); font-size: 18px; margin: 4px 0 0; }

/* ── login ────────────────────────────────────────────────────────────── */

.centered-card {
  margin: auto;
  width: min(520px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 32px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 22px;
}
.brand { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }

/* ── browse ───────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: var(--pad-t) var(--pad-r) 12px var(--pad-l);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.search-row { display: flex; gap: 12px; flex: 1 1 auto; min-width: 0; }

.status { padding: 18px var(--pad-r) 0 var(--pad-l); color: var(--fg-dim); }
.status.is-error { color: var(--danger); }

.browse-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.section { padding-top: 8px; }
.section-title {
  margin: 10px 0 2px;
  padding: 0 var(--pad-r) 0 var(--pad-l);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

/* Live TV channel tiles. Lettermarks rather than broadcaster logos: their marks
   are trademarks, and a generated tile also stays crisp at any screen density. */
.channels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: var(--gap);
  padding: var(--gap) var(--pad-r) 4px var(--pad-l);
}
.chan {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: inherit;
  font: inherit;
  padding: 0 0 12px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  min-height: var(--touch);
  touch-action: manipulation;
}
.chan:active { background: var(--bg-raised-2); transform: scale(0.98); }
.chan-mark {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chan-color, #333);
  color: #fff;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: 0.02em;
  /* Long names like "tagesschau24" shrink instead of overflowing. */
  padding: 0 10px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.chan-mark.is-long { font-size: 21px; }
.chan-name {
  padding: 0 12px;
  font-size: 19px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chan-desc {
  padding: 0 12px;
  font-size: 16px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--gap);
  padding: var(--gap) var(--pad-r) var(--gap) var(--pad-l);
  align-content: start;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
}
.card:active { background: var(--bg-raised-2); }
.card-thumb { position: relative; aspect-ratio: 16 / 9; background: #000; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-dur {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0, 0, 0, 0.82); border-radius: 8px;
  padding: 4px 9px; font-size: 17px; font-variant-numeric: tabular-nums;
}
.card-body { padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.card-title {
  font-size: 20px; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { font-size: 17px; color: var(--fg-dim); }

.disclaimer {
  margin: 0;
  padding: 12px var(--pad-r) var(--pad-b) var(--pad-l);
  font-size: 16px;
  color: var(--fg-dim);
  border-top: 1px solid var(--line);
}

/* ── player ───────────────────────────────────────────────────────────── */

.view-player { position: relative; background: #000; display: block; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #000; }

.chrome {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: space-between;
  opacity: 1;
  transition: opacity 220ms ease;
  pointer-events: none;
}
.chrome > * { pointer-events: auto; }
.chrome.is-hidden { opacity: 0; pointer-events: none; }
.chrome.is-hidden > * { pointer-events: none; }

.chrome-top {
  display: flex; align-items: center; gap: 14px;
  padding: var(--pad-t) var(--pad-r) 26px var(--pad-l);
  background: linear-gradient(to bottom, rgba(0,0,0,0.82), rgba(0,0,0,0));
}
.titles { flex: 1 1 auto; min-width: 0; }
.title-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.player-title { font-size: 22px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-badge {
  flex: 0 0 auto;
  background: #d3382f;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 5px 10px;
  border-radius: 7px;
}

/* Live has no timeline: drop the scrubber and the skip buttons entirely rather
   than leaving dead controls on screen. */
.view-player.is-live #seek,
.view-player.is-live #btn-back10,
.view-player.is-live #btn-fwd30,
.view-player.is-live #clock { display: none !important; }
.view-player.is-live .chrome-bottom { padding-top: 44px; }
.player-sub { font-size: 17px; color: var(--fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chrome-bottom {
  padding: 30px var(--pad-r) var(--pad-b) var(--pad-l);
  background: linear-gradient(to top, rgba(0,0,0,0.88), rgba(0,0,0,0));
  display: flex; flex-direction: column; gap: 6px;
}

/* Seek bar: a slim visual track inside a tall, finger-sized hit area. */
.seek { height: var(--touch); display: flex; align-items: center; cursor: pointer; touch-action: none; }
.seek-track { position: relative; width: 100%; height: 10px; border-radius: 6px; background: rgba(255,255,255,0.22); }
.seek-buffer { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px; background: rgba(255,255,255,0.34); }
.seek-progress { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px; background: var(--accent); }
.seek-knob {
  position: absolute; top: 50%; left: 0;
  width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
.seek.is-dragging .seek-knob { transform: scale(1.25); }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: nowrap; min-width: 0; }
.controls > * { flex: 0 0 auto; }
.spacer { flex: 1 1 auto; }
.clock { font-size: 19px; font-variant-numeric: tabular-nums; color: var(--fg-dim); white-space: nowrap; padding: 0 4px; }

.volume { width: 150px; height: var(--touch); display: flex; align-items: center; cursor: pointer; touch-action: none; }
.volume-track { position: relative; width: 100%; height: 10px; border-radius: 6px; background: rgba(255,255,255,0.22); }
.volume-fill { position: absolute; inset: 0 auto 0 0; width: 100%; border-radius: 6px; background: var(--fg); }

.menu {
  position: absolute; right: var(--pad-r); bottom: calc(var(--pad-b) + var(--touch) + 20px);
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; display: flex; flex-direction: column; gap: 6px;
  min-width: 260px; max-height: 60dvh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.7);
}
.menu button {
  min-height: 58px; padding: 0 18px; border: none; border-radius: 10px;
  background: transparent; color: var(--fg); font: inherit; text-align: left;
  display: flex; justify-content: space-between; gap: 16px; align-items: center; cursor: pointer;
}
.menu button:active { background: var(--bg-raised-2); }
.menu button[aria-current="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.menu .hint { font-size: 16px; color: var(--fg-dim); }
.menu button[aria-current="true"] .hint { color: var(--accent-ink); opacity: 0.75; }

.spinner {
  position: absolute; inset: 0; margin: auto;
  width: 220px; height: 120px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: var(--fg); font-size: 18px; pointer-events: none;
}
.spinner-ring {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.25); border-top-color: #fff;
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner-ring { animation-duration: 2.4s; } }

.debug {
  position: absolute; top: calc(var(--pad-t) + var(--touch) + 12px); left: var(--pad-l);
  margin: 0; padding: 14px 18px; max-width: min(560px, 60vw);
  background: rgba(0,0,0,0.82); border: 1px solid var(--line); border-radius: 12px;
  font: 400 15px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
  color: #cfe6ff; white-space: pre-wrap; pointer-events: none;
}

.player-error {
  position: absolute; inset: 0; margin: auto;
  width: min(600px, calc(100vw - 64px)); height: fit-content;
  padding: 28px; border-radius: 18px;
  background: var(--bg-raised); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 20px; align-items: flex-start;
}
.player-error p { margin: 0; }

/* A short screen (portrait Model S/X, or a small browser card) gets tighter
   chrome so the controls never eat the picture. */
@media (max-height: 620px) {
  :root { --touch: 56px; --touch-lg: 68px; --gap: 12px; }
  .chrome-top { padding-bottom: 14px; }
  .chrome-bottom { padding-top: 16px; }
  .player-title { font-size: 19px; }
  .volume { width: 110px; }
}
@media (max-width: 900px) {
  .clock { display: none; }
  .volume { width: 100px; }
}
/* Narrow browser card: shed the least essential controls rather than overflow. */
@media (max-width: 700px) {
  .volume { display: none; }
  .controls { gap: 8px; }
}
.view-player { overflow: hidden; }
