:root {
  --bg: #0f0f0f;
  --fg: #fff;
  --muted: rgba(255,255,255,.66);
  --accent: #d82828;
  --sheet: #ffffff;
  --sheet-fg: #111;
  --sheet-muted: #6b6b6b;
  --line: #e6e6e6;
  --soft: #f3f3f3;
  --col: min(100vw, calc(100dvh * 9 / 16));
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --sheet: #1b1b1b; --sheet-fg: #f1f1f1; --sheet-muted: #a3a3a3; --line: #2e2e2e; --soft: #262626; }
}
:root[data-theme="dark"] { --sheet: #1b1b1b; --sheet-fg: #f1f1f1; --sheet-muted: #a3a3a3; --line: #2e2e2e; --soft: #262626; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; }
a { color: inherit; }
button { font: inherit; cursor: pointer; }

/* ---------- feed ---------- */
#feed { position: fixed; inset: 0; overflow-y: scroll; scroll-snap-type: y mandatory; overscroll-behavior: contain;
  scrollbar-width: none; }
#feed::-webkit-scrollbar { display: none; }
.slide { height: 100dvh; scroll-snap-align: start; scroll-snap-stop: always; position: relative;
  display: flex; justify-content: center; }
.slide .frame { position: relative; width: var(--col); height: 100%; background: #000 center / cover no-repeat; }
#caption { position: fixed; left: 50%; transform: translateX(-50%); width: var(--col); bottom: 0; z-index: 4;
  padding: 60px 16px calc(20px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.75)); pointer-events: none; }
#caption[hidden] { display: none; }
#caption .channel { font-weight: 600; font-size: 15px; }
#caption .title { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.slide .meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 16px calc(20px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.75)); pointer-events: none; z-index: 3; }
.slide .channel { font-weight: 600; font-size: 15px; }
.slide .title { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.slide.message .frame { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 32px; background: var(--bg); gap: 14px; }
.slide.message h1 { font-size: 22px; margin: 0; }
.slide.message p { margin: 0; color: var(--muted); max-width: 320px; }

#player-wrap { position: fixed; top: 0; bottom: 0; left: 50%; width: var(--col); transform: translateX(-50%);
  pointer-events: none; z-index: 2; opacity: 0; transition: opacity .2s; }
#player-wrap.on { opacity: 1; }
#player-wrap iframe, #player { width: 100%; height: 100%; border: 0; }
#tap { position: fixed; top: 64px; bottom: 140px; left: 50%; width: var(--col); transform: translateX(-50%);
  background: none; border: 0; z-index: 4; display: none; }
#tap.on { display: block; }

#top { position: fixed; top: 0; left: 50%; transform: translateX(-50%); width: var(--col); z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: linear-gradient(rgba(0,0,0,.55), transparent); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand img { width: 26px; height: 26px; border-radius: 50%; background: #fff; }
.pill { font-size: 12px; background: rgba(255,255,255,.16); padding: 4px 10px; border-radius: 99px; margin-left: auto;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.icon-btn { margin-left: auto; background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 50%;
  width: 40px; height: 40px; display: grid; place-items: center; }
.pill:not([hidden]) + .icon-btn { margin-left: 0; }
.pill[hidden] { display: none; }
#soundHint { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(110px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.7); padding: 8px 14px; border-radius: 99px; font-size: 13px; z-index: 5; pointer-events: none; }
#status { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top)); z-index: 5;
  font-size: 12px; color: var(--muted); }

/* ---------- settings sheet ---------- */
#settings { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.5); display: flex; justify-content: center;
  align-items: flex-end; color-scheme: light dark; }
#settings[hidden] { display: none; }
.sheet { width: min(100%, 560px); max-height: 92dvh; overflow-y: auto; background: var(--sheet); color: var(--sheet-fg);
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(28px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { #settings { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -18px;
  background: var(--sheet); padding: 6px 0 8px; margin-top: -6px; z-index: 2; }
.sheet h2 { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--sheet-muted); margin: 22px 0 10px; }
.sheet h2 .muted { text-transform: none; letter-spacing: 0; }
.muted { color: var(--sheet-muted); }
.small { font-size: 13px; }
.sheet ol { padding-left: 20px; margin: 8px 0; }
.sheet li { margin-bottom: 6px; }
code { background: var(--soft); padding: 1px 5px; border-radius: 4px; }
.text-btn { background: none; border: 0; color: var(--accent); font-weight: 700; font-size: 16px; padding: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--soft); border: 1px solid var(--line);
  color: var(--sheet-fg); border-radius: 99px; padding: 6px 8px 6px 12px; font-size: 14px; }
.chip button { background: none; border: 0; color: var(--sheet-muted); font-size: 16px; line-height: 1; padding: 0 4px; }
.selectable .chip { padding: 6px 12px; }
.selectable .chip.on { background: var(--sheet-fg); color: var(--sheet); border-color: var(--sheet-fg); }
.picker { position: relative; margin-top: 10px; }
input[type=text], input[type=password], select { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--sheet); color: var(--sheet-fg); }
.results { position: absolute; left: 0; right: 0; top: 50px; background: var(--sheet); border: 1px solid var(--line);
  border-radius: 10px; max-height: 240px; overflow: auto; z-index: 5; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.results div { padding: 10px 12px; display: flex; justify-content: space-between; cursor: pointer; }
.results div:hover { background: var(--soft); }
.row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 14px; white-space: nowrap; }
.row select { width: auto; flex: 1; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: none; border: 0; color: var(--sheet-fg); padding: 9px 16px; }
.seg button.on { background: var(--sheet-fg); color: var(--sheet); }
.keyrow { display: flex; gap: 8px; }
.keyrow input { flex: 1; min-width: 0; }
button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 600; }
.slide.message button.primary { margin-top: 6px; }
#keyStatus.ok { color: #2e7d32; }
#keyStatus.bad { color: var(--accent); }
