/*
 * Results view (WP08): move annotations (move-extras.js), detail panel
 * (<monolith-detail-panel>), evaluation graph (<monolith-eval-graph>) and analysis
 * bar (<monolith-analysis-bar>). Tokens only (tokens.css), light and dark.
 *
 * Labels: `.label--<name>` sets --label-color from the --label-* tokens. The
 * colour always comes with an icon and a word (NFR-008); in the graph the
 * marker shape differs per label as well.
 *
 * Hierarchy (WP02, the reference use of the base.css primitives): the bar,
 * the move details and the graph are each a .panel (class set by their
 * elements; WP04 moved the details and the graph onto the primitive). Status and panel
 * headings use --text-panel-title, help and secondary facts --text-caption.
 * One primary button: Stop or Resume, whichever can act (primaryAction).
 *
 * Phone (below 720 px): controls wrap, the annotation word is dropped from
 * the move strip (icon, points and depth stay; the full text is in the
 * visually hidden summary), the graph is lower.
 */

/* ---- label colours -------------------------------------------------- */

.label--best { --label-color: var(--label-best); }
.label--good { --label-color: var(--label-good); }
.label--inaccuracy { --label-color: var(--label-inaccuracy); }
.label--mistake { --label-color: var(--label-mistake); }
.label--blunder { --label-color: var(--label-blunder); }
.label--none { --label-color: var(--color-text-muted); }

/* ---- move annotations (inside the move list) ------------------------ */

.move-extras {
  /* Containing block for the visually hidden summary: without it the
     absolutely positioned text escapes the phone move strip's scroller and
     widens the page. */
  position: relative;
  display: inline-grid;
  /* Fixed widths: nothing shifts while results stream in. */
  grid-template-columns: 2.5ch 11ch 4ch 5.5ch;
  align-items: baseline;
  gap: var(--space-1);
  color: var(--label-color);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.move-extras__icon {
  font-weight: var(--font-weight-bold);
  text-align: center;
}

.move-extras__word {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: var(--font-weight-semibold);
}

.move-extras__lost {
  color: var(--color-text);
  text-align: right;
}

.move-extras__depth {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.move-extras.label--none .move-extras__icon {
  color: var(--color-text-muted);
  font-weight: var(--font-weight-regular);
}

/*
 * Desktop: with annotations a turn no longer fits two moves on one line of
 * the narrow moves column (three-column layout from 1100 px, WP04), so each
 * annotated move gets its own line (the second one indented under the turn
 * number). From 720 to 1099 px the list is full width and keeps two moves
 * per turn line. Scoped with :has() so the move list looks as WP03 made it
 * when no annotations are shown.
 */
@media (min-width: 1100px) {
  .move-list__turns:has(.move-extras) .move-list__turn {
    flex-wrap: wrap;
  }

  .move-list__turns:has(.move-extras) .move-list__entry {
    flex: 1 1 calc(100% - 3ch - var(--space-1));
  }

  .move-list__turns:has(.move-extras) .move-list__entry + .move-list__entry {
    margin-left: calc(3ch + var(--space-1));
  }
}

.move-list__entry:has(.move-extras) .move-list__move {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* ---- panel headings ---------------------------------------------------- */

.analysis-bar__status,
.detail-panel__title,
.eval-graph__title {
  font-size: var(--text-panel-title);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-snug);
}

.detail-panel__subtitle {
  font-size: var(--text-caption);
  font-weight: var(--font-weight-semibold);
}

/* ---- analysis bar ---------------------------------------------------- */

.analysis-bar__head {
  display: grid;
  gap: var(--space-1);
}


.analysis-bar[data-status="failed"] .analysis-bar__status {
  color: var(--color-danger);
}

.analysis-bar[data-status="failed"] .analysis-bar__status::before {
  content: "\26A0\FE0E  ";
}

.analysis-bar__progress {
  width: 100%;
  height: var(--space-3);
  color: var(--color-text);
  background-color: var(--surface-sunken);
  accent-color: var(--color-accent);
}

.analysis-bar__controls,
.analysis-bar__depth {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.analysis-bar__controls button {
  max-width: 100%;
  white-space: normal;
}

.analysis-bar__depth-label {
  font-weight: var(--font-weight-semibold);
}

/*
 * [-] [ 16 ] [+] (FR-006). The field was `width: 5ch` under border-box with
 * the base input padding (2 x 12 px): a 25 px content box, and Chromium's
 * native spin button (about 15 px) took most of it, so only "1" and the
 * arrows showed. Now the content box itself is 4ch (two digits with room to
 * spare), the native spinner is hidden (the flanking buttons replace it;
 * ArrowUp/Down still step) and the digits are tabular.
 */
.analysis-bar__stepper {
  display: inline-flex;
  flex: none;
  align-items: center;
  /* Wider than the focus ring's reach (3 px ring + 2 px offset), so the ring
     of one control never touches its neighbour. */
  gap: var(--space-2);
}

.analysis-bar__depth-input {
  width: calc(4ch + 2 * var(--space-2) + 2px);
  padding-inline: var(--space-2);
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: var(--font-weight-semibold);
  appearance: textfield;
  -moz-appearance: textfield;
}

.analysis-bar__depth-input::-webkit-inner-spin-button,
.analysis-bar__depth-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

.analysis-bar__depth-step {
  font-weight: var(--font-weight-bold);
}

.analysis-bar__depth-help {
  flex-basis: 100%;
  color: var(--color-text-muted);
  font-size: var(--text-caption);
  line-height: var(--line-height-snug);
}

/* ---- detail panel ---------------------------------------------------- */

.detail-panel__body {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.detail-panel__move {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-semibold);
}

.detail-panel__verdict {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-3);
  padding-left: var(--space-2);
  border-left: 4px solid var(--label-color);
}

.detail-panel__icon,
.detail-panel__word {
  color: var(--label-color);
  font-weight: var(--font-weight-bold);
}

.detail-panel__depth {
  color: var(--color-text-muted);
  font-size: var(--text-caption);
}

.detail-panel__facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-1) var(--space-3);
  margin: 0;
  align-items: baseline;
}

.detail-panel__facts dt {
  font-weight: var(--font-weight-semibold);
}

.detail-panel__facts dd {
  margin: 0;
  min-width: 0;
}

.detail-panel__note,
.detail-panel__line-depth,
.detail-panel__loading,
.detail-panel__stale,
.detail-panel__waiting,
.detail-panel__empty {
  color: var(--color-text-muted);
  font-size: var(--text-caption);
}

.detail-panel__error {
  color: var(--color-danger);
}

.detail-panel__error::before {
  content: "\26A0\FE0E  ";
}

.detail-panel__line {
  display: grid;
  gap: var(--space-1);
}

.detail-panel__steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: 0;
  list-style: none;
}

/* Compact secondary buttons: still the 44 px target from base.css. */
.detail-panel__step-button,
.detail-panel__show,
.detail-panel__retry,
.detail-panel__refresh {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-caption);
}

.detail-panel__step-button {
  font-family: var(--font-mono);
}

/* ---- evaluation graph ------------------------------------------------ */

.eval-graph__frame {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.eval-graph__frame[hidden] {
  display: none;
}

.eval-graph__axis,
.eval-graph__note,
.eval-graph__empty {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.eval-graph__svg {
  width: 100%;
  height: auto;
  cursor: pointer;
  touch-action: manipulation;
}

.eval-graph__bg {
  fill: var(--color-surface);
}

.eval-graph__zero {
  stroke: var(--color-border);
  stroke-width: 1.5;
}

.eval-graph__edge {
  stroke: var(--color-surface-sunken);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}

.eval-graph__scale {
  fill: var(--color-text-muted);
  /* SVG user units: scales with the graph's viewBox, not a CSS text size. */
  font-size: 10px;
  font-family: var(--font-sans);
}

.eval-graph__cursor {
  stroke: var(--color-accent);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.eval-graph__line {
  fill: none;
  stroke: var(--color-text-muted);
  stroke-width: 2;
  stroke-linejoin: round;
}

.eval-graph__point {
  color: var(--label-color);
}

.eval-graph__mark {
  fill: currentColor;
  stroke: var(--color-surface);
  stroke-width: 1.5;
}

/* Good: a ring, so it differs from best by shape as well as colour. */
.eval-graph__mark--good {
  fill: var(--color-surface);
  stroke: currentColor;
  stroke-width: 2.5;
}

.eval-graph__chevron {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.eval-graph__halo {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 2;
}

.eval-graph__point:focus {
  outline: none;
}

.eval-graph__point:focus-visible .eval-graph__halo,
.eval-graph__point:focus-visible .eval-graph__mark {
  stroke: var(--color-focus);
  stroke-width: 3;
}

.eval-graph__details summary {
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
  cursor: pointer;
}

.eval-graph__details {
  min-width: 0;
  overflow-x: auto;
}

.eval-graph__table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  /* layout.css sets overflow-wrap: anywhere on the side panel; table cells
     must break between words only. */
  overflow-wrap: normal;
}

.eval-graph__table caption {
  text-align: left;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.eval-graph__table th,
.eval-graph__table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--color-surface-sunken);
  text-align: left;
}

.eval-graph__table tr[aria-current] {
  background: var(--surface-sunken);
  font-weight: var(--font-weight-semibold);
}

@media (prefers-reduced-motion: reduce) {
  .analysis-bar__progress {
    transition: none;
  }
}

/* ---- phone ------------------------------------------------------------ */

@media (max-width: 719.98px) {
  .move-extras {
    grid-template-columns: 2.5ch 3.5ch 4.5ch;
  }

  .move-extras__word {
    display: none;
  }

  .detail-panel__facts {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-panel__facts dd {
    margin-bottom: var(--space-1);
  }
}

/* 'Show on board' starts its own line under the fact it shows, so it never
   sits in the middle of a wrapped sentence (WP04 review cycle 1). */
.detail-panel__show {
  display: flex;
  width: fit-content;
  margin-top: var(--space-1);
}
