:root {
  --bg: #141416; --card: #1e1e22; --line: #2e2e35; --ink: #f2f2f2; --mute: #a3a3ad;
  --red: #e31b23; --red2: #ff5a61;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --sub: 20px;
  color-scheme: dark;
}
* { box-sizing: border-box; min-width: 0; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.5 "Noto Sans Georgian", -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; padding-bottom: var(--safe-b); overflow-x: clip; }
[hidden] { display: none !important; }
a { color: var(--red2); }

.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-t) + 8px) 12px 8px; background: rgba(20,20,22,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar h1 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); font-size: 24px; cursor: pointer; }
.icon-btn:active { background: #2a2a30; }

.view { max-width: 820px; margin: 0 auto; padding: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 14px; }
.card h2 { margin: 0 0 6px; font-size: 19px; }
.muted { color: var(--mute); } .small { font-size: 13px; } .hint { color: var(--mute); font-size: 13px; margin: 10px 0 0; }

.url-row { display: flex; gap: 8px; margin: 14px 0 10px; }
input[type=url], input[type=password], select {
  width: 100%; height: 46px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: #111114; border: 1px solid #3a3a42; border-radius: 12px; outline: none;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--red2); outline-offset: 2px; }
.btn { height: 46px; padding: 0 16px; border: 0; border-radius: 12px; font: inherit; font-weight: 600; color: #fff; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--red); } .btn.primary:active { background: #c3121a; }
.btn.ghost { background: #2c2c33; } .btn.wide { width: 100%; margin-top: 6px; }

.recent { list-style: none; margin: 6px 0 0; padding: 0; }
.recent li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.recent li:first-child { border-top: 0; }
.recent img { width: 96px; height: 54px; object-fit: cover; border-radius: 8px; background: #000; flex: none; }
.recent span { font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* player */
#watch { padding: 0 0 14px; }
.stage { position: relative; background: #000; }
.player { position: relative; width: 100%; aspect-ratio: 16 / 9; }
.player iframe, .player #yt { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.subs { position: absolute; left: 0; right: 0; bottom: 16%; display: flex; flex-direction: column; align-items: center; gap: 3px; pointer-events: none; padding: 0 4%; text-align: center; }
.subs span { display: inline; background: rgba(8,8,8,.8); color: #fff; padding: 1px 8px; border-radius: 4px; line-height: 1.45; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.subs .tr { font-size: var(--sub); font-weight: 600; }
.subs .orig { font-size: calc(var(--sub) * .62); } .subs .orig span { color: #d0d0d0; }
.start { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 0; background: rgba(0,0,0,.55); color: #fff; font: 700 22px/1.2 inherit; cursor: pointer; }
.start span { font-size: 14px; font-weight: 500; color: #ddd; }
.unlock { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); border: 0; border-radius: 999px; padding: 10px 16px; background: var(--red); color: #fff; font: 600 14px inherit; }
.fs { position: absolute; right: 4px; top: 4px; width: 40px; height: 40px; font-size: 20px; background: rgba(0,0,0,.35); }

.status { min-height: 22px; padding: 6px 14px 0; color: var(--mute); font-size: 13px; }
.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 8px 14px 0; }
.ctl label { display: block; font-size: 12px; color: var(--mute); margin-bottom: 4px; }
.toggle { width: 100%; height: 46px; border: 1px solid #3a3a42; border-radius: 12px; background: #111114; color: var(--ink); font: inherit; font-size: 15px; }
.toggle[aria-pressed=true] { border-color: var(--red); background: #2a1214; }
.row-vol { display: flex; align-items: center; gap: 10px; padding: 14px; font-size: 13px; color: var(--mute); }
.row-vol input { flex: 1; accent-color: var(--red); }
#dubVolVal { width: 44px; text-align: right; color: var(--ink); }

/* "theater" full screen (works on iPhone, keeps our subtitles) */
body.theater .bar, body.theater .controls, body.theater .row-vol, body.theater .status { display: none; }
body.theater #watch { max-width: none; padding: 0; }
body.theater .stage { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; }
body.theater .player { aspect-ratio: auto; height: 100dvh; width: 100vw; }
body.theater .subs { bottom: calc(10% + var(--safe-b)); }

/* settings */
dialog { width: min(560px, 100vw); max-height: 92dvh; margin: auto auto 0; padding: 0; border: 0; border-radius: 20px 20px 0 0; background: var(--card); color: var(--ink); }
@media (min-width: 600px) { dialog { margin: auto; border-radius: 20px; } }
dialog::backdrop { background: rgba(0,0,0,.6); }
.sheet { padding: 18px 18px calc(18px + var(--safe-b)); }
.sheet h2 { margin: 0 0 6px; } .sheet h3 { margin: 20px 0 8px; font-size: 14px; color: var(--red2); }
.sheet .btn.ghost { margin-top: 8px; }
.field { display: block; margin: 10px 0; font-size: 14px; color: var(--mute); }
.field select, .field input[type=range] { margin-top: 6px; }
.field input[type=range] { width: 100%; accent-color: var(--red); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--red); }
#keyMsg { margin-top: 6px; min-height: 18px; white-space: pre-wrap; }
.ok { color: #8fd98f; } .err { color: #ff8a8a; }

.toast { position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%); z-index: 60; max-width: 90vw; padding: 10px 16px; border-radius: 12px; background: #2c2c33; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
@media (prefers-reduced-motion: no-preference) { .toast { animation: up .2s ease-out; } @keyframes up { from { opacity: 0; transform: translate(-50%, 8px); } } }
.controls select, .controls .toggle { font-size: 14px; padding: 0 8px; }
