:root {
  --ink: #12111a;
  --ink-2: #1b1a24;
  --paper: #fff6ea;
  --coral: #ff6f5e;
  --coral-deep: #e2543f;
  --sky: #8ecbff;
  --gold: #ffcf6b;
  --muted: rgba(255, 246, 234, 0.62);
  --border: rgba(255, 246, 234, 0.14);
  --font-ar: "Baloo Bhaijaan 2", "Segoe UI", system-ui, sans-serif;
  --font-num: "Fredoka", "Baloo Bhaijaan 2", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-ar);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#stage { position: fixed; inset: 0; overflow: hidden; }

#scene {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* cinematic overlays */
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, transparent 48%, rgba(18, 17, 26, 0.55) 100%);
  mix-blend-mode: multiply;
}

.grain {
  position: absolute; inset: -50%; pointer-events: none;
  opacity: 0.055;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grainShift 0.9s steps(3) infinite;
}

@keyframes grainShift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-2%, 1%); }
  66% { transform: translate(1%, -2%); }
  100% { transform: translate(0, 0); }
}

.bar {
  position: absolute; left: 0; right: 0; height: 0;
  background: #08070d; pointer-events: none; z-index: 4;
  transition: height 620ms var(--ease);
}
.bar-top { top: 0; }
.bar-bottom { bottom: 0; }
body.cinema .bar { height: 7vh; }

/* top hud */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 22px 28px;
  transition: top 620ms var(--ease);
}
body.cinema .hud-top { top: 7vh; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(255, 111, 94, 0.18);
  animation: pulseDot 2.4s ease-in-out infinite;
}
@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 111, 94, 0.18); }
  50% { box-shadow: 0 0 0 8px rgba(255, 111, 94, 0.05); }
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.brand-tag {
  font-family: var(--font-num); font-size: 10.5px; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 9px; background: rgba(18, 17, 26, 0.35);
  backdrop-filter: blur(8px);
}

.shot-chip {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--muted);
  padding: 7px 15px; border-radius: 999px;
  background: rgba(18, 17, 26, 0.4);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
#shotIndex { font-family: var(--font-num); font-weight: 600; color: var(--paper); }
.shot-sep { opacity: 0.35; }
#shotName { color: var(--paper); font-weight: 500; }

/* title card */
.title-card {
  position: absolute; z-index: 5; inset-inline-start: 7%; top: 50%;
  transform: translateY(-50%);
  max-width: 460px; pointer-events: none;
  opacity: 1; transition: opacity 900ms var(--ease), transform 1200ms var(--ease);
}
.title-card.hide { opacity: 0; transform: translateY(-46%); }
.tc-kicker {
  font-size: 12px; letter-spacing: 3.4px; color: var(--gold);
  margin-bottom: 14px; font-weight: 600;
}
.tc-title {
  font-size: clamp(38px, 6vw, 76px); line-height: 1.02; font-weight: 700;
  text-shadow: 0 18px 46px rgba(18, 17, 26, 0.55);
  letter-spacing: -0.5px;
}
.tc-sub {
  margin-top: 16px; font-size: 14.5px; color: rgba(255, 246, 234, 0.78);
  line-height: 1.7; max-width: 34ch;
}

/* captions */
.caption {
  position: absolute; z-index: 6; bottom: 15vh; left: 50%;
  transform: translate(-50%, 12px);
  max-width: min(760px, 82vw);
  text-align: center;
  font-size: clamp(15px, 1.55vw, 21px);
  font-weight: 500; line-height: 1.65;
  padding: 11px 22px;
  border-radius: 14px;
  background: rgba(12, 11, 18, 0.42);
  border: 1px solid rgba(255, 246, 234, 0.09);
  backdrop-filter: blur(10px);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  opacity: 0; transition: opacity 700ms var(--ease), transform 700ms var(--ease);
  pointer-events: none;
}
.caption.show { opacity: 1; transform: translate(-50%, 0); }
body.cinema .caption { bottom: 17vh; }

/* bottom hud */
.hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 7;
  padding: 0 28px 22px; display: flex; flex-direction: column; gap: 14px;
  transition: bottom 620ms var(--ease);
}
body.cinema .hud-bottom { bottom: 7vh; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.ctrl {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-ar); font-size: 13.5px; font-weight: 600;
  color: var(--paper); cursor: pointer;
  padding: 9px 16px; border-radius: 12px;
  background: rgba(24, 22, 34, 0.62);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  transition: transform 260ms var(--ease), background 260ms var(--ease), border-color 260ms var(--ease);
}
.ctrl:hover {
  transform: translateY(-2px);
  background: rgba(38, 35, 52, 0.82);
  border-color: rgba(255, 246, 234, 0.28);
}
.ctrl:active { transform: translateY(0) scale(0.98); }
.ctrl.primary {
  background: linear-gradient(135deg, var(--coral), var(--coral-deep));
  border-color: transparent; color: #fff;
  box-shadow: 0 10px 26px rgba(255, 111, 94, 0.28);
}
.ctrl.primary:hover { background: linear-gradient(135deg, #ff8172, var(--coral-deep)); }
.ctrl.ghost { background: rgba(24, 22, 34, 0.34); }
.ctrl.off { opacity: 0.5; }
.ctrl svg { width: 16px; height: 16px; stroke-width: 2.2; }

.timecode {
  display: flex; align-items: center; gap: 5px; margin-inline-start: 6px;
  font-family: var(--font-num); font-size: 13px; letter-spacing: 0.6px;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
#tcNow { color: var(--paper); font-weight: 600; }
.tc-dash { opacity: 0.4; }

.speed {
  display: flex; gap: 3px; margin-inline-start: auto;
  padding: 3px; border-radius: 11px;
  background: rgba(24, 22, 34, 0.5);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.speed-btn {
  font-family: var(--font-num); font-size: 12px; font-weight: 500;
  color: var(--muted); background: transparent; border: 0;
  padding: 6px 11px; border-radius: 8px; cursor: pointer;
  transition: all 240ms var(--ease);
}
.speed-btn:hover { color: var(--paper); }
.speed-btn.active { background: rgba(255, 246, 234, 0.92); color: var(--ink); }

/* scrubber */
.scrub { position: relative; cursor: pointer; padding: 6px 0; }
.scrub-track {
  height: 4px; border-radius: 99px; overflow: hidden;
  background: rgba(255, 246, 234, 0.16);
}
.scrub-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--coral));
  border-radius: 99px;
}
.ticks { display: flex; gap: 2px; margin-top: 8px; }
.tick {
  flex: 1; font-family: var(--font-ar); font-size: 10.5px;
  color: rgba(255, 246, 234, 0.4); text-align: center;
  padding-top: 3px; border-top: 2px solid transparent;
  transition: color 240ms var(--ease);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tick:hover { color: var(--paper); }
.tick.active { color: var(--gold); border-top-color: var(--coral); }

/* loading */
.loading {
  position: absolute; inset: 0; z-index: 20;
  display: grid; place-items: center; gap: 18px;
  background: radial-gradient(circle at 50% 40%, #1d1a2b, #0b0a10 70%);
  transition: opacity 800ms var(--ease);
}
.loading.done { opacity: 0; pointer-events: none; }
.loading p { font-size: 13.5px; color: var(--muted); letter-spacing: 0.6px; }
.ld-orb {
  width: 54px; height: 54px; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent, var(--coral), var(--gold), transparent);
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 0);
  animation: spin 1.1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* responsive */
@media (max-width: 860px) {
  .hud-top { padding: 16px 18px; }
  .hud-bottom { padding: 0 18px 16px; }
  .brand-tag { display: none; }
  .ctrl span { display: none; }
  .ctrl { padding: 10px 12px; }
  .ctrl.primary span { display: inline; }
  .speed { margin-inline-start: 0; }
  .controls { gap: 8px; }
  .timecode { margin-inline-start: 0; }
  .title-card { inset-inline-start: 6%; max-width: 78vw; }
  .tick { font-size: 9px; }
  body.cinema .bar { height: 5vh; }
  body.cinema .hud-top { top: 5vh; }
  body.cinema .hud-bottom { bottom: 5vh; }
}

@media (max-width: 560px) {
  .ticks { display: none; }
  .caption { bottom: 20vh; font-size: 14px; padding: 9px 14px; }
  .shot-chip { font-size: 11.5px; padding: 6px 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .brand-dot, .ld-orb { animation: none; }
  * { transition-duration: 120ms !important; }
}
