:root {
  color-scheme: light;
  --indigo-velvet: #5e1c99;
  --lavender-mist: #f8f1ff;
  --thistle: #decdf5;
  --dim-grey: #656176;
  --charcoal: #534d56;
  --card-radius: 18px;
  /* Approx. vertical space used by header/panels; used to keep the 4x4 grid from being clipped. */
  --ui-chrome-height: 360px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--charcoal);
  background:
    radial-gradient(circle at top left, rgba(94, 28, 153, 0.18), transparent 32%),
    radial-gradient(circle at top right, rgba(222, 205, 245, 0.9), transparent 30%),
    linear-gradient(180deg, #ffffff 0%, var(--lavender-mist) 100%);
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 20px auto 32px;
  display: grid;
  gap: 22px;
}

.hero,
.board-panel,
.controls {
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(94, 28, 153, 0.12);
  border-radius: 28px;
  box-shadow: 0 24px 70px rgba(94, 28, 153, 0.09);
  backdrop-filter: blur(14px);
}

.hero {
  padding: 22px 24px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  width: fit-content;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(94, 28, 153, 0.18);
  color: var(--indigo-velvet);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(248, 241, 255, 0.85);
}

h1 {
  margin: 0;
  color: var(--indigo-velvet);
  font-family: "DM Serif Display", Georgia, serif;
  font-size: clamp(3rem, 6vw, 5rem);
  line-height: 0.95;
  font-weight: 400;
}

.compact-ui {
  --ui-chrome-height: 300px;
}

.compact-ui h1 {
  font-size: clamp(2.25rem, 4.8vw, 3.4rem);
}

.compact-ui .hero {
  justify-content: flex-start;
}

.compact-ui .app-shell {
  margin: 14px auto 22px;
  gap: 16px;
}

.compact-ui .board-panel {
  padding: 14px 16px 16px;
}

.compact-ui .stats {
  display: none;
}

.hero-copy {
  margin: 8px 0 0;
  color: var(--dim-grey);
  font-size: 1rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stat-card {
  min-width: 128px;
  padding: 16px 14px;
  border-radius: 18px;
  border: 1px solid rgba(94, 28, 153, 0.12);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.stat-label {
  display: block;
  color: var(--dim-grey);
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-card strong {
  color: var(--indigo-velvet);
  font-size: 1.5rem;
  font-weight: 800;
}

.board-panel {
  padding: 18px 20px 22px;
}

.status-text {
  margin: 4px 0 14px;
  color: var(--dim-grey);
  font-size: 1rem;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(var(--board-columns, 4), minmax(0, 1fr));
  gap: var(--board-gap, clamp(10px, 1.6vw, 16px));
  align-items: stretch;
  width: 100%;
  /*
    Keep cards from ballooning on wide screens while also respecting short viewports.
    With aspect-ratio 4/5, a 4x4 grid is ~1.25x as tall as it is wide.
  */
  max-inline-size: min(
    100%,
    clamp(280px, calc((100vh - var(--ui-chrome-height)) * 0.8), 640px)
  );
  margin-inline: auto;
}

.memory-card {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  width: 100%;
  aspect-ratio: 4 / 5;
  perspective: 1200px;
  cursor: pointer;
  outline: none;
}

.memory-card:disabled {
  cursor: default;
}

.memory-card:focus-visible .memory-card-inner {
  box-shadow: 0 0 0 4px rgba(94, 28, 153, 0.2);
}

.memory-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}

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

.memory-face {
  position: absolute;
  inset: 0;
  border-radius: var(--card-radius);
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 1px solid rgba(94, 28, 153, 0.12);
  box-shadow: 0 10px 22px rgba(94, 28, 153, 0.09);
  background: #ffffff;
}

.memory-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.memory-face--front {
  transform: rotateY(180deg);
}

.memory-face--back {
  transform: rotateY(0deg);
}

.memory-card.is-matched {
  opacity: 0.94;
}

.controls {
  padding: 18px 20px;
  display: flex;
  justify-content: flex-end;
}

.primary-button {
  border: 1px solid rgba(94, 28, 153, 0.18);
  background: linear-gradient(180deg, #fff 0%, rgba(248, 241, 255, 0.98) 100%);
  color: var(--indigo-velvet);
  padding: 12px 18px;
  border-radius: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(94, 28, 153, 0.08);
}

.primary-button:hover {
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(0);
}

@media (max-width: 980px) {
  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: min(100% - 20px, 1200px);
  }

  .game-board {
    gap: 10px;
  }

  .stat-card {
    min-width: calc(33.333% - 8px);
    flex: 1 1 0;
  }
}
