:root { --accent: #ff3d5a; --loop: #ffc94d; --bg: #07080b; --panel: #12141a; --chip: #1d212b; --line: #333846; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: #e8e8ea;
  font: 14px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---- Home screen ---- */
#home { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
#searchForm { display: flex; gap: 8px; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--panel);
  max-width: 760px; width: 100%; margin: 0 auto; }
#q { flex: 1; min-width: 0; height: 44px; background: #1d2029; border: 1px solid #2c303c; color: #fff; border-radius: 12px;
  padding: 0 14px; font: 16px inherit; user-select: text; -webkit-user-select: text; outline: none; }
#q:focus { border-color: #4a5266; }
#searchForm button { width: 48px; border: 0; border-radius: 12px; background: var(--accent); display: flex; align-items: center; justify-content: center; }
#searchForm svg { width: 22px; height: 22px; fill: #fff; }
#homeBody { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom); }
#homeBody section { max-width: 760px; margin: 0 auto; padding: 0 12px 16px; }
.sectionHead { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font-size: 13px;
  font-weight: 700; letter-spacing: .5px; text-transform: uppercase; opacity: .65; }
.sectionHead button { background: none; border: 0; font-size: 16px; padding: 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 4px; border-radius: 12px; }
.list li:active { background: #161a22; }
.item { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center; text-align: left; background: none; border: 0; padding: 6px 0; }
.thumb { position: relative; flex: none; width: 128px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: #1d2029; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb i { position: absolute; right: 4px; bottom: 4px; background: #000c; font: 600 11px system-ui, sans-serif; font-style: normal;
  padding: 1px 4px; border-radius: 4px; }
.info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.info b { font-size: 14px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.info span { font-size: 12px; opacity: .6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.forget { flex: none; width: 36px; height: 36px; border: 0; background: none; opacity: .4; font-size: 14px; }
.empty { opacity: .5; font-size: 14px; line-height: 1.5; text-align: center; margin: 32px 0; }

/* ---- Player header ---- */
#top { display: flex; align-items: center; gap: 4px; min-height: 48px; padding: 4px 12px 4px 4px;
  padding-top: max(4px, env(safe-area-inset-top)); background: var(--panel); }
#backBtn { width: 44px; height: 44px; flex: none; border: 0; background: none; display: flex; align-items: center; justify-content: center; }
#backBtn svg { width: 24px; height: 24px; fill: #fff; }
#videoTitle { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Video stage ---- */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#videoClip { position: absolute; overflow: hidden; transform-origin: 50% 50%; will-change: transform; background: #000; }
#videoClip iframe { border: 0; display: block; pointer-events: none; }
#gesture { position: absolute; inset: 0; z-index: 2; touch-action: none; }
#zoomReset { position: absolute; top: 10px; right: 10px; z-index: 3; height: 34px; font-size: 13px; background: #000b; }
#hint { position: absolute; left: 0; right: 0; bottom: 10px; z-index: 3; text-align: center; pointer-events: none;
  font-size: 12px; opacity: .55; transition: opacity 1s; text-shadow: 0 1px 3px #000; }

#flash { position: absolute; left: 50%; top: 50%; width: 84px; height: 84px; margin: -42px; border-radius: 50%;
  background: #000a; z-index: 3; pointer-events: none; display: flex; align-items: center; justify-content: center;
  animation: flash .4s ease-out forwards; }
#flash svg { width: 40px; height: 40px; fill: #fff; }
@keyframes flash { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.4); } }

#countIn { position: absolute; inset: 0; z-index: 4; pointer-events: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: radial-gradient(circle, #000a 0, #0005 45%, transparent 70%); }
#countNum { font: 800 120px/1 system-ui, sans-serif; color: #fff; text-shadow: 0 4px 30px #000; font-variant-numeric: tabular-nums; }
#countNum.pulse { animation: pulse .35s ease-out; }
#countNum.last { color: var(--loop); }
@keyframes pulse { from { transform: scale(1.35); opacity: .6; } to { transform: scale(1); opacity: 1; } }
#countSub { font: 600 14px system-ui, sans-serif; opacity: .8; margin-top: 6px; letter-spacing: .5px; }

#err { position: absolute; left: 12px; right: 12px; bottom: 40px; z-index: 4; background: #2a0d12ee;
  border: 1px solid var(--accent); border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.4; }

/* ---- Dock: scrub track + controls ---- */
#dock { background: var(--panel); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
#track { display: block; width: 100%; height: 120px; touch-action: none; cursor: grab; }
#track.dragging { cursor: grabbing; }
#controls { display: flex; align-items: center; gap: 8px; padding: 6px 10px 2px; touch-action: manipulation; }
#controls .spacer { flex: 1; }

#playBtn { position: relative; width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; transition: transform .08s; }
#playBtn:active { transform: scale(.92); }
#playBtn svg { position: absolute; width: 24px; height: 24px; fill: #fff; }

.chip { height: 40px; min-width: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--chip);
  font-weight: 600; white-space: nowrap; display: flex; align-items: center; justify-content: center; gap: 6px; }
.chip:active { transform: scale(.95); }
.chip.icon { padding: 0; width: 40px; font-size: 16px; }
.chip svg { width: 20px; height: 20px; fill: currentColor; }
.chip.nudge { animation: nudge .25s; }
@keyframes nudge { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
#loopBtn.armed { border: 1px dashed var(--loop); color: var(--loop); }
#loopBtn.on { width: 40px; padding: 0; background: var(--loop); border-color: var(--loop); color: #111; font-size: 18px; }
#settingsInfo { font-size: 13px; font-variant-numeric: tabular-nums; opacity: .85; }
#settingsInfo:empty { display: none; }

/* ---- Settings sheet ---- */
.sheet { position: absolute; left: 10px; right: 10px; bottom: 175px; margin: 0 auto; max-width: 420px; z-index: 6;
  background: #161922f4; border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px 12px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.sheet h4 { margin: 12px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; opacity: .55; }
.sheet .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; }
.sheet .head { margin-top: 2px; }
.sheet button { background: #262b37; border: 0; border-radius: 8px; padding: 8px 12px; font-weight: 600; }
.sheet .close { padding: 6px 10px; }
.speed input { flex: 1; accent-color: var(--accent); height: 32px; }
.speed b { width: 64px; text-align: right; font-size: 18px; font-variant-numeric: tabular-nums; }
.presets { gap: 6px; }
.volume input { flex: 1; accent-color: var(--loop); height: 32px; }
.volume.off { opacity: .4; pointer-events: none; }
.presets button { flex: 1; padding: 8px 0; font-size: 13px; }
.note { font-size: 12px; opacity: .65; margin: 2px 0 0; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper b { min-width: 40px; text-align: center; font-size: 20px; font-variant-numeric: tabular-nums; }
.stepper small { width: 28px; opacity: .6; }
.stepper button { width: 40px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #3a3f4d; border-radius: 15px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff;
  border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: #34c759; }
.switch input:checked + span::before { transform: translateX(20px); }
