:root {
  --ink: #263238;
  --muted: #63706c;
  --paper: #fffaf1;
  --panel: #ffffff;
  --line: #ded8cb;
  --leaf: #27745b;
  --leaf-dark: #1d5d49;
  --melon: #ff6f61;
  --lemon: #f6c445;
  --sky: #d9f0ff;
  --mint: #d8f4df;
  --shadow: 0 18px 48px rgba(38, 50, 56, 0.14);
}

* {
  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:
    radial-gradient(circle at 12px 12px, rgba(39, 116, 91, 0.1) 0 2px, transparent 2px)
      0 0 / 34px 34px,
    linear-gradient(135deg, var(--paper), var(--sky));
}

button {
  font: inherit;
}

.game-shell {
  width: min(960px, calc(100vw - 32px));
  min-height: calc(100vh - 40px);
  margin: 20px auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 18px;
}

.top-bar,
.scoreboard,
.message-row {
  width: 100%;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 4px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--leaf-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.45rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.9rem;
  line-height: 1.05;
}

.restart-button {
  min-width: 106px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--leaf);
  box-shadow: 0 9px 18px rgba(39, 116, 91, 0.18);
  cursor: pointer;
  font-weight: 800;
}

.restart-button:hover {
  background: var(--leaf-dark);
}

.restart-button:focus-visible,
.card:focus-visible {
  outline: 3px solid var(--lemon);
  outline-offset: 3px;
}

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

.score-box {
  min-height: 76px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 24px rgba(38, 50, 56, 0.08);
}

.score-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.score-box strong {
  font-size: clamp(1.18rem, 3vw, 1.65rem);
  line-height: 1;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
}

.board {
  width: min(100%, clamp(300px, calc(100vh - 320px), 600px));
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.9vw, 14px);
}

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

.card[disabled] {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: var(--shadow);
  line-height: 1;
}

.card-back {
  border: 2px solid rgba(255, 255, 255, 0.86);
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.15) 50% 75%, transparent 75%)
      0 0 / 22px 22px,
    var(--melon);
}

.card-back::after {
  content: "?";
  width: clamp(42px, 10vw, 62px);
  height: clamp(42px, 10vw, 62px);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--leaf-dark);
  background: var(--lemon);
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 900;
}

.card-front {
  transform: rotateY(180deg);
  border: 2px solid rgba(39, 116, 91, 0.1);
  background: var(--panel);
  font-size: clamp(2rem, 6.5vw, 3.6rem);
  overflow: hidden;
}

.fruit {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  transform: translateY(-2%);
}

.card.is-matched .card-front {
  background: var(--mint);
  box-shadow: 0 15px 36px rgba(39, 116, 91, 0.2);
}

.message-row {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding-bottom: 8px;
  color: var(--leaf-dark);
  font-weight: 750;
  text-align: center;
}

.message-row p {
  margin-bottom: 0;
}

.result-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: transparent;
}

.result-dialog::backdrop {
  background: rgba(38, 50, 56, 0.38);
}

.dialog-content {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dialog-content p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
}

.wide {
  width: 100%;
}

@media (max-width: 680px) {
  .game-shell {
    width: min(100vw - 20px, 520px);
    min-height: calc(100vh - 20px);
    margin: 10px auto;
    gap: 12px;
  }

  .top-bar {
    align-items: flex-start;
    padding-top: 10px;
  }

  .restart-button {
    min-width: 92px;
  }

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

  .score-box {
    min-height: 64px;
    padding: 10px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition: none;
  }
}
