:root {
  --bg: #0b0b0d;
  --surface: #17171b;
  --surface-2: #202026;
  --text: #f4f4f6;
  --text-dim: #9a9aa3;
  --accent: #ff3b5c;
  --danger: #ff5c5c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overscroll-behavior: none;
}
body {
  position: fixed; inset: 0; overflow: hidden;
}
button, input { font-family: inherit; }

.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.scroll-view {
  overflow-y: auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 90px);
  -webkit-overflow-scrolling: touch;
}

/* --- Feed --- */
#view-feed { background: #000; }
.feed-scroll {
  position: absolute; inset: 0;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
}
.short {
  position: relative;
  height: 100dvh;
  width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: #000;
  overflow: hidden;
}
.short-thumb {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
}
.player-slot {
  position: absolute; inset: 0;
  z-index: 0;
}
.player-slot iframe {
  width: 100%; height: 100%;
  pointer-events: none;
}
/* The thumbnail stays stacked ABOVE the iframe until we've confirmed real
   playback (player-playing, set on YT.PlayerState.PLAYING) — otherwise
   YouTube's own loading/paused UI, including its big center play button,
   shows through during the gap between "iframe exists" and "video is
   actually playing," which reads as the app being stuck. */
.short.player-playing .player-slot { z-index: 2; }
.short.player-playing .short-thumb { opacity: 0; transition: opacity .15s; }

.loading-spinner {
  position: absolute; top: 50%; left: 50%; z-index: 3;
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: short-spin .8s linear infinite;
}
.short.player-playing .loading-spinner { display: none; }
@keyframes short-spin { to { transform: rotate(360deg); } }

.short-ui {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 16px calc(var(--safe-bottom) + 100px);
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 12px;
  background: linear-gradient(to top, rgba(0,0,0,.65), rgba(0,0,0,0) 60%);
  pointer-events: none;
}
.short-meta { pointer-events: none; max-width: 78%; }
.short-channel { font-weight: 600; font-size: 14px; opacity: .85; }
.short-title { font-size: 15px; margin-top: 4px; line-height: 1.3; }
.short-actions { pointer-events: auto; display: flex; flex-direction: column; align-items: center; }
.heart-btn {
  background: rgba(0,0,0,.35); border: none; color: #fff;
  font-size: 28px; width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.heart-btn.active { color: var(--accent); }

.short.end-card {
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.caught-up-inner { text-align: center; max-width: 320px; margin: 0 auto; }
.caught-up-check {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--surface-2); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 16px;
}
.caught-up-inner h1 { font-size: 20px; margin: 0 0 8px; }
.caught-up-inner p { color: var(--text-dim); font-size: 14px; margin: 0 0 20px; }

.sound-gate {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 110px);
  transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 10px 18px;
  border-radius: 999px; font-size: 14px; z-index: 5;
}
.sound-gate.hidden { display: none; }

/* --- Tab bar --- */
#tabbar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  padding: 8px 0 calc(var(--safe-bottom) + 6px);
  background: rgba(10,10,12,.88);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255,255,255,.08);
  z-index: 20;
}
.tab-btn {
  background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; padding: 4px 14px;
}
.tab-btn .tab-icon { font-size: 18px; }
.tab-btn.active { color: var(--text); }

/* --- Shared controls --- */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 12px 18px; border-radius: 12px; font-size: 15px; font-weight: 600;
}
.btn-secondary {
  background: var(--surface-2); color: var(--text); border: none;
  padding: 12px 18px; border-radius: 12px; font-size: 15px; font-weight: 600;
  display: inline-block; text-align: center;
}
.btn-small {
  background: var(--surface-2); color: var(--text); border: none;
  padding: 7px 12px; border-radius: 9px; font-size: 13px;
}
.btn-small.danger { color: var(--danger); }
.muted { color: var(--text-dim); }
.muted.small { font-size: 12px; }
.empty-hint { color: var(--text-dim); text-align: center; margin-top: 40px; }

/* --- Channels --- */
.add-wrap { margin-bottom: 20px; }
.add-form { display: flex; gap: 8px; }
.add-input {
  flex: 1; background: var(--surface); border: 1px solid rgba(255,255,255,.12);
  color: var(--text); padding: 12px 14px; border-radius: 12px; font-size: 15px;
}
.add-status { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }
.channel-list { display: flex; flex-direction: column; gap: 10px; }
.channel-row {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); border-radius: 14px; padding: 10px;
}
.channel-thumb { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.channel-info { flex: 1; min-width: 0; }
.channel-title { font-weight: 600; font-size: 15px; }
.channel-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.channel-actions { display: flex; flex-direction: column; gap: 6px; }

/* --- Hearted --- */
.hearted-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.hearted-tile {
  background: var(--surface); border-radius: 12px; overflow: hidden; position: relative;
}
.hearted-tile img { width: 100%; aspect-ratio: 9/16; object-fit: cover; display: block; }
.hearted-title {
  font-size: 12px; padding: 6px 8px 2px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hearted-actions { display: flex; gap: 6px; padding: 4px 8px 8px; }

/* --- Settings --- */
.settings-section { margin-bottom: 28px; }
.settings-section h2 { font-size: 17px; margin: 0 0 8px; }
.settings-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.file-label { position: relative; cursor: pointer; }
.file-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.version-tag {
  margin-top: 14px; font-size: 12px; color: var(--text-dim);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.version-badge {
  background: var(--surface-2); color: var(--text);
  font-weight: 700; font-size: 11px; padding: 3px 8px; border-radius: 999px;
}
.reminder-banner {
  background: rgba(255,59,92,.12); color: #ffb0bd; border-radius: 10px;
  padding: 10px 12px; font-size: 13px; margin: 10px 0;
}

/* --- Modals --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal-card {
  background: var(--surface); width: 100%; max-width: 420px;
  border-radius: 18px 18px 0 0; padding: 18px; padding-bottom: calc(var(--safe-bottom) + 18px);
  display: flex; flex-direction: column; gap: 10px;
}
.modal-title { font-size: 15px; color: var(--text-dim); margin-bottom: 4px; }
.modal-option {
  background: var(--surface-2); color: var(--text); border: none;
  padding: 14px; border-radius: 12px; font-size: 15px; text-align: left;
}
.modal-cancel {
  background: none; color: var(--text-dim); border: none; padding: 10px; font-size: 14px;
}
.modal-date {
  background: var(--surface-2); color: var(--text); border: none;
  padding: 12px; border-radius: 12px; font-size: 15px;
}
.player-overlay { align-items: center; background: #000; }
.modal-player { width: 100%; max-width: 480px; aspect-ratio: 9/16; }
.modal-close {
  position: absolute; top: calc(var(--safe-top) + 16px); right: 16px;
  background: rgba(255,255,255,.15); color: #fff; border: none;
  padding: 8px 14px; border-radius: 10px;
}

/* --- Toast --- */
#toast-host {
  position: fixed; left: 0; right: 0; bottom: calc(var(--safe-bottom) + 76px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  background: rgba(20,20,24,.95); color: #fff; padding: 10px 16px;
  border-radius: 999px; font-size: 13px; opacity: 0; transform: translateY(8px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translateY(0); }

.fatal-error { padding: 40px 20px; color: var(--danger); text-align: center; }
