:root {
  --ink: #17211b;
  --muted: #5e6a62;
  --paper: #f6f1e8;
  --card: #fffdf8;
  --accent: #734c92;
  --accent-dark: #4d3066;
  --gold: #d7a441;
  --line: #d8d1c5;
  --good: #16784b;
  --bad: #a23434;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at top, #fff 0, var(--paper) 60%); }
button { font: inherit; }
.app-shell { width: min(1180px, 94vw); margin: 0 auto; padding: 2.5rem 0 4rem; }
.hero { text-align: center; }
.eyebrow { color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: .3rem 0 .7rem; font-family: Georgia, serif; font-size: clamp(2.6rem, 7vw, 5rem); line-height: .95; }
.hero > p:last-child { color: var(--muted); }
.toolbar { display: flex; justify-content: center; align-items: center; gap: .8rem; flex-wrap: wrap; margin: 1.5rem 0; }
.toolbar span { padding: .55rem .9rem; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
button { border: 0; }
#new-game, #play-again { cursor: pointer; padding: .7rem 1rem; color: white; background: var(--accent); border-radius: 999px; font-weight: 800; }
#new-game:hover, #play-again:hover { background: var(--accent-dark); }
button:disabled { cursor: default; }
.status { min-height: 1.5rem; text-align: center; color: var(--muted); }
.status.error { color: var(--bad); }
.memory-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.memory-card { cursor: pointer; min-width: 0; height: 280px; padding: 0; background: transparent; perspective: 1100px; }
.card-inner { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .45s ease; }
.memory-card.flipped .card-inner, .memory-card.matched .card-inner { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; overflow: hidden; border: 2px solid transparent; border-radius: 18px; box-shadow: 0 10px 32px rgb(35 31 24 / .09); backface-visibility: hidden; }
.card-back { display: grid; place-items: center; color: white; background: linear-gradient(145deg, var(--accent), var(--accent-dark)); border-color: rgb(255 255 255 / .25); }
.card-back::before { content: ""; position: absolute; inset: 12px; border: 1px solid rgb(255 255 255 / .34); border-radius: 12px; }
.back-symbol { font-family: Georgia, serif; font-size: 4rem; }
.card-front { display: grid; grid-template-rows: minmax(0, 1fr) auto; background: var(--card); transform: rotateY(180deg); }
.card-front img { width: 100%; height: 100%; min-height: 0; object-fit: contain; padding: .45rem; background: #e9e4da; }
.card-copy { display: grid; gap: .25rem; padding: .7rem .8rem; text-align: left; }
.card-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card-provider { overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.memory-card:hover:not(:disabled) .card-face, .memory-card:focus-visible .card-face { border-color: var(--gold); outline: none; }
.memory-card.matched .card-face { border-color: var(--good); }
.memory-card.mismatch .card-face { border-color: var(--bad); }
.result { margin: 2rem auto 0; max-width: 680px; padding: 2rem; text-align: center; background: var(--card); border: 2px solid var(--good); border-radius: 22px; }
.result h2 { margin-top: 0; font-family: Georgia, serif; font-size: 2rem; }
@media (max-width: 900px) { .memory-board { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 650px) {
  .memory-board { grid-template-columns: repeat(2, 1fr); }
  .memory-card { height: 250px; }
}


.size-control {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .45rem .7rem .45rem .9rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 700;
}

.size-control select {
  padding: .3rem .65rem;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  font: inherit;
}

/* Fit larger boards without shrinking the images excessively. */
.memory-board:has(.memory-card:nth-child(13)) {
  grid-template-columns: repeat(6, 1fr);
}

.memory-board:has(.memory-card:nth-child(13)) .memory-card {
  height: 235px;
}

@media (max-width: 1050px) {
  .memory-board:has(.memory-card:nth-child(13)) {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 650px) {
  .memory-board:has(.memory-card:nth-child(13)) {
    grid-template-columns: repeat(2, 1fr);
  }
}
