/* iOS system colors, light and dark, so the app looks like the UIKit version on every phone. */
:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.9, 0.25, 1);
  --bg: #f2f2f7;               /* systemGroupedBackground */
  --cell: #ffffff;             /* secondarySystemGroupedBackground */
  --cell-selected: #d1d1d6;
  --sheet: #ffffff;            /* systemBackground */
  --label: #000000;
  --secondary: rgba(60, 60, 67, 0.6);
  --placeholder: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --field-bg: #ffffff;
  --field-border: rgba(0, 0, 0, 0.16);
  --tint: #007aff;
  --red: #ff3b30;
  --blue: #007aff;
  --alert-bg: #f2f2f2;
  --sheet-dim: rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --cell: #1c1c1e;
    --cell-selected: #3a3a3c;
    --sheet: #1c1c1e;
    --label: #ffffff;
    --secondary: rgba(235, 235, 245, 0.6);
    --placeholder: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --field-bg: #1c1c1e;
    --field-border: rgba(255, 255, 255, 0.16);
    --tint: #0a84ff;
    --red: #ff453a;
    --blue: #0a84ff;
    --alert-bg: #252525;
    --sheet-dim: rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--font);
  color: var(--label);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
button { font-family: inherit; -webkit-appearance: none; appearance: none; cursor: pointer; }
svg { display: block; fill: currentColor; }

/* ---------- Station list ---------- */
#app {
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
  transform-origin: 50% 0;
  transition: transform 0.4s var(--ease), border-radius 0.4s var(--ease);
}
#app::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--sheet-dim);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s var(--ease);
}
#app.locked { pointer-events: none; }
/* Page sheet: the screen behind shrinks back, like iOS 13+ */
body.sheet-open { background: #000; }
body.sheet-open #app {
  transform: translateY(env(safe-area-inset-top)) scale(0.92);
  border-radius: 10px;
}
body.sheet-open #app::after { opacity: 1; }

#list {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + 20px) env(safe-area-inset-left);
}

.add-new {
  display: block;
  width: 100%;
  height: 91px;
  border: 0;
  padding: 0;
  background: none;
  color: var(--tint);
  font-size: 16px;
}
.add-new:active { opacity: 0.3; }

.group {
  margin: 55px 20px 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--cell);
  /* keeps the rounded clip during transforms on iOS */
  -webkit-mask-image: -webkit-radial-gradient(white, black);
}
.group:empty { display: none; }

.row-wrap {
  position: relative;
  height: 48px; /* the iOS table sizes rows to fit the 20pt label */
  overflow: hidden;
  transition: height 0.3s var(--ease), opacity 0.3s var(--ease);
}
.row-wrap.inserting, .row-wrap.deleting { height: 0; opacity: 0; }

.row {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  background: var(--cell);
  font-size: 20px;
  touch-action: pan-y;
  outline: none;
  transition: transform 0.35s var(--ease), background-color 0.5s ease;
}
.row.selected { background-color: var(--cell-selected); transition: transform 0.35s var(--ease); }
.row.dragging { transition: none; }
.row-wrap + .row-wrap .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 15px;
  right: 15px;
  height: 0.5px;
  background: var(--separator);
}
@media (max-resolution: 1dppx) {
  .row-wrap + .row-wrap .row::before { height: 1px; }
}
.row .title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 74px;
  border: 0;
  padding: 0;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 15px;
}
.action svg { width: 22px; height: 22px; }
/* Short rows: iOS shows only the icon on swipe actions; the title stays for screen readers. */
.action span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.action.copy { left: 0; background: var(--blue); }
.action.delete { right: 0; background: var(--red); }

.empty {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 20px;
  color: var(--secondary);
  font-size: 18px;
  font-weight: 500;
  line-height: 1.2;
  pointer-events: none;
}

/* ---------- Page sheet (add station form) ---------- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: calc(env(safe-area-inset-top) + 10px);
  z-index: 20;
  background: var(--sheet);
  border-radius: 10px 10px 0 0;
  transform: translateY(105%);
  transition: transform 0.4s var(--ease);
  touch-action: none;
  overflow: hidden;
}
.sheet.shown { transform: none; }
.sheet.dragging, .cover.dragging { transition: none; }

.stack {
  width: 280px;
  margin: 200px auto 0;
  display: flex;
  flex-direction: column;
  gap: 30px;
}
.field {
  height: 44px;
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 5px;
  padding: 0 7px;
  background: var(--field-bg);
  color: var(--label);
  font: 14px var(--font);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  -webkit-appearance: none;
  appearance: none;
}
.field::placeholder { color: var(--placeholder); }
.done {
  height: 30px;
  border: 0;
  padding: 0;
  background: none;
  color: var(--tint);
  font-size: 14px;
}
.done:active { opacity: 0.2; }

/* ---------- Full screen covers (ad and player) ---------- */
.cover {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  color: #fff;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.45s var(--ease);
}
.cover.shown { transform: none; }
.no-anim, .no-anim.shown { transition: none !important; }

.ad-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Player ---------- */
.player {
  display: flex;
  flex-direction: column;
}
.player-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 16px) 8px calc(env(safe-area-inset-left) + 16px);
}
.player-close {
  flex: none;
  border: 0;
  padding: 8px 0;
  background: none;
  color: #0a84ff;
  font-size: 17px;
}
.player-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-video {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding-bottom: env(safe-area-inset-bottom);
  object-fit: contain;
  background: #000;
}

/* ---------- Loading overlay (UIActivityIndicatorView .large) ---------- */
.loading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
}
.spinner {
  position: relative;
  width: 37px;
  height: 37px;
  animation: spin 1s steps(12) infinite;
}
.spinner i {
  position: absolute;
  left: 16.5px;
  top: 0;
  width: 4px;
  height: 11px;
  border-radius: 2px;
  background: currentColor;
  transform-origin: 2px 18.5px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Alert (UIAlertController .alert) ---------- */
.alert-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.alert-backdrop.shown { opacity: 1; }
.alert {
  width: 270px;
  border-radius: 14px;
  overflow: hidden;
  text-align: center;
  background: var(--alert-bg);
  transform: scale(1.15);
  transition: transform 0.25s var(--ease);
}
.alert-backdrop.shown .alert { transform: none; }
.alert-body { padding: 19px 16px 20px; }
.alert-title { margin: 0; font-size: 17px; font-weight: 600; line-height: 22px; }
.alert-message { margin: 2px 0 0; font-size: 13px; line-height: 18px; }
.alert-button {
  display: block;
  width: 100%;
  height: 44px;
  border: 0;
  border-top: 0.5px solid var(--separator);
  background: none;
  color: var(--tint);
  font-size: 17px;
}
.alert-button:active { background: rgba(127, 127, 127, 0.2); }

/* ---------- Install hint (browser tab only) ---------- */
.install-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  border-radius: 14px;
  background: var(--alert-bg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  line-height: 1.35;
}
.install-hint img { border-radius: 9px; flex: none; }
.install-hint p { margin: 0; flex: 1; }
.install-button {
  flex: none;
  border: 0;
  border-radius: 14px;
  padding: 6px 14px;
  background: var(--tint);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.install-close {
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(127, 127, 127, 0.2);
  color: var(--secondary);
  font-size: 18px;
  line-height: 28px;
  padding: 0;
}

@media (prefers-reduced-motion: reduce) {
  #app, .sheet, .cover, .row, .row-wrap, .alert, .alert-backdrop { transition-duration: 0.01s !important; }
}
