/* Video Downloader: same design language as the Training Hub (../garmin-raspberry-coach/DESIGN.md) and
   career-inbox. Graphite ground, raised flat rounded cards (no shadows, no gradients), condensed tabular
   figures for numbers, one violet accent for chrome only (tabs, primary actions, links, focus).
   State colours only tint what needs attention: running = info, failed = poor, downloaded = good. */

@font-face { font-family: "Barlow Semi Condensed"; src: url("/fonts/barlow-semi-condensed-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Barlow Semi Condensed"; src: url("/fonts/barlow-semi-condensed-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Barlow Semi Condensed"; src: url("/fonts/barlow-semi-condensed-800.woff2") format("woff2"); font-weight: 800; font-display: swap; }

:root {
  /* Graphite ramp: the only neutrals */
  --g0: #0e0f11; --g1: #141518; --g2: #1b1d21; --g3: #24272c; --g4: #2a2d32; --g5: #3a3e45;
  --g6: #6c7179; --g7: #8b9098; --g8: #a3a8af; --g9: #c9cdd2; --g10: #eef0f2;
  --ink: var(--g10); --soft: var(--g9); --muted: var(--g8); --line: var(--g4);
  --card: #1a1c20; --card-press: var(--g3);
  /* Accent: chrome only, never data */
  --accent: #8b7dff; --accent-fill: #6b5cf0; --accent-ink: #ffffff;
  /* States */
  --good: #46c98a; --fair: #f2b43c; --poor: #ff6b5e; --info: #7cc4ff;
  --poor-ground: #2e1715; --poor-line: #6b3328; --poor-ink: #ffd9d4;
  /* Type */
  --text: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  --figures: "Barlow Semi Condensed", var(--text);
  /* Shape */
  --r-card: 20px; --r-tile: 18px; --r-inset: 14px; --r-control: 12px; --r-pill: 999px;

  font-family: var(--text);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--g0);
  accent-color: var(--accent);
  caret-color: var(--accent);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { scrollbar-color: var(--g5) var(--g0); }
::selection { background: var(--accent-fill); color: var(--accent-ink); }
body { margin: 0; min-height: 100vh; background: var(--g0); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) 0 calc(78px + env(safe-area-inset-bottom)); }
main { width: min(760px, 100%); margin: auto; padding: 18px 16px 22px; }
h1 { margin: 0; font-size: 2rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; overflow-wrap: anywhere; }
h2 { margin: 0 0 .9rem; font-size: 1.05rem; font-weight: 700; }
a { color: var(--accent); text-underline-offset: 3px; }
.muted { color: var(--muted); }
.error { color: var(--poor); }
.icon { width: 20px; height: 20px; flex-shrink: 0; vertical-align: middle; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus:not(:focus-visible), a:focus:not(:focus-visible) { outline: none; }
a, button { touch-action: manipulation; }

/* Figures: condensed, heavy, tabular. Units go back to the system font. */
.fig { font-family: var(--figures); font-weight: 800; line-height: 1; }
.unit { font-family: var(--text); font-size: .78rem; font-weight: 600; color: var(--muted); margin-left: 3px; }

/* ---------- Controls ---------- */
button, input { font: inherit; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: var(--r-control);
  padding: 12px 16px; font-weight: 700; cursor: pointer; color: var(--ink); background: var(--card); text-decoration: none; white-space: nowrap;
  transition: background-color 120ms ease-out, transform 120ms ease-out; user-select: none; }
button:disabled { opacity: .5; cursor: default; }
button:active:not(:disabled), .button:active { transform: scale(.98); }
.primary { background: var(--accent-fill); color: var(--accent-ink); }
.secondary { background: var(--card); color: var(--ink); }
.card .secondary, dialog .secondary { background: var(--card-press); }
@media (hover: hover) { .secondary:hover:not(:disabled) { background: var(--card-press); } .card .secondary:hover:not(:disabled) { background: var(--g5); } }
.danger { background: var(--poor-ground); color: var(--poor-ink); box-shadow: inset 0 0 0 1px var(--poor-line); }
.small { padding: 8px 12px; font-size: .84rem; }
.block { width: 100%; }
.link-button { padding: 4px 0; background: none; color: var(--accent); font-size: .84rem; font-weight: 600; }
.icon-button { width: 44px; height: 44px; padding: 0; flex: 0 0 44px; }
.card .icon-button { background: var(--card-press); }
@media (hover: hover) { .card .icon-button:hover { background: var(--g5); } }
.icon-button.danger { background: var(--poor-ground); }
.back { width: 42px; height: 42px; flex: 0 0 42px; padding: 0; border-radius: var(--r-pill); }

input[type=search], input[type=text], input[type=password] { width: 100%; min-width: 0; padding: 14px; border: 1px solid transparent;
  border-radius: var(--r-control); background: var(--card); color: var(--ink); outline: none; }
input:focus-visible { border-color: var(--accent); outline: none; }
input::placeholder { color: var(--g7); }
dialog input[type=text] { background: var(--card-press); border-color: var(--g5); }

/* Segmented control (sources) */
.segmented { display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap: 2px; padding: 3px; border-radius: var(--r-control); background: var(--card); }
.segmented button { padding: 9px 6px; border-radius: 9px; background: none; color: var(--soft); font-size: .84rem; font-weight: 600; }
.segmented button.active { background: var(--card-press); color: var(--ink); }

/* Chips (seasons) */
.chip-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0; margin: 12px 0; scrollbar-width: none; }
.chip { flex: none; padding: 8px 12px; border-radius: var(--r-pill); background: var(--card); color: var(--soft); font-size: .84rem; font-weight: 600; }
.chip.active { background: var(--ink); color: var(--g0); }

/* Pills (status) */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: var(--r-pill); background: var(--card-press);
  color: var(--soft); font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill.good { color: var(--good); }
.pill.info { color: var(--info); }
.pill.poor { background: var(--poor-ground); color: var(--poor); }
.pill .icon { width: 14px; height: 14px; }

/* ---------- Layout ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; min-height: 42px; }
.page-header > div { min-width: 0; }
.page-header .sub { margin: 4px 0 0; color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.stack > * + * { margin-top: 12px; }
.hint { margin: 8px 2px 0; color: var(--muted); font-size: .84rem; }
.search { display: flex; gap: 8px; margin-top: 12px; }
.search .field { position: relative; flex: 1; min-width: 0; }
.search .field .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--g7); pointer-events: none; }
.search .field input { padding-left: 42px; }
.empty { padding: 36px 8px; color: var(--muted); text-align: center; }
.empty .icon { display: block; width: 32px; height: 32px; margin: 0 auto 10px; color: var(--g6); }

.card { padding: 16px; border-radius: var(--r-card); background: var(--card); overflow-wrap: anywhere; }
.card.flush { padding: 4px 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 0 0 4px; }
.card-head h2 { margin: 0; }
.card h3 { margin: 14px 0 2px; font-size: .84rem; font-weight: 600; color: var(--muted); }

/* Tiles: big figures in two columns */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile { padding: 14px 14px 13px; border-radius: var(--r-tile); background: var(--card); }
.tile .label { display: block; color: var(--muted); font-size: .84rem; font-weight: 600; margin-bottom: 6px; }
.tile .fig { font-size: 2rem; }
.hero .tiles .tile { background: var(--card-press); padding: 10px 12px; border-radius: var(--r-inset); }
.hero .tiles .fig { font-size: 1.6rem; }

/* Rows inside a card */
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 3px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.row .num { flex: 0 0 34px; text-align: center; font-size: 1.3rem; color: var(--soft); }
.row .end { display: flex; align-items: center; gap: 6px; flex: none; }
.row .end .fig { font-size: 1.3rem; }
a.row { margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
@media (hover: hover) { a.row:hover { background: var(--card-press); } }
.row.hl { margin: 0 -16px; padding-left: 13px; padding-right: 16px; box-shadow: inset 3px 0 0 var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.chev { color: var(--g6); }

/* Progress */
.bar { height: 4px; margin-top: 8px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--info); border-radius: 2px; transition: width .5s ease-out; }

/* ---------- Find: results ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 14px 10px; margin-top: 16px; }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.poster-card { display: block; color: inherit; text-decoration: none; min-width: 0; }
.poster { position: relative; aspect-ratio: 2 / 3; border-radius: var(--r-inset); background: var(--card); overflow: hidden; }
.wide .poster { aspect-ratio: 16 / 9; }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-card .t { margin-top: 7px; font-size: .92rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.poster-card .s { margin-top: 2px; color: var(--muted); font-size: .78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .poster-card:hover .poster { outline: 2px solid var(--g5); } }

/* ---------- Show ---------- */
.hero { padding: 18px 16px; border-radius: var(--r-card); background: var(--card); }
.hero-top { display: flex; gap: 14px; align-items: flex-start; }
.hero-top .poster { flex: 0 0 96px; }
.hero.wide .hero-top .poster { flex-basis: 150px; }
.hero h2 { margin: 0; font-size: 1.3rem; font-weight: 800; line-height: 1.15; letter-spacing: -.01em; text-wrap: balance; }
.hero p { margin: 8px 0 0; color: var(--soft); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.hero .tiles { margin-top: 14px; }
.folder-line { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--r-control); background: var(--card); color: var(--muted); font-size: .84rem; }
.folder-line .icon { color: var(--g7); }
.folder-line b { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.folder-line span { flex: 1; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions > * { flex: 1 1 auto; }

/* ---------- Login ---------- */
.login { max-width: 360px; margin: 14vh auto 0; text-align: center; }
.login img { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { margin: 14px 0 6px; font-size: 1.6rem; }
.login form { display: grid; gap: 10px; margin-top: 20px; }

/* ---------- Nav ---------- */
nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 8px max(8px, calc((100vw - 760px) / 2)) calc(8px + env(safe-area-inset-bottom)); background: var(--g1); border-top: 1px solid var(--line); }
nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px;
  padding: 6px 2px; color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 600; }
nav a .icon { width: 24px; height: 24px; }
nav a.active { color: var(--accent); }
@media (hover: hover) { nav a:hover { color: var(--ink); } nav a.active:hover { color: var(--accent); } }
nav .count { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; padding: 1px 5px; border-radius: var(--r-pill);
  background: var(--accent-fill); color: var(--accent-ink); font: 700 .68rem/1.3 var(--figures); text-align: center; }

/* ---------- Dialogs, toast, spinner ---------- */
dialog { width: min(420px, calc(100% - 32px)); padding: 18px; border: 0; border-radius: var(--r-card); background: var(--card); color: var(--ink); }
dialog::backdrop { background: #000000b3; }
dialog h2 { margin: 0 0 6px; }
dialog p { margin: 0 0 12px; color: var(--soft); font-size: .92rem; }
dialog .hint { margin: 10px 2px 0; }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
dialog#player { width: min(100vw, 960px); max-width: 100vw; padding: 0; background: #000; overflow: hidden; }
dialog#player video { display: block; width: 100%; max-height: 80vh; background: #000; }
dialog#player .dialog-actions { margin: 0; padding: 10px; }
html:has(dialog[open]), body:has(dialog[open]) { overflow: hidden; }
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20; max-width: 440px; margin: 0 auto;
  padding: 12px 16px; border-radius: var(--r-control); background: var(--g3); color: var(--ink); font-size: .92rem; font-weight: 600; text-align: center;
  box-shadow: 0 0 0 1px var(--g5); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--g5); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -4px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; } }
@media (max-width: 360px) { .tile .fig { font-size: 1.6rem; } h1 { font-size: 1.7rem; } }

/* ---------- Downloaded: file manager ---------- */
.head-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.head-left > div { min-width: 0; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 36px; font-size: .84rem; }
.toolbar .small .icon { width: 18px; height: 18px; }
.row.tap { cursor: pointer; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
@media (hover: hover) { .row.tap:hover { background: var(--card-press); } }
.row.tap:focus-visible { outline-offset: -2px; }
.row.selected { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.lead { display: grid; place-items: center; flex: 0 0 36px; height: 36px; border-radius: 10px; background: var(--card-press); color: var(--muted); }
.lead .icon { width: 20px; height: 20px; }
.check { display: grid; place-items: center; flex: 0 0 24px; width: 24px; height: 24px; margin: 6px; border-radius: 50%;
  border: 2px solid var(--g6); color: var(--accent-ink); }
.check.on { background: var(--accent-fill); border-color: var(--accent-fill); }
.check .icon { width: 16px; height: 16px; stroke-width: 2.4; }
.selbar { position: fixed; left: 0; right: 0; bottom: calc(69px + env(safe-area-inset-bottom)); z-index: 9; display: flex; gap: 8px;
  padding: 10px max(16px, calc((100vw - 760px) / 2 + 16px)); background: var(--g1); border-top: 1px solid var(--line); }
.selbar button { flex: 1; padding-left: 8px; padding-right: 8px; }
main:has(+ nav) { padding-bottom: 22px; }
body:has(.selbar) main { padding-bottom: 90px; }
body:has(.selbar) #toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
