/* =====================================================================
   style.css — 체스 아카데미 프로토타입
   반응형: 넓으면 보드+패널 2단, 좁으면 세로 1단
   ===================================================================== */
:root {
  --bg: #1e2126;
  --bg2: #262a31;
  --panel: #2b3038;
  --line: #3a404a;
  --text: #e7e9ee;
  --muted: #9aa2b1;
  --accent: #6ea8fe;
  --sq-light: #eeeed2;
  --sq-dark: #6f9b56;
  --good: #57c457;
  --bad: #e0574a;
  --amber: #e5a13a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { margin: 0 0 10px; font-size: 16px; }
a { color: var(--accent); }
button {
  font: inherit; cursor: pointer;
  background: var(--line);
  color: var(--text); border: 1px solid #464d59;
  border-radius: 8px; padding: 8px 12px;
}
button:hover { background: #444b57; }
button.primary { background: var(--accent); color: #10233f; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.05); }
button.danger { background: rgba(224,87,74,.14); border-color: rgba(224,87,74,.5); color: #f2b1aa; }
button.danger:hover { background: rgba(224,87,74,.24); }
input, textarea, select {
  font: inherit; width: 100%;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 66px; resize: vertical; font-family: ui-monospace, "Consolas", monospace; font-size: 13px; }
textarea.plain-textarea { font-family: inherit; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.hidden { display: none !important; }

/* ---------- 상단 바 ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 18px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-size: 18px; font-weight: 700; }
.brand span { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; }
.tabs { display: flex; gap: 6px; }
.tab { background: transparent; border: 1px solid transparent; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); border-color: var(--line); }
.score { margin-left: auto; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.score b { color: var(--text); font-size: 17px; }
.score button { padding: 4px 8px; font-size: 12px; }
.student-ctl, .speed-ctl { display: inline-flex; align-items: center; gap: 5px; }
.student-ctl select, .speed-ctl select { width: auto; min-width: 84px; padding: 4px 7px; font-size: 12px; }
.auto-advance-ctl { display: inline-flex; align-items: center; gap: 5px; margin: 0; color: var(--muted); white-space: nowrap; }
.auto-advance-ctl input { width: auto; }

/* ---------- 레이아웃 ---------- */
.layout { display: flex; gap: 22px; padding: 22px; align-items: flex-start; max-width: 1100px; margin: 0 auto; }
.layout.author-layout { max-width: 1280px; align-items: stretch; }
.layout.author-layout .board-area { width: min(620px, 52vw); position: sticky; top: 14px; }
.layout.author-layout .panel { flex-basis: 520px; max-height: calc(100vh - 92px); overflow: auto; }
.board-area { flex: 0 0 auto; width: min(560px, 60vw); }
.panel { flex: 1 1 340px; min-width: 300px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: stretch; }
  .layout.author-layout .board-area { position: static; width: 100%; }
  .layout.author-layout .panel { max-height: none; }
  .board-area { width: 100%; max-width: 520px; margin: 0 auto; }
  .panel { width: 100%; }
}

/* ---------- 보드 ---------- */
.board {
  position: relative;
  width: 100%; max-width: 100%; aspect-ratio: 1 / 1;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 8px; overflow: hidden; box-shadow: 0 8px 26px rgba(0,0,0,.4);
  user-select: none; touch-action: manipulation;
}
.board-resize-handle {
  position: absolute; right: 0; bottom: 0; z-index: 5;
  width: 24px; height: 24px; cursor: nwse-resize;
  background: transparent;
}
.annotation-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.annotation-circle {
  position: absolute; width: 11.2%; height: 11.2%; margin: -5.6% 0 0 -5.6%;
  border: calc(var(--sq) * .055) solid currentColor; border-radius: 50%; opacity: .9;
  box-sizing: border-box;
}
.annotation-arrow { stroke: currentColor; stroke-width: 1.45; stroke-linecap: square; opacity: .86; fill: none; }
.annotation-arrow-head { fill: currentColor; opacity: .86; }
.ann-green, .ann-blue { color: #d76b00; }
.ann-yellow { color: #ffd45a; }
.ann-red { color: #ff695f; }
.square { position: relative; display: flex; align-items: center; justify-content: center; }
.square.light { background: var(--sq-light); }
.square.dark  { background: var(--sq-dark); }
.coord { position: absolute; font-size: 10px; font-weight: 700; opacity: .65; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }
.square.light .coord { color: #6f9b56; }
.square.dark  .coord { color: #eeeed2; }

/* 말 — SVG 이미지 (background-image) */
.piece {
  position: absolute; inset: 3%; z-index: 2; pointer-events: auto;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.30));
  cursor: grab;
}
.piece:active { cursor: grabbing; }

/* 드래그 중 커서를 따라다니는 기물 이미지 */
.piece.piece-ghost {
  position: fixed; inset: auto; left: 0; top: 0; z-index: 999;
  pointer-events: none; cursor: grabbing;
  transform: scale(1.08);
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.45));
}

/* 드래그로 기물을 올리고 있는 칸 표시 */
.square.drag-hover::before {
  content: ''; position: absolute; inset: 0; z-index: 1;
  box-shadow: inset 0 0 0 4px rgba(110,168,254,.85);
}

/* 하이라이트 */
.square.sel::before,
.square.lastmove::before,
.square.hl-green::before,
.square.hl-red::before,
.square.hl-amber::before {
  content: ''; position: absolute; inset: 0; z-index: 1;
}
.square.sel::before      { background: rgba(255, 236, 120, .55); }
.square.lastmove::before { background: rgba(255, 236, 120, .38); }
.square.hl-green::before  { background: rgba(87, 196, 87, .60); box-shadow: inset 0 0 0 3px rgba(87,196,87,.9); }
.square.hl-red::before    { background: rgba(224, 87, 74, .58); box-shadow: inset 0 0 0 3px rgba(224,87,74,.9); }
.square.hl-amber::before  { background: rgba(229, 161, 58, .55); box-shadow: inset 0 0 0 3px rgba(229,161,58,.9); }

/* 합법수 점 / 잡는 수 링 */
.square.movedot::after {
  content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(20,20,20,.28); z-index: 1;
}
.square.light.movedot::after { background: rgba(20,20,20,.22); }
.square.capturedot::after {
  content: ''; position: absolute; inset: 8%; border-radius: 50%;
  border: 5px solid rgba(20,20,20,.28); z-index: 1;
}

/* ---------- 보드 하단 컨트롤 ---------- */
.status { margin: 12px 0 8px; padding: 10px 12px; border-radius: 8px; background: var(--bg2); font-size: 14px; min-height: 20px; }
.status.good { background: rgba(87,196,87,.16); border: 1px solid rgba(87,196,87,.4); }
.status.bad  { background: rgba(224,87,74,.16); border: 1px solid rgba(224,87,74,.4); }
.status.alt  { background: rgba(229,161,58,.16); border: 1px solid rgba(229,161,58,.4); }
.board-controls { display: flex; gap: 8px; }

/* ---------- 패널 공통 ---------- */
.row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.row.tight { margin: 0; gap: 6px; }
.row.tight button { padding: 6px 9px; font-size: 12px; }
.row.nav button { flex: 1; }
.filebtn { position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #464d59; border-radius: 8px; padding: 8px 12px; color: var(--text); background: var(--line); cursor: pointer; margin: 0; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* 문제 목록 */
.puzzle-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 230px; overflow-y: auto; }
.puzzle-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); cursor: pointer; border: 1px solid transparent; }
.puzzle-item:hover { border-color: var(--line); }
.puzzle-item.current { border-color: var(--accent); }
.puzzle-item .pt { flex: 1; font-size: 14px; }
.puzzle-item .chk { color: var(--good); font-weight: 700; width: 14px; }
.puzzle-item .chk.empty { color: var(--muted); }

.badges { display: flex; gap: 6px; margin: 8px 0; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); color: var(--muted); }
.badge.rating { color: #ffd479; border-color: rgba(255,212,121,.35); }
.badge.turn { color: var(--accent); }
.badge.sm { padding: 2px 7px; }

.puzzle-info h3 { margin-bottom: 4px; }

/* 피드백 */
.feedback { margin: 10px 0; }
.fb { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.fb.good { background: rgba(87,196,87,.16); border: 1px solid rgba(87,196,87,.45); }
.fb.alt  { background: rgba(229,161,58,.16); border: 1px solid rgba(229,161,58,.45); }
.fb.bad  { background: rgba(224,87,74,.16); border: 1px solid rgba(224,87,74,.45); }
.fb .cmt { margin: 6px 0 0; color: var(--muted); }

/* 비디오 */
.video-box { margin-top: 12px; }
.video-wrap { position: relative; padding-top: 56.25%; border-radius: 8px; overflow: hidden; background: #000; }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-box a { display: inline-block; margin-top: 8px; font-size: 13px; }

/* 정답 목록 (제작) */
.solution-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 4px; }
.sol-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); font-size: 14px; }
.sol-row .tag { font-size: 11px; color: var(--muted); }
.sol-row .pts { color: #ffd479; font-size: 12px; }
.sol-row .cm { color: var(--muted); font-size: 12px; flex: 1; }
.mini-del { margin-left: auto; padding: 2px 7px; font-size: 12px; }
.dot-correct, .dot-alternative { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot-correct { background: var(--good); }
.dot-alternative { background: var(--amber); }

/* 저작 라인 목록 */
.tc-row { display: flex; gap: 14px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.tc-row label { display: inline-flex; align-items: center; gap: 5px; margin: 0; color: var(--text); }
.alt-toggle { display: inline-flex; align-items: center; gap: 6px; margin: 8px 0; color: var(--text); cursor: pointer; }
.author-line { line-height: 2.1; font-size: 14px; margin: 8px 0; min-height: 26px; background: var(--bg2); border-radius: 8px; padding: 8px 10px; }
.study-movetree { max-height: 180px; overflow: auto; border: 1px solid var(--line); }
.author-line .mn { color: var(--muted); margin: 0 3px 0 8px; }
.author-line .mv { cursor: pointer; padding: 2px 6px; border-radius: 5px; margin: 0 1px; }
.author-line .mv.answer { background: rgba(87,196,87,.18); border: 1px solid rgba(87,196,87,.45); color: #cdeccd; }
.author-line .mv.reply  { background: rgba(255,255,255,.05); color: var(--muted); }
.author-line .mv:hover { filter: brightness(1.15); }
.author-line .mv.cur { outline: 2px solid var(--accent); }
.author-line .alts { color: var(--amber); font-size: 12px; margin: 0 4px; }
.author-line .pending { color: var(--amber); font-size: 12px; margin-top: 6px; }
.move-editor { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.move-edit-card { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.move-edit-card.active { border-color: var(--accent); }
.move-edit-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.move-edit-head b { color: var(--text); }
.move-edit-card textarea { min-height: 54px; font-family: inherit; }
.builder-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.builder-head h2 { margin-bottom: 2px; }
.builder-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 12px; }
.builder-tab { padding: 9px 8px; color: var(--muted); background: var(--bg2); border-color: var(--line); border-radius: 8px; font-size: 13px; }
.builder-tab:hover { color: var(--text); }
.builder-tab.active { color: #10233f; background: var(--accent); border-color: var(--accent); font-weight: 700; }
.builder-section { border: 1px solid var(--line); background: rgba(0,0,0,.08); border-radius: 8px; padding: 12px; margin: 12px 0; }
.builder-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.builder-section h3 { color: var(--accent); margin-bottom: 6px; }
.builder-pill { font-size: 12px; color: #cfe0ff; border: 1px solid rgba(110,168,254,.35); background: rgba(110,168,254,.12); border-radius: 999px; padding: 3px 8px; white-space: nowrap; }
.lesson-builder textarea { min-height: 58px; }
.lesson-builder #setupInput { min-height: 74px; }
.lesson-builder #authorMoveComment { min-height: 112px; font-family: inherit; line-height: 1.55; }
.author-current-target { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0 12px; padding: 9px 10px; background: rgba(110,168,254,.1); border: 1px solid rgba(110,168,254,.32); border-radius: 8px; }
.author-current-target span { color: var(--muted); font-size: 12px; }
.author-current-target b { color: #dbe8ff; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.author-current-target em { color: var(--muted); font-style: normal; }
.catalog-title-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.catalog-title-row b { color: var(--text); font-size: 14px; }
.author-catalog-tree { display: flex; flex-direction: column; gap: 6px; height: clamp(240px, 32vh, 360px); overflow-y: auto; overflow-x: hidden; margin: 0 0 16px; padding: 8px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; scrollbar-gutter: stable; overscroll-behavior: contain; }
.catalog-course { border: 1px solid rgba(255,255,255,.07); border-radius: 8px; overflow: hidden; background: rgba(255,255,255,.025); }
.catalog-course.active { border-color: rgba(110,168,254,.35); }
.catalog-course-btn, .catalog-lesson { width: 100%; text-align: left; background: transparent; border: 0; border-radius: 0; color: var(--text); }
.catalog-course-btn { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 8px 10px; font-weight: 700; }
.catalog-course-btn:hover, .catalog-lesson:hover { background: rgba(110,168,254,.1); }
.catalog-course-btn.active { background: rgba(110,168,254,.1); color: #dbe8ff; }
.catalog-disclosure { width: 15px; color: var(--muted); font-size: 12px; }
.catalog-course-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catalog-course-count { color: var(--muted); font-size: 12px; font-weight: 400; white-space: nowrap; }
.catalog-lessons { display: flex; flex-direction: column; padding: 3px 0 7px 24px; }
.catalog-lesson { padding: 7px 10px; color: var(--muted); font-size: 13px; border-left: 2px solid transparent; }
.catalog-lesson.active { background: rgba(110,168,254,.18); border-left-color: var(--accent); color: #f3f7ff; }
.catalog-empty { display: block; color: var(--muted); font-size: 12px; padding: 7px 10px; }
.study-target-bar { margin: 8px 0 14px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.025); }
.study-target-bar .author-current-target { margin-top: 0; }
.study-target-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.study-target-controls label { margin: 0; }
@media (max-width: 620px) {
  .study-target-controls { grid-template-columns: 1fr; }
}
.problem-bank-list { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; max-height: 420px; overflow: auto; }
.problem-bank-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; width: 100%; text-align: left; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.problem-bank-item:hover { border-color: var(--accent); background: #303640; }
.problem-bank-title, .problem-title { grid-column: 1; grid-row: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; color: var(--text); }
.problem-bank-meta, .problem-meta { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.problem-state { border-radius: 999px; padding: 3px 8px; font-size: 12px; white-space: nowrap; border: 1px solid var(--line); }
.problem-state { grid-column: 2; grid-row: 1; }
.problem-bank-item.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(110,168,254,.45); }
.problem-state.complete { color: #bff0bf; border-color: rgba(87,196,87,.5); background: rgba(87,196,87,.14); }
.problem-state.draft { color: #ffd18a; border-color: rgba(229,161,58,.55); background: rgba(229,161,58,.15); }
.piece-set-ctl { display: inline-flex; align-items: center; gap: 6px; }
.piece-set-ctl select { width: auto; padding: 6px 8px; }

/* 수순 목록 (학습) */
.move-list { line-height: 2; font-size: 14px; margin-top: 8px; }
.move-list .mn { color: var(--muted); margin: 0 4px 0 8px; }
.move-list .mv { cursor: pointer; padding: 1px 5px; border-radius: 4px; }
.move-list .mv:hover { background: var(--bg2); }
.move-list .mv.cur { background: var(--accent); color: #10233f; }

/* ---------- 모달 ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.promo-row { display: flex; gap: 10px; justify-content: center; }
.promo-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 14px; background: var(--bg2); }
.promo-btn .piece { position: static; inset: auto; width: 46px; height: 46px; }
.promo-btn small { color: var(--muted); }
.clf-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.clf { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--bg2); cursor: pointer; }
.fld { display: block; }
.fld input { margin-top: 4px; }

/* =====================================================================
   강의(코스) 화면
   ===================================================================== */
.courses-view { max-width: 1080px; margin: 0 auto; padding: 22px; }
.ranking-view, .settings-view { max-width: 860px; margin: 0 auto; padding: 22px; }
.courses-title { font-size: 26px; margin: 0 0 4px; }
.courses-sub { color: var(--muted); margin: 0 0 20px; }
.ranking-table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ranking-table th, .ranking-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.ranking-table th { color: var(--muted); font-size: 13px; background: var(--bg2); }
.ranking-table tr.me td { background: rgba(110,168,254,.12); color: var(--text); font-weight: 600; }
.compact-rank { margin-top: 8px; }
.student-ranking-panel { margin-top: 18px; }
.settings-panel { max-width: 520px; }
.ops-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 18px; }
.ops-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.ops-panel h2 { margin-bottom: 10px; }
.compact-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.compact-table th, .compact-table td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: left; vertical-align: top; }
.compact-table th { color: var(--muted); font-weight: 600; }
.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.metric { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.metric b { display: block; font-size: 20px; color: var(--text); }
.metric span { color: var(--muted); font-size: 12px; }
.status-note { color: var(--muted); font-size: 12px; line-height: 1.45; margin-top: 8px; }

/* 공통 버튼 */
.btn-primary { background: var(--accent); color: #10233f; border: none; border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary.big-start, .btn-primary.start-practice { margin-top: 18px; padding: 11px 18px; font-size: 15px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; }
.btn-ghost:hover:not([disabled]) { background: var(--bg2); color: var(--text); }
.btn-ghost[disabled] { opacity: .4; cursor: default; }

/* 난이도 배지 */
.diff-badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.diff-badge.beg { background: rgba(87,196,87,.18); color: #8fe08f; }
.diff-badge.int { background: rgba(229,161,58,.18); color: #f0c073; }
.diff-badge.adv { background: rgba(224,87,74,.18); color: #f0938a; }

/* 진도바 */
.progressbar { height: 7px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: 10px 0; }
.progressbar.big { height: 10px; }
.progressbar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #8fe08f); border-radius: 999px; transition: width .3s; }

/* 카드 그리드 */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.course-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; transition: transform .12s, border-color .12s; }
.course-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.cc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cc-time { color: var(--muted); font-size: 12px; }
.cc-title { font-size: 18px; margin: 0 0 6px; }
.cc-desc { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 4px; min-height: 42px; }
.cc-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.cc-pct { color: var(--muted); font-size: 12px; }

/* 작업 영역: 사이드바 + 본문 */
.course-workspace { display: flex; gap: 22px; align-items: flex-start; }
.course-sidebar { flex: 0 0 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; position: sticky; top: 14px; }
.side-title { font-size: 16px; margin: 10px 0 12px; }
.side-toc { display: flex; flex-direction: column; gap: 4px; }
.toc-item { display: flex; align-items: center; gap: 9px; text-align: left; background: transparent; border: none; color: var(--text); padding: 8px 9px; border-radius: 8px; cursor: pointer; font: inherit; }
.toc-item:hover { background: var(--bg2); }
.toc-item.active { background: rgba(110,168,254,.15); }
.toc-check { flex: 0 0 22px; height: 22px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); }
.toc-item.active .toc-check { color: var(--accent); }
.toc-name { font-size: 14px; }
.course-main { flex: 1 1 auto; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }

/* 상세 뷰 */
.detail-head h1 { font-size: 24px; margin: 10px 0 6px; }
.detail-desc { color: var(--muted); margin: 0 0 12px; }
.detail-pct { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.detail-cols { display: flex; gap: 24px; margin: 22px 0; flex-wrap: wrap; }
.detail-goals, .detail-toc { flex: 1 1 240px; }
.detail-goals ul { margin: 0; padding-left: 18px; line-height: 1.9; }
.dt-list { margin: 0; padding-left: 20px; line-height: 1; }
.dt-lesson { padding: 8px 4px; cursor: pointer; border-radius: 6px; list-style: none; margin-left: -20px; padding-left: 8px; }
.dt-lesson:hover { background: var(--bg2); }
.dt-num { display: inline-block; width: 22px; color: var(--accent); font-weight: 600; }

/* 레슨 뷰 */
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.crumb span { opacity: .6; margin: 0 4px; }
.lesson-title { font-size: 22px; margin: 0 0 12px; }
.lesson-explain { line-height: 1.7; color: #d6dae2; }
.mini-h { margin: 18px 0 8px; font-size: 15px; color: var(--accent); }
.key-ideas { margin: 0; padding-left: 20px; line-height: 1.9; }
.lesson-checks { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.lesson-checks .done { color: #bff0bf; border-color: rgba(87,196,87,.5); background: rgba(87,196,87,.14); }
.lesson-board-wrap { margin: 18px 0; max-width: 560px; }
.course-board { width: 100%; }
.board-step { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.board-step button { background: var(--line); border: 1px solid #464d59; color: var(--text); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.board-step #lsInfo { color: var(--muted); font-size: 13px; margin: 0 6px; }
.lesson-move-comment { position: relative; margin-top: 10px; padding: 10px 12px 18px; border-left: 3px solid var(--accent); background: rgba(255,255,255,.045); border-radius: 6px; line-height: 1.55; max-width: calc(100vw - 64px); overflow: auto; resize: none; }
.lesson-move-comment p { margin: 0; color: #dfe4ec; font-size: var(--lesson-comment-font, 14px); }
.lesson-move-comment .hint { font-size: var(--lesson-comment-font, 14px); }
.lesson-comment-title { color: var(--accent); font-size: var(--lesson-comment-title-font, 12px); font-weight: 700; margin-bottom: 4px; }
.lesson-comment-resize { position: absolute; right: 0; bottom: 0; width: 24px; height: 24px; cursor: nwse-resize; background: transparent; }
.no-video { color: var(--muted); font-size: 14px; background: var(--bg2); padding: 12px; border-radius: 8px; }
.video-link { display: inline-block; margin: 10px 0; }

/* 연습 뷰 */
.practice-head { display: flex; align-items: center; gap: 12px; }
.solved-tag { color: var(--good); font-size: 13px; }
.prob-q { font-size: 16px; font-weight: 600; margin: 14px 0; }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.option-btn { background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 14px; font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; }
.option-btn:hover:not([disabled]) { border-color: var(--accent); }
.option-btn[disabled] { cursor: default; }
.option-btn.opt-correct { background: rgba(87,196,87,.22); border-color: var(--good); color: #bff0bf; }
.option-btn.opt-wrong { background: rgba(224,87,74,.22); border-color: var(--bad); color: #f5b3ab; }
.prob-feedback { display: none; margin-top: 16px; padding: 14px; border-radius: 8px; }
.prob-feedback.show { display: block; }
.prob-feedback.good { background: rgba(87,196,87,.14); border: 1px solid rgba(87,196,87,.4); }
.prob-feedback.bad { background: rgba(224,87,74,.14); border: 1px solid rgba(224,87,74,.4); }
.fb-line { font-weight: 600; margin-bottom: 6px; }
.fb-explain { color: #d6dae2; line-height: 1.6; }
.prob-feedback .retry { margin-top: 12px; }
.practice-nav { display: flex; justify-content: space-between; margin-top: 20px; }

/* 반응형: 좁은 화면에서 사이드바를 위로 */
@media (max-width: 780px) {
  .course-workspace { flex-direction: column; }
  .course-sidebar { position: static; width: 100%; flex-basis: auto; }
  .courses-view { padding: 16px; }
}

/* ===================== 학생 관리 · 외부 사이트 추적 ===================== */
.student-view { padding: 22px 26px; max-width: 1080px; margin: 0 auto; }
.student-switch-row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 6px; }
.student-switch-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.student-switch-row select { margin: 0; min-width: 160px; }
.tracker-profile { margin-bottom: 16px; }
.tracker-fields { display: flex; flex-wrap: wrap; gap: 14px; }
.tracker-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1 1 200px; }
.tracker-fields input, .tracker-fields select { margin: 0; }
.tracker-status { min-height: 20px; margin: 10px 2px; font-size: 13px; }
.tracker-result { display: flex; flex-wrap: wrap; gap: 18px; }
.tracker-card {
  flex: 1 1 460px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 18px;
}
.tracker-card.lichess { border-top: 3px solid #b3b3b3; }
.tracker-card.chesscom { border-top: 3px solid #7fa650; }
.tracker-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.tracker-head b { font-size: 16px; }
.tracker-user { color: var(--accent); font-size: 14px; }
.tracker-sub { color: var(--muted); font-size: 12px; }
.tracker-h { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tracker-note { margin: 10px 0 0; font-size: 12px; color: var(--amber); }
.rating-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rating-table th, .rating-table td { padding: 6px 8px; text-align: center; border-bottom: 1px solid var(--line); }
.rating-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.rating-table .rt-name { text-align: left; color: var(--text); }
.rating-table .rt-cur { font-weight: 700; }
.rating-table .rt-note { text-align: left; color: var(--muted); font-size: 11px; }
.rating-table.games td, .rating-table.games th { border-bottom: 1px solid var(--line); }
.rating-table.games tr:last-child td { border-bottom: none; }
.rating-table.games .rt-total td { font-weight: 700; border-bottom: 2px solid var(--line); }
.dl { font-variant-numeric: tabular-nums; font-weight: 600; }
.dl.up { color: var(--good); }
.dl.down { color: var(--bad); }
.dl.flat { color: var(--muted); }
@media (max-width: 780px) {
  .student-view { padding: 14px; }
  .tracker-card { flex-basis: 100%; }
  .rating-table { font-size: 12px; }
}

/* ===================== PGN 대량 가져오기 모달 ===================== */
.modal.wide { width: min(920px, 95vw); max-height: 88vh; overflow-y: auto; }
.pgn-import-textarea { width: 100%; min-height: 160px; font-family: "Consolas", "SF Mono", monospace; font-size: 12.5px; }
.pgn-import-opts { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin: 12px 0; }
.pgn-import-opts label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.pgn-import-opts select { margin: 0; min-width: 160px; }
.pgn-import-summary { font-size: 13px; color: var(--muted); margin: 8px 0; }
.pgn-game-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; margin: 10px 0; }
.pgn-game-card {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  background: var(--bg2); font-size: 13px;
}
.pgn-game-card.has-error { border-color: var(--bad); }
.pgn-game-card .pgc-title { font-weight: 700; margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.pgn-game-card .pgc-meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.pgn-game-card .pgc-meta .bad-tag { color: var(--bad); }
.pgn-game-card .pgc-meta .good-tag { color: var(--good); }
.pgn-game-card .pgc-errors { color: var(--bad); font-size: 12px; margin-top: 6px; }
.pgn-game-card label { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.pgn-legend { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.6; }
.import-target { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; padding: 8px 10px; border-radius: 8px; border: 1px solid rgba(110,168,254,.32); background: rgba(110,168,254,.1); font-size: 13px; }
.import-target span, .import-target em { color: var(--muted); font-style: normal; }
.import-target b { color: #dbe8ff; }
.position-editor { display: grid; grid-template-columns: minmax(280px, 440px) minmax(220px, 1fr); gap: 16px; align-items: start; }
.position-board { width: min(440px, 100%); aspect-ratio: 1 / 1; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 8px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.pos-square { position: relative; display: flex; align-items: center; justify-content: center; }
.pos-square.light { background: var(--sq-light); }
.pos-square.dark { background: var(--sq-dark); }
.pos-square:hover { box-shadow: inset 0 0 0 3px rgba(110,168,254,.7); }
.pos-piece { position: absolute; inset: 5%; background-size: contain; background-repeat: no-repeat; background-position: center; cursor: grab; }
.pos-piece:active { cursor: grabbing; }
.position-tools { display: flex; flex-direction: column; gap: 10px; }
.position-palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.position-piece-btn { min-height: 54px; padding: 4px; display: flex; align-items: center; justify-content: center; }
.position-piece-btn .piece { position: static; inset: auto; width: 42px; height: 42px; pointer-events: none; }
.position-piece-btn.active { border-color: var(--accent); background: rgba(110,168,254,.18); }
.position-piece-btn.erase { grid-column: span 2; color: var(--muted); }
.position-castling { display: flex; gap: 10px; flex-wrap: wrap; }
.position-castling label { display: inline-flex; align-items: center; gap: 4px; margin: 0; color: var(--text); }
.position-castling input { width: auto; }
.position-fen-preview { margin-top: 8px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .position-editor { grid-template-columns: 1fr; }
}

/* ===================== Supabase login gate and role badge ===================== */
.auth-gate {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.auth-gate.hidden { display: none; }
.auth-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 36px 40px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5);
  max-width: 360px;
}
.auth-box h1 { margin: 0 0 8px; font-size: 22px; }
.auth-box p { color: var(--muted); margin: 0 0 18px; }
.auth-box button.primary { width: 100%; padding: 10px; font-size: 15px; }
.auth-user-badge { display: inline-flex; align-items: center; gap: 6px; margin-right: 10px; }
.auth-role-badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; font-weight: 700; }
.auth-role-badge.role-admin   { background: #e0574a33; color: #ff8f80; }
.auth-role-badge.role-teacher { background: #6ea8fe33; color: #6ea8fe; }
.auth-role-badge.role-student { background: #57c45733; color: #57c457; }
.auth-name { font-size: 12px; color: var(--muted); }

/* ===== 내 점수(학생) 화면 ===== */
.myscore-view { padding: 24px; max-width: 900px; margin: 0 auto; }
.myscore-view .ops-panel { margin-bottom: 16px; }
.myscore-summary { display: flex; gap: 16px; }
.myscore-stat { flex: 1; text-align: center; padding: 8px 0; }
.myscore-num { display: block; font-size: 30px; font-weight: 800; color: var(--fg, #eaeaea); }
.myscore-label { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.myscore-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.myscore-table th, .myscore-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.myscore-table th.num, .myscore-table td.num { text-align: right; white-space: nowrap; }
.pbar { background: var(--line); border-radius: 999px; height: 8px; overflow: hidden; min-width: 120px; }
.pbar-fill { background: #57c457; height: 100%; border-radius: 999px; transition: width .3s; }

/* ===== DB 회원 관리 · 배정 ===== */
.member-mgmt { margin-bottom: 16px; }
.member-mgmt.hidden { display: none; }
.member-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.member-table th, .member-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.member-table select { max-width: 160px; }
.member-email { font-size: 11px; color: var(--muted); margin-top: 2px; }
.member-status { font-size: 12px; margin-left: 6px; }
.member-save { margin-right: 4px; }

/* ===== 강의 공개/비공개 바 ===== */
.publish-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; margin: 8px 0 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.publish-bar.hidden { display: none; }
.publish-label { color: var(--muted); font-size: 13px; }
.publish-status { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.publish-status.st-draft { background: #8883; color: var(--muted); }
.publish-status.st-pub   { background: #57c45733; color: #57c457; }
.publish-status.st-dirty { background: #e0a24a33; color: #e6b25a; }
.publish-bar button:disabled { opacity: .45; cursor: default; }
.publish-msg { font-size: 12px; }
