/* ==========================================================================
   Screen "notebook" (js/ui/notebook.js): the mistake notebook with spaced repetition. Every class starts
   with .notebook-. Built on the shared components of css/system.css (.card, .btn, .chip, .segmented,
   .field, .select, .input, .empty, .badge) and on the kit's mini board; only layout and the few one-off
   decorations live here. Tokens come from styles.css, none is redefined.

   Layout
     phone      one column: heading, summary (figure, action, stats, box chart), weak spots as a strip that
                scrolls sideways, filters, one card per row (board 112px beside the text)
     tablet     the summary in two columns, cards in one or two columns (board 148px)
     desktop    summary in two columns, weak spots as one row, cards in two columns
   ========================================================================== */

.notebook {
  display: grid;
  gap: var(--space-7);
  min-width: 0;
}

/* ── Header ── */
.notebook-head { max-width: 48rem; }
.notebook-head .t-eyebrow { margin-bottom: var(--space-2); letter-spacing: 0.18em; }
.notebook-title {
  font-size: clamp(2.1rem, 1.5rem + 2.6vw, 3.4rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
}
.notebook-title:focus { outline: none; }
.notebook-sub { margin-top: var(--space-3); max-width: 58ch; line-height: 1.55; text-wrap: pretty; }
.notebook-unavailable {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--color-text-muted);
}

.notebook-h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 650;
  line-height: var(--lh-tight);
}
.notebook-h2:focus { outline: none; }
.notebook-lead { margin: var(--space-1) 0 0; max-width: 60ch; color: var(--color-text-muted); font-size: var(--text-base); line-height: var(--lh-normal); }
.notebook-section-head { display: grid; gap: var(--space-1); }

/* ── Summary ── */
.notebook-summary-host { min-width: 0; }
.notebook-summary {
  --card-pad: clamp(20px, 3vw, 36px);
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: var(--space-7) var(--space-8);
  align-items: start;
  background-image:
    radial-gradient(560px 260px at 0 0, rgba(221, 167, 52, 0.11), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.028), rgba(255, 255, 255, 0) 46%);
}
.notebook-due { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); align-content: start; min-width: 0; }
.notebook-due-figure {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-3);
  margin: 0;
}
/* The one hero figure of the screen: proportional figures in the UI face (not tabular, not the serif). */
.notebook-due-count {
  font-family: var(--font-ui);
  font-size: clamp(3.5rem, 2.6rem + 4vw, 5.25rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: var(--color-gold);
}
.notebook-due-label { font-size: var(--text-lg); font-weight: 600; color: var(--color-text); }
.notebook-due-note { margin: 0; color: var(--color-text-muted); font-size: var(--text-base); line-height: var(--lh-normal); }
.notebook-clear-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 650;
  line-height: var(--lh-tight);
}
.notebook-clear-title .ui-icon {
  flex: none;
  box-sizing: content-box;
  padding: 8px;
  border: 1px solid var(--color-perfect-bd);
  border-radius: 50%;
  background: var(--color-perfect-bg);
  color: var(--color-perfect);
}
.notebook-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-5);
  margin-top: var(--space-2);
}
.notebook-start { min-width: 15rem; }
.notebook-hint { margin: 0; max-width: 46ch; color: var(--color-text-muted); font-size: var(--text-sm); line-height: var(--lh-normal); }

/* The label wraps above the control when they do not fit side by side (a 320px phone, or a larger text size): the "20" of
   5 / 10 / 20 was cut off there (QA VIS-009). */
.notebook-size { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); min-width: 0; }
.notebook-size-label { color: var(--color-text-muted); font-size: var(--text-sm); font-weight: 600; }
.notebook-size-seg > button { min-width: 3.2rem; padding: 0 var(--space-3); }

.is-starting .notebook-start,
.is-starting .notebook-weak-train,
.is-starting .notebook-action { pointer-events: none; }

.notebook-side-panel { display: grid; gap: var(--space-5); min-width: 0; }
.notebook-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.02);
}
.notebook-stat {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: var(--space-4);
}
.notebook-stat + .notebook-stat { border-left: 1px solid var(--color-hairline); }
.notebook-stat-value { font-family: var(--font-ui); font-size: var(--text-3xl); font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; }
.notebook-stat.is-gold .notebook-stat-value { color: var(--color-gold); }
.notebook-stat-label { color: var(--color-text); font-size: var(--text-sm); font-weight: 650; }
.notebook-stat-hint { color: var(--color-text-muted); font-size: var(--text-xs); line-height: var(--lh-snug); }

/* ── Box chart (hand written SVG: thin bars from one baseline, hairline axis, values on the caps) ── */
.notebook-boxes { display: grid; gap: var(--space-2); margin: 0; min-width: 0; }
.notebook-boxes-title { font-size: var(--text-sm); font-weight: 650; letter-spacing: 0.02em; color: var(--color-text); }
.notebook-boxes-svg { display: block; width: 100%; max-width: 30rem; height: auto; overflow: visible; }
.notebook-bar { fill: var(--color-good); }
.notebook-bar.is-cleared { fill: var(--color-gold); }
.notebook-bar-stub { fill: var(--color-surface-4); }
.notebook-bar-axis { stroke: var(--color-hairline-strong); stroke-width: 1; }
.notebook-bar-value { fill: var(--color-text); font: 700 12px var(--font-ui); font-variant-numeric: tabular-nums; }
.notebook-bar-label { fill: var(--color-text-muted); font: 500 11px var(--font-ui); }
.notebook-boxes-caption { margin: 0; color: var(--color-text-muted); font-size: var(--text-xs); line-height: var(--lh-snug); }

/* ── Weak spots ── */
.notebook-weak { display: grid; gap: var(--space-4); min-width: 0; }
.notebook-weak-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(15.5rem, 1fr);
  gap: var(--space-3);
  margin: 0;
  padding: 0 0 var(--space-2);
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.notebook-weak-item {
  display: grid;
  align-content: start;
  gap: var(--space-2);
  padding: var(--space-4);
  scroll-snap-align: start;
  border: 1px solid var(--color-hairline);
}
.notebook-weak-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: var(--hit); }
.notebook-weak-name { margin: 0; font-size: var(--text-lg); font-weight: 650; line-height: var(--lh-snug); }
.notebook-weak-info { margin: -4px -10px -4px 0; flex: none; }
.notebook-weak-count { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); }
.notebook-weak-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.notebook-weak-train { flex: 1 1 auto; }

/* ── Toolbar ── */
.notebook-list { display: grid; gap: var(--space-4); min-width: 0; }
.notebook-list-head { grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: var(--space-2) var(--space-4); }
.notebook-count { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.notebook-tools { display: grid; gap: var(--space-3); min-width: 0; }
.notebook-tools-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 15rem); gap: var(--space-3); align-items: end; }
.notebook-field { min-width: 0; }
.notebook-search-input::-webkit-search-cancel-button { filter: invert(0.8); cursor: pointer; }

/* The status pills scroll sideways on a phone (five of them do not fit in 328px); the count is part of each one. */
.notebook-status {
  display: flex;
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.notebook-status::-webkit-scrollbar { display: none; }
.notebook-status > button { flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; scroll-snap-align: center; }
.notebook-status-n {
  min-width: 1.5em;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.08);
  /* The count sits on a lighter wash than the pill: muted text would fall under 4.5:1 there. */
  color: var(--color-text);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.notebook-status > [aria-pressed="true"] .notebook-status-n { background: rgba(221, 167, 52, 0.18); color: var(--color-gold); }

.notebook-more { min-width: 0; }
.notebook-more-summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--hit);
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.notebook-more-summary::-webkit-details-marker { display: none; }
.notebook-more-summary:hover { color: var(--color-text); }
.notebook-more-summary .ui-icon { transition: transform var(--dur-2) var(--ease-out); }
.notebook-more[open] .notebook-more-summary .ui-icon { transform: rotate(180deg); }
.notebook-more-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: var(--space-3); padding: var(--space-2) 0 var(--space-1); }
.notebook-clear { justify-self: start; }

/* ── Cards ── */
.notebook-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 31rem), 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.notebook-item { min-width: 0; display: grid; }
.notebook-list-empty { grid-column: 1 / -1; }
.notebook-card {
  --nb-board: 112px;
  --card-pad: var(--space-4);
  display: grid;
  grid-template-columns: var(--nb-board) minmax(0, 1fr);
  align-content: start;
  gap: var(--space-3) var(--space-4);
}
.notebook-card.is-due { border-color: var(--color-gold-dim); box-shadow: var(--shadow-1), inset 3px 0 0 var(--color-gold); }
.notebook-card > .notebook-tags,
.notebook-card > .notebook-card-foot,
.notebook-card > .notebook-actions,
.notebook-card > .notebook-panel { grid-column: 1 / -1; }

.notebook-card-board {
  width: var(--nb-board);
  height: var(--nb-board);
  overflow: hidden;
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.notebook-card-board .mini-board { display: block; width: 100%; height: 100%; }
.notebook-card-main { display: grid; align-content: start; gap: var(--space-1); min-width: 0; }
.notebook-card-kicker { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--space-3); margin: 0; }
.notebook-origin {
  color: var(--color-gold);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.notebook-side { color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 600; }
.notebook-card-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  font-weight: 650;
  line-height: var(--lh-snug);
  overflow-wrap: anywhere;
}
.notebook-card-title:focus { outline: none; }
.notebook-card-detail { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); line-height: var(--lh-snug); overflow-wrap: anywhere; }

.notebook-moves { display: grid; gap: var(--space-2); margin: var(--space-2) 0 0; }
.notebook-move { display: grid; grid-template-columns: 5.6rem minmax(0, 1fr); align-items: baseline; gap: var(--space-2); min-width: 0; }
.notebook-move-label { margin: 0; color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 650; letter-spacing: 0.04em; }
.notebook-move-value { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); margin: 0; min-width: 0; }
.notebook-san { font-size: var(--text-lg); font-weight: 700; letter-spacing: 0; font-variant-numeric: lining-nums; }
.notebook-san.is-best { color: var(--color-perfect); }
.notebook-move-meta { color: var(--color-text-muted); font-size: var(--text-sm); }

.notebook-tags { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.notebook-tag .ui-icon { color: var(--color-gold); }
.notebook-tag.is-plain { color: var(--color-text-muted); }

.notebook-card-foot {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-hairline);
}
.notebook-pips { display: inline-flex; align-items: center; gap: 5px; }
.notebook-pip { width: 10px; height: 10px; border: 1px solid var(--color-border); border-radius: 50%; background: transparent; }
.notebook-pip.is-on { border-color: var(--color-gold); background: var(--color-gold); }
.notebook-pip.is-cleared { border-color: var(--color-perfect); background: var(--color-perfect); }
.notebook-pips-text { margin-left: var(--space-2); color: var(--color-text); font-size: var(--text-sm); font-weight: 650; white-space: nowrap; }
.notebook-when { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); margin: 0; min-width: 0; font-size: var(--text-sm); }
.notebook-when-label { color: var(--color-text-muted); }
.notebook-when-text { color: var(--color-text); font-weight: 650; }
.notebook-when.is-due .notebook-when-label,
.notebook-when.is-due .notebook-when-text { color: var(--color-gold); }
.notebook-when-date { color: var(--color-text-muted); }
.notebook-last { grid-column: 1 / -1; margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); }

.notebook-actions { display: grid; grid-template-columns: auto auto minmax(0, 1fr) var(--hit); align-items: center; gap: var(--space-2); }
.notebook-action { min-width: 0; padding-inline: var(--space-3); }
.notebook-lines-toggle .ui-icon { transition: transform var(--dur-2) var(--ease-out); }
.notebook-lines-toggle.is-open .ui-icon { transform: rotate(180deg); }
.notebook-remove { grid-column: 4; justify-self: end; }
.notebook-remove:hover:not(:disabled) { color: var(--color-blunder); }

/* The stored engine lines and the review history of a card. */
.notebook-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: var(--space-4) var(--space-6);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-hairline);
}
.notebook-panel-block { display: grid; align-content: start; gap: var(--space-2); min-width: 0; }
.notebook-panel-title { margin: 0; color: var(--color-text-muted); font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.notebook-panel-empty { margin: 0; color: var(--color-text-muted); font-size: var(--text-sm); line-height: var(--lh-normal); }
.notebook-lines,
.notebook-history { display: grid; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.notebook-line { display: grid; grid-template-columns: 4rem minmax(0, 1fr); gap: var(--space-3); align-items: baseline; font-size: var(--text-sm); }
.notebook-line-eval { color: var(--color-text); font-weight: 700; font-variant-numeric: tabular-nums; }
.notebook-line-pv { color: var(--color-text-muted); overflow-wrap: anywhere; }
.notebook-history-item { display: flex; flex-wrap: wrap; gap: 0 var(--space-3); font-size: var(--text-sm); }
.notebook-history-date { min-width: 4.5rem; color: var(--color-text-muted); }
.notebook-history-acc { font-variant-numeric: tabular-nums; }
.notebook-history-flag { font-weight: 650; }
.notebook-history-flag.is-pass { color: var(--color-perfect); }
.notebook-history-flag.is-fail { color: var(--color-blunder); }

.notebook-more-host { display: grid; justify-items: center; }
.notebook-more-host:empty { display: none; }

/* ── Empty state ── */
.notebook-empty { display: grid; gap: var(--space-5); justify-items: center; }
.notebook-empty > .empty { width: 100%; }
.notebook-how { display: grid; gap: var(--space-4); width: 100%; }
.notebook-how .notebook-h2 { text-align: center; }
.notebook-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); margin: 0; padding: 0; list-style: none; }
.notebook-step {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-hairline);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
}
.notebook-step-n {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-gold-dim);
  border-radius: 50%;
  background: var(--color-gold-bg);
  color: var(--color-gold);
  font-weight: 700;
}
.notebook-step-text { min-width: 0; }
.notebook-step-title { margin: 0; font-size: var(--text-md); font-weight: 650; }
.notebook-step-body { margin: var(--space-1) 0 0; color: var(--color-text-muted); font-size: var(--text-sm); line-height: var(--lh-normal); }

/* ── Lesson dialog ── */
.notebook-concept { display: grid; grid-template-columns: minmax(0, 200px) minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.notebook-concept:focus-visible { outline-offset: 4px; border-radius: var(--radius-md); }
.notebook-concept + .notebook-concept { margin-top: var(--space-5); padding-top: var(--space-5); border-top: 1px solid var(--color-hairline); }
.notebook-concept-board { overflow: hidden; border: 1px solid var(--color-hairline-strong); border-radius: var(--radius-md); }
.notebook-concept-board .mini-board { display: block; width: 100%; height: auto; }
.notebook-concept-title { margin: 0; font-family: var(--font-display); font-size: var(--text-xl); font-weight: 650; line-height: var(--lh-tight); }
.notebook-concept-body { margin: var(--space-2) 0 0; color: var(--color-text-muted); line-height: var(--lh-normal); }
.notebook-concept-move { display: flex; align-items: center; gap: var(--space-2); margin: var(--space-3) 0 0; color: var(--color-gold); font-weight: 650; }
.notebook-concept-none { margin: 0; color: var(--color-text-muted); }

/* ── Breakpoints ── */
@media (max-width: 899px) {
  .notebook-summary { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 720px) {
  .notebook-card { --nb-board: 148px; --card-pad: var(--space-5); }
  .notebook-move { grid-template-columns: 6.4rem minmax(0, 1fr); }
}
@media (max-width: 719px) {
  .notebook { gap: var(--space-6); }
  .notebook-start { min-width: 0; width: 100%; }
  .notebook-cta { flex-direction: column; align-items: stretch; }
  .notebook-size { justify-content: space-between; }
  .notebook-size-seg { flex: 1 1 11rem; }
  .notebook-size-seg > button { flex: 1 1 0; min-width: 0; }
  .notebook-tools-row { grid-template-columns: minmax(0, 1fr); }
  .notebook-stat { padding: var(--space-3); }
  .notebook-stat-value { font-size: var(--text-2xl); }
  .notebook-steps { grid-template-columns: minmax(0, 1fr); }
  .notebook-concept { grid-template-columns: minmax(0, 1fr); }
  /* One column: the board is centred and as wide as the dialog allows (it used to hug the left edge at 220px). */
  .notebook-concept-board { width: 100%; max-width: 280px; margin-inline: auto; }
  .notebook-list-head { grid-template-columns: minmax(0, 1fr); }
  .notebook-move { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .notebook-card-foot { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 479px) {
  .notebook-actions { grid-template-columns: minmax(0, 1fr) auto var(--hit); }
  .notebook-remove { grid-column: 3; }
}
@media (max-width: 400px) {
  .notebook-stat-hint { display: none; }
}
@media (min-width: 1100px) {
  .notebook-weak-list { grid-auto-columns: minmax(15.5rem, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .notebook-more-summary .ui-icon,
  .notebook-lines-toggle .ui-icon { transition: none; }
}
