/*
 * Scoreboard components, in build order. Colours, gradients and shadows come from tokens only.
 * Motion is only where the addendum allows it: see the celebration zones at the end.
 */

/* Buttons ---------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-10);
  min-height: var(--target);
  padding: 0 var(--space-20);
  border: 0;
  border-radius: var(--radius-control);
  font: inherit;
  font-size: var(--text-17);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.btn--primary {
  background: var(--you);
  color: var(--on-dark);
}

/* Secondary: soft grey inside cards; white with a hairline on the page, where the soft
   grey would be almost the page colour. */
.btn--secondary {
  background: var(--card-soft);
  color: var(--ink);
}

.btn--secondary:not(.card .btn--secondary) {
  background: var(--card);
  border: 1px solid var(--line);
}

/* The fast-move tap area. */
.btn--dark {
  background: var(--ink);
  color: var(--on-dark);
  border-radius: var(--radius-panel);
}

.btn--block { display: flex; width: 100%; }
.btn--drill { min-height: var(--target-drill); }
.btn--tap { min-height: var(--target-tap); font-size: var(--text-19); }

/* Pressed: an instant state change, never an animation. */
.btn--primary:active,
.btn--primary.is-pressed { background: var(--ink); }
.btn--secondary:active,
.btn--secondary.is-pressed { background: var(--line); }
.btn--dark:active,
.btn--dark.is-pressed { background: var(--muted); }

/* A selected option in a group is filled. */
.btn-group[role="group"] > .btn--secondary[aria-pressed="true"] {
  background: var(--you);
  color: var(--on-dark);
}

/* The charged move wears its type's colour, as in the game (set with --move-type). */
.btn--charged {
  background: var(--move-type, var(--you));
  color: var(--on-dark);
}

.btn--charged:active,
.btn--charged.is-pressed { background: var(--ink); }

/* A charged-move choice: its type as a dot beside the name until chosen, then as the fill.
   The dot belongs to the name, so on narrow screens the cost can wrap below without it. */
.btn--charged-choice .btn__name::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: var(--space-10);
  border-radius: 50%;
  background: var(--move-type, var(--you));
}

.btn-group[role="group"] > .btn--secondary.btn--charged-choice[aria-pressed="true"] {
  background: var(--move-type, var(--you));
}

.btn-group[role="group"] > .btn--secondary.btn--charged-choice[aria-pressed="true"] .btn__name::before {
  background: var(--on-dark);
}

/* Type chip: the Pokémon's or move's type, a word plus its colour. */
.type-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: 2px var(--space-10);
  border-radius: var(--radius-pill);
  background: var(--move-type, var(--you));
  color: var(--on-dark);
  font-size: var(--text-13);
  font-weight: 600;
  vertical-align: middle;
}

.btn__icon {
  flex: none;
  width: 20px;
  height: 20px;
}

/* Toggles show the icon matching their state; the word stays for screen readers. */
.btn[aria-pressed="true"] .btn__icon--off,
.btn[aria-pressed="false"] .btn__icon--on { display: none; }

/* Icon-only button: a 48px square. */
.btn--icon {
  width: var(--target);
  min-height: var(--target);
  padding: 0;
}

.btn--icon .btn__icon {
  width: 24px;
  height: 24px;
}

.btn-group {
  display: flex;
  gap: var(--space-10);
}

.btn-group > .btn {
  flex: 1;
  flex-wrap: wrap;
  column-gap: var(--space-10);
  row-gap: 0;
  min-width: 0;
  padding: var(--space-4) var(--space-14);
  text-align: center;
}

/* Disabled-looking but present: e.g. the charged move before its energy exists. */
.btn:disabled,
.btn[aria-disabled="true"],
.btn.is-waiting {
  opacity: 0.45;
}

.btn:disabled { cursor: not-allowed; }

.is-focused {
  outline: 2px solid var(--you);
  outline-offset: 2px;
}

.link {
  display: inline-flex;
  align-items: center;
  min-height: var(--target);
  padding: 0 var(--space-4);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: var(--text-15);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  touch-action: manipulation;
}

.card .link { color: var(--you); }
.link--muted, .card .link--muted { color: var(--muted); }

/* Card: the only surface the drill runs on. Never tinted. ----------------- */

/* Grids inside cards never grow past the card (min-content would push them wider). */
.card {
  min-width: 0;
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-20);
}

/* ScoreBar, StreakPill, RepDots: on the gradient, above the card ---------- */

.score-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-16);
  padding: var(--space-14) var(--space-20);
  background: var(--score-bar);
  border: 1px solid var(--score-bar-border);
  border-radius: var(--radius-bar);
  box-shadow: var(--shadow-bar);
  color: var(--on-dark);
}

.score-bar__score {
  display: grid;
  gap: 2px;
}

.score-bar__label {
  font-family: var(--font-mono);
  font-size: var(--text-13);
  color: var(--on-dark-muted);
}

.score-bar__value {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--text-46);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-bar__score {
  flex: none;
}

.score-bar__side {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: var(--space-10);
  justify-items: end;
}

.streak-pill {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  min-height: 28px;
  padding: 0 var(--space-14);
  border-radius: var(--radius-pill);
  background: var(--streak);
  color: var(--ink);
  font-size: var(--text-13);
  font-weight: 800;
  white-space: nowrap;
}

.rep-dots {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  max-width: calc(10 * 20px + 9 * var(--space-4));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* 20x7 where there's room; narrower on small phones so ten always fit. */
.rep-dot {
  flex: 0 1 20px;
  min-width: 10px;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--dot-empty);
}

.rep-dot.is-perfect { background: var(--good); }
.rep-dot.is-off { background: var(--them); }

/* TurnLane: the drill's core. Calm zone: only the playhead and pulses change. */

.lane {
  position: relative;
  height: var(--lane-height);
  background: var(--lane-fill);
  border-radius: var(--radius-control);
  overflow: hidden;
}

.lane__tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--line);
}

/* Your pulses in the upper row, theirs in the lower, so both read without colour. */
.lane__pulse {
  position: absolute;
  top: 9px;
  width: 8px;
  height: 16px;
  margin-left: -4px;
  border-radius: 4px;
  background: var(--you);
}

.lane__pulse--them {
  top: auto;
  bottom: 9px;
  background: var(--them);
}

/* The charged throw: full height and wider, distinct from pulses by shape. */
.lane__throw {
  position: absolute;
  top: 5px;
  bottom: 5px;
  width: 12px;
  margin-left: -6px;
  border-radius: 6px;
  background: var(--you);
}

/* The playhead: the current turn. */
.lane__now {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1.5px;
  background: var(--ink);
}

.lane__flash {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: var(--ink);
}

/* Countdown: over the lane before a rep and after each throw, one segment per beat. */
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: var(--space-14);
  padding: 0 var(--space-14);
  background: var(--card-soft);
  border-radius: var(--radius-control);
}

.countdown__label {
  flex: none;
  font-size: var(--text-13);
  font-weight: 800;
  color: var(--ink);
}

.countdown__beats {
  flex: 1;
  display: flex;
  gap: var(--space-4);
}

.countdown__beat {
  flex: 1;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--line);
}

.countdown__beat.is-left {
  background: var(--you);
}

/* Counter: the live count, 70px, centred, label under it. */
.counter {
  display: grid;
  justify-items: center;
  gap: var(--space-4);
  text-align: center;
}

.counter__value {
  font-family: var(--font-text);
  font-weight: 800;
  font-size: var(--text-70);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.counter__label {
  font-size: var(--text-13);
  color: var(--muted);
}

/* FeedbackPanel: replaces the counter for ~1.2s after each throw. Icon and words, never colour alone. */
.feedback {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-14);
  min-height: 106px;
  padding: var(--space-16) var(--space-20);
  border-radius: var(--radius-panel);
  color: var(--ink);
}

.feedback__icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--on-dark);
}

.feedback__icon svg {
  width: 24px;
  height: 24px;
}

.feedback__title {
  font-size: var(--text-25);
  font-weight: 800;
  line-height: 1.1;
}

.feedback__detail {
  font-size: var(--text-15);
}

.feedback__points {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--text-19);
  font-variant-numeric: tabular-nums;
}

.feedback--perfect { background: var(--good-bg); }
.feedback--perfect .feedback__icon { background: var(--good); }
.feedback--late { background: var(--them-bg); }
.feedback--late .feedback__icon { background: var(--them); }
.feedback--early { background: var(--bad-bg); }
.feedback--early .feedback__icon { background: var(--bad); }

/* Bar: energy (hidden by default in the drill) ----------------------------- */

.bar {
  display: grid;
  gap: var(--space-4);
}

.bar__label {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-13);
  color: var(--muted);
}

.bar__track {
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--card-soft);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--you);
}

/* Tag: a plain label for the kind of screen, e.g. the unscored warm-up. */
.tag {
  justify-self: start;
  align-self: start;
  padding: var(--space-4) var(--space-10);
  border-radius: var(--radius-pill);
  background: var(--score-bar);
  color: var(--on-dark);
  font-size: var(--text-13);
  font-weight: 600;
}

/* LedgerTable -------------------------------------------------------------- */

.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-15);
}

.ledger th,
.ledger td {
  padding: var(--space-10);
  border-bottom: 1px solid var(--line);
  text-align: right;
}

.ledger th:first-child,
.ledger td:first-child {
  text-align: left;
}

.ledger thead th {
  font-size: var(--text-13);
  font-weight: 600;
  color: var(--muted);
}

.ledger td {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.ledger tfoot td,
.ledger tfoot th {
  border-bottom: 0;
  font-weight: 600;
}

/* Worst throw column: marked with a word in the header, not colour alone. */
.ledger .is-worst {
  background: var(--them-bg);
}

.ledger__tag {
  display: block;
  font-family: var(--font-text);
  font-size: var(--text-13);
  font-weight: 800;
  color: var(--ink);
}

.ledger .is-perfect { color: var(--good); }

.ledger__check {
  width: 14px;
  height: 14px;
}

/* Fields ------------------------------------------------------------------- */

.field {
  display: grid;
  gap: var(--space-4);
}

.field__label {
  font-size: var(--text-13);
  font-weight: 600;
}

.input,
.select {
  width: 100%;
  min-height: var(--target);
  padding: 0 var(--space-14);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming into the field */
}

.input:focus-visible,
.select:focus-visible {
  outline: 2px solid var(--you);
  outline-offset: 1px;
}

/* Back link: on the gradient, top left of secondary pages. */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--target);
  margin-left: calc(-1 * var(--space-4));
  color: var(--you);
  font-size: var(--text-15);
  font-weight: 600;
  text-decoration: none;
}

.back-link__icon {
  flex: none;
}

/* Skeleton rows and load errors -------------------------------------------- */

.skeleton {
  display: grid;
}

.skeleton__row {
  display: grid;
  gap: var(--space-10);
  padding: var(--space-14) 0;
  border-bottom: 1px solid var(--line);
}

.skeleton__bar {
  height: 12px;
  width: 70%;
  border-radius: var(--radius-pill);
  background: var(--card-soft);
}

.skeleton__bar--short {
  width: 40%;
}

.load-error {
  display: grid;
  gap: var(--space-14);
}

/* Celebration zones (addendum). Calm zone (lane, counter) has none of these. */

/* Feedback panel: 120ms fade and 8px rise; a perfect check pops once. */
.feedback {
  animation: feedback-in 120ms ease-out;
}

.feedback--perfect .feedback__icon {
  animation: check-pop 150ms ease-out 60ms;
}

/* Streak pill: scales once when it increments. */
.streak-pill.is-bumped {
  animation: streak-bump 180ms ease-out;
}

/* Summary: rep dots fill left to right over ~600ms. */
.rep-dots.is-filling .rep-dot {
  animation: dot-fill 120ms ease-out both;
  animation-delay: calc(var(--i, 0) * 50ms);
}

@keyframes feedback-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes check-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes streak-bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes dot-fill {
  from { opacity: 0; transform: scaleX(0.3); }
  to { opacity: 1; transform: none; }
}

/* Reduced motion: only the playhead and pulses move (they are the drill). */
@media (prefers-reduced-motion: reduce) {
  .feedback,
  .feedback--perfect .feedback__icon,
  .streak-pill.is-bumped,
  .rep-dots.is-filling .rep-dot {
    animation: none;
  }
}
