:root {
  --bg: #14161a;
  --surface: #1e2127;
  --surface-2: #272b33;
  --text: #f1f2f4;
  --muted: #9aa1ad;
  --accent: #f0b232;
  --accent-text: #1a1406;
  --danger: #ff6b6b;
  --radius: 14px;
  --gutter: 16px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eceef2;
    --text: #15171b;
    --muted: #5e6572;
    --accent: #c98a00;
    --accent-text: #ffffff;
    --danger: #c62828;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
/* Classes that set display (.icon-btn, .btn, dialog .row) would otherwise override the hidden attribute. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.bar h1 {
  flex: 1; margin: 0 8px; font-size: 1.25rem; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--text); display: grid; place-items: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle { fill: currentColor; stroke: none; }
.icon-btn.spinning svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spinning svg { animation: none; opacity: .5; } }

main { padding: 4px var(--gutter) calc(env(safe-area-inset-bottom) + 24px); max-width: 760px; margin: 0 auto; }

.section-title { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; margin: 20px 4px 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; list-style: none; padding: 0; margin: 0; }
.card { display: block; color: inherit; text-decoration: none; border-radius: var(--radius); }
.card .art {
  aspect-ratio: 1; width: 100%; border-radius: var(--radius); background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center; color: var(--muted); font-size: 2.2rem; font-weight: 700; overflow: hidden;
}
.card .name { margin: 8px 2px 0; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { margin: 2px 2px 0; color: var(--muted); font-size: .85rem; }
.card:active .art { transform: scale(.97); }

.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: var(--radius);
  color: inherit; text-decoration: none; background: var(--surface);
}
.item:active { background: var(--surface-2); }
.item .thumb { flex: none; width: 112px; aspect-ratio: 16/9; border-radius: 9px; background: var(--surface-2) center/cover no-repeat; }
.item .thumb.poster { width: 60px; aspect-ratio: 2/3; }
.item .text { min-width: 0; flex: 1; }
.item .t { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .s { color: var(--muted); font-size: .85rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .num { color: var(--muted); font-variant-numeric: tabular-nums; width: 1.6em; text-align: right; flex: none; font-size: .9rem; }
.progress { height: 3px; background: var(--surface-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); }

.hero { display: flex; gap: 14px; align-items: center; margin: 4px 0 16px; }
.hero .art { width: 96px; flex: none; aspect-ratio: 1; border-radius: var(--radius); background: var(--surface-2) center/cover no-repeat; }
.hero .meta { color: var(--muted); font-size: .9rem; margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 52px; padding: 0 28px; font-size: 1.05rem; }

.center { text-align: center; }
.empty { text-align: center; padding: 48px 8px; }
.empty h2 { margin: 0 0 8px; font-size: 1.3rem; }
.empty p { color: var(--muted); margin: 0 auto 20px; max-width: 34ch; }
.empty .after { margin: 12px auto 0; }
.text-link { display: inline-block; padding: 10px 4px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.notice { background: var(--surface); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0 12px; color: var(--muted); font-size: .9rem; }
.notice.error { color: var(--danger); }

.skeleton { background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

dialog {
  border: 0; border-radius: 20px; padding: 20px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog h2 { margin: 0 0 4px; }
dialog .row { display: flex; flex-direction: column; gap: 6px; margin: 16px 0 8px; font-weight: 600; }
dialog select { font: inherit; padding: 10px; border-radius: 10px; background: var(--surface-2); color: var(--text); border: 0; }
dialog .actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 16px; }
dialog .report { margin-top: 12px; }
dialog .report .btn { display: flex; width: 100%; }
dialog .report p { margin: 6px 0 0; }
dialog .support { border-top: 1px solid var(--surface-2); margin-top: 16px; padding-top: 12px; }
dialog .support h3 { margin: 0 0 4px; font-size: 1rem; }
dialog .support p { margin: 0 0 10px; }
dialog .support .btn { display: flex; width: 100%; }
dialog .support details { margin: 10px 0; }
dialog .support summary { cursor: pointer; color: var(--muted); font-size: .9rem; min-height: 32px; display: list-item; }
dialog .support .qr { display: block; width: 200px; height: 200px; margin: 8px auto 0; background: #fff; border-radius: 12px; padding: 6px; }
summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

a:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- profiles ---------- */
.profiles { list-style: none; padding: 0; margin: 24px auto; display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; max-width: 520px; }
.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; padding: 6px; border-radius: var(--radius); min-width: 96px; }
.profile .avatar { width: 84px; height: 84px; border-radius: 50%; background: var(--surface-2) center/cover no-repeat; display: grid; place-items: center; font-size: 2rem; font-weight: 700; color: var(--muted); }
.profile:active .avatar { transform: scale(.95); }
.profile .pname { font-weight: 600; }
dialog .inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 400; }
dialog .pin { font: inherit; font-size: 1.6rem; letter-spacing: .5em; text-align: center; width: 100%; padding: 10px; border-radius: 10px; border: 0; background: var(--surface-2); color: var(--text); margin-top: 8px; }

/* ---------- player ---------- */
html.player-open, html.player-open body { overflow: hidden; }
.player { position: fixed; inset: 0; z-index: 10; background: #000; color: #fff; display: flex; flex-direction: column; }
.player video { flex: 1; min-height: 0; width: 100%; background: #000; }
.player .p-top, .player .p-bottom {
  display: flex; align-items: center; gap: 8px;
  padding: 6px calc(env(safe-area-inset-right) + 8px) 6px calc(env(safe-area-inset-left) + 8px);
}
.player .p-top { padding-top: calc(env(safe-area-inset-top) + 6px); }
.player .p-bottom { justify-content: center; flex-wrap: wrap; padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
.player .icon-btn { color: #fff; }
.player .icon-btn:active { background: rgb(255 255 255 / .15); }
.player .p-cast.on, .player .p-repeat.on { color: var(--accent); }
.player .p-repeat:not(.on) { opacity: .6; }
/* While a video plays the buttons fade; a tap brings them back (player.js). */
.player .p-top, .player .p-bottom { transition: opacity .25s ease; }
.player.idle .p-top, .player.idle .p-bottom { opacity: 0; pointer-events: none; }
.player.idle { cursor: none; }
@media (prefers-reduced-motion: reduce) { .player .p-top, .player .p-bottom { transition: none; } }
.player .p-title { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.player .p-title strong, .player .p-title small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .p-title small { color: #b9bec7; }
.player .btn { background: rgb(255 255 255 / .14); color: #fff; min-height: 40px; padding: 0 14px; font-size: .95rem; }
.player .btn.primary { background: var(--accent); color: #1a1406; }
.player .p-status {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px)); background: rgb(20 22 26 / .92); border-radius: var(--radius);
  padding: 16px; text-align: center; pointer-events: auto;
}
.player .p-msg { margin: 0 0 12px; }
.player .p-msg:empty { display: none; }
.player .p-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.player .p-actions:empty { display: none; }
/* Landscape phone: give the picture all the height, keep controls compact. */
@media (orientation: landscape) and (max-height: 500px) {
  .player .p-top, .player .p-bottom { position: absolute; left: 0; right: 0; z-index: 1; background: linear-gradient(rgb(0 0 0 / .6), transparent); }
  .player .p-top { top: 0; }
  .player .p-bottom { bottom: 56px; background: none; opacity: .85; }
  .player video { height: 100%; }
}
