:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #ececec;
  --border-strong: #e0e0e0;
  --text: #0f0f10;
  --text-muted: #6b6b70;
  --text-soft: #9a9aa0;
  --accent: #0f0f10;
  --accent-fg: #ffffff;
  --hover: #f4f4f5;
  --shadow: 0 1px 2px rgba(15, 15, 16, 0.04),
    0 8px 24px rgba(15, 15, 16, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* Reserve space for the sticky player only when it's visible. */
body:has(.player:not([hidden])) .app {
  padding-bottom: calc(180px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.brand:hover .brand-name {
  opacity: 0.7;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.brand-name {
  font-size: 15px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.tab:hover {
  background: var(--hover);
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.tab svg {
  flex-shrink: 0;
}

@media (max-width: 480px) {
  .tab-label {
    display: none;
  }
  .tab {
    padding: 8px;
  }
}

/* search */
.search {
  margin-bottom: 24px;
}

.search-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-form:focus-within {
  border-color: var(--border-strong);
}

.search-icon {
  color: var(--text-soft);
  flex-shrink: 0;
}

.search-form input[type="text"] {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 16px; /* >=16px prevents iOS Safari from auto-zooming on focus */
  color: var(--text);
  padding: 10px 4px;
}

.search-form input[type="text"]::placeholder {
  color: var(--text-soft);
}

.btn-primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 10px 18px;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.05s ease;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:active {
  transform: translateY(1px);
}

/* results */
.results {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.results .empty,
.results .loading,
.results .error {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 16px;
}

.sentinel {
  text-align: center;
  font-size: 12px;
  color: var(--text-soft);
  padding: 18px 8px;
  min-height: 24px;
}

.sentinel.end {
  color: var(--text-soft);
}

.result {
  position: relative;
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 48px 10px 10px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.12s ease;
}

.fav-btn {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--text);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
  z-index: 1;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease,
    transform 0.05s ease;
}

.fav-btn:hover {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.fav-btn:active {
  transform: translateY(-50%) scale(0.92);
}

.fav-btn--check {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.fav-btn--remove:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fafafa;
}

.result:hover {
  border-color: var(--border-strong);
}

.result.active {
  border-color: var(--text);
}

.result-thumb-wrap {
  position: relative;
  width: 96px;
  height: 56px;
}

.result-thumb {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--hover);
  display: block;
}

.watched-check {
  display: none;
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(15, 15, 16, 0.78);
  color: #fafafa;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.result.is-watched .watched-check,
.result.is-completed .watched-check {
  display: inline-flex;
}

.result.is-completed .watched-check {
  background: #16a34a;
}

.result-body {
  min-width: 0;
}

.result-title {
  font-weight: 500;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  margin: 0 0 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.result-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.result-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-soft);
  display: inline-block;
}

.meta-date-short {
  display: none;
}

.result-desc {
  font-size: 12px;
  color: var(--text-soft);
  margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.result-duration {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.es-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.es-btn:hover {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  padding: 0;
}

.play-btn:hover {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.result.active .play-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

/* player */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #18181b;
  color: #fafafa;
  border-top: 1px solid #2a2a2e;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
  padding: 14px 24px calc(14px + env(safe-area-inset-bottom));
  padding-left: calc(24px + env(safe-area-inset-left));
  padding-right: calc(24px + env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: center;
  z-index: 10;
}

/* `display: grid` above overrides the UA `display: none` from the HTML
   `hidden` attribute, so we re-assert it here. */
.player[hidden] {
  display: none;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.player-info img {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: #2a2a2e;
}

.player-meta {
  min-width: 0;
}

.player-title {
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
}

.player-title .title-inner {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.player-title.marquee .title-inner {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  animation: title-marquee var(--marquee-duration, 14s) linear infinite;
}

@keyframes title-marquee {
  0%, 8% { transform: translateX(0); }
  92%, 100% { transform: translateX(var(--marquee-distance, -100%)); }
}

@media (prefers-reduced-motion: reduce) {
  .player-title.marquee .title-inner {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: none;
  }
}

.player.is-translating .player-meta::before {
  content: "ES";
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #18181b;
  background: #fafafa;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.player.is-error .player-title::after {
  content: " · error";
  color: #8a8a90;
  font-weight: 400;
}

.player-loading {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: #18181b;
  color: #fafafa;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.01em;
  z-index: 5;
  padding: 0 24px calc(env(safe-area-inset-bottom));
}

.player.is-loading .player-loading {
  display: flex;
}

.loading-dots {
  display: inline-block;
  width: 1.2em;
  text-align: left;
  margin-left: 1px;
}

.loading-dots span {
  display: inline-block;
  opacity: 0;
  animation: dot-pulse 1.4s infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0; }
  30% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-dots span {
    animation: none;
    opacity: 1;
  }
}

.player-channel {
  font-size: 12px;
  color: #a8a8ad;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.seek {
  flex: 1 1 auto;
  min-width: 80px;
}

.icon-btn {
  background: #fafafa;
  color: #18181b;
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.icon-btn:hover {
  opacity: 0.9;
}

.play-toggle .ic-pause,
.play-btn .ic-pause {
  display: none;
}

.play-toggle.is-playing .ic-play,
.result.is-playing .play-btn .ic-play {
  display: none;
}

.play-toggle.is-playing .ic-pause,
.result.is-playing .play-btn .ic-pause {
  display: inline;
}

.time {
  font-size: 11px;
  color: #a8a8ad;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  text-align: center;
}

.seek,
#vol {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 18px;
  cursor: pointer;
}

.seek::-webkit-slider-runnable-track,
#vol::-webkit-slider-runnable-track {
  height: 4px;
  background: #3a3a3e;
  border-radius: 2px;
}

.seek::-moz-range-track,
#vol::-moz-range-track {
  height: 4px;
  background: #3a3a3e;
  border-radius: 2px;
}

.seek::-webkit-slider-thumb,
#vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fafafa;
  margin-top: -4px;
  border: 0;
}

.seek::-moz-range-thumb,
#vol::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fafafa;
  border: 0;
}

.es-toggle {
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: #fafafa;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.es-toggle:hover {
  border-color: rgba(255, 255, 255, 0.45);
}

.es-toggle.active {
  background: #fafafa;
  color: #18181b;
  border-color: #fafafa;
}

.es-toggle:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: rgba(255, 255, 255, 0.22);
}

.aux-group {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #a8a8ad;
  flex-shrink: 0;
}

.aux-group #vol {
  width: 90px;
}

/* Chromeless select: render as plain text. Tap/click still opens the
   native picker. */
select#rate {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: #fafafa;
  cursor: pointer;
  outline: 0;
  border-radius: 6px;
  text-align: center;
  text-align-last: center;
}

select#rate:hover,
select#rate:focus {
  background: rgba(255, 255, 255, 0.08);
}

select#rate option {
  color: #18181b;
  background: #fafafa;
}

/* iOS / touch devices ignore programmatic volume on YouTube iframe and
   HTML5 audio — hide the slider so it doesn't look broken. */
@media (pointer: coarse) {
  .vol-group {
    display: none;
  }
}

#yt-host {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 720px) {
  .player {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .player-info img {
    width: 44px;
    height: 44px;
  }
  .player-controls {
    gap: 8px;
  }
  .player-controls .time {
    font-size: 10px;
    min-width: 28px;
  }
  .player-controls .icon-btn {
    width: 32px;
    height: 32px;
  }
  .player-controls select#rate,
  .player-controls select#voice {
    font-size: 11px;
    padding: 4px 4px;
    max-width: 96px;
  }
  .result {
    grid-template-columns: 48px 1fr;
    gap: 10px;
    padding: 10px 42px 10px 10px;
  }
  .fav-btn {
    width: 28px;
    height: 28px;
    right: 8px;
  }
  .result-thumb-wrap {
    width: 48px;
    height: 48px;
  }
  .watched-check {
    width: 18px;
    height: 18px;
    bottom: 2px;
    right: 2px;
  }
  .watched-check svg {
    width: 12px;
    height: 12px;
  }
  .result-title {
    -webkit-line-clamp: 2;
    white-space: normal;
    font-size: 13px;
    line-height: 1.3;
  }
  .result-meta {
    margin-bottom: 0;
    font-size: 10px;
    flex-wrap: nowrap;
    min-width: 0;
  }
  .result-meta > * {
    flex-shrink: 0;
  }
  .meta-channel {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .meta-date-full {
    display: none;
  }
  .meta-date-short {
    display: inline;
  }
  .result-desc {
    display: none;
  }
  .result-duration {
    display: none;
  }
}
