:root {
  color-scheme: light;
  --background: #f7f3ea;
  --ink: #1f2933;
  --muted: #667085;
  --panel: #fffdfa;
  --panel-strong: #fff7df;
  --line: #ded6c5;
  --accent: #1f8a70;
  --accent-dark: #176857;
  --berry: #c2415d;
  --sun: #f4b740;
  --shadow: 0 18px 40px rgba(61, 50, 31, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(31, 138, 112, 0.12), transparent 36%),
    linear-gradient(315deg, rgba(194, 65, 93, 0.14), transparent 32%),
    var(--background);
}

button {
  font: inherit;
}

.game-shell {
  width: min(980px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 20px;
}

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

h1,
h2 {
  margin: 0;
  line-height: 1;
}

h1 {
  font-size: clamp(2.25rem, 6vw, 4.5rem);
}

h2 {
  font-size: clamp(1.65rem, 4vw, 2.5rem);
}

.icon-button,
#play-again-button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 10px 22px rgba(31, 138, 112, 0.22);
  cursor: pointer;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  font-size: 1.5rem;
}

.icon-button:hover,
#play-again-button:hover {
  background: var(--accent-dark);
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stat {
  min-height: 82px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.88);
  box-shadow: 0 8px 18px rgba(61, 50, 31, 0.08);
}

.stat-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.stat strong {
  font-size: clamp(1.45rem, 4vw, 2.1rem);
}

.options-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.8);
}

.options-label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.segmented-control {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.segmented-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(31, 138, 112, 0.28);
  border-radius: 8px;
  color: var(--accent-dark);
  background: #fffdfa;
  cursor: pointer;
  font-weight: 800;
}

.segmented-button:hover,
.segmented-button.is-selected {
  color: #fff;
  background: var(--accent);
}

.board-wrap {
  padding: clamp(12px, 3vw, 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.74);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: clamp(8px, 2vw, 16px);
}

.board[data-pairs="10"] {
  grid-template-columns: repeat(5, minmax(72px, 1fr));
}

.board[data-pairs="12"] {
  grid-template-columns: repeat(6, minmax(72px, 1fr));
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  perspective: 900px;
  cursor: pointer;
}

.card:focus-visible {
  outline: 4px solid rgba(31, 138, 112, 0.36);
  outline-offset: 3px;
}

.card:disabled {
  cursor: default;
  opacity: 1;
}

.card-inner,
.card-back,
.card-front {
  position: absolute;
  inset: 0;
  border-radius: 8px;
}

.card-inner {
  transform-style: preserve-3d;
  transition: transform 240ms ease;
}

.card.is-face-up .card-inner {
  transform: rotateY(180deg);
}

.card-back,
.card-front {
  display: grid;
  place-items: center;
  backface-visibility: hidden;
}

.card-back {
  border: 2px solid rgba(31, 138, 112, 0.34);
  color: #fff;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.17), transparent 46%),
    linear-gradient(135deg, var(--accent), #0f766e);
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 900;
}

.card-front {
  grid-template-rows: 1fr auto;
  padding: clamp(8px, 2vw, 16px);
  border: 2px solid rgba(194, 65, 93, 0.34);
  background: var(--panel-strong);
  transform: rotateY(180deg);
}

.card.is-matched .card-front {
  border-color: rgba(31, 138, 112, 0.5);
  background: #eaf8ed;
}

.fruit-symbol {
  align-self: end;
  font-size: clamp(2rem, 8vw, 4.5rem);
  line-height: 1;
}

.fruit-label {
  align-self: end;
  width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(0.72rem, 2.2vw, 0.96rem);
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-complete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid rgba(31, 138, 112, 0.28);
  border-radius: 8px;
  background: rgba(234, 248, 237, 0.9);
}

.game-complete[hidden] {
  display: none;
}

.game-complete p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
}

#play-again-button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 800;
}

@media (max-width: 620px) {
  .game-shell {
    width: min(100vw - 20px, 560px);
    padding-top: 12px;
  }

  .status-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .options-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented-control {
    justify-content: stretch;
  }

  .segmented-button {
    flex: 1 1 90px;
  }

  .stat {
    min-height: 66px;
    padding: 10px;
  }

  .stat-label {
    font-size: 0.72rem;
  }

  .board {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
  }

  .board[data-pairs="10"],
  .board[data-pairs="12"] {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
  }

  .game-complete {
    align-items: stretch;
    flex-direction: column;
  }
}
