:root {
  --night: #0d1330;      /* sky after dark */
  --night-2: #18204a;    /* raised surface */
  --chalk: #eeecf6;      /* text */
  --dim: #9aa0c3;        /* secondary text */
  --star: #ffc83d;       /* crayon yellow, the one accent */
  --paint-red: #e2583e;  /* only in the lock-screen wash */
  --paint-blue: #3b6cf6; /* only in the lock-screen wash */

  --hand: "Caveat Brush", "Segoe Print", cursive;
  --ui: "Atkinson Hyperlegible", system-ui, sans-serif;

  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --pad: clamp(14px, 2.4vw, 28px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--chalk);
  font: 400 16px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--star); outline-offset: 3px; border-radius: 6px; }

/* ---------- custom cursor (fine pointers only) ---------- */
.cursor { display: none; }
@media (pointer: fine) {
  html, html * { cursor: none !important; }
  .cursor { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 100; }
  .cursor-dot, .cursor-ring {
    position: absolute; left: 0; top: 0; border-radius: 50%;
    translate: var(--x, -100px) var(--y, -100px);
  }
  .cursor-dot {
    width: 6px; height: 6px; margin: -3px 0 0 -3px;
    background: var(--star);
    box-shadow: 0 0 10px rgb(255 200 61 / .7);
  }
  .cursor-ring {
    width: 28px; height: 28px; margin: -14px 0 0 -14px;
    border: 1.5px solid rgb(238 236 246 / .55);
    translate: var(--rx, -100px) var(--ry, -100px);
    transition: width .2s var(--ease-out), height .2s var(--ease-out), margin .2s var(--ease-out),
                background-color .2s, border-color .2s, opacity .25s;
  }
  .cursor.is-hover .cursor-ring {
    width: 42px; height: 42px; margin: -21px 0 0 -21px;
    border-color: rgb(255 200 61 / .8);
    background: rgb(255 200 61 / .1);
  }
  .cursor.is-down .cursor-ring { width: 22px; height: 22px; margin: -11px 0 0 -11px; }
  .cursor.is-hidden :is(.cursor-dot, .cursor-ring), .cursor.is-idle :is(.cursor-dot, .cursor-ring) { opacity: 0; }
}

/* ---------- lock screen ---------- */
.lock {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: var(--pad);
  overflow: hidden;
}
.wash {
  position: absolute; inset: -20%;
  background:
    radial-gradient(38% 30% at 22% 28%, rgb(59 108 246 / .38), transparent 70%),
    radial-gradient(30% 26% at 80% 72%, rgb(226 88 62 / .28), transparent 70%),
    radial-gradient(22% 20% at 70% 20%, rgb(255 200 61 / .16), transparent 70%);
  filter: blur(30px);
}
.lock-inner { position: relative; width: min(100%, 640px); text-align: center; }

.title {
  margin: 0 0 6px;
  font: 400 clamp(44px, 9vw, 68px)/1 var(--hand);
  letter-spacing: .01em;
  color: var(--chalk);
  text-wrap: balance;
}
.title .w { display: inline-block; white-space: nowrap; }
.title .l {
  display: inline-block;
  transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--r, 0deg));
  transition: transform 1.1s var(--ease-out);
}
.title.is-scattered .l { transition: none; }
.lock-sub { margin: 0 0 32px; color: var(--dim); }
.lock-sub em { font-style: normal; color: var(--chalk); }

.pin { position: relative; }
.pin-input {
  position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none;
}
.pin-slots { display: flex; justify-content: center; gap: 14px; }
.pin-slots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid rgb(238 236 246 / .45);
  transition: background-color .15s, border-color .15s, transform .25s var(--ease-out);
}
.pin-slots span.on { background: var(--star); border-color: var(--star); transform: scale(1.1); }
.pin.is-wrong .pin-slots { animation: shake .4s; }
.pin.is-wrong .pin-slots span.on { background: var(--paint-red); border-color: var(--paint-red); }
.pin.is-busy .pin-slots span.on { animation: pulse .8s ease-in-out infinite alternate; }
.pin-msg { min-height: 24px; margin: 14px 0 18px; font-size: 15px; color: var(--dim); }
.pin-msg.err { color: #ff9a85; }

.keypad {
  display: grid; grid-template-columns: repeat(3, 72px);
  justify-content: center; gap: 12px 22px;
}
.keypad button {
  height: 72px; border-radius: 50%;
  font: 400 28px/1 var(--ui);
  background: rgb(238 236 246 / .06);
  transition: background-color .15s, transform .12s var(--ease-out);
  display: grid; place-items: center;
}
.keypad button:hover { background: rgb(238 236 246 / .12); }
.keypad button:active { transform: scale(.94); background: rgb(255 200 61 / .22); }
.keypad button[data-key="back"] { background: none; }
.keypad svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }

@keyframes shake { 20%, 60% { translate: -8px 0; } 40%, 80% { translate: 8px 0; } }
@keyframes pulse { to { opacity: .45; } }

body.is-unlocking .lock { opacity: 0; transform: scale(1.03); transition: opacity .5s ease, transform .5s ease; }

/* ---------- player ---------- */
.player { position: fixed; inset: 0; background: #000; }
.player video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }

.gesture { position: absolute; inset: 0 0 96px; display: grid; grid-template-columns: 1fr 1.2fr 1fr; }

.top, .controls {
  position: absolute; left: 0; right: 0;
  transition: opacity .3s ease, transform .3s var(--ease-out);
}
.top {
  top: 0; display: flex; align-items: baseline; gap: 14px;
  padding: calc(var(--pad) + env(safe-area-inset-top)) var(--pad) 48px;
  background: linear-gradient(rgb(0 0 0 / .6), transparent);
  pointer-events: none;
}
.brand { margin: 0; font: 400 26px/1 var(--hand); color: var(--star); }
.film { margin: 0; color: var(--dim); font-size: 15px; }

.controls {
  bottom: 0;
  padding: 56px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgb(13 19 48 / .55) 40%, rgb(13 19 48 / .9));
}
.player.is-idle .top { opacity: 0; transform: translateY(-8px); }
.player.is-idle .controls { opacity: 0; transform: translateY(8px); pointer-events: none; }

.row { display: flex; align-items: center; gap: 4px; }
.spacer { flex: 1; }
.btn {
  width: 44px; height: 44px; border-radius: 10px;
  display: grid; place-items: center;
  transition: background-color .15s, color .15s;
}
.btn:hover { background: rgb(238 236 246 / .1); }
.btn:active svg { transform: scale(.9); }
.btn svg { width: 24px; height: 24px; fill: currentColor; transition: transform .12s; }
.btn svg .o { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn svg text { font: 700 7.5px var(--ui); text-anchor: middle; fill: currentColor; }
.btn-text { width: auto; min-width: 44px; padding: 0 10px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

.i-pause, .player.is-playing .i-play { display: none; }
.player.is-playing .i-pause { display: block; }
.i-exit, .player.is-fs .i-enter { display: none; }
.player.is-fs .i-exit { display: block; }

.vol { display: flex; align-items: center; }
.vol .x { display: none; }
.vol.is-muted .x { display: block; }
.vol.is-muted .w1, .vol.is-muted .w2, .vol.is-low .w2 { display: none; }
.vol-range {
  width: 0; opacity: 0; margin: 0;
  transition: width .25s var(--ease-out), opacity .2s, margin .25s;
  appearance: none; background: none; height: 44px;
}
.vol:hover .vol-range, .vol:focus-within .vol-range { width: 84px; opacity: 1; margin: 0 8px 0 2px; }
.vol-range::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--chalk) var(--v, 100%), rgb(238 236 246 / .25) 0); }
.vol-range::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--chalk) var(--v, 100%), rgb(238 236 246 / .25) 0); }
.vol-range::-webkit-slider-thumb { appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: var(--chalk); }
.vol-range::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: var(--chalk); }

.time { margin: 0 0 0 10px; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.time .sep { margin: 0 6px; color: var(--dim); }
#dur { color: var(--dim); }

/* scrubber */
.scrub { position: relative; height: 22px; margin: 0 0 4px; display: flex; align-items: center; touch-action: none; }
.scrub-track { position: relative; width: 100%; height: 4px; border-radius: 2px; background: rgb(238 236 246 / .2); overflow: hidden; transition: height .15s var(--ease-out); }
.scrub:hover .scrub-track, .scrub.is-drag .scrub-track { height: 7px; border-radius: 4px; }
.scrub-buffer, .scrub-fill, .scrub-hover { position: absolute; inset: 0 auto 0 0; width: 0; }
.scrub-buffer { background: rgb(238 236 246 / .3); }
.scrub-hover { background: rgb(238 236 246 / .25); opacity: 0; }
.scrub:hover .scrub-hover { opacity: 1; }
.scrub-fill { background: var(--star); }
.scrub-thumb {
  position: absolute; left: 0; top: 50%; width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px;
  border-radius: 50%; background: var(--star); box-shadow: 0 0 0 4px rgb(255 200 61 / .2);
  scale: 0; transition: scale .15s var(--ease-out);
}
.scrub:hover .scrub-thumb, .scrub.is-drag .scrub-thumb, .scrub:focus-visible .scrub-thumb { scale: 1; }
.scrub-tip {
  position: absolute; bottom: 26px; left: 0; translate: -50% 0;
  padding: 4px 8px; border-radius: 6px;
  background: var(--chalk); color: var(--night);
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.scrub:hover .scrub-tip, .scrub.is-drag .scrub-tip { opacity: 1; }

/* menus */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; bottom: 52px; min-width: 132px;
  padding: 6px; border-radius: 12px;
  background: rgb(24 32 74 / .96);
  box-shadow: 0 12px 32px rgb(0 0 0 / .45);
  display: grid; gap: 2px;
  transform-origin: bottom right;
  animation: pop .18s var(--ease-out);
}
.menu button {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  text-align: left; padding: 9px 12px; border-radius: 8px; font-size: 15px;
}
.menu button:hover { background: rgb(238 236 246 / .08); }
.menu button[aria-checked="true"] { color: var(--star); font-weight: 700; }
.menu button[aria-checked="true"]::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--star); }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }

/* overlays */
.big-play {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--star); color: var(--night);
  display: grid; place-items: center;
  box-shadow: 0 10px 40px rgb(255 200 61 / .3);
  transition: transform .2s var(--ease-out), opacity .2s;
}
.big-play:hover { transform: scale(1.06); }
.big-play svg { width: 36px; height: 36px; fill: currentColor; margin-left: 4px; }
.player.is-playing .big-play, .player.is-waiting .big-play { opacity: 0; pointer-events: none; transform: scale(.8); }

.spinner {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; border: 3px solid rgb(238 236 246 / .2); border-top-color: var(--star);
  animation: spin .8s linear infinite; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.player.is-waiting .spinner { opacity: 1; }
@keyframes spin { to { rotate: 360deg; } }

.flash {
  position: absolute; top: 50%; left: 50%; translate: -50% -50%;
  min-width: 88px; padding: 12px 18px; border-radius: 999px;
  background: rgb(13 19 48 / .7); text-align: center;
  font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums;
  opacity: 0; pointer-events: none;
}
.flash.left { left: 22%; }
.flash.right { left: 78%; }
.flash.show { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: 0; scale: .9; } 20% { opacity: 1; scale: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }

.toast {
  position: absolute; left: var(--pad); bottom: 132px;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 10px 10px 16px; border-radius: 12px;
  background: rgb(24 32 74 / .94); font-size: 15px;
  opacity: 0; translate: 0 8px; pointer-events: none;
  transition: opacity .25s, translate .25s var(--ease-out);
}
.toast.show { opacity: 1; translate: 0 0; pointer-events: auto; }
.toast button { padding: 6px 12px; border-radius: 8px; background: rgb(238 236 246 / .1); font-weight: 700; }
.toast button:hover { background: rgb(238 236 246 / .18); }

@media (max-width: 640px) {
  .time { font-size: 13px; margin-left: 4px; }
  #pipBtn, .vol-range { display: none; }
  .btn { width: 40px; }
  .keypad { grid-template-columns: repeat(3, 68px); gap: 10px 18px; }
  .keypad button { height: 68px; }
  .toast { bottom: 120px; right: var(--pad); }
}
@media (max-width: 400px) {
  .film { display: none; }
  #qualityBtn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
