:root {
  --bg: #f6f5f1;
  --text: #1d1d1f;
  --muted: #4a4a4f;
  --card: #ffffff;
  --card-border: #c9c6bd;
  --select: #1d4ed8;
  --correct: #15803d;
  --correct-bg: #dcfce7;
  --wrong: #b91c1c;
  --wrong-bg: #fee2e2;
  --dealt-bg: #dbeafe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

.site-nav {
  padding: 8px 16px;
  border-bottom: 1px solid var(--card-border);
}
.site-nav a {
  color: var(--select);
}

main {
  max-width: 620px;
  margin: 0 auto;
  padding: 8px 16px 32px;
}

h1 {
  font-size: 1.6rem;
  margin: 8px 0 0;
}
h2 {
  font-size: 1.15rem;
  margin: 4px 0;
}
.hint {
  margin: 0 0 12px;
  color: var(--muted);
}

/* Drill tabs: wrap onto extra lines on narrow screens rather than scroll. */
.drill-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 8px;
}
.drill-tabs [role="tab"] {
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
}
.drill-tabs [role="tab"][aria-selected="true"] {
  color: #fff;
  background: var(--select);
  border-color: var(--select);
}
.drill-tabs [role="tab"]:disabled {
  color: var(--muted);
  background: transparent;
  border-style: dashed;
  cursor: not-allowed;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.levels {
  display: flex;
  gap: 6px;
}
.levels button,
.mute {
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
}
.levels button[aria-pressed="true"],
.mute[aria-pressed="true"] {
  border-color: var(--select);
  box-shadow: inset 0 0 0 2px var(--select);
  font-weight: 600;
}
.levels[hidden] {
  display: none;
}
.mute {
  margin-left: auto;
}

/* The Spread narrows as rows are added, so a whole Spread fits a short
   screen while each card keeps its playing-card proportions. */
.spread {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  max-width: max(240px, calc(3 * (100vh - 280px) / (1.4 * var(--rows, 3))));
  margin: 0 auto;
}

/* Given cards sit above the Spread, at the same card size. */
.given {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  max-width: max(240px, calc(3 * (100vh - 280px) / (1.4 * var(--rows, 3))));
  margin: 0 auto 14px;
}
.given[hidden] {
  display: none;
}
.card.given-card {
  cursor: default;
}
.card.blank {
  display: flex;
  align-items: center;
  justify-content: center;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
  font-size: 2rem;
  cursor: default;
}

.card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 100 / 140;
  padding: 6px;
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s, background-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.card svg {
  display: block;
  width: 100%;
  height: 100%;
}
.slot {
  position: relative;
}
.key {
  position: absolute;
  top: 4px;
  left: 8px;
  pointer-events: none;
  font-size: 0.75rem;
  color: var(--muted);
}
.card[aria-pressed="true"] {
  border: 4px solid var(--select);
  padding: 4px;
  transform: translateY(-3px);
}
.card:focus-visible {
  outline: 3px solid var(--select);
  outline-offset: 2px;
}
.card.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
}
.card.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
}
/* Give up: the revealed Set gets a thick dashed outline, distinct from a green "solved". */
.card.revealed {
  border: 4px dashed var(--select);
  padding: 4px;
}

/* Complete the Card: one row per attribute, a label then three Values. */
.values {
  display: grid;
  gap: 8px;
  max-width: 420px;
  margin: 0 auto;
}
.values[hidden],
.spread[hidden] {
  display: none;
}
.value-row {
  display: grid;
  grid-template-columns: 4.5em repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 8px;
}
.value-label {
  color: var(--muted);
  font-size: 0.9rem;
}
.value {
  width: 100%;
  min-height: 44px;
  padding: 0 6px 0 16px;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.1s, background-color 0.15s;
}
.value:focus-visible {
  outline: 3px solid var(--select);
  outline-offset: 2px;
}
.value:disabled {
  color: var(--muted);
  background: transparent;
  cursor: default;
}
.value.correct {
  color: var(--text);
  border-color: var(--correct);
  background: var(--correct-bg);
  font-weight: 600;
}
.value.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
}
.value.revealed {
  color: var(--text);
  border: 2px dashed var(--select);
  font-weight: 600;
}

/* Wrong pick: only the answer area shakes. */
.values.shake,
.spread.shake {
  animation: shake 0.4s ease-in-out;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
@media (prefers-reduced-motion: reduce) {
  .values.shake,
  .spread.shake {
    animation-duration: 0.01s;
  }
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}
.status {
  margin: 0;
  min-height: 1.4em;
  font-weight: 600;
}
/* Wraps on a narrow screen when three buttons (Set or No Set) don't fit. */
.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
  margin-left: auto;
}
.secondary {
  min-height: 44px;
  padding: 0 14px;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
}
.secondary:disabled {
  color: var(--muted);
  background: transparent;
  cursor: default;
}
.action {
  min-height: 44px;
  padding: 0 18px;
  font: inherit;
  border-radius: 8px;
  border: 2px solid var(--select);
  background: var(--select);
  color: #fff;
  cursor: pointer;
}
.action:disabled {
  background: transparent;
  color: var(--muted);
  border-color: var(--card-border);
  cursor: default;
}

/* Holds the shared pattern defs without taking space (display:none would break patterns). */
.defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* Stats for the current Drill and Level: four figures in a row (two on narrow screens). */
.stats {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px solid var(--card-border);
}
.stats h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}
.stats dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}
@media (max-width: 420px) {
  .stats dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.stats dt {
  font-size: 0.8rem;
  color: var(--muted);
}
.stats dd {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Full Game: cards left in the deck, under the hint. */
.deck {
  margin: -6px 0 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.deck[hidden] {
  display: none;
}

/* Full Game: cards just dealt glow briefly so you see what changed. */
.card.dealt {
  animation: dealt 0.8s ease-out;
}
@keyframes dealt {
  from {
    border-color: var(--select);
    background-color: var(--dealt-bg);
  }
}

/* Full Game end screen: the game's figures, then New game. */
.game-over {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--card);
  border: 2px solid var(--select);
  border-radius: 10px;
}
.game-over[hidden] {
  display: none;
}
.game-over h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}
.game-over dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}
@media (max-width: 420px) {
  .game-over dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.game-over dt {
  font-size: 0.8rem;
  color: var(--muted);
}
.game-over dd {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
