/* ---------- player ---------- */
.player {
  --p-pad: clamp(12px, 2.5vw, 48px);
  --p-btn: 44px;
  --p-ico: 26px;
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background: #000;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.player[hidden], .player [hidden] { display: none !important; }
.player video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.player.idle { cursor: none; }
.player.native video { visibility: hidden; }

/* ---------- on-screen display ---------- */
.osd {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(rgba(0, 0, 0, 0.72), transparent 22%, transparent 64%, rgba(0, 0, 0, 0.88));
  transition: opacity 0.25s ease;
}
.player.idle .osd { opacity: 0; pointer-events: none; }
.player.has-panel .osd, .player.has-panel .p-upnext, .player.has-panel .p-subs { display: none; }
.osd-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) var(--p-pad) 14px;
}
.osd-title { min-width: 0; }
.osd-title-main, .osd-title-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.osd-title-main { font-size: clamp(1rem, 1.8vw, 1.6rem); font-weight: 600; }
.osd-title-sub { margin-top: 2px; color: #d6d6d6; font-size: clamp(0.85rem, 1.3vw, 1.15rem); }
.osd-bottom { padding: 0 var(--p-pad) max(16px, env(safe-area-inset-bottom)); }
.controls { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.controls .spacer { flex: 1; }
.time { margin-left: 10px; color: #ddd; font-size: 0.95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.p-ends { margin-left: 10px; color: #aaa; }

.player .icon-btn { width: var(--p-btn); height: var(--p-btn); color: #fff; }
.player .icon-btn svg { width: var(--p-ico); height: var(--p-ico); }
.player .icon-btn.big svg { width: calc(var(--p-ico) * 1.4); height: calc(var(--p-ico) * 1.4); }
.player .icon-btn:focus-visible { background: var(--accent); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9); }
.player .icon-btn text { fill: currentColor; font-family: inherit; }

/* ---------- seek bar ---------- */
.seek { position: relative; height: 24px; }
.seek-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 10px;
  height: 4px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.25);
  transition: height 0.12s ease, top 0.12s ease;
}
.seek:hover .seek-track, .seek:focus-within .seek-track { top: 9px; height: 6px; }
.seek-buffer, .seek-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.seek-buffer { background: rgba(255, 255, 255, 0.35); }
.seek-fill { background: var(--accent); }
.seek input, .vol {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  cursor: pointer;
  margin: 0;
}
.seek input { position: absolute; inset: 0; width: 100%; height: 24px; }
.seek input::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.seek input::-moz-range-track { height: 4px; background: transparent; }
.seek input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--accent); }
.seek input::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--accent); }
.seek input:focus-visible { outline: none; box-shadow: none; }
.seek input:focus-visible::-webkit-slider-thumb { background: #fff; box-shadow: 0 0 0 5px var(--accent); }
.seek input:focus-visible::-moz-range-thumb { background: #fff; box-shadow: 0 0 0 5px var(--accent); }
.seek-bubble {
  position: absolute;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(20, 20, 20, 0.92);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
}
.vol { width: 90px; height: 24px; }
.vol::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); }
.vol::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.35); }
.vol::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fff; }
.vol::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; }
.vol:focus-visible { box-shadow: none; }
.vol:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--accent); }
.vol:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 5px var(--accent); }

/* ---------- subtitles layer ---------- */
.p-subs {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.player video::cue { background: rgba(0, 0, 0, 0.6); }

/* ---------- toast and double-tap ripple ---------- */
.p-toast {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.85);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  white-space: pre;
  pointer-events: none;
}
.p-ripple {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.2rem;
  font-weight: 600;
  pointer-events: none;
}
.p-ripple.left { left: 0; border-radius: 0 50% 50% 0; }
.p-ripple.right { right: 0; border-radius: 50% 0 0 50%; }
.p-ripple.center { display: none; }

/* ---------- menus ---------- */
.p-menu {
  position: absolute;
  right: var(--p-pad);
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 84px);
  z-index: 3;
  width: min(360px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  background: rgba(24, 24, 24, 0.97);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.menu-head {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-weight: 600;
}
.menu-back {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-left: -8px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.menu-back svg { width: 22px; height: 22px; }
.menu-back:focus-visible { background: var(--accent); box-shadow: none; }
.menu-list { overflow-y: auto; padding: 6px 0; overscroll-behavior: contain; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 8px 14px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: rgba(255, 255, 255, 0.08); }
.menu-item:focus-visible { background: var(--accent); color: #fff; box-shadow: none; }
.menu-item[disabled] { opacity: 0.45; cursor: default; }
.menu-check, .menu-icon { display: grid; place-items: center; width: 22px; height: 22px; flex: none; }
.menu-check svg, .menu-icon svg, .menu-go svg { width: 20px; height: 20px; }
.menu-item.on .menu-check { color: var(--accent); }
.menu-item.on:focus-visible .menu-check { color: #fff; }
.menu-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.menu-label small { display: block; color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-item:focus-visible .menu-label small, .menu-item:focus-visible .menu-hint { color: #e8f8ff; }
.menu-hint { flex: none; color: var(--muted); font-size: 0.85rem; }
.menu-go { display: grid; place-items: center; flex: none; color: var(--muted); }
.menu-note { display: flex; align-items: center; gap: 10px; padding: 10px 14px; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.menu-spin {
  width: 16px;
  height: 16px;
  flex: none;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.menu-row { display: flex; gap: 8px; padding: 6px 14px; }
.menu-chip {
  flex: 1;
  min-height: 42px;
  padding: 6px 4px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.menu-chip:focus-visible { background: var(--accent); box-shadow: none; }

/* ---------- playback info ---------- */
.p-stats {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 58px);
  left: var(--p-pad);
  z-index: 2;
  width: min(420px, calc(100vw - 24px));
  padding: 6px 8px 12px 14px;
  border-radius: 10px;
  background: rgba(10, 10, 10, 0.82);
  font-size: 0.85rem;
}
.p-stats-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.p-stats .icon-btn { --p-btn: 36px; --p-ico: 20px; }
.p-stats table { width: 100%; border-collapse: collapse; }
.p-stats th { padding: 3px 12px 3px 0; color: var(--muted); font-weight: 400; text-align: left; white-space: nowrap; vertical-align: top; }
.p-stats td { padding: 3px 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* ---------- up next ---------- */
.p-upnext {
  position: absolute;
  right: var(--p-pad);
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 96px);
  z-index: 2;
  display: flex;
  gap: 14px;
  width: min(520px, calc(100vw - 24px));
  padding: 12px;
  border-radius: 10px;
  background: rgba(20, 20, 20, 0.94);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.player.idle .p-upnext { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 16px); }
.p-upnext-art {
  flex: 0 0 38%;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: #666;
}
.p-upnext-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.p-upnext-art svg { width: 40%; height: 40%; }
.p-upnext-body { min-width: 0; flex: 1; }
.p-upnext-kicker { color: var(--accent); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.p-upnext-title, .p-upnext-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-upnext-title { margin-top: 2px; font-weight: 600; }
.p-upnext-sub { color: #ccc; font-size: 0.9rem; }
.p-upnext-count { margin-top: 4px; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.p-upnext-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.player .btn { padding: 10px 16px; color: #fff; }
.player .btn:focus-visible { box-shadow: 0 0 0 3px #fff; filter: brightness(1.15); }
.player .btn:not(.primary):focus-visible { background: var(--accent); }

/* ---------- dialog (errors, still watching, TV player) ---------- */
.p-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 24px;
  border-radius: 12px;
  background: rgba(28, 28, 28, 0.97);
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.7);
  text-align: center;
  line-height: 1.5;
}
.p-panel h2 { margin: 0 0 8px; font-size: 1.3rem; font-weight: 600; }
.p-panel p { margin: 0 auto; max-width: 52ch; color: #d0d0d0; }
.p-panel-art {
  aspect-ratio: 16 / 9;
  margin: -8px -8px 16px;
  border-radius: var(--radius);
  background: var(--surface-2) center / cover no-repeat;
}
.p-panel-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }
.p-panel.native { background: rgba(16, 16, 16, 0.92); }

/* ---------- phones ---------- */
@media (max-width: 560px) {
  .player { --p-btn: 38px; --p-ico: 22px; }
  .vol, .p-ends, #p-mute, #p-pip { display: none; }
  .controls { gap: 0; flex-wrap: wrap; }
  .time { order: -1; flex: 1 0 100%; margin: 0 0 2px; font-size: 0.85rem; }
  .controls .spacer { flex: 1 1 0; min-width: 0; }
  .p-upnext { flex-direction: column; gap: 8px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 120px); }
  .p-upnext-art { display: none; }
  .p-menu { right: 12px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 104px); }
  .p-stats { left: 12px; font-size: 0.8rem; }
  .p-panel { padding: 18px; }
}

/* ---------- TV and large screens: bigger targets, obvious focus ---------- */
@media (min-width: 1600px) {
  .player { --p-btn: 64px; --p-ico: 36px; }
  .osd-title-main { font-size: 2rem; }
  .osd-title-sub { font-size: 1.4rem; }
  .time { font-size: 1.35rem; }
  .seek { height: 32px; }
  .seek input { height: 32px; }
  .seek-track { top: 13px; height: 6px; }
  .seek:hover .seek-track, .seek:focus-within .seek-track { top: 12px; height: 8px; }
  .seek input::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -10px; }
  .seek input::-moz-range-thumb { width: 24px; height: 24px; }
  .seek-bubble { bottom: 36px; font-size: 1.2rem; }
  .vol { width: 140px; }
  .player .icon-btn:focus-visible { box-shadow: 0 0 0 4px #fff; transform: scale(1.08); }
  .p-toast { font-size: 1.5rem; padding: 12px 24px; }
  .p-menu { width: 520px; font-size: 1.35rem; bottom: 150px; }
  .menu-head { min-height: 64px; }
  .menu-item { min-height: 64px; padding: 10px 20px; }
  .menu-check, .menu-icon, .menu-check svg, .menu-icon svg, .menu-go svg { width: 28px; height: 28px; }
  .menu-chip { min-height: 58px; }
  .menu-note, .menu-hint, .menu-label small { font-size: 1.05rem; }
  .p-stats { width: 640px; font-size: 1.2rem; top: 120px; }
  .p-upnext { width: 760px; font-size: 1.3rem; bottom: 160px; }
  .p-panel { width: 820px; font-size: 1.35rem; padding: 40px; }
  .p-panel h2 { font-size: 2rem; }
  .player .btn { padding: 16px 28px; font-size: 1.3rem; }
  .player .btn svg { width: 28px; height: 28px; }
  .player .btn:focus-visible { box-shadow: 0 0 0 5px #fff; transform: scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
  .menu-spin { animation-duration: 2.4s; }
}
