/* Page «Игра с кучей камней» (tasks 19–21). Only tokens from main.css, so dark mode comes for free. */

.stage .callout h3 {
  margin-bottom: 0.4em;
}

.stage [id$="-feedback"],
#play-result,
#paint-summary {
  margin-top: 14px;
}

/* ---------- 1. Play ---------- */

.play-setup {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.play-setup-row {
  align-items: end;
  gap: 12px 16px;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background 0.15s, border-color 0.15s;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--primary);
  border-color: var(--primary);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 2px;
}

.play-arena {
  display: grid;
  gap: 18px;
}

.play-question {
  font-size: 1.15rem;
  font-weight: 650;
  margin-bottom: 12px;
}

.play-predict .btn-group .btn {
  min-width: 140px;
}

.play-predict > :last-child {
  margin: 10px 0 0;
}

.play-board {
  display: grid;
  gap: 16px;
}

.pile {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.pile-count {
  min-width: 2.2ch;
  font-size: clamp(3rem, 2rem + 4vw, 4.5rem);
  font-weight: 800;
  line-height: 1;
}

.play-turn {
  font-weight: 700;
  color: var(--primary);
}

.play-turn.is-bot {
  color: var(--lose2);
}

/* Track: rail, finish zone, trail of positions and the moving marker */
.track {
  position: relative;
  height: 66px;
  margin: 0 18px;
}

.track-rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 30px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
}

.track-finish {
  position: absolute;
  right: 0;
  top: 25px;
  height: 18px;
  border-left: 2px solid var(--win);
  border-radius: 0 999px 999px 0;
  background: repeating-linear-gradient(45deg, var(--win-soft) 0 6px, color-mix(in srgb, var(--win) 28%, var(--win-soft)) 6px 12px);
}

.track-label {
  position: absolute;
  top: 46px;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  transform: translateX(-50%);
}

.track-label-start {
  left: 0;
}

.track-label-finish {
  color: var(--win);
  font-weight: 700;
}

.track-dots {
  position: absolute;
  inset: 0;
}

.track-dot {
  position: absolute;
  top: 30px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transform: translateX(-50%);
}

.track-dot.is-start {
  background: var(--text);
}

.track-dot.is-student {
  background: var(--primary);
}

.track-dot.is-bot {
  background: var(--lose2);
}

.track-marker {
  position: absolute;
  top: 0;
  display: grid;
  place-items: center;
  min-width: 34px;
  height: 24px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 0.85rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
  transition: left 0.45s cubic-bezier(0.3, 0.7, 0.3, 1), background 0.2s;
}

.track-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  border: 5px solid transparent;
  border-top-color: var(--primary);
  border-bottom: 0;
  transform: translateX(-50%);
}

.track-marker.is-finished {
  background: var(--win);
}

.track-marker.is-finished::after {
  border-top-color: var(--win);
}

.move-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr));
  gap: 10px;
}

.move-btn {
  flex-direction: column;
  gap: 2px;
  min-height: 66px;
}

.move-op {
  font-size: 1.3rem;
  font-weight: 800;
}

.move-result {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.move-btn.is-finish {
  border-color: var(--win);
}

.move-btn.is-finish .move-result {
  color: var(--win);
  font-weight: 750;
}

.move-btn.is-bot-choice,
.move-btn.is-bot-choice:disabled {
  opacity: 1;
  border-color: var(--lose2);
  box-shadow: 0 0 0 3px var(--lose2-soft);
}

.history {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: turn;
}

.history:empty {
  display: none;
}

.history li {
  counter-increment: turn;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.85rem;
}

.history li::before {
  content: counter(turn) ".";
  color: var(--faint);
  font-weight: 700;
}

.history li.is-student {
  background: var(--primary-soft);
}

.history li.is-bot {
  background: var(--lose2-soft);
}

.history-who {
  color: var(--muted);
}

.history-move {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#play-result h3:focus {
  outline: none;
}

/* ---------- 2. Paint ---------- */

.paint-toolbar,
.strategy-toolbar,
.exam-toolbar,
.code-toolbar-row {
  margin-bottom: 16px;
}

/* Grid and explanation side by side; on phones the explanation sits right under the grid. */
.paint-board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

@media (max-width: 760px) {
  .paint-board {
    grid-template-columns: minmax(0, 1fr);
  }
}

.paint-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.paint-step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
}

.paint-step.is-current {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  color: var(--text);
  font-weight: 650;
}

.paint-step.is-done {
  color: var(--win);
  font-weight: 700;
}

.paint-task p {
  margin-bottom: 10px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  position: relative;
  display: inline-block;
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.paint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 5px;
  padding-top: 6px;
  touch-action: none; /* dragging over cells paints instead of scrolling */
  user-select: none;
  -webkit-user-select: none;
}

.paint-cell {
  position: relative;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.paint-cell:hover {
  border-color: var(--border-strong);
}

.paint-cell.is-painted,
.legend-swatch.is-painted {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.paint-cell.cls-W1,
.strip-cell.cls-W1 {
  background: var(--win-soft);
  border-color: color-mix(in srgb, var(--win) 45%, transparent);
  color: var(--win);
}

.paint-cell.cls-L1,
.strip-cell.cls-L1 {
  background: var(--lose-soft);
  border-color: color-mix(in srgb, var(--lose) 45%, transparent);
  color: var(--lose);
}

.paint-cell.cls-W2,
.strip-cell.cls-W2 {
  background: var(--win2-soft);
  border-color: color-mix(in srgb, var(--win2) 45%, transparent);
  color: var(--win2);
}

.paint-cell.cls-L2,
.strip-cell.cls-L2 {
  background: var(--lose2-soft);
  border-color: color-mix(in srgb, var(--lose2) 45%, transparent);
  color: var(--lose2);
}

.paint-cell.is-locked {
  cursor: help;
}

.paint-cell.is-other,
.legend-swatch.is-other {
  background: var(--surface-2);
  color: var(--faint);
}

.paint-cell.is-missed::before,
.legend-swatch.is-missed::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px dashed var(--primary);
  border-radius: 6px;
}

.legend-swatch.is-missed::before {
  inset: 1px;
  border-radius: 4px;
}

.paint-cell.is-wrong-cell::after,
.legend-swatch.is-wrong-cell::after {
  content: "✗";
  position: absolute;
  top: -7px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--lose);
  color: var(--surface);
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.legend-swatch.is-wrong-cell::after {
  top: 1px;
  right: 1px;
}

.paint-cell.is-selected {
  box-shadow: 0 0 0 2px var(--text);
  z-index: 1;
}

.paint-cell.is-answer {
  z-index: 1;
  box-shadow: 0 0 0 3px var(--primary);
  font-weight: 800;
  animation: pop 0.3s ease;
}

.paint-actions {
  gap: 8px;
}

.paint-explain {
  min-height: 150px;
}

.explain-title {
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.explain-moves {
  display: grid;
  gap: 6px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}

.explain-moves li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface);
}

.explain-move {
  font-weight: 650;
}

.explain-unknown {
  min-width: 34px;
  color: var(--faint);
  font-weight: 700;
  text-align: center;
}

.explain-finish {
  color: var(--win);
  font-size: 0.85rem;
  font-weight: 700;
}

.explain-conclusion {
  font-weight: 600;
}

.explain-conclusion.is-wrong-text {
  color: var(--lose);
}

.summary-list {
  display: grid;
  gap: 8px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}

.summary-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

/* ---------- 3. Strategy tree ---------- */

.strategy-card {
  display: grid;
  gap: 12px;
}

.tree-wrap {
  overflow-x: auto;
}

.tree-intro {
  color: var(--muted);
}

.tree {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tree .tree {
  margin-left: 10px;
  padding-left: 14px;
  border-left: 2px solid var(--border);
}

.tree-node {
  padding: 8px 0 2px;
}

.tree-node.is-closed > .tree {
  border-left-color: color-mix(in srgb, var(--win) 55%, transparent);
}

.tree-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-height: 30px;
}

.tree-who {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tree-who.is-petya {
  background: var(--info-soft);
  color: var(--info);
}

.tree-who.is-vanya {
  background: var(--warn-soft);
  color: var(--warn);
}

.tree-pos {
  font-size: 1.1rem;
  font-weight: 800;
}

.tree-move {
  font-weight: 700;
}

.tree-status {
  font-size: 0.85rem;
  color: var(--muted);
}

.tree-status.is-ok {
  color: var(--win);
  font-weight: 700;
}

.tree-choices {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 6px 0 2px;
}

.tree-error {
  margin: 6px 0 0;
  color: var(--lose);
  font-size: 0.92rem;
  font-weight: 600;
}

/* ---------- 4. Exam ---------- */

.exam-questions {
  display: grid;
  gap: 14px;
  margin: 18px 0;
}

.exam-question {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

@media (max-width: 480px) {
  .exam-question {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }
}

.exam-question p {
  margin: 0 0 4px;
}

.exam-q-item {
  padding-left: 1em;
}

.exam-question .answer-row {
  margin-top: 12px;
}

.exam-q-feedback {
  margin-top: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
}

.exam-actions {
  gap: 8px;
}

.exam-breakdown h3 {
  margin-bottom: 12px;
}

.strip-wrap {
  overflow-x: auto;
  margin-bottom: 10px;
  padding: 4px 2px 8px;
}

.strip {
  display: flex;
  gap: 3px;
  width: max-content;
}

.strip-cell {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.strip-cell.is-answer {
  box-shadow: inset 0 0 0 2px currentColor;
  font-weight: 800;
}

.breakdown-lines {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.breakdown-lines li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
