:root {
  --bg: #111;
  --fg: #f4f4f4;
  --muted: #9a9a9a;
  --accent: #e53935;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 16px/1.4 system-ui, sans-serif; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
#app { min-height: 100%; padding: 16px; }
[hidden] { display: none !important; }
header { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
header h1 { flex: 1; margin: 0; font-size: 1.4rem; }
button { font: inherit; padding: 10px 16px; border-radius: 10px; border: 0; background: #2a2a2a; color: var(--fg); }
.grid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
[data-state="ready"] .empty-note { display: none; }
.search { display: flex; gap: 8px; margin: 0 0 12px; }
/* 16px+ text so iPhone Safari doesn't zoom in on focus. */
.search input { flex: 1; min-width: 0; font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 10px; border: 1px solid #444; background: #000; color: var(--fg); }
.search input[data-state="locked"] { cursor: pointer; }
.search-empty { color: var(--muted); }
.empty-note, .error-note { color: var(--muted); }
[data-testid="screen-player"]:not([data-state="error"]) .error-note { display: none; }
/* Player: the app's own full-screen layout (never the browser's native
   fullscreen, whose built-in play button would bypass unlocking). The video
   fills the whole screen, letterboxed; Back / Play / Pause float on top, clear
   of the iPad's rounded corners and home bar. */
[data-testid="screen-player"] { position: fixed; inset: 0; z-index: 10; background: #000; }
/* Controls hide while playing (app.js sets data-controls); the session bar stays. */
[data-testid="screen-player"] :is(header, .controls, .seek) { transition: opacity 0.2s; }
[data-testid="screen-player"][data-controls="hidden"] :is(header, .controls, .seek) {
  opacity: 0; visibility: hidden; transition: opacity 0.4s, visibility 0s 0.4s;
}
[data-testid="screen-player"][data-controls="hidden"] { cursor: none; }
[data-testid="screen-player"] video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
[data-testid="screen-player"] header {
  position: absolute; z-index: 2; margin: 0;
  top: calc(12px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left));
}
.controls {
  position: absolute; z-index: 2; left: 0; right: 0; display: flex; gap: 16px; justify-content: center;
  bottom: calc(20px + env(safe-area-inset-bottom));
}
[data-testid="screen-player"] button { background: rgb(30 30 30 / 0.75); backdrop-filter: blur(6px); padding: 12px 22px; font-size: 1.05rem; }
[data-testid="screen-player"] .error-note { position: absolute; z-index: 2; top: 45%; width: 100%; text-align: center; }
/* The prompt covers only the visible area (above a phone's on-screen keyboard);
   app.js keeps --visible-top / --visible-height in step with visualViewport. */
[data-testid="unlock-prompt"] {
  position: fixed; left: 0; right: 0; top: var(--visible-top, 0); height: var(--visible-height, 100%);
  z-index: 20; display: grid; place-items: center; overflow: hidden; background: rgb(0 0 0 / 0.7);
}
.unlock-card { background: #1d1d1d; padding: 24px; border-radius: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; width: min(360px, calc(100vw - 32px)); }
.unlock-card h2, .unlock-card p { margin: 0; }
.unlock-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }

/* A picked folder's videos to choose from: a scrolling list in a card. */
[data-testid="drive-choose"] {
  position: fixed; inset: 0; z-index: 15; display: grid; place-items: center; background: rgb(0 0 0 / 0.7);
}
.choose-card { background: #1d1d1d; padding: 20px; border-radius: 16px; display: grid; gap: 12px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); grid-template-rows: auto minmax(0, 1fr) auto; }
.choose-card h2 { margin: 0; overflow-wrap: anywhere; }
.choose-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.choose-list label { display: flex; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid #333; overflow-wrap: anywhere; }
.choose-list input { width: 22px; height: 22px; flex: none; }
.choose-list li[data-state="in-library"] { color: var(--muted); }
.choose-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }

/* Library grid (M2) */
.grid li { background: #1d1d1d; border-radius: 12px; overflow: hidden; cursor: pointer; display: grid; }
.grid li img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; display: block; }
.grid li span { padding: 10px 12px; font-weight: 600; }
.grid li .tile-note { padding-top: 0; font-weight: 400; color: var(--muted); }
.grid li [data-testid="downloaded-badge"] { margin: 0 12px 10px; justify-self: start; padding: 2px 10px; border-radius: 999px; background: #2e7d32; color: #fff; font-size: 0.85rem; font-weight: 600; }
.grid li[data-unavailable="true"] { opacity: 0.4; }
.search [data-testid="library-filter"][aria-pressed="true"] { background: var(--fg); color: #000; }
.jobs { list-style: none; margin: 0; padding: 0; }
[data-testid="import-status"] { color: var(--muted); margin: 8px 0; }
progress[data-testid="import-progress"] { display: block; width: 100%; margin: 4px 0; }
[data-import="error"] { color: var(--accent); }
[data-role="settings-list"] { list-style: none; padding: 0; display: grid; gap: 8px; }
[data-role="settings-list"] li { display: flex; align-items: center; gap: 12px; background: #1d1d1d; padding: 8px 12px; border-radius: 10px; }
[data-role="settings-list"] li span { flex: 1; }

.import-help { color: var(--muted); font-size: 0.9rem; margin: -8px 0 12px; }
.import-help strong { color: var(--fg); font-weight: 600; }

.app-version { font-size: 0.75rem; font-weight: 500; color: var(--muted); margin-left: 6px; vertical-align: middle; }

/* Optional feature: watch-time limit */
.session-bar {
  position: absolute; z-index: 2; display: flex; gap: 14px; align-items: center;
  top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right));
  background: rgb(30 30 30 / 0.75); backdrop-filter: blur(6px); padding: 8px 14px; border-radius: 10px;
  font-variant-numeric: tabular-nums; font-size: 0.95rem;
}
[data-testid="session-remaining"] { font-weight: 700; }
/* The clock: a shortcut to a new time limit (behind Face ID). */
[data-testid="screen-player"] .timer-button { display: grid; place-items: center; padding: 6px; margin: -6px 0 -6px -8px; background: none; backdrop-filter: none; min-width: 44px; min-height: 44px; }
[data-testid="screen-player"][data-state="time-up"]::after {
  content: "Time is up"; position: absolute; z-index: 2; top: 40%; width: 100%; text-align: center;
  font-size: 2rem; font-weight: 700; color: var(--fg); text-shadow: 0 2px 12px #000;
}
/* The parent's picture, above "Time is up". */
.time-up-picture {
  position: absolute; z-index: 2; left: 50%; top: 14%; transform: translateX(-50%);
  max-width: min(70vw, 420px); max-height: 42vh; border-radius: 16px; box-shadow: 0 4px 24px #000;
}
[data-testid="screen-player"][data-state="time-up"]:has(.time-up-picture:not([hidden]))::after { top: auto; bottom: 26%; }
.time-up-settings { display: grid; gap: 10px; background: #1d1d1d; padding: 12px; border-radius: 10px; }
.time-up-settings h2 { margin: 0; font-size: 1.05rem; }
.time-up-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.time-up-row > span:first-child { min-width: 4.5em; color: var(--muted); }
[data-testid="time-up-picture-preview"] { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
[data-testid="time-up-picture-status"], [data-testid="time-up-sound-status"] { color: var(--accent); }
.budget-prompt {
  position: fixed; left: 0; right: 0; top: var(--visible-top, 0); height: var(--visible-height, 100%);
  z-index: 15; display: grid; place-items: center; overflow: auto; background: rgb(0 0 0 / 0.7);
}
.budget-card { background: #1d1d1d; padding: 24px; border-radius: 16px; display: grid; gap: 14px; text-align: center; max-width: calc(100vw - 32px); }
.budget-card h2 { margin: 0; }
.budget-options { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.budget-custom { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
.budget-custom input { width: 5em; margin-left: 8px; font-size: 1.1rem; padding: 8px; border-radius: 8px; border: 1px solid #444; background: #000; color: var(--fg); }
[data-testid="budget-custom-error"] { flex-basis: 100%; margin: 0; color: var(--accent); }
@media (max-height: 500px) {
  .budget-card { padding: 10px 14px; gap: 8px; }
  .budget-card h2 { font-size: 1.1rem; }
  .budget-options button { padding: 8px 14px; }
}
.budget-options button { font-size: 1.1rem; padding: 14px 20px; }
.feature-settings { display: grid; gap: 10px; margin: 16px 0; }
.feature-toggle { display: flex; align-items: center; gap: 10px; }

/* Seek (M8): scrub bar with elapsed / total, just above the buttons */
.seek {
  position: absolute; z-index: 2; display: flex; align-items: center; gap: 12px;
  left: calc(20px + env(safe-area-inset-left)); right: calc(20px + env(safe-area-inset-right));
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: rgb(30 30 30 / 0.6); backdrop-filter: blur(6px); padding: 8px 14px; border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.seek input[type="range"] { flex: 1; height: 32px; accent-color: var(--fg); }

/* Playlist: holding a tile starts selecting; ticked tiles show their place. */
.grid li { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; position: relative; transition: transform 0.15s; }
/* While held, the tile sinks until selecting starts; its picture can't be dragged away. */
.grid li[data-holding] { transform: scale(0.94); transition: transform 0.4s ease-out; }
.grid li img { pointer-events: none; -webkit-user-drag: none; }
.grid li[aria-checked="true"] { outline: 3px solid var(--fg); outline-offset: -3px; }
[data-testid="selection-number"] {
  position: absolute; top: 8px; left: 8px; min-width: 2em; padding: 4px 8px !important; text-align: center;
  border-radius: 999px; background: var(--fg); color: var(--bg); font-variant-numeric: tabular-nums;
}
.selection-bar {
  position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 5; margin-top: 16px;
  display: flex; gap: 12px; align-items: center;
  background: rgb(30 30 30 / 0.9); backdrop-filter: blur(6px); padding: 10px 14px; border-radius: 12px;
}
[data-testid="selection-count"] { flex: 1; font-weight: 600; }
[data-testid="selection-play"] { background: var(--fg); color: var(--bg); font-weight: 600; }
