:root {
  --bg: #0b0f0e;
  --fg: #eef4f2;
  --dim: #93a5a0;
  --accent: #2ee6a8;
  --behind: rgba(46, 230, 168, .38);
  --ahead: rgba(46, 230, 168, .78);
  --track: rgba(255, 255, 255, .16);
  --panel: rgba(14, 20, 19, .94);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; display: flex; }

.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
  touch-action: none;            /* gestures own every touch on the video area */
  user-select: none;
}

#video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }

.dimmer { position: absolute; inset: 0; pointer-events: none; background: #000; opacity: 0; transition: opacity .12s linear; }

.subs {
  position: absolute; left: 6%; right: 6%; bottom: 92px;
  text-align: center; font-size: 17px; line-height: 1.35; font-weight: 600;
  color: #fff; text-shadow: 0 2px 8px rgba(0, 0, 0, .9);
  pointer-events: none; white-space: pre-line;
}

/* ---------- gestures HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; }

.ripple {
  position: absolute; top: 50%; transform: translate(-50%, -50%) scale(.6);
  padding: 12px 20px; border-radius: 999px;
  background: rgba(0, 0, 0, .55); color: #fff; font-weight: 700; font-size: 15px;
  opacity: 0; transition: opacity .25s ease, transform .25s ease;
  display: flex; align-items: center; gap: 8px;
}
.ripple.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.level {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: none; flex-direction: column; align-items: center; gap: 10px;
  background: rgba(0, 0, 0, .55); padding: 14px 12px; border-radius: 14px;
}
.level.show { display: flex; }
.level-bar { width: 8px; height: 120px; border-radius: 4px; background: var(--track); position: relative; overflow: hidden; }
.level-bar i { position: absolute; left: 0; right: 0; bottom: 0; height: 0%; background: var(--accent); border-radius: 4px; }
.level span { font-size: 12px; color: var(--dim); }

.scrub-preview {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, .7); color: #fff; padding: 8px 14px; border-radius: 10px;
  font-variant-numeric: tabular-nums; font-weight: 600; opacity: 0; transition: opacity .12s;
}
.scrub-preview.show { opacity: 1; }

/* ---------- controls ---------- */
.controls {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(0, 0, 0, .55), transparent 22%, transparent 62%, rgba(0, 0, 0, .72));
  opacity: 1; transition: opacity .22s ease; pointer-events: none;
}
.controls.hide { opacity: 0; }
.controls .top, .controls .bottom { pointer-events: auto; }
.controls.hide .top, .controls.hide .bottom { pointer-events: none; }

.top { display: flex; align-items: center; gap: 10px; }
.title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62%; }
.badge { font-size: 11px; color: var(--dim); border: 1px solid var(--track); padding: 2px 7px; border-radius: 999px; }
.spacer { flex: 1; }

.icon {
  appearance: none; border: 0; background: rgba(255, 255, 255, .1); color: var(--fg);
  width: 34px; height: 34px; border-radius: 9px; font-size: 15px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
}
.icon:active { background: rgba(255, 255, 255, .22); }

.bottom { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.time { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--fg); white-space: nowrap; }
.cacheline { display: flex; justify-content: flex-end; padding: 0 2px; }
.info { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- progress ---------- */
.progress { position: relative; padding: 10px 0; cursor: pointer; }
.ptrack { position: relative; height: 4px; border-radius: 2px; background: var(--track); overflow: visible; }
.ptrack > div { position: absolute; top: 0; height: 100%; border-radius: 2px; left: 0; width: 0; }
.p-buffered { background: rgba(255, 255, 255, .22); }
.p-behind { background: var(--behind); }
.p-ahead { background: var(--ahead); }
.p-played { background: var(--accent); }
.p-thumb {
  position: absolute; top: 50%; width: 12px; height: 12px; margin-left: -6px;
  border-radius: 50%; background: var(--accent); transform: translateY(-50%);
  box-shadow: 0 0 0 3px rgba(46, 230, 168, .22);
}
.progress .tooltip {
  position: absolute; bottom: 26px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .8); color: #fff; font-size: 12px; padding: 4px 8px;
  border-radius: 7px; opacity: 0; pointer-events: none; font-variant-numeric: tabular-nums;
}
.progress .tooltip.show { opacity: 1; }

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 50%; bottom: 96px; z-index: 35; transform: translateX(-50%);
  background: var(--panel); color: var(--fg); padding: 10px 14px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px; font-size: 13px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.toast button {
  appearance: none; border: 0; background: transparent; color: var(--accent);
  font-weight: 700; font-size: 13px; cursor: pointer; padding: 0;
}

/* ---------- spinner ---------- */
.spinner { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner[hidden] { display: none; }
.spinner i {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .2); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- sheet ---------- */
.sheet { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; z-index: 30; }
.sheet[hidden] { display: none; }
.sheet-panel {
  width: 100%; background: var(--panel); border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px;
  max-height: 78%; overflow: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.sheet-row { display: flex; flex-direction: column; gap: 6px; }
.sheet-row > label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; border: 1px solid var(--track); background: rgba(255, 255, 255, .06);
  color: var(--fg); border-radius: 999px; padding: 7px 13px; font-size: 13px; cursor: pointer;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: rgba(46, 230, 168, .12); }
.chip[disabled] { opacity: .45; cursor: not-allowed; }
.sheet-note { font-size: 11px; color: var(--dim); line-height: 1.5; }

/* ---------- start screen ---------- */
.start { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 40; padding: 20px; }
.start[hidden] { display: none; }
.start-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 12px; }
.start-card h1 { font-size: 20px; margin: 0; }
.start-card p { margin: 0; color: var(--dim); font-size: 13px; }
.start-card input {
  background: #121917; border: 1px solid var(--track); color: var(--fg);
  border-radius: 10px; padding: 12px; font-size: 14px; width: 100%;
}
.primary { appearance: none; border: 0; background: var(--accent); color: #04120d; font-weight: 800; padding: 12px; border-radius: 10px; font-size: 14px; cursor: pointer; }
.err { color: #ff8a7a; font-size: 12px; min-height: 16px; }

.stamp { position: absolute; right: 8px; bottom: 2px; font-size: 9px; color: rgba(147, 165, 160, .55); pointer-events: none; }
