:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --sunk: #ecebe6;
  --text: #1b1b1a;
  --muted: #74726c;
  --line: #e2e0da;
  --accent: #e5484d;
  --accent-text: #ffffff;
  --ok: #2f9e5b;
  --radius: 14px;
  --shadow: 0 10px 40px rgb(0 0 0 / 0.14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1c1c1b;
    --sunk: #262624;
    --text: #ecebe8;
    --muted: #9a978f;
    --line: #2e2d2a;
    --accent: #ff5f63;
    --shadow: 0 10px 40px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, .button { font: inherit; color: inherit; }
button, .button {
  border: 0; border-radius: 999px; padding: 8px 16px; cursor: pointer;
  background: var(--sunk); text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.ghost { background: transparent; }
.small { font-size: 13px; padding: 6px 12px; }
.icon { background: transparent; padding: 8px; border-radius: 50%; line-height: 0; color: var(--muted); }
.icon:hover { background: var(--sunk); color: var(--text); }
.muted { color: var(--muted); }
.error { color: var(--accent); min-height: 1.4em; margin: 0; font-size: 14px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(320px, 100%); display: grid; gap: 12px; text-align: center; }
.login h1 { margin: 0 0 8px; font-size: 22px; letter-spacing: -0.01em; }
.logo { width: 36px; height: 56px; margin: 0 auto; border-radius: 9px; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; left: 14px; top: 19px; border-left: 12px solid #fff; border-top: 9px solid transparent; border-bottom: 9px solid transparent; }
.login input, #search {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.login input { text-align: center; letter-spacing: 0.15em; font-size: 17px; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; background: var(--sunk); padding: 3px; border-radius: 999px; }
.tabs button { background: transparent; padding: 6px 16px; color: var(--muted); font-weight: 500; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / 0.08); }
.stats { margin-left: auto; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: 16px 16px 96px; }
.bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
#search { flex: 1 1 220px; }
.chips { display: flex; gap: 6px; }
.chip { padding: 7px 14px; border: 1px solid var(--line); background: transparent; }
.chip[aria-checked="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; max-width: 420px; margin: 0 auto; }

/* Reels */
.ongoing { display: grid; gap: 8px; margin-bottom: 16px; }
.job { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.job .meta { font-size: 13px; color: var(--muted); }
.job.failed .meta { color: var(--accent); }
.progress { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--sunk); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.6s ease; }
.progress.indeterminate i { width: 30% !important; animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

.reel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.reel { display: grid; gap: 6px; }
.reel .poster {
  position: relative; aspect-ratio: 9 / 16; border-radius: var(--radius); overflow: hidden; background: var(--sunk);
  padding: 0; display: block; width: 100%;
}
.reel .poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.reel .poster::after {
  content: ""; position: absolute; inset: auto auto 12px 12px; width: 34px; height: 34px; border-radius: 50%;
  background: rgb(0 0 0 / 0.45) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 7v10l8-5z' fill='white'/%3E%3C/svg%3E") center / 22px no-repeat;
}
.reel .dur { position: absolute; right: 8px; top: 8px; z-index: 1; font-size: 12px; color: #fff; background: rgb(0 0 0 / 0.45); padding: 1px 7px; border-radius: 999px; }
.reel .info { display: flex; justify-content: space-between; align-items: start; gap: 6px; }
.reel .title { font-weight: 600; font-size: 14px; line-height: 1.3; }
.reel .sub { font-size: 12px; color: var(--muted); }

/* Library */
.gphotos { border: 1px solid var(--line); background: var(--surface); }
.google-row { display: flex; align-items: center; gap: 10px; padding: 10px 0 14px; border-top: 1px solid var(--line); font-size: 14px; }
.google-row span { flex: 1; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.tile {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 10px; overflow: hidden; background: var(--sunk); display: block; width: 100%;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.25s ease; }
.tile:hover img { transform: scale(1.03); }
.tile .badge { position: absolute; right: 6px; bottom: 6px; font-size: 11px; color: #fff; background: rgb(0 0 0 / 0.5); padding: 1px 7px; border-radius: 999px; }
.tile .state { position: absolute; left: 6px; bottom: 6px; font-size: 11px; color: #fff; background: rgb(0 0 0 / 0.5); padding: 1px 7px; border-radius: 999px; }
.tile .state.failed { background: var(--accent); }
.tile .title { position: absolute; inset: auto 0 0; padding: 22px 8px 6px; font-size: 12px; color: #fff; text-align: left; background: linear-gradient(transparent, rgb(0 0 0 / 0.6)); opacity: 0; transition: opacity 0.2s; }
.tile:hover .title { opacity: 1; }
.tile .pick {
  position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #fff; background: rgb(0 0 0 / 0.2); opacity: 0; transition: opacity 0.15s;
}
.tile:hover .pick, .picking .tile .pick { opacity: 1; }
.tile.picked { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.picked .pick { opacity: 1; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12l4 4 8-8' stroke='white' stroke-width='3' fill='none'/%3E%3C/svg%3E") center / 14px no-repeat; border-color: var(--accent); }
.more { height: 1px; }

.pick-bar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; box-shadow: var(--shadow);
}

/* Side sheet */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.35); z-index: 10; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 11; background: var(--surface);
  box-shadow: var(--shadow); overflow-y: auto; padding: 16px 20px 32px; animation: in 0.2s ease;
}
@keyframes in { from { transform: translateX(30px); opacity: 0; } }
.sheet .close { position: sticky; top: 0; z-index: 2; display: block; margin: 0 -8px 8px auto; background: var(--surface); border-radius: 50%; font-size: 22px; line-height: 1; padding: 6px 10px; }
.sheet video, .sheet .photo { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; display: block; }
.sheet .photo { object-fit: contain; }
.sheet h2 { font-size: 18px; margin: 14px 0 4px; line-height: 1.3; }
.sheet .when { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.sheet .summary { margin: 10px 0; }
.labels { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.labels span { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--sunk); cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.sheet h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 20px 0 6px; }
.transcript { display: grid; gap: 2px; }
.line { display: grid; grid-template-columns: 44px 1fr; gap: 8px; text-align: left; border-radius: 8px; padding: 6px 8px; background: transparent; white-space: normal; }
.line:hover { background: var(--sunk); }
.line.now { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.line time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.highlight { font-size: 13px; }

/* Dialogs */
dialog { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.player { background: #000; max-width: min(420px, 94vw); max-height: 94dvh; overflow: hidden; }
.player video { display: block; width: 100%; max-height: calc(94dvh - 56px); aspect-ratio: 9 / 16; background: #000; }
.player-actions { display: flex; justify-content: space-between; padding: 8px; }
.player-actions .ghost { color: #fff; }
.settings { width: min(400px, 94vw); padding: 18px 20px; }
.settings-head { display: flex; justify-content: space-between; align-items: center; }
.settings h2 { margin: 0; font-size: 18px; }
.pair-box { display: grid; justify-items: center; gap: 10px; margin: 16px 0; text-align: center; }
.qr { background: #fff; padding: 10px; border-radius: 12px; line-height: 0; }
.qr svg { width: 220px; height: 220px; }
.code { font: 600 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.18em; }
.devices { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; }
.devices li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.devices li div { flex: 1; min-width: 0; }
.devices small { color: var(--muted); display: block; }

.toast {
  position: fixed; left: 50%; bottom: max(80px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow);
}

@media (max-width: 560px) {
  .top { gap: 8px; }
  .stats { display: none; }
  .reel-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .media-grid { grid-template-columns: repeat(3, 1fr); gap: 3px; }
  .tile { border-radius: 4px; }
  .tile .pick { opacity: 0; }
  .chips { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
