:root {
  --accent: #ff5468;
  --accent2: #a01226;
  --accent-rgb: 255, 84, 104;
  --bg: #070509;
  --panel: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.10);
  --text: #f6f1f4;
  --muted: rgba(246, 241, 244, 0.58);
  --font: "Tajawal", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 20px;
  --reserve: 232px;   /* vertical space taken by header + title + controls around the 16:9 frame */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- atmosphere ---------- */
#backdrop { position: fixed; inset: 0; z-index: 0; overflow: hidden;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(var(--accent-rgb), 0.20), transparent 62%),
    radial-gradient(760px 480px at 6% 108%, rgba(var(--accent-rgb), 0.13), transparent 60%),
    linear-gradient(180deg, #0b080d, #060408); }
/* Vaelor look: the brand's red/black metallic texture sits behind everything */
#backdrop::before { content: ""; position: absolute; inset: 0; opacity: 0; background: url("themes/vaelor-bg.webp") center / cover no-repeat; transition: opacity 0.8s; }
body.brand-vaelor #backdrop::before { opacity: 0.42; }
body.brand-vaelor #backdrop::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 45%, transparent 30%, rgba(6, 3, 6, 0.72) 100%); }
#ambient { position: absolute; inset: -12%; width: 124%; height: 124%; object-fit: cover; filter: blur(70px) saturate(1.5); opacity: 0.30; transition: opacity 0.8s; }
#grain { position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: 0.05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }

#app { position: relative; z-index: 2; display: flex; flex-direction: column; height: 100%; }

/* ---------- header ---------- */
#top { display: flex; align-items: center; gap: 14px; padding: 10px 22px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
#brandMark { flex: none; height: 42px; width: auto; filter: drop-shadow(0 5px 12px rgba(0, 0, 0, 0.65)) drop-shadow(0 0 16px rgba(var(--accent-rgb), 0.38)); }
.vmark { width: 54px; height: auto; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.7)) drop-shadow(0 0 18px rgba(var(--accent-rgb), 0.45)); }
#brandLogo { height: 34px; max-width: 120px; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6)); border-radius: 8px; }
.brandText { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
#brandName { font-weight: 800; font-size: 15px; letter-spacing: 0.22em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(180deg, #fff, #c9c4d6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brandSub { font-size: 9.5px; letter-spacing: 0.34em; color: var(--accent); font-weight: 700; margin-top: 3px; }
.grow { flex: 1; }

#peopleWrap { position: relative; }
#people { display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 6px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: inherit; font: inherit; cursor: pointer; transition: 0.18s; }
#people:hover, #people[aria-expanded="true"] { border-color: rgba(var(--accent-rgb), 0.55); background: rgba(var(--accent-rgb), 0.12); }
#people[hidden] { display: none; }

#peopleList { position: absolute; z-index: 15; top: calc(100% + 10px); left: 0; width: 250px; max-width: calc(100vw - 24px); max-height: min(340px, 60vh); overflow: auto; padding: 8px; background: rgba(17, 11, 19, 0.94); animation: pop 0.14s ease-out; }
#peopleList h4 { margin: 4px 8px 8px; font-size: 11px; letter-spacing: 0.16em; color: var(--accent); font-weight: 800; }
#peopleList .row { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; }
#peopleList .row:hover { background: rgba(255, 255, 255, 0.06); }
#peopleList .row img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #241a26; flex: none; box-shadow: 0 0 0 2px rgba(var(--accent-rgb), 0.35); }
#peopleList .row span { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#peopleList .row small { margin-inline-start: auto; font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
#peopleList .empty { padding: 10px 8px 12px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
#people .stack { display: flex; }
#people .stack img, #people .stack .more { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #120d14; margin-inline-start: -9px; object-fit: cover; background: #241a26; }
#people .stack > :first-child { margin-inline-start: 0; }
#people .stack .more { display: grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--muted); }
#people b { font-size: 13px; font-weight: 700; }
#people small { color: var(--muted); font-size: 11.5px; }

button.ghost { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--muted); transition: 0.18s; padding: 0; }
button.ghost:hover { color: #fff; border-color: rgba(var(--accent-rgb), 0.55); background: rgba(var(--accent-rgb), 0.12); }
button.ghost svg { width: 17px; height: 17px; }
button.ghost.wide { width: 100%; border-radius: 12px; height: 36px; font-size: 13px; }

/* ---------- stage ---------- */
#stage { position: relative; flex: 1; min-height: 0; display: flex; justify-content: center; padding: 4px 22px 18px; }
#theater { width: 100%; max-width: 1480px; display: flex; flex-direction: column; min-height: 0; gap: 12px; }
#frameWrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }

/* the video frame: thin metallic bezel + accent glow, 16:9 contained in the free space */
#frame { position: relative; aspect-ratio: 16 / 9; width: min(100%, calc((100vh - var(--reserve)) * 16 / 9)); width: min(100%, calc((100dvh - var(--reserve)) * 16 / 9)); max-height: 100%; border-radius: var(--radius); background: #000; padding: 0;
  box-shadow: 0 28px 70px -18px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.07), 0 0 80px -18px rgba(var(--accent-rgb), 0.45); overflow: hidden; }
#frame::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 4;
  padding: 1.5px; background: linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.06) 38%, rgba(var(--accent-rgb), 0.6) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
#vid { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
#playerBox, #playerBox iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
/* with our own controls the iframe never takes the pointer: a click on the picture toggles play, double-click goes fullscreen, and YouTube's hover/tap chrome never appears */
body:not(.native) #playerBox iframe { pointer-events: none; }
body:not(.native) #frame { cursor: pointer; }

.spinner { position: absolute; z-index: 3; inset: 0; display: grid; place-items: center; pointer-events: none; }
.spinner::before { content: ""; width: 46px; height: 46px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.12); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.overlayIn { position: absolute; inset: 0; z-index: 6; display: grid; place-content: center; justify-items: center; gap: 6px; text-align: center; background: rgba(7, 5, 9, 0.78); backdrop-filter: blur(10px); padding: 20px; }
.overlayIn h2 { margin: 6px 0 0; font-size: 20px; }
.overlayIn p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

/* preparing the video on our server (the quality you pick is fetched in full before it plays) */
#prep { z-index: 7; gap: 4px; }
.prepWrap { position: relative; width: 92px; height: 92px; margin-bottom: 8px; display: grid; place-items: center; }
.prepRing { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(var(--accent) var(--p, 0%), rgba(255, 255, 255, 0.10) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px)); mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px)); }
.prepWrap span { font-weight: 800; font-size: 19px; color: #fff; font-variant-numeric: tabular-nums; }
.prepBar { width: min(320px, 70%); height: 5px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin-top: 4px; }
.prepBar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.7); transition: width 0.4s; }

/* poster facade: our own cover (instead of YouTube's pre-play chrome) until the first frame plays */
#poster { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; background: #000; }
#poster::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, rgba(0,0,0,0.05), rgba(0,0,0,0.55)), linear-gradient(180deg, transparent 55%, rgba(0,0,0,0.65)); }
#posterImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#poster .bigPlay { position: relative; z-index: 2; width: 88px; height: 88px; }
#poster .bigPlay svg { width: 34px; height: 34px; }

/* ---------- meta ---------- */
#meta { display: flex; flex-direction: column; gap: 6px; padding: 0 4px; }
#title { margin: 0; font-size: 20px; font-weight: 800; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#subline { display: flex; align-items: center; gap: 14px; min-height: 22px; }
.sync { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: #6b6470; box-shadow: 0 0 0 0 transparent; }
.sync[data-state="ok"] i { background: #4be08c; box-shadow: 0 0 10px 1px rgba(75, 224, 140, 0.7); }
.sync[data-state="sync"] i { background: #ffc24a; box-shadow: 0 0 10px 1px rgba(255, 194, 74, 0.6); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
#toast { font-size: 12.5px; color: var(--accent); opacity: 0; transform: translateY(3px); transition: 0.3s; }
#toast.show { opacity: 1; transform: none; }

/* ---------- controls ---------- */
.glass { background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.03)); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(14px); box-shadow: 0 10px 40px -12px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.08); }
#controls { display: flex; align-items: center; gap: 14px; padding: 10px 16px; }
button.round { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 6px 22px rgba(var(--accent-rgb), 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35); transition: transform 0.12s, filter 0.2s; }
button.round:hover { filter: brightness(1.1); }
button.round:active { transform: scale(0.94); }
button.round svg { width: 20px; height: 20px; }
.time { flex: none; font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); min-width: 40px; text-align: center; }

#seek { position: relative; flex: 1; height: 28px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
#seek .track { position: relative; width: 100%; height: 5px; border-radius: 99px; background: rgba(255, 255, 255, 0.14); overflow: hidden; transition: height 0.15s; }
#seek:hover .track, #seek.drag .track { height: 8px; }
#seekFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.7); }
#seekThumb { position: absolute; top: 50%; left: 0; width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.3), 0 3px 10px rgba(0, 0, 0, 0.6); transform: scale(0); transition: transform 0.15s; pointer-events: none; }
#seek:hover #seekThumb, #seek.drag #seekThumb { transform: scale(1); }
#seekTip { position: absolute; bottom: 30px; left: 0; transform: translateX(-50%); padding: 3px 8px; border-radius: 8px; background: rgba(15, 10, 17, 0.95); border: 1px solid var(--line); font-size: 11.5px; font-variant-numeric: tabular-nums; opacity: 0; pointer-events: none; transition: opacity 0.12s; }
#seek:hover #seekTip, #seek.drag #seekTip { opacity: 1; }

.vol { display: flex; align-items: center; gap: 4px; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 78px; height: 5px; border-radius: 99px; background: linear-gradient(90deg, var(--accent) var(--v, 100%), rgba(255, 255, 255, 0.16) var(--v, 100%)); outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: #fff; }

.qual { display: flex; align-items: center; gap: 8px; flex: none; }
select { background: rgba(255, 255, 255, 0.06); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 12.5px; outline: none; cursor: pointer; }
select:hover { border-color: rgba(var(--accent-rgb), 0.55); }
select option { background: #160f18; }
#qualityNow { font-size: 11px; color: var(--accent); letter-spacing: 0.04em; min-width: 38px; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(7, 5, 9, 0.82); backdrop-filter: blur(16px); padding: 24px; text-align: center; }
.card { max-width: 460px; display: grid; justify-items: center; }
.card h1 { margin: 18px 0 8px; font-size: 22px; font-weight: 800; }
.card p { margin: 0 0 20px; color: var(--muted); line-height: 1.8; font-size: 14.5px; }
.card b, .overlayIn b { color: var(--accent); }
.ring { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; position: relative; background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.02)); border: 1px solid var(--line); box-shadow: 0 0 60px -10px rgba(var(--accent-rgb), 0.6); }
.ring::before { content: ""; position: absolute; inset: -7px; border-radius: 50%; border: 1px dashed rgba(var(--accent-rgb), 0.5); animation: spin 18s linear infinite; }
.ring.warn { box-shadow: 0 0 60px -10px rgba(255, 190, 70, 0.55); }
.mark { width: 38px; height: 38px; color: var(--accent); }
.mark svg { width: 100%; height: 100%; }
.ring.warn .mark { color: #ffc24a; }

.bigPlay { width: 104px; height: 104px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 14px 50px rgba(var(--accent-rgb), 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.4); animation: breathe 2.4s ease-in-out infinite; }
.bigPlay svg { width: 40px; height: 40px; margin-inline-start: 4px; }
@keyframes breathe { 50% { transform: scale(1.06); box-shadow: 0 18px 70px rgba(var(--accent-rgb), 0.75), inset 0 2px 0 rgba(255, 255, 255, 0.4); } }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: 0; border-radius: 999px; padding: 11px 30px; font-weight: 800; font-size: 15px; box-shadow: 0 8px 28px rgba(var(--accent-rgb), 0.4); }
button.primary:hover { filter: brightness(1.1); }

/* ---------- settings ---------- */
#settings { position: absolute; z-index: 12; top: 62px; inset-inline-end: 20px; width: 290px; padding: 16px 18px; background: rgba(17, 11, 19, 0.92); }
#settings h3 { margin: 0 0 12px; font-size: 14px; letter-spacing: 0.08em; }
#settings .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 4px; }
#settings .hint { color: var(--muted); font-size: 11.5px; margin: 0 0 12px; }
#settings input[type="checkbox"] { width: 38px; height: 22px; -webkit-appearance: none; appearance: none; border-radius: 99px; background: rgba(255, 255, 255, 0.18); position: relative; cursor: pointer; transition: 0.2s; }
#settings input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: 0.2s; }
#settings input[type="checkbox"]:checked { background: var(--accent); }
#settings input[type="checkbox"]:checked::after { inset-inline-start: 19px; }
.keys { display: grid; gap: 6px; margin: 14px 0; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); font-size: 12px; color: var(--muted); }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; margin-inline-end: 4px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07); font: 600 11px ui-monospace, Consolas, monospace; color: var(--text); text-align: center; }

#diag { position: absolute; z-index: 20; inset: 58px 14px 14px 14px; margin: 0; padding: 14px; overflow: auto; border-radius: 14px; background: rgba(0, 0, 0, 0.94); border: 1px solid var(--line); color: #b6f7c0; font: 11.5px/1.55 ui-monospace, Consolas, monospace; direction: ltr; text-align: left; white-space: pre-wrap; }

/* ---------- fullscreen: controls float over the video and fade out when idle ---------- */
body.fs #top, body.fs #meta { display: none; }
body.fs #stage { padding: 0; }
body.fs #theater { max-width: none; gap: 0; }
body.fs #frame { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; border-radius: 0; box-shadow: none; }
body.fs #frame::after { display: none; }
body.fs #frameWrap { align-items: stretch; }
body.fs #controls { position: absolute; z-index: 9; left: 24px; right: 24px; bottom: 22px; transition: opacity 0.35s, transform 0.35s; }
body.fs.idle #controls { opacity: 0; transform: translateY(14px); pointer-events: none; }
body.fs.idle { cursor: none; }

@media (min-width: 1500px) {
  #title { font-size: 23px; }
  #controls { padding: 12px 20px; gap: 18px; }
}
@media (max-width: 520px) {
  .brandSub { display: none; }
  #brandName { letter-spacing: 0.16em; font-size: 14px; }
  #people { gap: 6px; padding: 4px 10px 4px 5px; }
  #people small { display: none; }
  #people .stack img, #people .stack .more { width: 22px; height: 22px; margin-inline-start: -8px; }
  #people .stack > :nth-child(n+4) { display: none; }
  #top { gap: 8px; }
}
@media (max-width: 720px) {
  :root { --reserve: 268px; }
  #top { padding: 10px 14px; gap: 10px; }
  #brandLogo { height: 28px; max-width: 96px; }
  #brandMark { height: 34px; }
  #stage { padding: 2px 12px 12px; }
  #theater { gap: 10px; }
  /* row 1: play, time, scrubber, length, fullscreen -- row 2: mute + quality */
  #controls { gap: 8px 10px; padding: 10px 12px; flex-wrap: wrap; }
  #playBtn { order: 1; } #tCur { order: 2; min-width: 34px; } #seek { order: 3; flex: 1 1 90px; min-width: 90px; }
  #tDur { order: 4; min-width: 34px; } #fsBtn { order: 5; }
  .vol { order: 6; margin-inline-end: auto; } .qual { order: 7; margin-inline-start: auto; }
  .vol input { display: none; }
  #poster .bigPlay { width: 64px; height: 64px; }
  #poster .bigPlay svg { width: 26px; height: 26px; }
  #title { font-size: 16px; -webkit-line-clamp: 2; }
  #qualityNow { display: none; }
  #settings { inset-inline-end: 12px; width: min(300px, calc(100vw - 24px)); }
  #peopleList { width: min(280px, calc(100vw - 24px)); }
  .card h1 { font-size: 19px; }
  .bigPlay { width: 92px; height: 92px; }
}
/* phones held sideways: video first, everything else compact */
@media (max-height: 540px) {
  :root { --reserve: 128px; }
  #top { padding: 6px 14px; }
  #brandLogo { height: 24px; }
  #brandMark { height: 30px; }
  .brandSub { display: none; }
  #meta { display: none; }
  #stage { padding: 0 14px 8px; }
  #theater { gap: 8px; }
  #controls { padding: 6px 12px; flex-wrap: nowrap; }
  #playBtn, #tCur, #seek, #tDur, .vol, .qual, #fsBtn { order: 0; margin: 0; }
  #seek { flex: 1 1 auto; }
  button.round { width: 38px; height: 38px; }
  .vol input { display: block; width: 60px; }
}
@media (max-height: 540px) and (max-width: 720px) { .vol input { display: none; } }
/* touch screens: bigger targets, scrub handle always visible */
@media (pointer: coarse) {
  #seek { height: 40px; }
  #seek .track { height: 7px; }
  #seekThumb { transform: scale(1); width: 18px; height: 18px; margin: -9px 0 0 -9px; }
  button.ghost { width: 40px; height: 40px; }
  #people { padding-block: 7px; }
  select { padding: 8px 12px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
