:root {
  color-scheme: dark;
  --bg: #0e0f11;
  --surface: #1a1c20;
  --surface-2: #25282e;
  --border: #33373e;
  --text: #f2f3f5;
  --muted: #9aa0a9;
  --accent: #e82127;
  --ok: #4ade80;
  --danger: #f87171;
  --radius: 12px;
  --topbar: 72px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

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

button,
select {
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

input[type='search'],
input[type='url'],
input[type='password'] {
  min-height: 52px;
  width: 100%;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: 52px;
  padding: 0 12px;
}

.icon-btn.big svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  stroke: none;
}

[hidden] {
  display: none !important;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 12px;
  align-items: center;
  height: var(--topbar);
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.search {
  display: flex;
  flex: 1;
  gap: 10px;
}

.search-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.history {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 20;
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.5);
}

.history-item {
  display: flex;
  align-items: center;
}

.history-query {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  border: 0;
  background: none;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-query:hover,
.history-query:focus-visible {
  background: var(--surface);
}

.history-remove {
  border: 0;
  background: none;
  color: var(--muted);
}

.history-remove svg {
  width: 20px;
  height: 20px;
}

/* ---------- home ---------- */

.home {
  padding: 20px 16px 40px;
}

.message {
  color: var(--muted);
}

/* Part of the home view, so it's hidden while a video plays (and can't cover its controls). */
.app-version {
  position: fixed;
  right: 12px;
  bottom: 8px;
  color: var(--muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.5;
  pointer-events: none;
}

/* Covers the results while a search runs; the top bar stays usable above it. */
.search-overlay {
  position: fixed;
  inset: var(--topbar) 0 0 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  justify-content: center;
  background: rgb(14 15 17 / 0.8);
  color: var(--muted);
  font-size: 1.1rem;
}

.search-overlay .spinner {
  position: static;
  margin: 0;
}

.search-overlay p {
  margin: 0;
}

.message.error,
.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

.section-title {
  margin: 4px 0 16px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}

.thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgb(0 0 0 / 0.8);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.badge.live {
  background: var(--accent);
  font-weight: 700;
}

.card-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-weight: 600;
  line-height: 1.3;
}

.card-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- player ---------- */

.player-view {
  height: calc(100vh - var(--topbar));
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  user-select: none;
  touch-action: manipulation; /* double taps skip; they shouldn't zoom the page */
}

/* Play/pause and ±10 s in the middle of the video; they show and hide with the scrubber. */
.center-controls {
  position: absolute;
  inset: 0;
  display: flex;
  gap: clamp(32px, 10vw, 120px);
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.stage.show-controls .center-controls {
  opacity: 1;
}

.stage.show-controls .center-controls button {
  pointer-events: auto;
}

.center-controls .icon-btn {
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.45);
  color: #fff;
}

.center-play {
  width: 88px;
  height: 88px;
}

.center-play svg {
  width: 42px;
  height: 42px;
  fill: currentColor;
  stroke: none;
}

.skip {
  width: 64px;
  height: 64px;
}

.skip svg {
  width: 38px;
  height: 38px;
}

.icon-text {
  fill: currentColor;
  stroke: none;
  font: 700 6.5px system-ui, sans-serif;
  text-anchor: middle;
}

.stage.is-loading .center-play,
.stage.is-live .skip {
  visibility: hidden;
}

/* "−10s" / "+10s" flashed on the side that was double-tapped. */
.skip-hint {
  position: absolute;
  top: 0;
  bottom: 0;
  display: grid;
  width: 40%;
  place-items: center;
  background: radial-gradient(circle, rgb(255 255 255 / 0.18), transparent 65%);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

.skip-hint.back {
  left: 0;
}

.skip-hint.forward {
  right: 0;
}

.skip-hint.show {
  opacity: 1;
  transition: none;
}

.video-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

body.pseudo-fullscreen .topbar {
  display: none;
}

body.pseudo-fullscreen .player-view {
  height: 100vh;
}

.controls {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 48px 20px 18px;
  background: linear-gradient(transparent, rgb(0 0 0 / 0.85));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.stage.show-controls .controls {
  opacity: 1;
  pointer-events: auto;
}

.video-title {
  overflow: hidden;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.control-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

.control-row .icon-btn {
  border: 0;
  background: rgb(255 255 255 / 0.12);
}

.icon-pause,
.stage.is-playing .icon-play {
  display: none;
}

.stage.is-playing .icon-pause {
  display: block;
}

.time {
  min-width: 4.5ch;
  font-variant-numeric: tabular-nums;
}

/* Tap to switch between elapsed and remaining time; wide enough for "−1:23:45". */
.time-toggle {
  min-width: 7ch;
  padding: 0 4px;
  border: 0;
  background: none;
  text-align: left;
}

.seek {
  flex: 1;
  min-width: 0;
  height: 48px;
  accent-color: var(--accent);
}

.quality {
  border: 0;
  background: rgb(255 255 255 / 0.12);
}

.spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border: 5px solid rgb(255 255 255 / 0.2);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.stats {
  position: absolute;
  top: 12px;
  left: 12px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgb(0 0 0 / 0.7);
  font: 0.75rem/1.4 ui-monospace, Menlo, monospace;
  pointer-events: none;
}

.player-error {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: min(640px, calc(100% - 32px));
  padding: 16px 20px;
  transform: translate(-50%, -50%);
  border-radius: var(--radius);
  background: rgb(0 0 0 / 0.85);
  color: var(--danger);
  text-align: center;
}

/* ---------- shared from phone ---------- */

.share-banner {
  position: fixed;
  top: calc(var(--topbar) + 12px);
  left: 50%;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
  width: min(720px, calc(100% - 32px));
  padding: 10px 10px 10px 18px;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.5);
}

.share-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- iPhone setup page ---------- */

.back-link {
  display: inline-grid;
  place-items: center;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}

.page-title {
  margin: 0;
  font-size: 1.15rem;
}

.setup {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.lead {
  color: var(--muted);
  line-height: 1.5;
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-left: 1.4em;
}

.steps h2 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.steps p,
.note {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.5;
}

.steps label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
}

.row {
  display: flex;
  gap: 10px;
}

a.button {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

a.button.primary {
  background: var(--accent);
}

code {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.9em;
}

.dialog-link {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- dialogs ---------- */

.dialog {
  width: min(560px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.dialog h2 {
  margin: 0 0 16px;
}

.dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
}

.dialog label.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.dialog label.check input {
  width: 22px;
  height: 22px;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.spacer {
  flex: 1;
}

.status {
  min-height: 1.4em;
  margin: 0 0 8px;
}

@media (max-width: 600px) {
  :root {
    font-size: 16px;
  }
  .search button {
    display: none;
  }
  .control-row {
    flex-wrap: wrap;
  }
}
