:root {
  color-scheme: light;
  --ink: #17324d;
  --muted: #667789;
  --cream: #f3f6fa;
  --paper: #fcfdff;
  --sage: #dbe9f6;
  --moss: #2f6690;
  --moss-dark: #173b5e;
  --coral: #e97a5e;
  --gold: #efc66c;
  --line: rgba(23, 50, 77, 0.12);
  --shadow: 0 18px 50px rgba(24, 57, 88, 0.12);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--cream);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 5% 5%, rgba(239, 198, 108, 0.24), transparent 25rem),
    radial-gradient(circle at 95% 95%, rgba(47, 102, 144, 0.16), transparent 30rem),
    var(--cream);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.hidden {
  display: none !important;
}

.brand,
.game-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 16px;
  color: var(--paper);
  background: var(--moss);
  box-shadow: 0 8px 20px rgba(47, 102, 144, 0.22);
  font-size: 22px;
}

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

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 5vw, 2.25rem);
  font-weight: 500;
  letter-spacing: -0.035em;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--moss);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.hero {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  align-items: center;
  gap: 24px;
  min-height: 235px;
  margin: 30px 0 24px;
  padding: clamp(28px, 5vw, 52px);
  overflow: hidden;
  border-radius: 32px;
  color: var(--paper);
  background:
    radial-gradient(circle at 84% 25%, rgba(123, 178, 219, 0.35), transparent 12rem),
    var(--moss-dark);
  box-shadow: var(--shadow);
}

.hero-kicker {
  margin-bottom: 8px;
  color: #b9d6ec;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h2 {
  max-width: 550px;
  margin-bottom: 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 6vw, 3.8rem);
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.hero-description {
  max-width: 540px;
  margin-bottom: 0;
  color: #d3e3ef;
  line-height: 1.55;
}

.sample-cards {
  position: relative;
  min-height: 150px;
}

.sample-card {
  position: absolute;
  display: grid;
  width: 92px;
  aspect-ratio: 0.78;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
  font-size: 2.5rem;
}

.sample-card:nth-child(1) {
  top: 22px;
  left: 0;
  rotate: -12deg;
}

.sample-card:nth-child(2) {
  z-index: 2;
  top: 0;
  left: 64px;
  rotate: 5deg;
}

.sample-card:nth-child(3) {
  top: 35px;
  left: 127px;
  rotate: 15deg;
}

.sample-card-back {
  color: #e9d39d;
  background: #3978a8;
}

.sample-card-front {
  background: var(--paper);
}

.setup-panel {
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 253, 247, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

fieldset {
  margin: 0 0 28px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 14px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
}

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

.choice {
  position: relative;
}

.choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.choice label {
  display: flex;
  min-height: 76px;
  padding: 13px;
  flex-direction: column;
  justify-content: center;
  border: 1.5px solid var(--line);
  border-radius: 17px;
  background: var(--paper);
  cursor: pointer;
  transition: 160ms ease;
}

.choice label:hover {
  border-color: rgba(47, 102, 144, 0.45);
  transform: translateY(-2px);
}

.choice input:focus-visible + label {
  outline: 3px solid rgba(233, 122, 94, 0.35);
  outline-offset: 2px;
}

.choice input:checked + label {
  border-color: var(--moss);
  background: var(--sage);
  box-shadow: inset 0 0 0 1px var(--moss);
}

.choice-title {
  font-weight: 750;
}

.choice-detail {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.pack-options {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}

.pack-choice label {
  align-items: center;
  padding: 12px 8px;
  text-align: center;
}

.pack-preview {
  margin-bottom: 7px;
  font-size: 1.65rem;
}

.home-actions,
.result-actions {
  display: flex;
  gap: 12px;
}

.button {
  min-height: 52px;
  padding: 0 23px;
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  font-weight: 750;
  transition: 160ms ease;
}

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

.button:focus-visible,
.icon-button:focus-visible,
.text-button:focus-visible,
.card:focus-visible {
  outline: 3px solid rgba(233, 122, 94, 0.55);
  outline-offset: 3px;
}

.button-primary {
  color: white;
  background: var(--coral);
  box-shadow: 0 10px 22px rgba(233, 122, 94, 0.24);
}

.button-secondary {
  border: 1px solid var(--line);
  background: var(--paper);
}

.home-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 8px 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.text-button {
  padding: 3px;
  border: 0;
  color: var(--moss);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.game-screen {
  display: flex;
  max-width: 920px;
  margin: 0 auto;
  flex-direction: column;
}

.game-header {
  justify-content: space-between;
}

.game-heading {
  flex: 1;
  text-align: center;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--paper);
  cursor: pointer;
  font-size: 1.25rem;
}

.pause-button {
  color: white;
  background: var(--moss);
}

.status-bar {
  display: grid;
  width: min(100%, 500px);
  margin: 24px auto 18px;
  padding: 13px 8px;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.86);
  box-shadow: 0 8px 28px rgba(24, 57, 88, 0.08);
}

.status-bar div {
  text-align: center;
}

.status-bar div + div {
  border-left: 1px solid var(--line);
}

.status-label {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.status-bar strong {
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.board-wrap {
  display: flex;
  min-height: 0;
  flex: 1;
  align-items: center;
  justify-content: center;
}

.game-board {
  display: grid;
  width: min(100%, 820px);
  max-height: calc(100dvh - 245px);
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: clamp(5px, 1.4vw, 12px);
}

.card {
  position: relative;
  min-width: 0;
  padding: 0;
  aspect-ratio: 0.82;
  border: 0;
  border-radius: clamp(9px, 2vw, 17px);
  background: transparent;
  cursor: pointer;
  perspective: 700px;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 320ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

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

.card-face {
  position: absolute;
  display: grid;
  inset: 0;
  place-items: center;
  overflow: hidden;
  border-radius: inherit;
  backface-visibility: hidden;
}

.card-back {
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e7cb88;
  background:
    radial-gradient(circle at center, transparent 30%, rgba(255, 255, 255, 0.06) 31%, transparent 33%),
    var(--moss);
  box-shadow: 0 7px 15px rgba(23, 59, 94, 0.18);
  font-size: clamp(0.75rem, 3vw, 1.4rem);
}

.card-front {
  border: 1.5px solid rgba(47, 102, 144, 0.18);
  background: var(--paper);
  box-shadow: 0 8px 20px rgba(23, 59, 94, 0.12);
  transform: rotateY(180deg);
  font-size: clamp(1rem, 5.5vw, 2.75rem);
}

.game-board[data-size="64"] .card-front {
  font-size: clamp(0.95rem, 4.3vw, 2rem);
}

.card.matched .card-front {
  border-color: #8bb5d4;
  background: var(--sage);
  animation: match-pop 350ms ease;
}

.game-message {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
}

.results-screen {
  display: flex;
  max-width: 620px;
  margin: 0 auto;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
}

.celebration {
  display: grid;
  width: 78px;
  height: 78px;
  margin-bottom: 20px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--moss);
  box-shadow: 0 0 0 12px var(--sage), 0 16px 30px rgba(47, 102, 144, 0.2);
  font-size: 2rem;
}

.results-screen h1 {
  margin-bottom: 10px;
  font-size: clamp(2.2rem, 8vw, 4rem);
}

.best-message {
  color: var(--moss);
  font-weight: 700;
}

.result-time {
  margin: 28px 0;
}

.result-time span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-time strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(4rem, 18vw, 7rem);
  font-weight: 400;
  letter-spacing: -0.06em;
}

.result-stats {
  display: grid;
  width: 100%;
  margin-bottom: 30px;
  grid-template-columns: repeat(3, 1fr);
  border-block: 1px solid var(--line);
}

.result-stats div {
  padding: 18px 10px;
}

.result-stats div + div {
  border-left: 1px solid var(--line);
}

.result-stats strong,
.result-stats span {
  display: block;
}

.result-stats strong {
  font-size: 1.35rem;
}

.result-stats span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
}

.modal {
  position: fixed;
  z-index: 10;
  display: grid;
  inset: 0;
  padding: 20px;
  place-items: center;
  background: rgba(12, 37, 62, 0.76);
  backdrop-filter: blur(10px);
}

.modal-card {
  width: min(100%, 390px);
  padding: 34px;
  border-radius: 28px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.modal-card h2 {
  margin-bottom: 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 500;
}

.modal-card p:not(.eyebrow) {
  margin-bottom: 24px;
  color: var(--muted);
  line-height: 1.5;
}

.modal-card .button {
  width: 100%;
  margin-bottom: 10px;
}

.modal-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 18px;
  color: white;
  background: var(--moss);
  font-size: 1.35rem;
}

@keyframes match-pop {
  50% {
    transform: rotateY(180deg) scale(1.06);
  }
}

@media (max-width: 700px) {
  .screen {
    padding-inline: 16px;
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 30px 25px;
  }

  .sample-cards {
    display: none;
  }

  .difficulty-options {
    grid-template-columns: repeat(2, 1fr);
  }

  .pack-options {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 430px) {
  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 13px;
  }

  .hero {
    margin-top: 22px;
    border-radius: 25px;
  }

  .setup-panel {
    padding: 20px 16px;
    border-radius: 23px;
  }

  .choice label {
    min-height: 67px;
  }

  .home-actions,
  .result-actions {
    flex-direction: column;
  }

  .home-footer {
    align-items: center;
    flex-direction: column;
  }

  .game-screen {
    padding-inline: 10px;
  }

  .game-heading h1 {
    font-size: 1.45rem;
  }

  .icon-button {
    width: 43px;
    height: 43px;
  }

  .status-bar {
    margin: 18px auto 12px;
  }

  .game-board {
    max-height: calc(100dvh - 220px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
