/* ============================================
   ATG Play — Watch (player, Netflix-style)
   ============================================ */

body.watch-body { background: #000; overflow: hidden; }

.player-wrap { position: fixed; inset: 0; background: #000; display: flex; align-items: center; justify-content: center; }
#video {
  width: 100%; height: 100%; background: #000;
  object-fit: contain;
  touch-action: none;
}
.player-wrap:fullscreen {
  inset: 0;
  width: 100vw;
  height: 100vh;
  width: 100dvw;
  height: 100dvh;
  transform: none;
}

/* phone landscape: rotate the whole player when the OS can't lock orientation (iOS) */
.player-wrap.rotated {
  inset: auto; top: 50%; left: 50%;
  width: 100vh; height: 100vw;
  width: 100dvh; height: 100dvw;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center center;
}

/* hide native cue rendering — we use #subOverlay instead */
video::cue { background: transparent; color: transparent; text-shadow: none; }

/* ── custom subtitle overlay ── */
.sub-overlay {
  position: absolute; left: 0; right: 0;
  bottom: var(--sub-bottom-idle, 5%);          /* default: low, away from controls when idle */
  z-index: 8; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 0 8%; text-align: center;
  transition: bottom .25s ease;
}
.player-wrap:not(.idle) .sub-overlay { bottom: var(--sub-bottom-active, 18%); }   /* push up when controls visible */

.sub-line {
  display: inline-block; max-width: 90%;
  background: rgba(0,0,0,var(--sub-bg, 0));
  color: var(--sub-color, #fff);
  font-family: "Inter", "Noto Sans Thai", system-ui, sans-serif;
  font-size: var(--sub-font-size, 34px);
  font-weight: var(--sub-weight, 600); line-height: 1.42;
  padding: var(--sub-pad, 0); border-radius: var(--sub-radius, 0);
  text-shadow:
    0 2px 4px rgba(0,0,0,.95),
    0 0 2px rgba(0,0,0,1),
    1px 1px 1px rgba(0,0,0,.95),
    -1px -1px 1px rgba(0,0,0,.95);
  white-space: pre-wrap; word-break: break-word;
}
.sub-line b { font-weight: 800; }
.sub-line i { font-style: italic; }
.player-wrap[data-sub-shadow="none"] .sub-line { text-shadow: none; }
.player-wrap[data-sub-shadow="soft"] .sub-line {
  text-shadow:
    0 1px 2px rgba(0,0,0,.8),
    0 0 2px rgba(0,0,0,.75);
}
.player-wrap[data-sub-shadow="strong"] .sub-line {
  text-shadow:
    0 2px 4px rgba(0,0,0,.95),
    0 0 2px rgba(0,0,0,1),
    1px 1px 1px rgba(0,0,0,.95),
    -1px -1px 1px rgba(0,0,0,.95);
}

/* overlay controls fade with .idle on the wrapper */
.player-wrap.idle { cursor: none; }
.player-wrap.idle .controls, .player-wrap.idle .top-bar { opacity: 0; pointer-events: none; }
.player-wrap.idle .top-bar { transform: translateY(-12px); }
.player-wrap.idle .controls { transform: translateY(14px); }
.player-wrap.controls-locked .controls,
.player-wrap.controls-locked .top-bar,
.player-wrap.controls-locked .skip-btn {
  opacity: 0;
  pointer-events: none;
}

/* ── top bar ── */
.top-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 32px;
  background: linear-gradient(180deg, rgba(0,0,0,.78), transparent);
  transition: opacity .3s, transform .3s; color: #fff;
}
.top-bar .back { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 16px; font-weight: 700; opacity: .95; transition: opacity .2s, transform .2s; }
.top-bar .back:hover { opacity: 1; transform: translateX(-3px); }
.top-bar .back svg { width: 30px; height: 30px; }

/* ── bottom controls ── */
.controls {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 10;
  padding: 0 32px 22px; color: #fff;
  background: linear-gradient(0deg, rgba(0,0,0,.9) 6%, rgba(0,0,0,.42) 52%, transparent);
  transition: opacity .3s, transform .3s;
}

/* seek row + remaining time */
.seek-row { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.seek { position: relative; flex: 1; height: 5px; background: rgba(255,255,255,.28); border-radius: 100px; cursor: pointer; transition: height .12s ease; touch-action: none; }
.seek-row:hover .seek { height: 8px; }
.seek-buffer { position: absolute; top: 0; height: 100%; background: rgba(255,255,255,.42); border-radius: 100px; }
.seek-fill { position: absolute; top: 0; height: 100%; background: var(--accent); border-radius: 100px; }
.seek-knob {
  position: absolute; top: 50%; width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
  transform: translate(-50%, -50%) scale(0); transition: transform .12s ease; box-shadow: 0 0 9px rgba(229,9,20,.75);
}
.seek-row:hover .seek-knob { transform: translate(-50%, -50%) scale(1); }
.seek-tip {
  position: absolute; bottom: 18px; transform: translateX(-50%);
  background: rgba(0,0,0,.82); border: 1px solid var(--border-strong); border-radius: 9px;
  padding: 5px; box-shadow: var(--shadow); pointer-events: none;
  opacity: 0; transition: opacity .12s, transform .12s;
}
.seek-tip.show { opacity: 1; }
.seek-row:hover .seek-tip { transform: translateX(-50%) translateY(-2px); }
.seek-thumb { display: block; width: 168px; height: 94px; border-radius: 5px; background: #000; object-fit: cover; }
.seek-tip-time { display: block; text-align: center; margin-top: 5px; font-size: 13px; font-weight: 700; color: #fff; font-variant-numeric: tabular-nums; }
.time-remain { font-size: 14px; color: #e6e6ec; font-weight: 600; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* control row: left group · centered title · right group */
.ctrl-row { display: flex; align-items: center; gap: 22px; }
.ctrl-left, .ctrl-right { display: flex; align-items: center; gap: 22px; }
.ctrl-right { gap: 24px; }
.ctrl-title { flex: 1; min-width: 0; text-align: center; font-size: 15px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 12px; }
.ctrl-btn { background: none; border: none; color: #fff; cursor: pointer; display: flex; padding: 0; opacity: .92; transition: opacity .15s, transform .15s; }
.ctrl-btn:hover { opacity: 1; transform: scale(1.14); }
.ctrl-btn:active { transform: scale(.96); }
.ctrl-btn svg { width: 28px; height: 28px; }
.ctrl-btn.big svg { width: 36px; height: 36px; }

/* volume — slider expands on hover */
.vol { display: flex; align-items: center; gap: 6px; }
.vol input { width: 0; opacity: 0; accent-color: var(--accent); cursor: pointer; transition: width .2s, opacity .2s; }
.vol:hover input, .vol:focus-within input { width: 84px; opacity: 1; }

/* popup menus (quality / audio / subtitles / speed) */
.quality-wrap { position: relative; }
.quality-menu {
  position: absolute; bottom: 50px; right: 0; min-width: 180px;
  background: rgba(14,14,19,.97); border: 1px solid var(--border-strong); border-radius: 10px; padding: 6px;
  box-shadow: var(--shadow); backdrop-filter: blur(12px);
  opacity: 0; pointer-events: none; transform: translateY(10px); transition: var(--transition);
}
.quality-menu.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.quality-menu .menu-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text3); padding: 6px 12px 5px; }
.quality-menu button { display: block; width: 100%; text-align: left; padding: 9px 12px 9px 30px; border-radius: 7px; background: none; border: none; color: var(--text2); font: inherit; font-size: 14px; cursor: pointer; position: relative; transition: background var(--t-fast, .16s), color var(--t-fast, .16s); }
.quality-menu button:hover { background: var(--surface2); color: #fff; }
.quality-menu button.active { color: #fff; font-weight: 700; }
.quality-menu button.active::before { content: "✓"; position: absolute; left: 11px; color: var(--accent); font-weight: 800; }
.quality-menu.settings-menu {
  width: min(560px, calc(100vw - 32px));
  max-height: min(70vh, 430px);
  display: grid;
  grid-template-columns: minmax(150px, .82fr) minmax(290px, 1.38fr);
  align-items: start;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px;
}
.settings-menu .menu-section {
  min-width: 0;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  background: rgba(255,255,255,.028);
  padding: 6px;
}
.settings-menu .quality-section {
  max-height: min(54vh, 350px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.settings-menu .playback-section {
  display: grid;
  gap: 6px;
}
.settings-menu .menu-control {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: var(--text2);
  font-size: 14px;
}
.settings-menu .menu-control > span {
  color: #f1f1f5;
  font-weight: 600;
}
.settings-menu .menu-control em {
  min-width: 38px;
  text-align: right;
  color: var(--text3);
  font-size: 12px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
}
.settings-menu input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}
.watch-select {
  position: relative;
  min-width: 0;
}
.watch-select-btn {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 7px;
  color: #fff;
  font: inherit !important;
  font-size: 13px !important;
  font-weight: 700;
  padding: 7px 10px !important;
  outline: none;
  text-align: left !important;
}
.watch-select-btn::before,
.watch-select-option::before { content: none !important; }
.watch-select-btn:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.28);
}
.watch-select-chevron {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text3);
  transition: transform .16s ease;
}
.watch-select.open .watch-select-chevron { transform: rotate(180deg); }
.watch-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  padding: 5px;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(22,22,30,.98);
  box-shadow: 0 14px 38px rgba(0,0,0,.48);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(-5px) scale(.98);
  pointer-events: none;
  transition: opacity .14s ease, transform .14s ease;
}
.watch-select.open .watch-select-menu {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.quality-menu.settings-menu .watch-select-option {
  padding: 9px 10px !important;
  border-radius: 7px;
  text-align: left;
  color: var(--text2);
}
.quality-menu.settings-menu .watch-select-option:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.quality-menu.settings-menu .watch-select-option.active {
  background: rgba(229,9,20,.22);
  color: #fff;
  font-weight: 800;
}
.settings-menu .swatches {
  display: flex;
  align-items: center;
  gap: 10px;
}
.quality-menu.settings-menu button.swatch {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  padding: 0;
  border: 2px solid rgba(255,255,255,.45);
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 1px 8px rgba(0,0,0,.35);
}
.quality-menu.settings-menu button.swatch:hover {
  background: var(--swatch);
  border-color: #fff;
}
.quality-menu.settings-menu button.swatch.active::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #101014;
  transform: translate(-50%, -50%);
}
.settings-menu .menu-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin: 4px 4px;
  padding: 10px 12px;
  min-height: 48px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.045);
  transition: background var(--t-fast, .16s), border-color var(--t-fast, .16s);
}
.settings-menu .menu-toggle:hover {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.2);
}
.settings-menu .menu-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.settings-menu .toggle-slider {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
  transition: background var(--t-fast, .16s), box-shadow var(--t-fast, .16s);
}
.settings-menu .toggle-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
  transition: transform var(--t-fast, .16s);
}
.settings-menu .menu-toggle input:checked + .toggle-slider {
  background: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), 0 0 16px rgba(229,9,20,.22);
}
.settings-menu .menu-toggle input:checked + .toggle-slider::after {
  transform: translateX(18px);
}
.settings-menu .toggle-text {
  min-width: 0;
  line-height: 1.25;
}
.settings-menu .playback-toggles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
.quality-menu.settings-menu button.menu-reset {
  width: calc(100% - 12px);
  margin: 5px 6px 2px;
  padding: 8px 10px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.06);
  color: #fff;
}
.quality-menu.settings-menu button.menu-reset:hover {
  background: rgba(255,255,255,.12);
}

/* mobile gestures */
.mobile-lock-btn {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 14;
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 50%;
  background: rgba(8,8,12,.52);
  color: #fff;
  cursor: pointer;
  opacity: .96;
  transition: opacity .2s, transform .2s, background .2s;
  backdrop-filter: blur(10px);
}
.mobile-lock-btn svg { width: 22px; height: 22px; }
.mobile-lock-btn:active { transform: scale(.94); }
.player-wrap.idle:not(.controls-locked) .mobile-lock-btn { opacity: 0; pointer-events: none; }
.player-wrap.controls-locked .mobile-lock-btn {
  display: flex;
  opacity: 1;
  background: rgba(20,20,26,.72);
  border-color: rgba(255,255,255,.36);
}
.gesture-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}
.skip-flash,
.gesture-hud,
.scrub-hud {
  position: absolute;
  left: 50%;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  pointer-events: none;
  opacity: 0;
}
.skip-flash {
  width: min(42vw, 190px);
  height: min(42vw, 190px);
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255,255,255,.16), rgba(255,255,255,.06) 48%, transparent 70%);
  border: 1px solid rgba(255,255,255,.18);
  font-size: 24px;
  font-weight: 900;
  transform: translate(-50%, -50%) scale(.82);
}
.skip-left { left: 26%; }
.skip-right { left: 74%; }
.skip-flash.show { animation: skipFlash .56s ease-out; }
@keyframes skipFlash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.74); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.12); }
}
.gesture-hud,
.scrub-hud {
  min-width: 138px;
  min-height: 54px;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(0,0,0,.62);
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 16px 44px rgba(0,0,0,.42);
  backdrop-filter: blur(10px);
  transform: translate(-50%, -50%) scale(.96);
  transition: opacity .12s, transform .12s;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
}
.gesture-hud.show,
.scrub-hud.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.scrub-hud {
  flex-direction: column;
  gap: 2px;
  min-width: 168px;
}
.scrub-hud span {
  color: var(--accent-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.scrub-hud strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

/* center play & loading */
.center-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 9; pointer-events: none; }
.center-overlay .spinner { width: 64px; height: 64px; border-width: 5px; }
.big-play { width: 90px; height: 90px; border-radius: 50%; background: rgba(229,9,20,.92); display: flex; align-items: center; justify-content: center; cursor: pointer; pointer-events: auto; transition: var(--transition); box-shadow: 0 10px 34px rgba(0,0,0,.5); }
.big-play:hover { transform: scale(1.08); background: var(--accent-2); }
.big-play svg { width: 44px; height: 44px; color: #fff; margin-left: 5px; }

/* play/pause tap feedback */
.tap-flash { position: absolute; width: 92px; height: 92px; border-radius: 50%; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; }
.tap-flash svg { width: 44px; height: 44px; color: #fff; }
.tap-flash.go { animation: tapFlash .5s ease-out; }
@keyframes tapFlash { 0% { opacity: .92; transform: scale(.65); } 100% { opacity: 0; transform: scale(1.35); } }

/* skip intro / outro / next button */
.skip-btn {
  position: absolute; bottom: 128px; right: 36px; z-index: 11;
  background: rgba(20,20,26,.82); color: #fff; border: 1.5px solid rgba(255,255,255,.55);
  border-radius: 8px; padding: 12px 26px; font: inherit; font-size: 16px; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow); transition: var(--transition); backdrop-filter: blur(6px);
}
.skip-btn:hover { background: #fff; color: #0b0b0f; border-color: #fff; transform: translateY(-2px); }
.skip-btn.hidden { display: none; }

.player-error { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 16px; color: #fff; text-align: center; z-index: 12; padding: 24px; }
.player-error.show { display: flex; }

@media (max-width: 640px) {
  .top-bar { padding: 16px 18px; }
  .top-bar .back span { display: none; }
  .controls { padding: 0 max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .ctrl-row { gap: 14px; }
  .ctrl-left, .ctrl-right { gap: 14px; }
  .ctrl-title { display: none; }
  .ctrl-btn { min-width: 42px; min-height: 42px; align-items: center; justify-content: center; }
  .ctrl-btn svg { width: 26px; height: 26px; }
  .ctrl-btn.big svg { width: 32px; height: 32px; }
  .vol { display: none; }
  .vol:hover input { width: 64px; }
  .mobile-lock-btn { display: flex; }
  .quality-menu {
    right: max(-8px, calc(env(safe-area-inset-right) * -1));
    max-width: calc(100vw - 28px);
  }
  .quality-menu.settings-menu {
    width: min(500px, calc(100vw - 28px));
    max-height: min(74vh, 440px);
    grid-template-columns: 1fr;
  }
  .settings-menu .quality-section { max-height: 180px; }
  .settings-menu .menu-control {
    grid-template-columns: 78px minmax(0, 1fr) 50px;
    min-height: 48px;
  }
  .skip-btn {
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(108px + env(safe-area-inset-bottom));
    padding: 10px 18px;
    font-size: 14px;
  }
  .sub-line { font-size: min(var(--sub-font-size, 34px), 32px); }
}

@media (max-width: 820px) and (orientation: landscape) {
  .top-bar { padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left)); }
  .controls { padding: 0 max(18px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
  .ctrl-row { gap: 12px; }
  .ctrl-left, .ctrl-right { gap: 10px; }
  .ctrl-btn { min-width: 40px; min-height: 40px; align-items: center; justify-content: center; }
  .ctrl-btn svg { width: 24px; height: 24px; }
  .ctrl-btn.big svg { width: 30px; height: 30px; }
  .ctrl-title, .vol { display: none; }
  .mobile-lock-btn { display: flex; }
  .sub-overlay { padding: 0 12%; }
  .sub-line { font-size: min(var(--sub-font-size, 34px), 30px); }
  .quality-menu.settings-menu {
    width: min(620px, calc(100vw - 34px));
    grid-template-columns: minmax(140px, .82fr) minmax(300px, 1.38fr);
    max-height: min(78vh, 360px);
  }
  .settings-menu .quality-section { max-height: min(62vh, 290px); }
}
