:root {
  --bg: #07090c;
  --panel: #0f141a;
  --line: #1d2630;
  --text: #e8eef4;
  --muted: #8a97a6;
  --accent: #7fd4ff;
  --accent-dim: rgba(127, 212, 255, 0.16);
  --bar-h: 64px;
  --gutter: clamp(12px, 2.5vw, 28px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #102030 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

button, select, input { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
/* Three columns so the part selector sits in the exact center, whatever the brand's width. */
.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  min-height: var(--bar-h);
  padding: 10px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 12, 0.7);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 10px; justify-self: start; }
.mark { width: 26px; height: 26px; color: var(--accent); }
.name { font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; font-size: 15px; }

.parts {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.parts button {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas: "num dur" "title title";
  column-gap: 10px;
  align-items: baseline;
  text-align: left;
  min-width: 170px;
  padding: 7px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.parts button:hover { background: rgba(255, 255, 255, 0.04); }
.parts button[aria-selected="true"] { background: var(--accent-dim); box-shadow: inset 0 0 0 1px rgba(127, 212, 255, 0.35); }
.parts button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.parts .num { grid-area: num; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.parts [aria-selected="true"] .num { color: var(--accent); }
.parts .title { grid-area: title; font-weight: 600; white-space: nowrap; }
.parts .dur { grid-area: dur; justify-self: end; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Stage */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: clamp(10px, 2vh, 24px) var(--gutter);
  min-height: 0;
}

.stage {
  position: relative;
  width: min(100%, calc((100dvh - var(--bar-h) - 90px) * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(0, 0, 0, 0.6);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

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

.stage:fullscreen { width: 100%; height: 100%; border-radius: 0; aspect-ratio: auto; }
.stage:-webkit-full-screen { width: 100%; height: 100%; border-radius: 0; }

.hint { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }

/* Big play + spinner + error */
.bigplay {
  position: absolute; inset: 0; margin: auto;
  width: 84px; height: 84px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(7, 9, 12, 0.55);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, opacity 0.2s;
}
.bigplay:hover { transform: scale(1.06); background: rgba(127, 212, 255, 0.25); }
.bigplay svg { width: 36px; height: 36px; fill: #fff; margin-left: 4px; }
.stage:not([data-state="idle"]):not([data-state="paused"]):not([data-state="ended"]) .bigplay { opacity: 0; pointer-events: none; }

.spinner {
  position: absolute; inset: 0; margin: auto; width: 48px; height: 48px;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.stage[data-state="loading"] .spinner { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; padding: 12px 16px; border-radius: 10px; background: rgba(40, 10, 10, 0.85);
  border: 1px solid #5a2323; max-width: 80%; text-align: center;
}

/* Controls */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 28px 14px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), rgba(0, 0, 0, 0));
  transition: opacity 0.25s, transform 0.25s;
}
.stage.hide-ui .controls { opacity: 0; transform: translateY(8px); pointer-events: none; }
.stage.hide-ui { cursor: none; }

.timeline { position: relative; height: 18px; display: flex; align-items: center; }
.track {
  position: absolute; left: 0; right: 0; height: 4px; border-radius: 4px;
  background: rgba(255, 255, 255, 0.18); overflow: hidden; transition: height 0.12s;
}
.timeline:hover .track { height: 6px; }
.buffered, .played { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.buffered { background: rgba(255, 255, 255, 0.28); }
.played { background: var(--accent); }

.timeline input[type="range"] {
  position: relative; width: 100%; height: 18px; margin: 0;
  -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer;
}
.timeline input[type="range"]::-webkit-slider-runnable-track { height: 18px; background: transparent; }
.timeline input[type="range"]::-moz-range-track { height: 18px; background: transparent; }
.timeline input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: 2px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 4px rgba(127, 212, 255, 0.3); opacity: 0; transition: opacity 0.12s;
}
.timeline input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; opacity: 0; transition: opacity 0.12s;
}
.timeline:hover input::-webkit-slider-thumb, .timeline input:focus-visible::-webkit-slider-thumb { opacity: 1; }
.timeline:hover input::-moz-range-thumb, .timeline input:focus-visible::-moz-range-thumb { opacity: 1; }
.timeline input:focus-visible { outline: none; }
.timeline:has(input:focus-visible) .track { box-shadow: 0 0 0 2px var(--accent); }

.hovertime {
  position: absolute; bottom: 22px; transform: translateX(-50%);
  padding: 3px 7px; border-radius: 6px; background: rgba(0, 0, 0, 0.85);
  font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none;
}

.row { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.spacer { flex: 1; }

.icon {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer;
}
.icon:hover { background: rgba(255, 255, 255, 0.1); }
.icon:focus-visible, .quality select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon svg { width: 22px; height: 22px; fill: currentColor; }

.i-pause, .i-muted, .i-exit { display: none; }
.stage[data-state="playing"] .i-play, .stage[data-state="loading"] .i-play { display: none; }
.stage[data-state="playing"] .i-pause, .stage[data-state="loading"] .i-pause { display: block; }
.stage.muted .i-vol { display: none; }
.stage.muted .i-muted { display: block; }
.stage.is-fs .i-enter { display: none; }
.stage.is-fs .i-exit { display: block; }

.volume { display: flex; align-items: center; }
.volume input {
  width: 0; opacity: 0; transition: width 0.18s, opacity 0.18s; accent-color: var(--accent); cursor: pointer;
}
.volume:hover input, .volume:focus-within input { width: 80px; opacity: 1; margin-right: 6px; }

.time { margin-left: 8px; font-size: 13px; font-variant-numeric: tabular-nums; color: #cfd8e1; white-space: nowrap; }
.time .sep { margin: 0 5px; color: var(--muted); }

.quality select {
  height: 30px; padding: 0 8px; border-radius: 7px; border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.4); font-size: 12px; cursor: pointer;
}
.quality select option { background: #111; }

/* Narrow screens */
@media (max-width: 720px) {
  :root { --bar-h: 112px; }
  .bar { grid-template-columns: 1fr; gap: 10px; }
  .brand { justify-self: center; }
  .parts { width: 100%; }
  .parts button { flex: 1; min-width: 0; }
  .parts .title { white-space: normal; font-size: 13px; }
  .stage { border-radius: 10px; }
  .hint { display: none; }
  .volume input, .quality { display: none; }
  .icon { width: 34px; height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0s !important; }
}
