/* ============================================================
   AI CHESS COACH — chess.com Game-Review-style layout
   Two columns (board left, tabbed sidebar right). Site design
   tokens (--surface, --border, --accent, --text, --text-soft).
   ============================================================ */

.ai-page {
  padding-top: calc(var(--header-h, 80px) + 1rem);
  padding-bottom: 3rem;
}
.ai-container { max-width: 1480px; }

/* ================ Compact hero ================ */
.ai-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 1rem;
}
.ai-hero__text { min-width: 0; }
.ai-hero__eyebrow {
  display: block;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  color: var(--accent);
  margin-bottom: 0.2rem;
  text-transform: uppercase;
}
.ai-hero__title {
  font-family: 'Cairo', sans-serif;
  font-weight: 800;
  font-size: clamp(1.3rem, 2.4vw, 1.8rem);
  line-height: 1.15;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.005em;
}

.ai-hero__quota {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.ai-hero__quota-num {
  font-family: 'Cairo', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  display: inline-flex;
  align-items: baseline;
  gap: 0.15rem;
}
.ai-hero__quota-num b { font-weight: 800; }
.ai-hero__quota-slash { color: var(--text-soft); font-weight: 400; margin: 0 0.1rem; }
.ai-hero__quota-bar {
  width: 70px;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}
.ai-hero__quota-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(.2,.8,.2,1);
}
.ai-hero__quota-plan {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
}

@media (max-width: 600px) {
  .ai-hero { flex-direction: column; align-items: flex-start; gap: 0.7rem; }
}

/* ================ Two-column main grid ================ */
.ai-stage-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: start;
}
@media (max-width: 1100px) {
  .ai-stage-grid { grid-template-columns: 1fr; }
}

.ai-stage-grid__board { min-width: 0; }
.ai-stage-grid__side  {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 1101px) {
  .ai-stage-grid__side {
    position: sticky;
    top: calc(var(--header-h, 80px) + 1rem);
    align-self: start;
    max-height: calc(100vh - var(--header-h, 80px) - 2rem);
  }
}

/* ================ Stage (board area) ================ */
.ai-stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  min-height: 600px;
  position: relative;
}

/* ================ Right-pane tabs ================ */
.ai-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem 0.4rem 0;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.ai-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.65rem 0.4rem;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  font-family: 'Cairo', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-tab:hover { color: var(--accent); }
.ai-tab.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 -2px 0 var(--accent) inset;
}
.ai-tab__ico { font-size: 0.95rem; }

.ai-pane {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.ai-pane.is-active { display: flex; flex-direction: column; }
.ai-pane__inner {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1;
}
.ai-pane__hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-soft);
  line-height: 1.65;
}

/* Empty state inside a pane (e.g. "Analysis" tab before any PGN) */
.ai-pane__empty {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 2.5rem 1.2rem;
  gap: 0.75rem;
}
.ai-pane__empty-ico { font-size: 3rem; color: var(--accent); opacity: 0.85; }
.ai-pane__empty h4 { font-family: 'Cairo', sans-serif; font-weight: 800; font-size: 1.1rem; color: var(--text); margin: 0; }
.ai-pane__empty p {
  margin: 0 auto;
  max-width: 36ch;
  color: var(--text-soft);
  font-size: 0.88rem;
  line-height: 1.75;
}
.ai-pane__empty .ai-btn { width: auto; align-self: center; padding: 0.7rem 1.3rem; }

/* ================ Sections inside a pane ================ */
.ai-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.95rem 1rem;
}
.ai-section + .ai-section { margin-top: 0.85rem; }
.ai-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}
.ai-section__title {
  margin: 0 0 0.65rem;
  font-family: 'Cairo', sans-serif;
  font-weight: 800;
  font-size: 0.96rem;
  color: var(--text);
}
.ai-section__head + .ai-section__title { margin: 0; }
.ai-section__head .ai-section__title { margin: 0; }

/* ================ Openings list ================ */
.ai-openings-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 60vh;
  overflow-y: auto;
  padding-inline-end: 4px;
}
.ai-opening-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--text);
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: start;
  line-height: 1.4;
  transition: 0.15s;
  width: 100%;
  display: block;
}
.ai-opening-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateX(-2px);
}
[dir="ltr"] .ai-opening-btn:hover { transform: translateX(2px); }
.ai-opening-btn small {
  display: block;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-top: 3px;
  font-weight: 400;
}
.ai-opening-btn:hover small { color: var(--accent); }
.ai-openings__loading {
  color: var(--text-soft);
  font-size: 0.85rem;
  padding: 0.5rem;
}

/* ================ Upload zone ================ */
.ai-upload-zone {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 0.9rem;
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  cursor: pointer;
  transition: 0.18s;
  margin-bottom: 0.7rem;
}
.ai-upload-zone:hover,
.ai-upload-zone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.ai-upload-zone__icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--royal-navy, #0F1E4A);
  border-radius: 8px;
  font-size: 1.15rem;
  font-weight: 800;
  flex-shrink: 0;
}
.ai-upload-zone__text strong { display: block; font-size: 0.88rem; font-weight: 800; color: var(--text); }
.ai-upload-zone__text span { display: block; font-size: 0.74rem; color: var(--text-soft); margin-top: 1px; }

.ai-or {
  display: flex; align-items: center; gap: 0.7rem;
  margin: 0.7rem 0;
  font-family: 'Cairo', sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: var(--text-soft);
}
.ai-or::before, .ai-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.ai-pgn-paste {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.65;
  resize: vertical;
  min-height: 90px;
  margin-bottom: 0.85rem;
  transition: 0.18s;
}
.ai-pgn-paste:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ================ Buttons ================ */
.ai-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.18s;
  width: 100%;
}
.ai-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ai-btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--royal-navy, #0F1E4A);
}
.ai-btn--primary:hover { filter: brightness(0.95); background: var(--accent); color: var(--royal-navy, #0F1E4A); }
.ai-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.ai-btn__loader[hidden] { display: none; }
.ai-btn--send { width: 42px; height: 42px; flex-shrink: 0; padding: 0; font-size: 1.05rem; }
.ai-link {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ai-link:hover { filter: brightness(0.9); }
.ai-card__refresh {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-soft);
  width: 28px; height: 28px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: 0.18s;
}
.ai-card__refresh:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ================ History list ================ */
.ai-history { display: flex; flex-direction: column; gap: 0.4rem; max-height: 380px; overflow-y: auto; padding-inline-end: 2px; }
.ai-history__empty {
  color: var(--text-soft);
  text-align: center;
  padding: 1rem 0.85rem;
  font-size: 0.85rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.ai-history__item {
  position: relative;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: 0.15s;
}
.ai-history__item:hover { border-color: var(--accent); background: var(--accent-soft); }
.ai-history__item.is-active { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent) inset; }
.ai-history__date { font-size: 0.74rem; color: var(--text-soft); margin-bottom: 0.35rem; }
.ai-history__stats { display: flex; gap: 0.4rem; flex-wrap: wrap; font-size: 0.78rem; }
.ai-history__chip {
  padding: 1px 8px;
  border-radius: 50px;
  background: var(--surface-3);
  font-size: 0.74rem;
  color: var(--text);
}
.ai-history__chip--acc { background: rgba(43,182,115,0.15); color: #2BB673; }
.ai-history__chip--blunder { background: rgba(220,70,70,0.15); color: #DC4646; }
.ai-history__chip--mistake { background: rgba(220,140,50,0.15); color: #DC8C32; }

/* ================ Empty board hint inside Stage ================ */
.ai-empty-hint {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  margin-top: 0.85rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 10px;
  font-size: 0.88rem;
}
.ai-empty-hint strong {
  display: block;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
}
.ai-empty-hint span { color: var(--text-soft); line-height: 1.65; }

/* Old empty banner (kept for backward-compat with renderReport JS) */
.ai-empty-banner {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 10px;
  font-size: 0.88rem;
}
.ai-empty-banner__icon { font-size: 1.4rem; color: var(--accent); flex-shrink: 0; }
.ai-empty-banner strong { display: block; font-weight: 800; color: var(--text); margin-bottom: 2px; }
.ai-empty-banner span { color: var(--text-soft); }

/* ================ Chat ================ */
.ai-chat-card { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ai-chat-suggest {
  display: flex; gap: 0.35rem; flex-wrap: wrap;
  margin-bottom: 0.7rem;
}
.ai-chat-suggest__btn {
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  font-family: 'Cairo', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s;
}
.ai-chat-suggest__btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.ai-persona-row {
  display: flex; align-items: center; gap: 0.55rem;
  margin: 0 0 0.85rem;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ai-persona-lbl {
  font-size: 0.72rem;
  color: var(--text-soft);
  white-space: nowrap;
  font-weight: 700;
}
.ai-persona-select {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.3rem 0.4rem;
  font-family: 'Cairo', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.ai-persona-select:focus { outline: none; color: var(--accent); }
.ai-persona-select option { background: var(--surface); color: var(--text); }

.ai-chat {
  flex: 1;
  min-height: 220px;
  overflow-y: auto;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.6rem;
  display: flex; flex-direction: column;
  gap: 0.55rem;
}
.ai-chat__msg {
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.75;
  max-width: 88%;
  word-wrap: break-word;
}
.ai-chat__msg--bot { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); align-self: flex-start; border-top-inline-start-radius: 4px; }
.ai-chat__msg--user { background: var(--accent); color: var(--royal-navy, #0F1E4A); align-self: flex-end; border-top-inline-end-radius: 4px; font-weight: 600; }
.ai-chat__msg--loading { opacity: 0.6; font-style: italic; }
.ai-chat__msg--streaming::after {
  content: '▋';
  display: inline-block;
  margin-inline-start: 4px;
  animation: ai-blink 1s steps(2) infinite;
  color: var(--accent);
}
@keyframes ai-blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.ai-chat-context {
  font-size: 0.74rem;
  color: var(--text-soft);
  margin-bottom: 0.5rem;
  padding: 0 0.2rem;
}

.ai-chat-form { display: flex; gap: 0.5rem; align-items: stretch; }
.ai-chat-form input {
  flex: 1;
  padding: 0.65rem 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Cairo', sans-serif;
  font-size: 0.9rem;
  transition: 0.18s;
}
.ai-chat-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ================ Toast / loading ================ */
.ai-toast {
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.ai-toast.is-error { background: rgba(220,70,70,0.1); border-color: rgba(220,70,70,0.4); color: #DC4646; }
.ai-toast.is-ok    { background: rgba(43,182,115,0.1); border-color: rgba(43,182,115,0.4); color: #2BB673; }

.ai-loading-state { text-align: center; padding: 2.5rem 1.5rem; }
.ai-loading-state__spinner {
  width: 50px; height: 50px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1.2rem;
  animation: ai-spin 0.8s linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

/* ================ Review (board area) ================ */
.ai-review { padding: 0; }
.ai-review--solo .ai-review__board-wrap { width: 100%; }

.ai-review__board-wrap { display: flex; flex-direction: column; gap: 0.7rem; }
.ai-review__board {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.35);
}
.ai-review__controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  justify-content: center;
  padding: 0.45rem 0.55rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ai-review__nav {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: 0.15s;
  display: grid; place-items: center;
}
.ai-review__nav:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.ai-review__counter {
  padding: 0 0.7rem;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  color: var(--text);
  font-size: 0.88rem;
}

.ai-active-mistake[hidden] { display: none; }
.ai-active-mistake {
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 8px;
}
.ai-active-mistake__head {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text);
}
.ai-active-mistake__text { margin: 0; color: var(--text); font-size: 0.9rem; line-height: 1.75; }

.ai-explore-banner {
  align-self: center;
  margin-bottom: 0.5rem;
  background: var(--accent);
  color: var(--royal-navy, #0F1E4A);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: 0.15s;
}
.ai-explore-banner:hover { filter: brightness(0.95); }
.ai-explore-banner[hidden] { display: none; }

/* ================ Stats (post-PGN report) ================ */
.ai-report__head {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 0;
  padding: 0.85rem 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.85rem;
}
.ai-stat { text-align: center; padding: 0 0.3rem; border-inline-end: 1px solid var(--border); }
.ai-stat:last-child { border-inline-end: none; }
.ai-stat__num {
  font-family: 'Cairo', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
}
.ai-stat__num--acc      { color: #2BB673; }
.ai-stat__num--blunder  { color: #DC4646; }
.ai-stat__num--mistake  { color: #DC8C32; }
.ai-stat__num--inacc    { color: #C9A663; }
.ai-stat__lbl {
  font-size: 0.66rem;
  color: var(--text-soft);
  margin-top: 0.4rem;
  letter-spacing: 0.04em;
}

/* ================ Move list ================ */
.ai-review__moves {
  background: transparent;
  padding: 0;
  max-height: none;
  overflow: visible;
}
.ai-review__title {
  margin: 0 0 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-family: 'Cairo', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
}
.ai-move-row {
  display: grid;
  grid-template-columns: 26px 1fr 1fr;
  gap: 0.3rem;
  align-items: center;
  margin-bottom: 0.2rem;
}
.ai-move-row__num { font-size: 0.74rem; color: var(--text-soft); text-align: center; font-weight: 600; }
.ai-move {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: ui-monospace, "SF Mono", "Cairo", monospace;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: start;
  transition: 0.12s;
}
.ai-move:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.ai-move.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.ai-move.is-blunder    { background: rgba(220,70,70,0.10);  color: #DC4646; border-color: rgba(220,70,70,0.3); }
.ai-move.is-mistake    { background: rgba(220,140,50,0.10); color: #DC8C32; border-color: rgba(220,140,50,0.3); }
.ai-move.is-inaccuracy { background: rgba(201,166,99,0.08); color: #C9A663; border-color: rgba(201,166,99,0.3); }
.ai-move.is-blunder.is-active    { background: rgba(220,70,70,0.25); color: #fff; border-color: #DC4646; box-shadow: 0 0 0 1px #DC4646 inset; }
.ai-move.is-mistake.is-active    { background: rgba(220,140,50,0.25); color: #fff; border-color: #DC8C32; box-shadow: 0 0 0 1px #DC8C32 inset; }
.ai-move.is-inaccuracy.is-active { background: rgba(201,166,99,0.25); color: #fff; border-color: #C9A663; box-shadow: 0 0 0 1px #C9A663 inset; }
.ai-move__san { display: inline-block; }
.ai-move__glyph {
  font-family: ui-monospace, "SF Mono", monospace;
  font-weight: 800;
  font-size: 0.78em;
  margin-inline-start: 0.25rem;
  letter-spacing: -0.04em;
  vertical-align: 1px;
}
.ai-move__glyph--blunder    { color: #DC4646; }
.ai-move__glyph--mistake    { color: #DC8C32; }
.ai-move__glyph--inaccuracy { color: #C9A663; }
.ai-review__legend {
  display: flex;
  justify-content: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  font-size: 0.74rem;
  color: var(--text-soft);
}
.ai-review__legend span { display: inline-flex; align-items: center; gap: 0.25rem; }

/* ================ Annotation panel (chess.com style) ================ */
.ai-anno {
  display: block;
  padding: 0.95rem 1.05rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 10px;
  font-family: 'Cairo', sans-serif;
}
.ai-anno[hidden] { display: none; }
.ai-anno--is-blunder    { border-inline-start-color: #DC4646; }
.ai-anno--is-mistake    { border-inline-start-color: #DC8C32; }
.ai-anno--is-inaccuracy { border-inline-start-color: #C9A663; }

.ai-anno__head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.55rem; margin-bottom: 0.65rem; }
.ai-anno__chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  font-weight: 700; font-size: 0.82rem;
  background: var(--surface-3); color: var(--text);
}
.ai-anno__chip--is-blunder    { background: rgba(220,70,70,0.18); color: #DC4646; }
.ai-anno__chip--is-mistake    { background: rgba(220,140,50,0.18); color: #DC8C32; }
.ai-anno__chip--is-inaccuracy { background: rgba(201,166,99,0.20); color: #C9A663; }
.ai-anno__glyph { font-family: ui-monospace, monospace; font-weight: 800; font-size: 0.92rem; letter-spacing: -0.04em; }
.ai-anno__label { font-size: 0.82rem; }
.ai-anno__move { flex: 1; font-size: 0.9rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ai-anno__move strong { font-family: ui-monospace, "Cairo", monospace; color: var(--accent); }
.ai-anno__delta {
  font-family: ui-monospace, monospace;
  font-weight: 800; font-size: 0.85rem;
  color: var(--text-soft);
  padding: 0.2rem 0.55rem;
  background: var(--surface-3);
  border-radius: 6px;
}
.ai-anno--is-blunder    .ai-anno__delta { color: #DC4646; }
.ai-anno--is-mistake    .ai-anno__delta { color: #DC8C32; }
.ai-anno--is-inaccuracy .ai-anno__delta { color: #C9A663; }
.ai-anno__mute {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 0.95rem;
  transition: 0.15s;
}
.ai-anno__mute:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ai-anno__text { margin: 0 0 0.85rem; color: var(--text); font-size: 0.9rem; line-height: 1.85; }
.ai-anno__text strong { font-family: ui-monospace, "Cairo", monospace; color: var(--accent); }
.ai-anno__text em { font-style: normal; color: var(--accent); font-weight: 700; }
.ai-anno__actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.4rem; }
.ai-anno__btn {
  display: inline-flex;
  align-items: center; justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: 'Cairo', sans-serif; font-weight: 700; font-size: 0.82rem;
  cursor: pointer;
  transition: 0.15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-anno__btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.ai-anno__btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-anno__btn-icon { font-size: 0.95rem; flex-shrink: 0; }
.ai-anno__btn--best {
  background: var(--accent);
  color: var(--royal-navy, #0F1E4A);
  border-color: var(--accent);
}
.ai-anno__btn--best:hover:not(:disabled) { filter: brightness(0.95); background: var(--accent); color: var(--royal-navy, #0F1E4A); }

/* ================ Eval graph ================ */
.ai-evalgraph {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.4rem 0.2rem;
  overflow: hidden;
}
.ai-eg__svg { display: block; width: 100%; height: 80px; cursor: crosshair; }
.ai-eg__base { stroke: var(--border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ai-eg__fill { fill: var(--accent); fill-opacity: 0.10; }
.ai-eg__line { fill: none; stroke: var(--accent); stroke-width: 1.3; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.ai-eg__dot { stroke: var(--surface); stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: pointer; }
.ai-eg__dot--blunder    { fill: #DC4646; }
.ai-eg__dot--mistake    { fill: #DC8C32; }
.ai-eg__dot--inaccuracy { fill: #C9A663; }
.ai-eg__cursor { stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-dasharray: 3 3; pointer-events: none; transition: x1 0.2s ease, x2 0.2s ease; }

/* ================ Mistake legacy + report ================ */
.ai-mistakes { padding: 0.4rem 0; }
.ai-mistakes__title { font-family: 'Cairo', sans-serif; font-size: 0.95rem; font-weight: 800; margin: 0 0 0.85rem; color: var(--text); }
.ai-mistake { padding: 0.85rem 1rem; background: var(--surface-2); border: 1px solid var(--border); border-inline-start: 3px solid; border-radius: 8px; margin-bottom: 0.6rem; }
.ai-mistake--blunder    { border-inline-start-color: #DC4646; }
.ai-mistake--mistake    { border-inline-start-color: #DC8C32; }
.ai-mistake--inaccuracy { border-inline-start-color: #C9A663; }
.ai-mistake__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.45rem; flex-wrap: wrap; gap: 0.5rem; }
.ai-mistake__title { font-weight: 700; color: var(--text); }
.ai-mistake__sev { font-size: 0.7rem; padding: 2px 9px; border-radius: 999px; background: var(--surface-3); color: var(--text-soft); }
.ai-mistake__sev--blunder    { background: rgba(220,70,70,0.18); color: #DC4646; }
.ai-mistake__sev--mistake    { background: rgba(220,140,50,0.18); color: #DC8C32; }
.ai-mistake__sev--inaccuracy { background: rgba(201,166,99,0.2); color: #C9A663; }
.ai-mistake__text { color: var(--text); font-size: 0.92rem; line-height: 1.8; margin: 0; }

/* Force-hide the legacy review-empty-hint text shown by old templates */
.ai-review__empty-hint { display: none; }

/* ============================================================
   Board settings — zoom + color override + popover panel
   ============================================================ */

/* Zoom — change the board-wrap max-width so the board grows/shrinks within
   the column without overflowing the layout. The wrapper width caps at the
   actual column space, so 120% just expands toward (but never past) the
   container's edges. */
.ai-stage { --ai-board-zoom: 1; }
.ai-stage .ai-review--solo .ai-review__board-wrap {
  width: 100%;
  max-width: calc(720px * var(--ai-board-zoom, 1));
  margin-inline: auto;
  transition: max-width 0.25s cubic-bezier(.2,.8,.2,1);
}

/* Board color overrides — target chessground square classes.
   Defaults are the bundled "brown" theme; we override per data-attr. */
.ai-stage[data-ai-board="blue"]   cg-board square.light  { background-color: #dee3e6 !important; }
.ai-stage[data-ai-board="blue"]   cg-board square.dark   { background-color: #8ca2ad !important; }
.ai-stage[data-ai-board="green"]  cg-board square.light  { background-color: #ebecd0 !important; }
.ai-stage[data-ai-board="green"]  cg-board square.dark   { background-color: #779556 !important; }
.ai-stage[data-ai-board="wood"]   cg-board square.light  { background-color: #d2a679 !important; }
.ai-stage[data-ai-board="wood"]   cg-board square.dark   { background-color: #8b5a2b !important; }
.ai-stage[data-ai-board="purple"] cg-board square.light  { background-color: #ead7f5 !important; }
.ai-stage[data-ai-board="purple"] cg-board square.dark   { background-color: #8b6dac !important; }
.ai-stage[data-ai-board="ic"]     cg-board square.light  { background-color: #ECDAB9 !important; }
.ai-stage[data-ai-board="ic"]     cg-board square.dark   { background-color: #AE8A68 !important; }

/* Settings popover */
.ai-settings-pop {
  position: absolute;
  z-index: 9999;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px -10px rgba(0,0,0,0.5);
  padding: 0.85rem;
  font-family: 'Cairo', sans-serif;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.ai-settings-pop[hidden] { display: none; }

.ai-settings-pop__row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ai-settings-pop__row--quiet { align-items: flex-end; }
.ai-settings-pop__lbl {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.ai-settings-pop__lbl em {
  font-style: normal;
  margin-inline-start: auto;
  color: var(--accent);
  font-weight: 700;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
}

/* Color swatch chips */
.ai-settings-pop__chips {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
}
.ai-chip {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}
.ai-chip--swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--sw, #ccc);
  border: 2px solid var(--border);
  transition: 0.15s;
}
.ai-chip--swatch:hover { transform: scale(1.05); border-color: var(--accent); }
.ai-chip--swatch.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  transform: scale(1.05);
}

/* Range slider — gold accent */
.ai-settings-pop__zoom {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.ai-settings-pop__zoom::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.ai-settings-pop__zoom::-moz-range-thumb {
  width: 18px; height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--surface);
}

/* Sound toggle */
.ai-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  position: relative;
}
.ai-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.ai-toggle__track {
  display: inline-block;
  width: 42px;
  height: 22px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  transition: 0.18s;
}
.ai-toggle__thumb {
  position: absolute;
  top: 1px; inset-inline-start: 1px;
  width: 18px; height: 18px;
  background: var(--text-soft);
  border-radius: 50%;
  transition: 0.18s;
}
.ai-toggle input:checked + .ai-toggle__track { background: var(--accent); border-color: var(--accent); }
.ai-toggle input:checked + .ai-toggle__track .ai-toggle__thumb {
  inset-inline-start: calc(100% - 19px);
  background: var(--royal-navy, #0F1E4A);
}

/* ============================================================
   New severity tiers: ! Excellent + !! Brilliant
   Plus move-list filter toggle.
   ============================================================ */

/* Move-list bar with filter button */
.ai-movelist__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0 0 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.ai-movelist__bar .ai-review__title {
  margin: 0;
  padding: 0;
  border: 0;
}
.ai-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  font-family: 'Cairo', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.15s;
  white-space: nowrap;
}
.ai-filter-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.ai-filter-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--royal-navy, #0F1E4A);
}
.ai-filter-btn__ico { font-size: 0.85rem; }

/* Brilliant (!!) — teal/cyan glow */
.ai-move.is-brilliant {
  background: rgba(38, 201, 195, 0.12);
  color: #26C9C3;
  border-color: rgba(38, 201, 195, 0.35);
}
.ai-move.is-brilliant.is-active {
  background: rgba(38, 201, 195, 0.30);
  border-color: #26C9C3;
  color: #fff;
  box-shadow: 0 0 0 1px #26C9C3 inset, 0 0 12px -2px rgba(38,201,195,0.5);
}
.ai-move__glyph--brilliant { color: #26C9C3; }

/* Excellent (!) — fresh green */
.ai-move.is-excellent {
  background: rgba(123, 185, 90, 0.12);
  color: #7BB95A;
  border-color: rgba(123, 185, 90, 0.32);
}
.ai-move.is-excellent.is-active {
  background: rgba(123, 185, 90, 0.30);
  border-color: #7BB95A;
  color: #fff;
  box-shadow: 0 0 0 1px #7BB95A inset;
}
.ai-move__glyph--excellent { color: #7BB95A; }

/* Annotation chip variants */
.ai-anno--is-brilliant    { border-inline-start-color: #26C9C3; }
.ai-anno--is-excellent    { border-inline-start-color: #7BB95A; }
.ai-anno__chip--is-brilliant { background: rgba(38,201,195,0.18); color: #26C9C3; }
.ai-anno__chip--is-excellent { background: rgba(123,185,90,0.18); color: #7BB95A; }
.ai-anno--is-brilliant .ai-anno__delta { color: #26C9C3; }
.ai-anno--is-excellent .ai-anno__delta { color: #7BB95A; }

/* Animate the brilliancy chip — subtle gold-shimmer pulse */
.ai-anno__chip--is-brilliant {
  animation: ai-brill-pulse 2.4s ease-in-out infinite;
}
@keyframes ai-brill-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(38,201,195,0.0); }
  50%      { box-shadow: 0 0 0 4px rgba(38,201,195,0.18); }
}

/* Eval-graph dots for the new tiers */
.ai-eg__dot--brilliant { fill: #26C9C3; }
.ai-eg__dot--excellent { fill: #7BB95A; }

/* Legend count chips */
.ai-review__legend em {
  font-style: normal;
  font-family: ui-monospace, monospace;
  color: var(--text);
  font-weight: 700;
  margin-inline-start: 0.15rem;
  padding: 0 0.3rem;
  background: var(--surface-3);
  border-radius: 4px;
  font-size: 0.7em;
}

/* When zoom > 100%, board can grow — make sure inner board fills wrapper */
.ai-stage .ai-review__board { width: 100%; }
