/* ==========================================================================
   course-player.css — SSRobotics course player
   A full-screen learning window: video stage on the left, chaptered playlist
   on the right, progress that survives a refresh.

   Design language follows chaingpt-theme.css: orange (--neon #ff6d00) → gold
   (--neon-2 #ffd700), dark glass panels, rounded corners, soft orange glow.
   Every rule has a [data-theme="light"] counterpart.
   ========================================================================== */

:root {
  --cp-accent: #ff6d00;
  --cp-accent-2: #ffb347;
  --cp-gold: #ffd700;
  --cp-bg: #05070d;
  --cp-panel: rgba(13, 18, 30, .82);
  --cp-panel-2: rgba(255, 255, 255, .045);
  --cp-line: rgba(255, 255, 255, .10);
  --cp-text: #e8eaf0;
  --cp-dim: #94a3b8;
  --cp-dim2: #64748b;
  --cp-rail: 372px;
}

[data-theme="light"] {
  --cp-bg: #f6f7fb;
  --cp-panel: rgba(255, 255, 255, .92);
  --cp-panel-2: rgba(15, 23, 42, .04);
  --cp-line: rgba(15, 23, 42, .10);
  --cp-text: #0f172a;
  --cp-dim: #5a6478;
  --cp-dim2: #7c8698;
}

/* ---------- 1. the shell ------------------------------------------------ */
#cp-root {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: none;
  background: var(--cp-bg);
  color: var(--cp-text);
  font-family: 'Outfit', 'Noto Sans Thai', system-ui, sans-serif;
  opacity: 0;
  transition: opacity .28s ease;
}
#cp-root.cp-open { display: flex; flex-direction: column; }
#cp-root.cp-in { opacity: 1; }
body.cp-lock { overflow: hidden !important; }

/* a faint version of the site's ambient orbs so the window feels part of the
   same world rather than a plain black box dropped on top */
#cp-root::before {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(680px 420px at 12% -8%, rgba(255, 109, 0, .13), transparent 70%),
    radial-gradient(560px 380px at 105% 8%, rgba(255, 179, 71, .10), transparent 70%);
}
[data-theme="light"] #cp-root::before {
  background:
    radial-gradient(680px 420px at 12% -8%, rgba(255, 109, 0, .10), transparent 70%),
    radial-gradient(560px 380px at 105% 8%, rgba(255, 179, 71, .08), transparent 70%);
}

/* ---------- 2. top bar -------------------------------------------------- */
.cp-bar {
  position: relative; z-index: 3;
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 14px;
  padding: 12px clamp(14px, 2.4vw, 26px);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--cp-line);
  background: var(--cp-panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.cp-back {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--cp-line);
  background: var(--cp-panel-2);
  color: var(--cp-text);
  font-size: 1rem; cursor: pointer;
  display: grid; place-items: center;
  transition: background .18s, border-color .18s, transform .18s;
}
.cp-back:hover {
  background: rgba(255, 109, 0, .15);
  border-color: rgba(255, 109, 0, .45);
  transform: translateX(-2px);
}
.cp-head { flex: 1 1 auto; min-width: 0; }
.cp-kicker {
  font-size: .64rem; letter-spacing: 2.4px; text-transform: uppercase;
  color: var(--cp-accent); font-weight: 700; margin-bottom: 2px;
}
.cp-title {
  font-family: 'Space Grotesk', 'Noto Sans Thai', sans-serif;
  font-size: clamp(.98rem, 1.5vw, 1.22rem); font-weight: 700; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin: 0;
}
.cp-bar-tools { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }

/* circular completion meter */
.cp-ring { position: relative; width: 44px; height: 44px; flex: 0 0 auto; }
.cp-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.cp-ring circle { fill: none; stroke-width: 4; stroke-linecap: round; }
.cp-ring .cp-ring-bg { stroke: var(--cp-line); }
.cp-ring .cp-ring-fg { stroke: url(#cp-grad); transition: stroke-dashoffset .45s ease; }
.cp-ring b {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: .62rem; font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--cp-text);
}
.cp-rail-toggle { display: none; }

/* ---------- 3. body: stage + rail --------------------------------------- */
.cp-body {
  position: relative; z-index: 2;
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--cp-rail);
}

.cp-stage {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ---------- 4. the video ------------------------------------------------ */
.cp-video-wrap {
  position: relative;
  flex: 0 0 auto;
  background: #000;
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
}
.cp-video-wrap video {
  width: 100%; height: 100%; display: block; object-fit: contain; background: #000;
}
.cp-video-wrap.cp-idle .cp-controls { opacity: 0; pointer-events: none; }
.cp-video-wrap.cp-idle { cursor: none; }

/* centre play / replay affordance */
.cp-bigplay {
  position: absolute; inset: 0; margin: auto;
  width: 82px; height: 82px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--cp-accent), var(--cp-accent-2));
  color: #fff; font-size: 1.7rem;
  display: grid; place-items: center;
  box-shadow: 0 12px 40px rgba(255, 109, 0, .45);
  transition: transform .2s ease, opacity .2s ease;
}
.cp-bigplay:hover { transform: scale(1.07); }
.cp-video-wrap.cp-playing .cp-bigplay { opacity: 0; pointer-events: none; transform: scale(.8); }

/* "no video yet" placeholder — a lesson can be reading-only */
.cp-novideo {
  position: absolute; inset: 0;
  display: grid; place-items: center; gap: 10px; align-content: center;
  color: var(--cp-dim);
  background: linear-gradient(135deg, #0a0f1a, #12182a);
  text-align: center; padding: 24px;
}
.cp-novideo i { font-size: 2.4rem; color: var(--cp-accent); opacity: .8; }
.cp-novideo span { font-size: .9rem; }

/* the rules above set display on elements the player toggles with the [hidden]
   attribute — without these guards `display:block/grid` would beat `hidden`
   and a reading-only lesson would still show a dead black video box. */
.cp-video-wrap video[hidden],
.cp-bigplay[hidden],
.cp-novideo[hidden] { display: none !important; }

/* ---------- 5. custom controls ------------------------------------------ */
.cp-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 26px 14px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, .88), rgba(0, 0, 0, .45) 55%, transparent);
  transition: opacity .25s ease;
  display: flex; flex-direction: column; gap: 8px;
  color: #fff;
}
.cp-scrub {
  position: relative; height: 16px; cursor: pointer;
  display: flex; align-items: center;
}
.cp-scrub-track {
  position: relative; width: 100%; height: 5px; border-radius: 4px;
  background: rgba(255, 255, 255, .24); overflow: hidden;
  transition: height .15s ease;
}
.cp-scrub:hover .cp-scrub-track { height: 8px; }
.cp-scrub-buf { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(255, 255, 255, .2); }
.cp-scrub-fill {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: linear-gradient(90deg, var(--cp-accent), var(--cp-gold));
}
.cp-scrub-knob {
  position: absolute; top: 50%; left: 0;
  width: 13px; height: 13px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(255, 109, 0, .55);
  transform: translate(-50%, -50%) scale(0);
  transition: transform .15s ease; pointer-events: none;
}
.cp-scrub:hover .cp-scrub-knob { transform: translate(-50%, -50%) scale(1); }
.cp-scrub-tip {
  position: absolute; bottom: 20px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .9); border: 1px solid rgba(255, 255, 255, .16);
  padding: 3px 8px; border-radius: 6px; font-size: .72rem;
  font-variant-numeric: tabular-nums; pointer-events: none; opacity: 0;
  transition: opacity .12s; white-space: nowrap;
}
.cp-scrub:hover .cp-scrub-tip { opacity: 1; }

.cp-btns { display: flex; align-items: center; gap: 6px; }
.cp-btn {
  width: 38px; height: 38px; border: none; border-radius: 10px;
  background: transparent; color: #fff; cursor: pointer; font-size: .98rem;
  display: grid; place-items: center;
  transition: background .16s, color .16s;
}
.cp-btn:hover { background: rgba(255, 255, 255, .14); color: var(--cp-accent-2); }
.cp-btn[disabled] { opacity: .34; cursor: not-allowed; }
.cp-btn[disabled]:hover { background: transparent; color: #fff; }
.cp-time {
  font-size: .78rem; font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, .88); padding: 0 8px; white-space: nowrap;
}
.cp-spacer { flex: 1 1 auto; }

/* volume slides open on hover — keeps the bar uncluttered */
.cp-vol { display: flex; align-items: center; }
.cp-vol input {
  width: 0; opacity: 0; margin: 0;
  transition: width .22s ease, opacity .22s ease, margin .22s ease;
  accent-color: var(--cp-accent);
}
.cp-vol:hover input, .cp-vol input:focus { width: 82px; opacity: 1; margin: 0 8px 0 2px; }

.cp-rate {
  border: 1px solid rgba(255, 255, 255, .22); border-radius: 8px;
  background: transparent; color: #fff; cursor: pointer;
  font-size: .74rem; font-weight: 700; padding: 7px 9px; min-width: 44px;
  font-family: inherit;
}
.cp-rate:hover { border-color: var(--cp-accent); color: var(--cp-accent-2); }

/* toast that confirms a keyboard shortcut fired */
.cp-flash {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, .78); border: 1px solid rgba(255, 255, 255, .16);
  color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: .92rem; font-weight: 600; pointer-events: none;
  opacity: 0; transition: opacity .2s ease;
}
.cp-flash.on { opacity: 1; }

/* ---------- 6. below the video ------------------------------------------ */
.cp-info { padding: clamp(16px, 2.4vw, 30px); }
.cp-lesson-meta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: .74rem; color: var(--cp-dim); margin-bottom: 8px;
}
.cp-chip {
  border: 1px solid var(--cp-line); border-radius: 999px;
  padding: 3px 10px; background: var(--cp-panel-2);
  font-weight: 600; letter-spacing: .3px;
}
.cp-chip.cp-chip-on {
  border-color: rgba(37, 194, 110, .45); color: #25c26e;
  background: rgba(37, 194, 110, .10);
}
.cp-lesson-title {
  font-family: 'Space Grotesk', 'Noto Sans Thai', sans-serif;
  font-size: clamp(1.15rem, 2.2vw, 1.75rem); font-weight: 800;
  line-height: 1.28; margin: 0 0 10px;
}
.cp-lesson-desc {
  color: var(--cp-dim); line-height: 1.8; font-size: .95rem;
  margin: 0 0 20px; max-width: 74ch;
}

.cp-tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--cp-line);
  margin-bottom: 18px; overflow-x: auto; scrollbar-width: none;
}
.cp-tabs::-webkit-scrollbar { display: none; }
.cp-tab {
  flex: 0 0 auto;
  border: none; background: transparent; cursor: pointer;
  color: var(--cp-dim); font-family: inherit; font-size: .88rem; font-weight: 600;
  padding: 11px 16px; border-bottom: 2px solid transparent;
  transition: color .18s, border-color .18s;
}
.cp-tab:hover { color: var(--cp-text); }
.cp-tab.on { color: var(--cp-accent); border-bottom-color: var(--cp-accent); }
.cp-panel { display: none; animation: cpFade .3s ease; }
.cp-panel.on { display: block; }
@keyframes cpFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* resource links */
.cp-res { display: grid; gap: 10px; max-width: 640px; }
.cp-res a {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-radius: 12px;
  border: 1px solid var(--cp-line); background: var(--cp-panel-2);
  color: var(--cp-text); text-decoration: none; font-size: .9rem; font-weight: 600;
  transition: border-color .18s, background .18s, transform .18s;
}
.cp-res a:hover {
  border-color: rgba(255, 109, 0, .5); background: rgba(255, 109, 0, .09);
  transform: translateX(4px);
}
.cp-res a i:first-child { color: var(--cp-accent); font-size: 1.05rem; width: 20px; text-align: center; }
.cp-res a .cp-res-go { margin-left: auto; color: var(--cp-dim2); font-size: .8rem; }

/* notes */
.cp-notes {
  width: 100%; max-width: 720px; min-height: 190px; resize: vertical;
  border-radius: 12px; border: 1px solid var(--cp-line);
  background: var(--cp-panel-2); color: var(--cp-text);
  font-family: inherit; font-size: .92rem; line-height: 1.75; padding: 14px 16px;
}
.cp-notes:focus { outline: none; border-color: rgba(255, 109, 0, .55); }
.cp-notes-hint { font-size: .74rem; color: var(--cp-dim2); margin-top: 8px; }

.cp-empty { color: var(--cp-dim2); font-size: .9rem; padding: 12px 0; }

/* "about this course" panel */
.cp-about { max-width: 74ch; color: var(--cp-dim); line-height: 1.85; font-size: .92rem; }
.cp-about p { margin: 0 0 10px; }
.cp-about b { color: var(--cp-text); font-weight: 700; }

/* ---------- 7. the playlist rail ---------------------------------------- */
.cp-rail {
  min-height: 0; min-width: 0;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--cp-line);
  background: var(--cp-panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.cp-rail-head {
  flex: 0 0 auto; padding: 16px 18px 12px; border-bottom: 1px solid var(--cp-line);
}
.cp-rail-head h4 {
  font-family: 'Space Grotesk', 'Noto Sans Thai', sans-serif;
  font-size: .95rem; font-weight: 700; margin: 0 0 8px;
  display: flex; align-items: center; gap: 8px;
}
.cp-rail-head h4 i { color: var(--cp-accent); }
.cp-rail-sub {
  font-size: .74rem; color: var(--cp-dim); display: flex; gap: 10px; flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.cp-rail-bar {
  height: 5px; border-radius: 4px; background: var(--cp-line);
  overflow: hidden; margin-top: 10px;
}
.cp-rail-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--cp-accent), var(--cp-gold));
  transition: width .45s ease;
}
.cp-list { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 8px 0 24px; }

.cp-sec-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 18px; border: none; background: transparent; cursor: pointer;
  color: var(--cp-text); font-family: inherit; text-align: left;
}
.cp-sec-head:hover { background: var(--cp-panel-2); }
.cp-sec-head .cp-sec-name { flex: 1 1 auto; font-size: .86rem; font-weight: 700; }
.cp-sec-head .cp-sec-n { font-size: .7rem; color: var(--cp-dim2); font-variant-numeric: tabular-nums; }
.cp-sec-head .cp-caret { color: var(--cp-dim2); font-size: .72rem; transition: transform .22s ease; }
.cp-sec.collapsed .cp-caret { transform: rotate(-90deg); }
.cp-sec.collapsed .cp-sec-items { display: none; }

.cp-item {
  display: flex; align-items: flex-start; gap: 11px; width: 100%;
  padding: 11px 18px 11px 16px;
  border: none; border-left: 3px solid transparent; background: transparent;
  color: var(--cp-text); font-family: inherit; text-align: left; cursor: pointer;
  transition: background .16s, border-color .16s;
}
.cp-item:hover { background: var(--cp-panel-2); }
.cp-item.on { background: rgba(255, 109, 0, .11); border-left-color: var(--cp-accent); }
.cp-item.on .cp-item-title { color: var(--cp-accent); }
.cp-item-state {
  flex: 0 0 auto; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%;
  display: grid; place-items: center; font-size: .58rem;
  border: 1.5px solid var(--cp-line); color: transparent;
}
.cp-item.done .cp-item-state {
  background: #25c26e; border-color: #25c26e; color: #fff;
}
.cp-item.on .cp-item-state { border-color: var(--cp-accent); }
.cp-item-main { flex: 1 1 auto; min-width: 0; }
.cp-item-title { font-size: .84rem; font-weight: 600; line-height: 1.45; }
.cp-item-sub {
  font-size: .7rem; color: var(--cp-dim2); margin-top: 3px;
  display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums;
}
.cp-item-sub i { font-size: .64rem; }
/* thin resume bar showing how far into this lesson the learner got */
.cp-item-prog { height: 3px; border-radius: 3px; background: var(--cp-line); margin-top: 6px; overflow: hidden; }
.cp-item-prog i { display: block; height: 100%; width: 0; background: var(--cp-accent); }
.cp-item.done .cp-item-prog { display: none; }

/* ---------- 8. tablet / phone ------------------------------------------- */
@media (max-width: 1080px) {
  :root { --cp-rail: 320px; }
}

@media (max-width: 900px) {
  .cp-body { grid-template-columns: minmax(0, 1fr); }
  .cp-rail-toggle {
    display: grid; place-items: center;
    width: 40px; height: 40px; border-radius: 12px;
    border: 1px solid var(--cp-line); background: var(--cp-panel-2);
    color: var(--cp-text); cursor: pointer; font-size: 1rem;
  }
  /* the playlist becomes a bottom sheet so the video keeps the full width */
  .cp-rail {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: min(76dvh, 620px);
    border-left: none; border-top: 1px solid var(--cp-line);
    border-radius: 20px 20px 0 0;
    transform: translateY(101%);
    transition: transform .32s cubic-bezier(.22, 1, .36, 1);
    box-shadow: 0 -18px 50px rgba(0, 0, 0, .5);
    z-index: 6;
  }
  body.cp-rail-on .cp-rail { transform: translateY(0); }
  /* the grab handle below is absolutely positioned — anchor it to the head,
     not to whichever ancestor happens to be positioned */
  .cp-rail-head { padding-top: 20px; position: relative; }
  /* grab handle */
  .cp-rail-head::before {
    content: ''; position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 42px; height: 4px; border-radius: 3px; background: var(--cp-line);
  }
  .cp-list { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  .cp-scrim {
    position: fixed; inset: 0; background: rgba(0, 0, 0, .55);
    opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 5;
  }
  body.cp-rail-on .cp-scrim { opacity: 1; pointer-events: auto; }
}

@media (max-width: 640px) {
  .cp-bar { padding: 10px 12px; gap: 10px; }
  .cp-kicker { display: none; }
  .cp-ring { width: 38px; height: 38px; }
  .cp-info { padding: 16px 14px 40px; }
  .cp-btn { width: 34px; height: 34px; font-size: .9rem; }
  .cp-controls { padding: 22px 8px 8px; }
  .cp-time { font-size: .72rem; padding: 0 4px; }
  .cp-vol { display: none; }          /* phones use hardware volume keys */
  .cp-rate { padding: 6px 7px; min-width: 40px; font-size: .7rem; }
}

/* landscape phone: the video should own the screen */
@media (max-height: 500px) and (orientation: landscape) {
  .cp-bar { padding-top: 6px; padding-bottom: 6px; }
  .cp-video-wrap { aspect-ratio: auto; height: calc(100dvh - 60px); }
}

@media (prefers-reduced-motion: reduce) {
  #cp-root, .cp-rail, .cp-scrub-track, .cp-item, .cp-panel { transition: none !important; animation: none !important; }
}

/* ---------- 9. the "Start learning" affordance on the cards -------------- */
.project-card .project-btn[data-course] { cursor: pointer; }
