/*
 * Theory custom-tag exercise UI (Phase 1: radio / radio_icon).
 * Paired with theory-study-viewer.js renderExercisePanel().
 *
 * NOTE (icon-font lesson): do NOT set font-family on a wildcard selector here.
 * Option labels are plain text and the piece glyphs are Unicode characters, so
 * the page font renders them correctly; a `* { font-family }` rule would risk
 * breaking Boxicons/FontAwesome icons elsewhere in the viewer.
 */

/* ===========================================================================
 * Cohesive board theme — replaces the default warm "brown" lichess theme with a
 * soft slate-blue board + the app's blue accent (#3b82f6), so the chessboard
 * matches the cool slate UI instead of clashing with it. Scoped to .ck-study-app
 * (loads after chessground.brown.css → these win). Squares drawn with a single
 * conic-gradient checkerboard so the two colours are fully controlled.
 * ========================================================================= */
.ck-study-app cg-board {
  background-color: #e9eef6;                 /* light squares */
  background-image: conic-gradient(
    #98adc9 90deg,                            /* dark squares */
    #e9eef6 90deg 180deg,
    #98adc9 180deg 270deg,
    #e9eef6 270deg
  );
  background-size: 25% 25%;
}

/* Interactive states → app blue (was green/olive). */
.ck-study-app cg-board square.move-dest {
  background: radial-gradient(rgba(59, 130, 246, 0.5) 19%, rgba(59, 130, 246, 0) 21%);
}
.ck-study-app cg-board square.oc.move-dest {
  background: radial-gradient(transparent 0%, transparent 79%, rgba(59, 130, 246, 0.32) 80%);
}
.ck-study-app cg-board square.move-dest:hover { background: rgba(59, 130, 246, 0.26); }
.ck-study-app cg-board square.last-move { background-color: rgba(59, 130, 246, 0.24); }
.ck-study-app cg-board square.selected { background-color: rgba(59, 130, 246, 0.42); }
.ck-study-app cg-board square.check {
  background: radial-gradient(ellipse at center,
    rgba(239, 68, 68, 0.92) 0%, rgba(239, 68, 68, 0.82) 26%, rgba(239, 68, 68, 0) 80%);
}

/* Board framed as a clean card (matches the 12px-radius design system). */
.ck-study-app .ck-study-board-wrap { background: transparent; }
.ck-study-app .ck-study-board {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12), 0 0 0 1px #e2e8f0;
}

/* Dark mode: a MEDIUM slate board (not near-black) so both the white (cream)
 * and the black chess pieces stay clearly visible — the previous deep board hid
 * the dark pieces. It still reads as a distinct card on the dark page. */
html[data-theme="dark"] .ck-study-app cg-board {
  background-color: #9aa6ba;
  background-image: conic-gradient(
    #6b7a93 90deg, #9aa6ba 90deg 180deg, #6b7a93 180deg 270deg, #9aa6ba 270deg);
}
html[data-theme="dark"] .ck-study-app .ck-study-board {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45), 0 0 0 1px #475569;
}

/* Custom-tag exercises clear the move-centric status box — hide it when empty
 * instead of showing an empty bordered panel. */
.ck-study-app .ck-practice-notice:empty {
  display: none;
}

/* Phase 3 — solved badge on practice-list items (student's own progress). */
.ck-study-app [data-item-type="practice"].is-solved { color: #059669; }
.ck-study-app .ck-item-solved {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #10b981;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  flex: 0 0 auto;
}
html[data-theme="dark"] .ck-study-app .ck-item-solved { background: #34d399; color: #064e3b; }

/* collect_stars info chip: stars collected / moves / par. */
.ck-study-app .ck-ex-collect-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 2px;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
  border: 1px solid #fcd34d;
  color: #92400e;
  font-weight: 700;
  font-size: 14px;
  font-family: 'Inter', system-ui, sans-serif;
}
html[data-theme="dark"] .ck-study-app .ck-ex-collect-info {
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.4);
  color: #fcd34d;
}

.ck-exercise-host {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ck-ex-caption {
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
}

/* Option grid -------------------------------------------------------------- */
.ck-ex-options {
  display: grid;
  gap: 10px;
}

.ck-ex-options--auto  { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.ck-ex-options--2col  { grid-template-columns: repeat(2, 1fr); }
.ck-ex-options--3col  { grid-template-columns: repeat(3, 1fr); }
.ck-ex-options--4col  { grid-template-columns: repeat(4, 1fr); }
.ck-ex-options--2x2   { grid-template-columns: repeat(2, 1fr); }
.ck-ex-options--2x3   { grid-template-columns: repeat(2, 1fr); }
.ck-ex-options--3x2   { grid-template-columns: repeat(3, 1fr); }

.ck-ex-options--inline {
  display: flex;
  flex-wrap: wrap;
}

/* Option button ------------------------------------------------------------ */
.ck-ex-option {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #ffffff;
  color: #1e293b;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease, transform 120ms ease;
}

.ck-ex-option:hover:not(:disabled) {
  border-color: #3b82f6;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.ck-ex-option:focus-visible {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

.ck-ex-option.is-selected {
  border-color: #3b82f6;
  background: #eff6ff;
}

.ck-ex-option.is-correct {
  border-color: #10b981;
  background: #ecfdf5;
  color: #047857;
}

.ck-ex-option.is-wrong {
  border-color: #ef4444;
  background: #fef2f2;
  color: #b91c1c;
}

.ck-ex-option:disabled {
  cursor: default;
  opacity: 0.85;
}

.ck-ex-option-icon {
  font-size: 30px;
  line-height: 1;
  font-weight: 400; /* the chess glyphs inherit the button's bold otherwise → heavy */
  color: #334155;
}
html[data-theme="dark"] .ck-ex-option-icon { color: #e2e8f0; }

.ck-ex-option-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Check button ------------------------------------------------------------- */
.ck-ex-check {
  align-self: flex-start;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
}

.ck-ex-check:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Square-pick / value / text / palette --------------------------------- */
.ck-ex-hint-text {
  font-size: 13px;
  color: #475569;
  line-height: 1.5;
}

.ck-ex-value-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ck-ex-value-input,
.ck-ex-text-input {
  flex: 1 1 140px;
  min-width: 120px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: 15px;
  color: #1e293b;
}

.ck-ex-value-input:focus-visible,
.ck-ex-text-input:focus-visible {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

/* Piece palette (place_pieces) */
.ck-ex-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ck-ex-palette-piece {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #ffffff;
  color: #1e293b;
  cursor: pointer;
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.ck-ex-palette-piece:hover {
  border-color: #3b82f6;
}

.ck-ex-palette-piece.is-selected {
  border-color: #3b82f6;
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

/* Mobile: never more than 2 columns regardless of authored layout. */
@media (max-width: 480px) {
  .ck-ex-options--3col,
  .ck-ex-options--4col,
  .ck-ex-options--3x2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---------------------------------------------------------------------------
 * Board coordinates OUTSIDE the board. Chessground's in-board coords are hidden;
 * the viewer JS (renderCoordRuler) renders large, bold a-h / 1-8 labels in the
 * board wrap's left + bottom padding so they never overlap squares/pieces.
 * The wrap keeps aspect-ratio:1 (border-box) → padding shrinks the square board
 * a little and frees a strip on the left + bottom for the labels, aligned to
 * the 8 rows/columns via flex:1 cells.
 * ------------------------------------------------------------------------- */
.ck-study-app .cg-wrap coords {
  display: none !important; /* render our external ruler instead */
}

.ck-study-app .ck-study-board-wrap {
  overflow: visible;
  padding-left: 20px;
  padding-bottom: 20px;
  box-sizing: border-box;
}

.ck-study-app .ck-coord-ranks,
.ck-study-app .ck-coord-files {
  position: absolute;
  display: flex;
  pointer-events: none;
  user-select: none;
  z-index: 1;
}

.ck-study-app .ck-coord-ranks {
  left: 0;
  top: 0;
  width: 20px;
  height: calc(100% - 20px); /* aligns with the 8 board rows */
  flex-direction: column;
}

.ck-study-app .ck-coord-files {
  left: 20px;
  bottom: 0;
  height: 20px;
  width: calc(100% - 20px); /* aligns with the 8 board columns */
  flex-direction: row;
}

.ck-study-app .ck-coord-ranks > span,
.ck-study-app .ck-coord-files > span {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(11px, 1.5vw, 16px);
  color: #334155;
  line-height: 1;
}

html[data-theme="dark"] .ck-study-app .ck-coord-ranks > span,
html[data-theme="dark"] .ck-study-app .ck-coord-files > span {
  color: #cbd5e1;
}

/* ============================================================
 * Phase 4a — PUZZLE-RACER mode. Strips the study chrome down to
 * just the board + exercise so the student drills, Lichess-style.
 * No wildcard font-family (icon-font lesson).
 * ============================================================ */
.ck-study-app.is-race-mode [data-study-role="picker-wrap"],
.ck-study-app.is-race-mode .ck-study-tab-btn,
.ck-study-app.is-race-mode [data-study-tab="theory"],
.ck-study-app.is-race-mode .ck-study-top-actions,
.ck-study-app.is-race-mode .ck-study-top,
.ck-study-app.is-race-mode .ck-study-games,
.ck-study-app.is-race-mode [data-study-role="controls"] {
  display: none !important;
}
/* Racer layout: BOARD LEFT, QUESTION RIGHT — side by side so the student
 * never scrolls between the position and the answers (Lichess-style). */
.ck-study-app.is-race-mode .ck-study-layout {
  display: grid;
  grid-template-columns: minmax(320px, 600px) minmax(300px, 1fr);
  gap: 20px;
  align-items: start;
}
.ck-study-app.is-race-mode .ck-study-right {
  position: sticky;
  top: 12px;
}
/* The move-tree has no place in a race (it would leak the solution line). */
.ck-study-app.is-race-mode [data-study-role="move-tree-section"] {
  display: none !important;
}
.ck-study-app.is-race-mode .ck-practice-question {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.45;
}
@media (max-width: 860px) {
  .ck-study-app.is-race-mode .ck-study-layout { grid-template-columns: 1fr; }
  .ck-study-app.is-race-mode .ck-study-right { position: static; }
}
/* Hide the outer page shell (breadcrumb buttons, "Chi tiết lý thuyết", title
 * chip) so the racer is just the board + exercise — and so no nav-away links
 * tempt the student out of the topic. */
.ck-theories-viewer-shell.is-race-shell > .ck-financial-header,
.ck-theories-viewer-shell.is-race-shell > .ck-financial-toolbar {
  display: none !important;
}

.ck-race-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 14px;
  padding: 10px 16px;
  border-radius: 12px;
  background: linear-gradient(90deg, #eff6ff, #f5f3ff);
  border: 1px solid #bfdbfe;
  font-family: 'Inter', system-ui, sans-serif;
}
.ck-race-bar-progress { font-weight: 800; color: #1d4ed8; font-size: 15px; }
.ck-race-bar-clock { font-weight: 800; color: #047857; font-size: 18px; font-variant-numeric: tabular-nums; }
.ck-race-bar-clock.is-low { color: #ef4444; animation: ckRacePulse 1s infinite; }
@keyframes ckRacePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.ck-race-finish {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(15, 23, 42, 0.92);
  border-radius: 12px;
  text-align: center;
  padding: 24px;
}
.ck-race-finish-title { font-size: 30px; font-weight: 900; color: #ffffff; font-family: 'Inter', system-ui, sans-serif; }
.ck-race-finish-stat { font-size: 17px; color: #e2e8f0; font-family: 'Inter', system-ui, sans-serif; }
.ck-race-finish-btn {
  margin-top: 6px;
  padding: 12px 24px;
  border-radius: 12px;
  background: #3b82f6;
  color: #ffffff;
  font-weight: 800;
  font-size: 15px;
  text-decoration: none;
  font-family: 'Inter', system-ui, sans-serif;
}
.ck-race-finish-btn:hover { background: #2563eb; color: #ffffff; }

/* ============================================================
 * name_square ("Gọi tên ô") — board ruler hidden, student names the
 * ringed piece's square via a file/rank picker. No wildcard font-family
 * (icon-font lesson); the piece glyph uses unicode chess chars, not an
 * icon font, so it is safe.
 * ============================================================ */

/* HideCoordinates: suppress the external a-h/1-8 ruler (in-board coords are
 * already hidden by the .cg-wrap coords rule). The "Hiện nhãn" help button
 * removes this class to reveal the ruler temporarily. */
.ck-study-app .ck-study-board-wrap.is-hide-coords .ck-coord-ranks,
.ck-study-app .ck-study-board-wrap.is-hide-coords .ck-coord-files {
  display: none !important;
}

.ck-ns-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.ck-ns-glyph {
  font-size: 30px;
  line-height: 1;
  color: #ffffff;
  text-shadow: -1px -1px 0 #333, 1px -1px 0 #333, -1px 1px 0 #333, 1px 1px 0 #333;
}
.ck-ns-glyph.is-black {
  color: #141414;
  text-shadow: -1px -1px 0 #eee, 1px -1px 0 #eee, -1px 1px 0 #eee, 1px 1px 0 #eee;
}
.ck-ns-lead { font-size: 13px; color: #64748b; }
.ck-ns-name { font-size: 17px; font-weight: 700; color: #1e293b; }
.ck-ns-dots { display: flex; gap: 6px; margin-left: auto; }
.ck-ns-dot { width: 10px; height: 10px; border-radius: 50%; background: #e2e8f0; }
.ck-ns-dot.is-active { background: #3b82f6; }
.ck-ns-dot.is-done { background: #10b981; }

.ck-ns-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ck-ns-btn {
  width: 34px;
  padding: 7px 0;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #ffffff;
  color: #1e293b;
  cursor: pointer;
  font-family: 'Inter', system-ui, sans-serif;
}
.ck-ns-btn:hover { border-color: #3b82f6; background: #eff6ff; }
.ck-ns-btn.is-active { background: #3b82f6; border-color: #2563eb; color: #ffffff; }

.ck-ns-ctrl { display: flex; align-items: center; gap: 10px; margin: 10px 0 8px; }
.ck-ns-picklabel { font-size: 13px; color: #64748b; }
.ck-ns-pick {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #1d4ed8;
  min-width: 40px;
  font-variant-numeric: tabular-nums;
}
.ck-ns-ctrl .ck-ex-check { margin-left: auto; }
.ck-ns-help {
  font-size: 12px;
  padding: 5px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  color: #475569;
  cursor: pointer;
  font-family: 'Inter', system-ui, sans-serif;
}
.ck-ns-help:hover { background: #eff6ff; border-color: #bfdbfe; }
