:root {
  --bg: #0c0c0e;
  --card: #1a1a1e;
  --card2: #24242a;
  --line: #33333a;
  --cream: #f2ede2;
  --muted: #9a9aa2;
  --accent: #e6543f;
  --danger: #ff6b6b;
  --slot: #7fd08a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  overflow-x: hidden;
}

#app { min-height: 100dvh; }

.screen { min-height: 100dvh; padding: 24px; }
.hidden { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }
.accent { color: var(--accent); }

.centerbox {
  max-width: 420px;
  margin: 20vh auto 0;
  text-align: center;
}
.centerbox h1 { font-size: 28px; letter-spacing: 2px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  background: var(--card2);
  color: var(--cream);
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #1a0d0a; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--cream);
  border-radius: 10px;
  width: 44px;
  height: 44px;
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--card2); }

.search-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { font-weight: 800; letter-spacing: 2px; font-size: 18px; }
.header-icons { display: flex; gap: 10px; }

.search-bar {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.search-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--cream);
  font-size: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 20px;
}
.grid-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}
.grid-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg); }
.thumb-wrap { position: relative; }
.duration-badge {
  position: absolute;
  right: 6px; bottom: 6px;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
}
.grid-item .meta { padding: 8px 10px; }
.grid-item .title { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.grid-item .channel { font-size: 11px; color: var(--muted); margin-top: 4px; }

.subpage-header { display: flex; align-items: center; gap: 14px; }
.subpage-header h2 { margin: 0; }

.list { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
}
.list-item img { width: 100px; height: 56px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.list-item .title { font-weight: 600; font-size: 14px; }
.list-item .channel { color: var(--muted); font-size: 12px; margin-top: 2px; }

.settings-body { margin-top: 20px; display: flex; flex-direction: column; gap: 22px; max-width: 480px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.setting-row label { font-size: 14px; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--cream); font-size: 18px; cursor: pointer;
}
.stepper span { min-width: 40px; text-align: center; font-weight: 700; }

.segmented { display: flex; gap: 8px; }
.segmented button {
  border: 1px solid var(--line); background: var(--card); color: var(--cream);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.segmented button.active { background: var(--accent); color: #1a0d0a; border-color: var(--accent); }

#screen-player { padding: 0; position: relative; background: #000; }
#player-container { position: relative; width: 100%; height: 100dvh; background: #000; }
/* Sized precisely to the video's real aspect-fitted rect by
   layoutVideoAndSubtitles() in app.js, rather than stretched to fill the
   whole container -- that's what makes any letterboxed/pillarboxed space
   real, known area the subtitle box can use instead of overlaying the
   picture. #yt-player-wrapper (not #yt-player) is the sizing target
   because YT.Player replaces the #yt-player div with an <iframe> that
   reuses its id -- a stable wrapper is needed so JS always has the same
   element to position, whether or not the player has loaded yet. */
#yt-player-wrapper, #local-video-player { position: absolute; background: #000; }
#yt-player-wrapper iframe { width: 100% !important; height: 100% !important; }
#local-video-player { object-fit: contain; }

/* Floating mode: the video shrinks into a small movable/resizable box while
   the subtitle overlay, HUD, and controls stay in their normal full-screen
   positions -- only the video itself relocates. A YouTube iframe is a
   separate browsing context, so touches landing on it never reach this
   page's own pointer listeners; #float-drag-handle is a real, always-on-top
   strip specifically so dragging still works over a YouTube video, not just
   local/Drive <video> playback. */
#player-container.floating {
  position: fixed;
  z-index: 40;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
}
#float-drag-handle {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 24px;
  z-index: 2;
  background: rgba(0,0,0,0.55);
  touch-action: none;
  cursor: grab;
}
#float-drag-handle:active { cursor: grabbing; }
#float-drag-handle::after {
  content: "\2807\2807\2807";
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  letter-spacing: 3px;
  color: rgba(255,255,255,0.6);
  font-size: 12px;
}
#float-resize-handle {
  position: absolute;
  right: 0; bottom: 0;
  width: 26px; height: 26px;
  z-index: 2;
  background: rgba(255,255,255,0.85);
  border-top-left-radius: 8px;
  touch-action: none;
  cursor: nwse-resize;
}
#float-resize-handle::after {
  content: "";
  position: absolute; right: 6px; bottom: 6px;
  width: 10px; height: 10px;
  border-right: 2px solid #333;
  border-bottom: 2px solid #333;
}

.subtitle-box {
  position: absolute;
  left: 6%;
  right: 6%;
  text-align: center;
  pointer-events: none;
}
.subtitle-box.pos-top { top: 6%; }
.subtitle-box.pos-bottom { bottom: 14%; }
/* Applied by layoutVideoAndSubtitles() when there's real empty space next
   to the video (e.g. a 16:9 video in a taller-than-16:9 viewport) -- uses
   the full width of that space instead of the narrower 6%-margin overlay
   above, and top/height come from JS as exact pixel bands. */
.subtitle-box.in-deadspace {
  left: 0; right: 0; bottom: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.subtitle-box .bubble {
  display: inline-block;
  background: rgba(0,0,0,0.55);
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: clamp(16px, 3.2vw, 26px);
}
#subtitle-next { opacity: 0.7; margin-top: 4px; }

.hud {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.8);
  border-radius: 14px;
  padding: 14px 26px;
  font-weight: 700;
  font-size: 22px;
}

.progress-ring {
  position: absolute;
  top: 24px; right: 24px;
  width: 44px; height: 44px;
  transform: rotate(-90deg);
}
.progress-ring-track {
  fill: none;
  stroke: #dadada;
  stroke-width: 4;
}
.progress-ring-fill {
  fill: none;
  stroke: #3f8cff;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 113.1; /* 2 * PI * r(18) */
  stroke-dashoffset: 113.1;
  transition: stroke-dashoffset 0.2s linear;
}

.resume-pill {
  position: absolute;
  right: 24px; bottom: 90px;
  background: #7fd08a;
  color: #06210a;
  border: none;
  border-radius: 16px;
  padding: 12px 20px;
  font-weight: 700;
  cursor: pointer;
  touch-action: none;
}

/* Draggable/relocatable and remembered across videos, same idea as the
   resume pill -- shown whenever the current video is liked, independent of
   the info-panel's own heart toggle button, which stays hidden along with
   the rest of the overlay when it's closed. */
#liked-badge {
  position: absolute;
  right: 20px; top: 20px;
  font-size: 28px;
  z-index: 45;
  touch-action: none;
  cursor: grab;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.7));
}

.timeline {
  position: absolute;
  left: 24px; right: 24px; bottom: 90px;
}
.timeline-track { height: 6px; background: rgba(255,255,255,0.3); border-radius: 3px; }
.timeline-fill { height: 100%; background: var(--accent); border-radius: 3px; width: 0%; }
.timeline-times { display: flex; justify-content: space-between; margin-top: 6px; font-size: 13px; }

.player-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 70px;
  background: linear-gradient(to top, rgba(12,12,14,0.95), transparent);
  padding: 20px 24px 10px;
}
.overlay-title-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.overlay-title { font-weight: 700; font-size: 18px; }
.overlay-channel { color: var(--muted); font-size: 13px; margin-top: 2px; }
.overlay-slot-info { color: var(--slot); font-size: 13px; margin-top: 8px; }
.overlay-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; }
.overlay-controls button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--cream); cursor: pointer; }
.overlay-controls label { color: var(--muted); margin-left: 6px; }

.player-controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(0,0,0,0.5);
}
/* Scoped smaller than the header/overlay icon buttons -- 11 buttons at the
   original 44px would need ~620px of row width, which overflowed off both
   edges of a phone screen (hiding the first and last buttons) even before
   wrapping was added. Smaller buttons wrapped to two rows both fit and stay
   comfortably tappable. */
.player-controls .icon-btn {
  width: 38px;
  height: 38px;
  font-size: 16px;
}

@media (max-width: 480px) {
  .screen { padding: 16px; }
  .overlay-controls { gap: 6px; }
}

/* List of per-group AI summaries, each jumping playback to that group's
   start time when tapped. Sits above the screen-off overlay (50) so it's
   reachable even from there, below the lock overlay (60) so locking still
   wins over it. */
.summary-panel {
  position: absolute;
  inset: 0;
  z-index: 55;
  background: rgba(10,10,12,0.97);
  overflow-y: auto;
  padding: 20px;
}
.summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 12px;
}
.summary-item {
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.summary-item .ts {
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  margin-right: 8px;
}

/* Blacks out the picture while playback keeps running underneath (audio
   keeps playing) -- a purely visual toggle, not the OS-level background
   playback the lock/side-button case needs, which is a separate, much more
   limited thing (see the autopictureinpicture attribute on the local video
   element instead). Sits below the lock overlay (z-index 60) so locking
   still works while in this mode. */
#screen-off-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#screen-off-playpause {
  width: 84px; height: 84px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 34px;
  cursor: pointer;
}
#screen-off-hint {
  color: rgba(255,255,255,0.5);
  font-size: 12px;
}

/* Sits on top of everything (including the floating video, z-index 40) so
   it can absorb every touch -- transparent rather than dimmed, since the
   point is to stop accidental taps while still watching, not to hide the
   picture. */
#lock-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  touch-action: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-bottom: 36px;
}
#lock-hint {
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
}
#lock-icon {
  background: rgba(0,0,0,0.55);
  border: none;
  border-radius: 50%;
  width: 50px; height: 50px;
  font-size: 22px;
  color: #fff;
  cursor: pointer;
}
