/* ===================================================================
   Futuristic theme — tokens drive both dark (default) and light themes.
   Theme is selected via <html data-theme="dark|light">.
   =================================================================== */
:root {
  /* dark (default) */
  --bg: #070b12;
  --bg-glow-1: rgba(34, 211, 238, .10);
  --bg-glow-2: rgba(124, 92, 255, .12);
  --grid-line: rgba(120, 170, 230, .045);

  --surface: rgba(17, 25, 40, .72);
  --surface-2: rgba(31, 43, 64, .55);
  --surface-solid: #0e1623;
  --ink: #e6f1ff;
  --muted: #8aa0b6;
  --line: rgba(120, 165, 215, .16);
  --board-edge: rgba(90, 200, 255, .35);

  --accent: #22d3ee;
  --accent-2: #a855f7;
  --accent-ink: #04141a;
  --accent-soft: rgba(34, 211, 238, .14);
  --glow: rgba(34, 211, 238, .45);

  --btn-bg: rgba(255, 255, 255, .045);
  --hover: rgba(255, 255, 255, .10);

  --ok: #34d399;   --ok-bg: rgba(52, 211, 153, .14);  --ok-ink: #6ee7b7;  --ok-line: rgba(52, 211, 153, .42);
  --bad: #fb7185;  --bad-bg: rgba(251, 113, 133, .14); --bad-ink: #fda4af; --bad-line: rgba(251, 113, 133, .42);
  --ans: #fbbf24;  --ans-bg: rgba(251, 191, 36, .14);  --ans-ink: #fcd34d; --ans-line: rgba(251, 191, 36, .42);
  --danger: #f43f5e;

  --threat: #fb5773;
  --opp: #34d399;
  --light-sq: #c3d0ea;
  --dark-sq: #41557f;

  --zebra: rgba(255, 255, 255, .04);
  --shadow: 0 14px 44px rgba(0, 0, 0, .5);
  --radius: 13px;
}

html[data-theme="light"] {
  --bg: #eaf0f9;
  --bg-glow-1: rgba(6, 182, 212, .14);
  --bg-glow-2: rgba(124, 58, 237, .12);
  --grid-line: rgba(30, 70, 130, .05);

  --surface: rgba(255, 255, 255, .80);
  --surface-2: rgba(15, 27, 45, .045);
  --surface-solid: #ffffff;
  --ink: #0e1b2e;
  --muted: #5a6b80;
  --line: rgba(20, 45, 90, .14);
  --board-edge: rgba(30, 90, 160, .30);

  --accent: #0891b2;
  --accent-2: #7c3aed;
  --accent-ink: #ffffff;
  --accent-soft: rgba(8, 145, 178, .12);
  --glow: rgba(8, 145, 178, .30);

  --btn-bg: rgba(15, 27, 45, .04);
  --hover: rgba(15, 27, 45, .08);

  --ok: #059669;   --ok-bg: rgba(5, 150, 105, .12);   --ok-ink: #047857;  --ok-line: rgba(5, 150, 105, .36);
  --bad: #e11d48;  --bad-bg: rgba(225, 29, 72, .10);  --bad-ink: #be123c; --bad-line: rgba(225, 29, 72, .34);
  --ans: #b45309;  --ans-bg: rgba(217, 119, 6, .12);  --ans-ink: #b45309; --ans-line: rgba(217, 119, 6, .36);
  --danger: #e11d48;

  --threat: #e11d48;
  --opp: #059669;
  --light-sq: #e6ecf6;
  --dark-sq: #7c93bb;

  --zebra: rgba(15, 27, 45, .035);
  --shadow: 0 12px 34px rgba(25, 50, 95, .14);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  line-height: 1.5;
  background: var(--bg);
  background-image:
    radial-gradient(900px 600px at 12% -8%, var(--bg-glow-1), transparent 60%),
    radial-gradient(800px 600px at 110% 10%, var(--bg-glow-2), transparent 55%);
  background-attachment: fixed;
}
/* faint tech grid overlay */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 30%, transparent 85%);
}

body { transition: background-color .3s ease, color .25s ease; }
.btn, .icon-btn, .board-controls button, .mn-btn, .m-btn, .course-tile,
.train-stats .stat, .video-close, .notation .mv {
  transition: transform .11s ease, border-color .14s ease, box-shadow .16s ease, color .11s ease;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 24px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand {
  font-family: ui-monospace, "Consolas", monospace;
  font-size: 19px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
  background: linear-gradient(92deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar nav { display: flex; gap: 16px; align-items: center; margin-left: auto; }
.topbar nav a { color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.topbar nav a:hover { color: var(--ink); }
.icon-btn {
  background: var(--btn-bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 5px 11px; cursor: pointer; font-size: 15px; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); transform: translateY(-1px); }
.icon-btn:active { transform: scale(.94); }

.container { max-width: 1120px; margin: 0 auto; padding: 28px 24px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
h1, h2, h3 { margin: 0 0 .4em; letter-spacing: .2px; }
h1 { font-weight: 750; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: "Consolas", "Courier New", monospace; }

/* ---- buttons (crisp, no background fade) ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 15px;
  border-radius: 10px; background: var(--btn-bg); color: var(--ink);
  border: 1px solid var(--line); cursor: pointer; font-size: 14px;
  font-weight: 600; text-decoration: none;
}
.btn:hover { color: var(--ink); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 18px -10px var(--glow); transform: translateY(-1px); text-decoration: none; }
.btn-primary:hover, .btn.danger:hover { text-decoration: none; }
.btn-primary, .btn-primary:hover { color: var(--accent-ink); }
.btn:active { transform: translateY(0) scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; border-color: var(--line); }
.btn-primary {
  background: var(--accent); border: 1px solid var(--accent);
  color: var(--accent-ink); font-weight: 700; box-shadow: 0 6px 18px -8px var(--glow);
}
.btn-primary:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 10px 24px -8px var(--glow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0) scale(.97); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.xs { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: var(--bad-line); background: var(--bad-bg); }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); box-shadow: 0 8px 18px -10px var(--bad); }

/* ---- flashes ---- */
.flashes { max-width: 1120px; margin: 14px auto 0; padding: 0 24px; }
.flash { padding: 11px 15px; border-radius: 10px; margin-bottom: 8px; border: 1px solid var(--line); }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
.flash-error { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-line); }

/* ---- library tiles ---- */
.course-grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.course-tile {
  display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: var(--ink);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  text-decoration: none; transition: transform .12s ease, border-color .12s ease, box-shadow .15s ease;
}
.course-tile:hover {
  transform: translateY(-4px); border-color: var(--accent);
  box-shadow: 0 16px 40px -14px var(--glow); text-decoration: none;
}
.course-tile .thumb { aspect-ratio: 16 / 10; background: var(--surface-2); overflow: hidden; }
.course-tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 64px; color: var(--accent);
  background:
    radial-gradient(circle at 50% 40%, var(--accent-soft), transparent 70%),
    repeating-linear-gradient(45deg, transparent 0 18px, var(--zebra) 18px 19px);
}
.tile-name { padding: 13px 15px; font-weight: 650; font-size: 15px; }

/* ---- course detail ---- */
.course-header { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 24px; }
.course-hero {
  width: 210px; aspect-ratio: 16 / 10; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--line); flex-shrink: 0;
  box-shadow: var(--shadow);
}
@media (max-width: 640px) { .course-header { flex-direction: column; } .course-hero { width: 100%; } }

.course-card, .admin-course {
  background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.chapter-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.study-list { list-style: none; padding: 0; margin: 6px 0 0; }
.study-list li { padding: 5px 0; }
.badge {
  font-size: 11px; background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); padding: 1px 8px; border-radius: 99px; margin-left: 6px;
}
.empty { text-align: center; padding: 64px 0; }

/* ---- admin ---- */
.admin-chapter {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 13px 15px; margin-top: 12px;
}
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-head h2, .row-head h3 { margin: 0; }
.actions { display: flex; gap: 6px; align-items: center; }
.actions form { margin: 0; }
.study-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.study-table td { padding: 7px 5px; border-top: 1px solid var(--line); vertical-align: middle; }
.study-table td.actions { text-align: right; white-space: nowrap; }
.study-table td.reorder { white-space: nowrap; width: 1%; }
.study-table td.reorder form { display: inline; margin: 0; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form select, .form input, .form textarea {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px;
}
.inline-form select { padding: 7px 9px; }

/* ---- forms ---- */
.form {
  max-width: 760px; background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: var(--radius); padding: 24px;
}
.form label { display: block; margin-bottom: 16px; font-weight: 600; }
.form input, .form textarea, .form select {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  font-size: 14px; font-weight: 400; font-family: inherit;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
.form select { max-width: 280px; }
.form input:focus, .form textarea:focus, .inline-form select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.form textarea.mono { font-family: "Consolas", monospace; font-size: 12.5px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.breadcrumbs { margin-bottom: 18px; color: var(--muted); }
.breadcrumbs span { margin: 0 5px; opacity: .6; }

/* ---- study / train layout ---- */
.study-layout { display: grid; grid-template-columns: minmax(320px, 560px) minmax(0, 1fr); gap: 28px; align-items: start; }
.study-layout > .board-col, .study-layout > .info-col, .study-layout > .right-col { min-width: 0; }
.right-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.under-controls { margin-top: 0; }
@media (max-width: 860px) {
  .study-layout { grid-template-columns: 1fr; }
  /* on phones: board, then the buttons, then the box */
  .right-col .under-controls { order: -1; }
}

.board-col { width: 100%; }
.board {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border: 1px solid var(--board-edge); border-radius: 10px; overflow: hidden; user-select: none;
  box-shadow: 0 0 0 1px var(--line), var(--shadow), inset 0 0 30px rgba(34, 211, 238, .05);
}
.sq { width: 100%; height: 100%; position: relative; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
/* file/rank labels on the board edges — colored to contrast with the square */
.coord {
  position: absolute; z-index: 2; pointer-events: none; user-select: none;
  font-size: clamp(8px, 1.5vmin, 12px); font-weight: 700; line-height: 1;
}
.coord-file { right: 3px; bottom: 2px; }
.coord-rank { left: 3px; top: 2px; }
.sq.light > .coord { color: var(--dark-sq); }
.sq.dark > .coord { color: var(--light-sq); }
.piece { width: 100%; height: 100%; object-fit: contain; pointer-events: none; z-index: 2; }
.hl { z-index: 1; pointer-events: none; box-shadow: inset 0 0 0 4px currentColor; }
.hl-threat { color: var(--threat); background: color-mix(in srgb, var(--threat) 28%, transparent); }
.hl-opp { color: var(--opp); background: color-mix(in srgb, var(--opp) 28%, transparent); }

.overlay { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }
.arrow { stroke-width: .18; stroke-linecap: round; opacity: .9; }
.arrow-threat { stroke: var(--threat); }
.arrow-opp { stroke: var(--opp); }
.arrow-answer { stroke: var(--accent); opacity: .95; }

.board-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; justify-content: center; }
.board-controls.move-controls { margin-top: 14px; }
.board-controls button {
  background: var(--btn-bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 12px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.board-controls button:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); transform: translateY(-1px); }
.board-controls button:active { transform: scale(.95); }
.board-controls button:disabled { opacity: .38; cursor: not-allowed; transform: none; box-shadow: none; border-color: var(--line); }
.counter { min-width: 60px; text-align: center; color: var(--muted); }

.info-col {
  background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: var(--radius); padding: 22px;
}
.comment-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-height: 90px; }
.comment-box p { margin: 0 0 10px; }
.move-meta { display: flex; gap: 18px; margin: 14px 0; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.dot-threat { background: var(--threat); }
.dot-opp { background: var(--opp); }
.study-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; justify-content: center; }
.sibling-nav { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.sibling-nav ul { list-style: none; padding: 0; margin: 0; }
.sibling-nav li { padding: 3px 0; }
.sibling-nav li.current a { color: var(--ink); font-weight: 700; }

/* study form: mode tabs + visual editor */
.mode-tabs { display: flex; gap: 8px; margin: 2px 0 18px; }
.mode-tabs .tab {
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 600;
  background: var(--btn-bg); border: 1px solid var(--line); color: var(--muted);
}
.mode-tabs .tab:hover { border-color: var(--accent); color: var(--ink); }
.mode-tabs .tab.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.editor { display: grid; grid-template-columns: minmax(240px, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 760px) { .editor { grid-template-columns: 1fr; } }
.editor-board .board { cursor: pointer; }
.editor-board .board-controls { flex-wrap: wrap; }
.ed-promo { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.ed-promo select { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.editor-side label { display: block; font-weight: 600; margin-bottom: 14px; }
.editor-side textarea {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px; font-family: inherit;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.editor-side textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sq.target { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); }

/* ---- image / video fields ---- */
.image-field { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
.image-field legend { padding: 0 6px; color: var(--muted); font-weight: 600; }
.image-field label { font-weight: 600; }
.current-image { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.current-video { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.current-video code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.current-image img { width: 120px; aspect-ratio: 16/10; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.inline-check { font-weight: 400 !important; display: flex; align-items: center; gap: 6px; }
.inline-check input { width: auto !important; margin: 0 !important; }

/* ---- video overlay ---- */
body.no-scroll { overflow: hidden; }
.video-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.video-overlay[hidden] { display: none; }
.video-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 14, .82); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.video-modal {
  position: relative; z-index: 1; width: min(960px, 92vw);
  background: var(--surface-solid); border: 1px solid var(--board-edge); border-radius: 12px;
  overflow: hidden; box-shadow: 0 24px 70px rgba(0, 0, 0, .6), 0 0 0 1px var(--glow);
}
.video-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 15px; border-bottom: 1px solid var(--line); font-weight: 600; }
.video-close { background: var(--btn-bg); color: var(--ink); border: 1px solid var(--line); border-radius: 7px; width: 32px; height: 32px; cursor: pointer; font-size: 15px; }
.video-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.video-embed { aspect-ratio: 16 / 9; width: 100%; background: #000; }
.video-embed iframe, .video-embed video { width: 100%; height: 100%; border: 0; display: block; }
.video-fallback { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 10px; color: var(--ink); }

/* ---- training ---- */
.train-board .sq { cursor: pointer; }
.sq.sel { box-shadow: inset 0 0 0 4px var(--accent); }
.sq.lastmove { background-image: linear-gradient(color-mix(in srgb, var(--accent) 30%, transparent), color-mix(in srgb, var(--accent) 30%, transparent)); }
.sq.answer { box-shadow: inset 0 0 0 4px var(--accent); }
.board.flash-correct { animation: flashGlow .4s ease; }
.board.flash-wrong { animation: shake .36s ease; }
@keyframes flashGlow {
  0% { box-shadow: 0 0 0 0 transparent; }
  40% { box-shadow: 0 0 0 5px var(--glow); }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); } 40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}
.train-stats { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.train-stats .stat {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 99px; padding: 5px 15px; font-size: 13px; font-weight: 650;
}
.train-status { padding: 12px 15px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 12px; font-weight: 600; }
.train-status.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
.train-status.bad { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-line); }
.train-status.answer { background: var(--ans-bg); color: var(--ans-ink); border-color: var(--ans-line); }

.move-history-block { margin: 14px 0; }
.notation {
  position: relative;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px; max-height: 220px; overflow-y: auto; overflow-x: hidden;
  font-family: "Consolas", monospace; font-size: 14px;
}
.notation .hrow { display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 4px; align-items: center; }
.notation .hrow:nth-child(even) { background: var(--zebra); }
.notation .hnum { color: var(--muted); text-align: right; padding-right: 4px; }
.notation .mv { color: var(--ink); padding: 2px 6px; border-radius: 4px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notation .mv[data-ply]:hover { background: var(--hover); }
.notation .mv.empty { cursor: default; }
.notation .mv.cur { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* ---- music player ---- */
.music-player {
  position: fixed; right: 16px; bottom: 16px; z-index: 900;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-radius: 99px; padding: 7px 11px; box-shadow: var(--shadow);
}
.music-player[hidden] { display: none; }
.m-btn { background: transparent; color: var(--ink); border: none; cursor: pointer; font-size: 16px; line-height: 1; padding: 5px 7px; border-radius: 7px; }
.m-btn:hover { background: var(--hover); }
.m-title { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--muted); padding: 0 4px; cursor: pointer; }
.m-title:hover { color: var(--ink); text-decoration: underline; }
.m-vol { display: flex; align-items: center; }
.m-vol #m-vol-slider { width: 0; opacity: 0; padding: 0; margin: 0; transition: width .18s ease, opacity .18s ease; accent-color: var(--accent); }
.m-vol:hover #m-vol-slider, .m-vol:focus-within #m-vol-slider { width: 90px; opacity: 1; margin-left: 4px; }
@media (max-width: 560px) { .m-title { max-width: 90px; } }

/* music library popup */
.music-modal { position: fixed; inset: 0; z-index: 1050; display: flex; align-items: center; justify-content: center; }
.music-modal[hidden] { display: none; }
.mm-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 14, .78); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.mm-card {
  position: relative; z-index: 1; width: min(460px, 92vw); max-height: 80vh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface-solid); border: 1px solid var(--board-edge);
  border-radius: 14px; box-shadow: var(--shadow), 0 0 0 1px var(--glow);
}
.mm-head { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.mm-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.mm-item { display: flex; align-items: center; gap: 8px; padding: 2px; }
.mm-name {
  flex: 1; min-width: 0; text-align: left; background: transparent; color: var(--ink);
  border: 1px solid transparent; padding: 9px 11px; border-radius: 9px; cursor: pointer;
  font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mm-name:hover { border-color: var(--accent); }
.mm-item.current .mm-name { color: var(--accent); }
.mm-del { flex: none; background: var(--btn-bg); border: 1px solid var(--line); color: var(--muted); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 14px; }
.mm-del:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.mm-empty { padding: 20px; text-align: center; }
.mm-upload { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.mm-upload #mm-file-name { flex: 1; min-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- info-column panels (actions on top, detail below) ---- */
.panel-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.panel-actions .board-controls { margin-top: 0; }
.panel-detail .study-title { font-size: 22px; margin-bottom: 12px; }
.panel-detail .train-stats { margin-top: 0; }

/* line / study action buttons laid out as an even grid (no awkward wrap) */
.board-controls.line-controls,
.study-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px; margin-top: 0; justify-content: stretch;
}
.board-controls.line-controls button, .study-actions .btn { width: 100%; justify-content: center; }

/* ---- move navigation (in the info column) ---- */
.move-nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mn-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px; border-radius: 10px; cursor: pointer;
  background: var(--btn-bg); color: var(--ink); border: 1px solid var(--line);
}
.mn-btn .mn-ico { font-size: 16px; line-height: 1; }
.mn-btn .mn-lbl { font-size: 11px; font-weight: 600; letter-spacing: .3px; color: var(--muted); }
.mn-btn:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 16px -10px var(--glow); transform: translateY(-1px); }
.mn-btn:hover .mn-lbl { color: var(--ink); }
.mn-btn:active { transform: translateY(0) scale(.95); }
.mn-btn:disabled { opacity: .38; cursor: not-allowed; transform: none; box-shadow: none; border-color: var(--line); }
.mn-btn:disabled .mn-lbl { color: var(--muted); }

/* ---- toast notifications ---- */
.toast-stack {
  position: fixed; top: 16px; right: 16px; z-index: 1100;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none; max-width: min(360px, 90vw);
}
.toast {
  pointer-events: auto; cursor: pointer;
  background: var(--surface-solid); color: var(--ink);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 11px; padding: 11px 15px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  opacity: 0; transform: translateX(24px) scale(.96);
  transition: opacity .26s ease, transform .26s cubic-bezier(.2,.8,.2,1);
}
.toast.in { opacity: 1; transform: translateX(0) scale(1); }
.toast.out { opacity: 0; transform: translateX(24px) scale(.96); }
.toast-ok { border-left-color: var(--ok); }
.toast-bad { border-left-color: var(--bad); }
.toast-answer { border-left-color: var(--ans); }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .2s ease; transform: none; }
  .toast.in, .toast.out { transform: none; }
}

/* ---- topbar: user / logout ---- */
.nav-user {
  font-family: ui-monospace, "Consolas", monospace; font-weight: 700;
  font-size: 13px; letter-spacing: .3px; color: var(--ink);
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px;
  background: var(--surface-2);
}
.topbar nav .nav-link { display: inline-flex; }
.nav-logout { margin: 0; display: inline-flex; }

/* ---- auth / status pages (login, change pw, banned, errors) ---- */
.auth-wrap { display: flex; justify-content: center; padding: 36px 0; }
.auth-card { width: min(440px, 100%); }
.auth-title { text-align: center; margin-bottom: 8px; }
.auth-card .muted { text-align: center; }
.status-card { text-align: center; padding: 34px 28px; }
.status-emoji { font-size: 54px; line-height: 1; margin-bottom: 10px; }
.status-line { font-size: 16px; margin: 6px 0 12px; }
.status-card .form-actions { justify-content: center; margin-top: 16px; }

/* ---- role pills ---- */
.role-pill {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; padding: 2px 9px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
}
.role-admin { color: var(--accent-2); border-color: var(--accent-2); background: transparent; }
.role-creator { color: var(--accent); border-color: var(--accent); background: transparent; }
.role-visitor { color: var(--muted); }
.role-off { color: var(--ans-ink); border-color: var(--ans-line); background: var(--ans-bg); }
.role-ban { color: var(--bad-ink); border-color: var(--bad-line); background: var(--bad-bg); }

/* ---- user management ---- */
.user-list { display: flex; flex-direction: column; gap: 14px; }
.user-card {
  background: var(--surface); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: var(--radius); padding: 16px 18px;
}
.user-card.is-banned { border-color: var(--bad-line); }
.user-card .user-id { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-card .user-id h2 { margin: 0; font-size: 18px; }
.ban-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}
.ban-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.ban-form input, .ban-form select {
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-size: 13px;
}
.ban-form input[type="text"] { min-width: 180px; }
.ban-form .ban-amount { width: 70px; }
.course-grants { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

/* ---- course progress ---- */
.course-progress-block {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 22px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.cp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.cp-label { font-weight: 700; }
.cp-head .cp-meta { color: var(--muted); font-size: 13px; }
.cp-head form { margin: 0 0 0 auto; }
.cp-bar {
  height: 10px; border-radius: 99px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line);
}
.cp-fill {
  height: 100%; border-radius: 99px; min-width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .4s cubic-bezier(.2,.8,.2,1);
}
/* inline bar on the variant page */
.course-progress { margin: 14px 0 4px; }
.course-progress .cp-bar { height: 8px; }
.course-progress .cp-text { display: block; margin-top: 6px; color: var(--muted); font-size: 12.5px; }

/* ---- completion highlighting ---- */
.done-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  color: var(--ok-ink); background: var(--ok-bg); border: 1px solid var(--ok-line);
  padding: 1px 8px; border-radius: 99px; vertical-align: middle;
}
.done-tick { color: var(--ok); font-weight: 800; margin-right: 6px; }
.chapter-block.is-done > .row-head h2 { color: var(--ok-ink); }
.study-item.is-done .study-open { color: var(--ok-ink); }
.mm-item.is-done .mm-name { color: var(--ok-ink); }

/* ---- study list rows / variant overlay openers ---- */
.study-item { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.study-open {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; font-weight: 650; color: var(--accent); text-align: left;
}
.study-open:hover { text-decoration: underline; }
.badge.video-badge { cursor: pointer; font: inherit; font-size: 11px; }
.badge.video-badge:hover { background: var(--accent); color: var(--accent-ink); }
.variant-modal .mm-name { display: block; }
.variant-modal .mm-upload { justify-content: flex-start; }

/* ---- admin: study container blocks (variants nested inside) ---- */
.admin-study {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 13px; margin: 10px 0 0 14px;
}
.admin-study .study-head { display: flex; align-items: center; gap: 10px; }
.admin-study .study-head .reorder { display: inline-flex; gap: 2px; }
.admin-study .study-head .reorder form { display: inline; margin: 0; }
.admin-study .study-table { margin-top: 6px; }
