:root {
  color-scheme: light;
  --ink: #1e272e;
  --muted: #68727d;
  --line: #d8dee5;
  --paper: #f7f4ee;
  --surface: #ffffff;
  --accent: #ff1744;
  --accent-dark: #b7372d;
  --teal: #217c7e;
  --gold: #facc15;
  --green: #16a34a;
  --shadow: 0 18px 40px rgba(30, 39, 46, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(232, 93, 79, 0.18), transparent 30rem),
    linear-gradient(135deg, #f7f4ee 0%, #edf5f4 58%, #f7f0de 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
}

.practice,
.review {
  min-width: 0;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(216, 222, 229, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.practice {
  min-height: calc(100vh - 56px);
  padding: 22px;
}

.review {
  padding: 20px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 3.6rem, 4.8rem);
  line-height: 0.95;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 1.4rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(82px, 1fr));
  gap: 10px;
}

.scoreboard div {
  min-height: 70px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.scoreboard span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.scoreboard strong {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  min-height: 620px;
}

.controls {
  min-width: 0;
  border-right: 1px solid var(--line);
  padding-right: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.control-group {
  min-width: 0;
  display: grid;
  gap: 9px;
}

.control-group label,
.answer-panel label {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.segments {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.practice-type-segments {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segment {
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  background: var(--teal);
  color: #fff;
}

.segment:disabled {
  cursor: default;
  opacity: 0.52;
}

input[type="range"],
select {
  width: 100%;
  min-width: 0;
}

input[type="range"] {
  accent-color: var(--accent);
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

output {
  color: var(--ink);
  font-weight: 800;
}

.primary-button,
.answer-row button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.primary-button:hover,
.answer-row button:hover {
  background: var(--accent-dark);
}

.board-start-button {
  min-width: 150px;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(232, 93, 79, 0.28);
}

.board-start-button:hover {
  background: var(--accent-dark);
}

.stage-wrap {
  display: grid;
  grid-template-rows: auto minmax(420px, 1fr) auto;
  gap: 14px;
  min-width: 0;
}

.timer {
  min-height: 38px;
  color: var(--muted);
  font-weight: 800;
}

.stage {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 1;
  min-height: 0;
  justify-self: center;
  overflow: visible;
}

.stage.hidden-state {
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.board-shell {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  grid-template-rows: 24px minmax(0, 1fr);
  width: 100%;
}

.board-corner {
  grid-column: 1;
  grid-row: 1;
}

.board-top-labels,
.board-side-labels {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.board-top-labels {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
}

.board-side-labels {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(9, minmax(0, 1fr));
}

.board-label {
  display: grid;
  place-items: center;
}

.board-grid {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  aspect-ratio: 1;
  border: 2px solid #27313a;
  border-radius: 8px;
  overflow: hidden;
  background:
    conic-gradient(from 90deg, #ffffff 25%, #eef1f4 0 50%, #ffffff 0 75%, #eef1f4 0)
    0 0 / calc(200% / 9) calc(200% / 9);
}

.board-message {
  color: var(--muted);
  font-weight: 800;
}

.empty-field {
  display: grid;
  place-items: center;
}

.answer-field {
  display: grid;
}

.inline-answer-panel {
  grid-column: 2 / 9;
  grid-row: 2 / 9;
  align-self: center;
  justify-self: stretch;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(216, 222, 229, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 28px rgba(30, 39, 46, 0.12);
}

.inline-answer-panel.compact {
  grid-column: 2 / 9;
  grid-row: 6 / 9;
}

.inline-answer-panel.draggable {
  position: absolute;
  z-index: 4;
  width: min(76%, 360px);
  transform: translate(-50%, -50%);
  justify-self: auto;
  align-self: auto;
  touch-action: none;
}

.drag-handle {
  cursor: move;
}

.answer-status,
.answer-preview {
  min-height: 24px;
  color: var(--muted);
  font-weight: 800;
}

.answer-preview {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.inline-key-row {
  display: grid;
  gap: 6px;
}

.inline-key-row.digits {
  grid-template-columns: repeat(9, minmax(0, 1fr));
}

.inline-key-row.shapes,
.inline-key-row.actions {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.inline-key-row.colors {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.inline-key-row button {
  min-height: 36px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.inline-key-row.digits button {
  aspect-ratio: 1;
  min-height: 0;
  padding: 0 2px;
  font-size: clamp(0.78rem, 2.1vw, 1rem);
  line-height: 1;
}

.inline-key-row button:hover {
  border-color: var(--teal);
}

.inline-key-row .inline-color-key {
  color: #fff;
  text-shadow: 0 1px 3px rgba(30, 39, 46, 0.45);
}

.inline-key-row .shape-key,
.picker-row .shape-key {
  width: 24px;
  height: 24px;
}

.inline-key-row .shape-key.triangle,
.picker-row .shape-key.triangle {
  width: 0;
  height: 0;
  border-left-width: 11px;
  border-right-width: 11px;
  border-bottom-width: 20px;
}

.digit-strip {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: grid;
  place-items: center;
  padding: 24px;
}

.digits {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(3rem, 10vw, 8rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  word-break: break-all;
  color: #27313a;
}

.memory-field,
.shape-field,
.position-field,
.card-field {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
}

.dynamic-field {
  display: block;
}

.dynamic-runner {
  position: absolute;
  left: var(--from-x);
  top: var(--from-y);
  z-index: 2;
  transform: translate(-50%, -50%);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.85rem, 3vw, 2.4rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
  color: #27313a;
  white-space: nowrap;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.8);
  animation: dynamic-flight var(--flight-duration) linear forwards;
  pointer-events: none;
}

.match-card {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 3px;
  border: 1px solid rgba(39, 49, 58, 0.22);
  border-radius: 8px;
  background: #27313a;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.match-card::before {
  content: "";
  position: absolute;
  inset: 18%;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 6px;
}

.match-card.revealed,
.match-card.matched {
  background: #fff;
  box-shadow: 0 6px 14px rgba(30, 39, 46, 0.12);
}

.match-card.revealed::before,
.match-card.matched::before {
  display: none;
}

.match-card.matched {
  border-color: var(--green);
}

.match-card-face {
  position: absolute;
  inset: 8%;
  display: none;
  place-items: center;
  border-radius: 6px;
  font-size: clamp(0.8rem, 3vw, 1.7rem);
  font-weight: 900;
  line-height: 1;
}

.match-card.revealed .match-card-face,
.match-card.matched .match-card-face {
  display: grid;
}

@keyframes dynamic-flight {
  from {
    left: var(--from-x);
    top: var(--from-y);
  }

  to {
    left: var(--to-x);
    top: var(--to-y);
  }
}

.memory-item {
  position: relative;
  display: grid;
  place-items: center;
  align-self: stretch;
  justify-self: stretch;
  min-width: 0;
}

.memory-item strong {
  position: relative;
  z-index: 1;
  grid-column: 1;
  grid-row: 1;
  color: currentColor;
  font-size: clamp(1.1rem, 3vw, 2.2rem);
  line-height: 1;
}

.memory-item.on-token strong {
  color: #fff;
  text-shadow: 0 1px 3px rgba(30, 39, 46, 0.45);
}

.memory-item .shape,
.memory-item .color-memory-dot {
  grid-column: 1;
  grid-row: 1;
}

.color-memory-dot {
  width: min(68%, 64px);
  height: min(68%, 64px);
  border-radius: 50%;
}

.shape {
  display: block;
  align-self: center;
  justify-self: center;
  width: min(68%, 64px);
  height: min(68%, 64px);
  transform: none;
}

.shape.large {
  width: min(78%, 120px);
  height: min(78%, 120px);
}

.shape.circle {
  border-radius: 50%;
}

.shape.square {
  border-radius: 8px;
}

.shape.triangle {
  width: 0;
  height: 0;
  border-left: min(3.1vw, 32px) solid transparent;
  border-right: min(3.1vw, 32px) solid transparent;
  border-bottom: min(5.6vw, 58px) solid currentColor;
  background: transparent;
}

.shape.triangle.large {
  border-left-width: min(6vw, 58px);
  border-right-width: min(6vw, 58px);
  border-bottom-width: min(10vw, 108px);
}

.shape.diamond {
  transform: rotate(45deg);
}

.position-cell {
  border: 0;
  background: transparent;
  display: grid;
  place-items: center;
}

.position-cell.answerable:hover {
  background: rgba(33, 124, 126, 0.12);
}

.position-cell.selected {
  background: rgba(232, 93, 79, 0.18);
}

.position-cell.matched::after,
.position-cell.missed::after,
.position-cell.extra::after {
  content: "";
  width: 48%;
  height: 48%;
  border-radius: 50%;
}

.position-cell.matched::after {
  background: var(--green);
}

.position-cell.missed::after {
  border: 3px solid var(--accent);
}

.position-cell.extra::after {
  border: 3px solid var(--gold);
}

.position-cell:disabled {
  cursor: default;
}

.position-dot {
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 8px rgba(232, 93, 79, 0.16);
}

.answer-panel {
  display: grid;
  gap: 8px;
}

.shape-legend {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.shape-picker {
  display: grid;
  gap: 8px;
}

.picker-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.picker-row button,
.picker-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.picker-row button.active {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 2px var(--teal);
}

.color-swatch {
  color: #fff;
}

.picker-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.picker-actions span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
}

.answer-row input {
  min-height: 46px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
}

.hidden {
  display: none;
}

.feedback {
  margin: 18px 0;
  min-height: 84px;
  padding: 14px;
  border-radius: 8px;
  background: #f1f4f5;
  color: var(--muted);
  font-weight: 700;
}

.feedback.result-correct,
.history .result-correct {
  color: var(--green);
}

.feedback.result-wrong,
.history .result-wrong {
  color: var(--accent);
}

.replay-button {
  min-width: 128px;
  padding: 0 18px;
}

.review-summary {
  margin-bottom: 12px;
}

.position-review-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
}

.feedback .board-shell {
  width: min(100%, 284px);
}

.feedback .board-grid {
  border-width: 1px;
  border-color: var(--line);
  border-radius: 8px;
}

.position-review-cell {
  display: grid;
  place-items: center;
}

.position-review-cell::after {
  content: "";
  width: 48%;
  height: 48%;
  border-radius: 50%;
}

.position-review-cell.matched::after {
  background: var(--green);
}

.position-review-cell.missed::after {
  border: 3px solid var(--accent);
}

.position-review-cell.extra::after {
  border: 3px solid var(--gold);
}

.history {
  margin: 0;
  padding-left: 22px;
}

.history li {
  margin: 0 0 12px;
  padding-left: 4px;
}

.history strong {
  display: block;
}

.history span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .practice {
    min-height: auto;
  }

  .review {
    max-height: none;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 18px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    max-width: 390px;
    margin: 0;
    padding: 10px;
  }

  .practice,
  .review {
    padding: 14px;
  }

  .topbar {
    display: grid;
  }

  h1 {
    font-size: 2.15rem;
  }

  .scoreboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-wrap {
    grid-template-rows: auto minmax(340px, 1fr) auto;
  }

  .stage {
    width: min(100%, 370px);
  }

  .segment {
    font-size: 0.9rem;
  }

  .inline-answer-panel {
    grid-column: 1 / -1;
    grid-row: 2 / 9;
    padding: 8px;
  }

  .inline-answer-panel.compact {
    grid-column: 1 / -1;
    grid-row: 5 / 9;
  }

  .inline-answer-panel.draggable {
    width: min(92%, 320px);
  }

  .inline-key-row.digits,
  .inline-key-row.colors {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .answer-row {
    grid-template-columns: 1fr;
  }
}
