/* The Model One Challenge.
   Loaded only on /<locale>/challenge/ (see PAGE_ASSETS in src/templates/layout.ts).
   Built entirely on the shared tokens in tokens.css — no new colours. */

.challenge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
}

/* --- level rail ---------------------------------------------------------- */

.game__rail {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
}

.game__rail-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-subtle);
  font-size: 0.85rem;
}

.game__rail-dot {
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: var(--radius-pill);
  background: var(--ink-100);
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 700;
}

.game__rail-item.is-current {
  border-color: var(--accent-300);
  background: var(--surface-tinted);
  color: var(--accent-700);
}

.game__rail-item.is-current .game__rail-dot {
  background: var(--accent-500);
  color: var(--text-on-accent);
}

.game__rail-item.is-solved .game__rail-dot {
  background: var(--accent-100);
  color: var(--accent-700);
}

.game__rail-item.is-solved .game__rail-dot::after {
  content: '✓';
}

.game__rail-item.is-solved .game__rail-dot {
  font-size: 0;
}

.game__rail-item.is-solved .game__rail-dot::after {
  font-size: 0.8rem;
}

/* --- level header -------------------------------------------------------- */

.game__badge {
  margin: 0;
  color: var(--accent-600);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game__title {
  margin: var(--space-2) 0 var(--space-3);
  color: var(--text-strong);
  font-size: 1.5rem;
  line-height: 1.25;
}

.game__brief,
.game__objective {
  margin: 0 0 var(--space-2);
  color: var(--text-body);
  max-width: 60ch;
}

.game__objective {
  font-weight: 600;
  color: var(--text-strong);
}

.game__instructions {
  margin: 0 0 var(--space-5);
  color: var(--text-subtle);
  font-size: 0.85rem;
  max-width: 70ch;
}

/* --- board --------------------------------------------------------------- */

.game__board {
  position: relative;
  display: grid;
  gap: var(--space-4);
}

.game__wires {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.game__wire {
  fill: none;
  stroke: var(--accent-300);
  stroke-width: 2;
  stroke-dasharray: 4 4;
}

.game__col-title {
  margin: 0 0 var(--space-3);
  color: var(--text-subtle);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.game__tray,
.game__slots {
  display: grid;
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
}

/* --- pieces and slots ---------------------------------------------------- */

.game__piece,
.game__slot {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.game__piece {
  box-shadow: var(--shadow-sm);
  touch-action: none;
}

.game__piece:hover {
  border-color: var(--accent-300);
  transform: translateY(-1px);
}

.game__piece.is-selected {
  border-color: var(--accent-500);
  box-shadow: var(--shadow-accent);
}

.game__piece-label,
.game__slot-label {
  display: block;
  color: var(--text-strong);
  font-weight: 650;
}

.game__piece-detail,
.game__slot-detail {
  display: block;
  margin-top: var(--space-1);
  color: var(--text-subtle);
  font-size: 0.85rem;
}

.game__piece--ghost {
  position: fixed;
  z-index: 60;
  width: 220px;
  margin: 0;
  transform: translate(-50%, -50%) rotate(-1.5deg);
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  opacity: 0.95;
}

.game__slot {
  background: var(--surface-muted);
  border-style: dashed;
}

.game__slot.is-over {
  border-color: var(--accent-500);
  border-style: solid;
  background: var(--surface-tinted);
}

.game__slot.is-filled {
  background: var(--surface);
  border-style: solid;
  border-color: var(--accent-200);
  cursor: default;
}

.game__slot.is-wrong {
  border-color: var(--ink-400);
  animation: game-shake 0.3s ease;
}

@keyframes game-shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.game__chip {
  display: inline-block;
  margin-top: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--accent-500);
  color: var(--text-on-accent);
  font-size: 0.8rem;
  font-weight: 650;
}

/* --- bar, hints and reward ------------------------------------------------ */

.game__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.game__counters {
  display: flex;
  gap: var(--space-4);
  margin: 0;
  color: var(--text-body);
}

.game__counter-label {
  color: var(--text-subtle);
  font-size: 0.85rem;
}

.game__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.btn--assistant {
  border: 1px solid var(--accent-300);
  background: var(--surface-tinted);
  color: var(--accent-700);
}

.btn--assistant:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Deliberately the quietest button in the bar: "Start over" throws away every level, so it
   should never compete with "Reset level" for a hurried click. */
.btn--quiet {
  border: 1px solid transparent;
  background: none;
  color: var(--text-subtle);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn--quiet:hover {
  color: var(--text-strong);
}

.game__hint {
  margin: var(--space-4) 0 0;
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--accent-500);
  border-radius: var(--radius-sm);
  background: var(--surface-tinted);
  color: var(--text-strong);
}

.game__hint.is-exhausted {
  border-left-color: var(--ink-300);
  background: var(--surface-muted);
  color: var(--text-subtle);
}

.game__hint-note {
  margin: var(--space-3) 0 0;
  color: var(--text-subtle);
  font-size: 0.8rem;
}

.game__reward {
  margin-top: var(--space-5);
  padding: var(--space-5);
  border-radius: var(--radius-md);
  background: var(--surface-tinted);
  border: 1px solid var(--accent-200);
}

.game__reward-flag {
  margin: 0 0 var(--space-2);
  color: var(--accent-600);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game__reward h4 {
  margin: 0 0 var(--space-2);
  color: var(--text-strong);
  font-size: 1.15rem;
}

.game__reward p {
  margin: 0 0 var(--space-3);
  color: var(--text-body);
  max-width: 62ch;
}

.game__reward-link {
  font-weight: 650;
}

/* --- completion ----------------------------------------------------------- */

.game--done {
  text-align: center;
}

.game--done .game__brief {
  margin-inline: auto;
}

.game__score {
  margin: var(--space-4) 0;
  color: var(--text-strong);
  font-size: 1.1rem;
  font-weight: 650;
}

.game--done .game__actions {
  justify-content: center;
}

.game__copied {
  margin-top: var(--space-3);
  color: var(--accent-600);
  font-size: 0.9rem;
}

/* --- noscript fallback ---------------------------------------------------- */

.challenge__fallback {
  padding: var(--space-5);
}

.challenge__fallback-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
}

/* --- focus and motion ------------------------------------------------------ */

.game__piece:focus-visible,
.game__slot:focus-visible,
.game__rail-item:focus-visible {
  outline: 3px solid var(--accent-500);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .game__piece,
  .game__slot {
    transition: none;
  }

  .game__slot.is-wrong {
    animation: none;
  }
}

/* --- breakpoints ----------------------------------------------------------- */

@media (min-width: 640px) {
  .challenge {
    padding: var(--space-6);
  }

  .game__title {
    font-size: 1.75rem;
  }
}

@media (min-width: 960px) {
  .game__board {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: var(--space-6);
  }
}

/* --- arcade level (level 6) ------------------------------------------------ */

.game__arcade {
  /* The board is a two-column grid on wide screens; the arcade uses the full width. */
  grid-column: 1 / -1;
}

.arcade__hud,
.arcade__next {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: 0 0 var(--space-3);
  color: var(--text-strong);
  font-size: 0.9rem;
}

.arcade__stat-label {
  color: var(--text-subtle);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.arcade__stage {
  position: relative;
  height: clamp(260px, 45vh, 420px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-muted);
}

.arcade__stage:focus-visible {
  outline: 3px solid var(--accent-500);
  outline-offset: 2px;
}

.arcade__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.arcade__overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: var(--space-3);
  justify-items: center;
  padding: var(--space-4);
  text-align: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.arcade__overlay[hidden] {
  display: none;
}

.arcade__overlay-text {
  margin: 0;
  max-width: 40ch;
  color: var(--text-strong);
  font-weight: 600;
}

.arcade__lanes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: var(--space-2);
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
}

.arcade__lane {
  display: block;
  width: 100%;
  height: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.arcade__lane.is-active {
  border-color: var(--accent-500);
  background: var(--surface-tinted);
}

.arcade__lane:focus-visible {
  outline: 3px solid var(--accent-500);
  outline-offset: 2px;
}

/* Outcome feedback. Colour is never the only signal: the canvas draws a tick or a cross,
   the live region says what happened, and a miss names the module it should have gone to. */
.arcade__lane.is-correct {
  border-color: var(--positive-500);
  background: var(--positive-100);
  animation: arcade-pop 0.48s ease;
}

.arcade__lane.is-wrong {
  border-color: var(--negative-500);
  background: var(--negative-100);
  animation: game-shake 0.3s ease;
}

@keyframes arcade-pop {
  40% {
    transform: translateY(-4px) scale(1.03);
  }
}

.arcade__stage.is-wrong {
  animation: arcade-flash 0.48s ease;
}

@keyframes arcade-flash {
  0% {
    box-shadow: inset 0 0 0 0 var(--negative-500);
  }
  30% {
    box-shadow: inset 0 0 0 3px var(--negative-500);
  }
  100% {
    box-shadow: inset 0 0 0 0 var(--negative-500);
  }
}

.arcade__lane-label {
  display: block;
  color: var(--text-strong);
  font-weight: 600;
  font-size: 0.85rem;
}

.arcade__lane-detail {
  display: block;
  color: var(--text-subtle);
  font-size: 0.75rem;
}

.arcade__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.arcade__steady {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-body);
  font-size: 0.85rem;
}

.arcade__controls-hint {
  margin: 0;
  flex: 1 1 22ch;
  color: var(--text-subtle);
  font-size: 0.8rem;
}

@media (prefers-reduced-motion: reduce) {
  /* Steady mode is switched on in main.ts as well; this only calms the chrome.
     The feedback colours stay — it is the movement that is dropped, not the meaning. */
  .arcade__lane {
    transition: none;
  }

  .arcade__lane.is-correct,
  .arcade__lane.is-wrong,
  .arcade__stage.is-wrong {
    animation: none;
  }
}
