/*
 * Results view (WP08): move annotations (move-extras.js), detail panel
 * (<hokito-detail-panel>), evaluation graph (<hokito-eval-graph>) and analysis
 * bar (<hokito-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.
 *
 * 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: 700;
  text-align: center;
}

.move-extras__word {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.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: 400;
}

/*
 * Desktop: with annotations a turn no longer fits two moves on one line of
 * the side panel, so each annotated move gets its own line (the second one
 * indented under the turn number). Scoped with :has() so the move list looks
 * as WP03 made it when no annotations are shown.
 */
@media (min-width: 720px) {
  .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;
}

/* ---- shared panel look ---------------------------------------------- */

.analysis-bar,
.detail-panel,
.eval-graph {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
}

.detail-panel__title,
.eval-graph__title {
  font-size: var(--text-md);
}

.detail-panel__subtitle {
  font-size: var(--text-sm);
}

.analysis-bar [aria-disabled="true"],
.detail-panel [aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
}

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

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

.analysis-bar__status {
  font-weight: 600;
}

.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: 0.75rem;
  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: 600;
}

.analysis-bar__depth-input {
  width: 5ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.analysis-bar__depth-step {
  padding-inline: var(--space-3);
  font-weight: 700;
}

.analysis-bar__depth-help,
.analysis-bar__note,
.analysis-bar__memory {
  flex-basis: 100%;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.analysis-bar__settings {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

.analysis-bar__settings[hidden] {
  display: none;
}

.analysis-bar__field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.analysis-bar__field label {
  min-width: 12ch;
}

.analysis-bar__warning {
  font-weight: 600;
}

.analysis-bar__warning::before {
  content: "\26A0\FE0E  ";
}

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

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

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

.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: 700;
}

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

.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: 600;
}

.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-sm);
}

.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;
}

.detail-panel__step-button,
.detail-panel__show,
.detail-panel__retry,
.detail-panel__refresh {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
}

.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);
  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(--color-surface-sunken);
  font-weight: 600;
}

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

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

@media (max-width: 719.98px) {
  .analysis-bar,
  .detail-panel,
  .eval-graph {
    padding: var(--space-2);
  }

  .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);
  }
}
