:root {
  --navy: #101c3b;
  --navy-soft: #17264b;
  --blue: #2754d7;
  --blue-dark: #1d43b3;
  --cream: #f7f3ea;
  --paper: #fffdf8;
  --gold: #c7943f;
  --muted: #6f7687;
  --line: #dedbd3;
  --shadow: 0 28px 70px rgba(16, 28, 59, 0.13);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--navy);
  background:
    radial-gradient(circle at 14% 8%, rgba(199, 148, 63, 0.09), transparent 24rem),
    linear-gradient(180deg, #fbf9f4 0%, #f3efe6 100%);
  font-family: "DM Sans", sans-serif;
}

button, a { font: inherit; }
button { color: inherit; }

.page-shell {
  width: min(1180px, calc(100% - 44px));
  margin: 0 auto;
}

.arcade-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color 160ms ease;
}

.arcade-link:hover,
.arcade-link:focus-visible {
  color: var(--blue);
}

.site-header {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(16, 28, 59, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.19em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--paper);
  background: var(--navy);
  border-radius: 50%;
  font-family: "GFS Didot", serif;
  font-size: 22px;
}

.best-badge {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.15em;
}

.best-badge strong {
  min-width: 64px;
  padding: 7px 11px;
  color: var(--navy);
  background: rgba(16, 28, 59, 0.06);
  border: 1px solid rgba(16, 28, 59, 0.1);
  border-radius: 4px;
  font-size: 14px;
  letter-spacing: 0.05em;
  text-align: center;
}

main { padding: 20px 0 42px; }

.intro {
  max-width: 800px;
  margin: 0 auto 40px;
  text-align: center;
}

.eyebrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 0 0 18px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.21em;
}

.eyebrow span {
  width: 27px;
  height: 1px;
  background: var(--gold);
}

h1 {
  margin: 0;
  font-family: "GFS Didot", Georgia, serif;
  font-size: clamp(42px, 6vw, 70px);
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: -0.035em;
}

h1 em { color: var(--blue); font-weight: 400; }

.lede {
  max-width: 620px;
  margin: 24px auto 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.game-panel {
  overflow: hidden;
  max-width: 720px;
  margin: 0 auto;
  background: rgba(255, 253, 248, 0.86);
  border: 1px solid rgba(16, 28, 59, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.game-toolbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
}

.round-label { display: flex; align-items: center; gap: 11px; }
.status-dot {
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(199, 148, 63, 0.14);
}
.round-label div, .timer-wrap, .progress-text { display: flex; flex-direction: column; }
.round-label span:not(.status-dot), .timer-wrap span, .progress-text span {
  color: #9296a1;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.16em;
}
.round-label strong { margin-top: 3px; font-size: 11px; letter-spacing: 0.07em; }

.timer-wrap { align-items: center; }
.timer-wrap strong {
  margin-top: 1px;
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}
.timer-wrap.danger strong { color: #b83434; }

.icon-button {
  justify-self: end;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  color: var(--paper);
  background: var(--navy);
  border: 2px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 5px 14px rgba(16, 28, 59, .24);
  cursor: pointer;
  transition: background 160ms, box-shadow 160ms, transform 160ms;
}
.icon-button:hover { background: var(--blue); box-shadow: 0 7px 18px rgba(16, 28, 59, .3); transform: translateY(-1px); }
.icon-button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.icon-button:disabled { opacity: .55; cursor: wait; }
.icon-button span { font-size: 9px; font-weight: 700; letter-spacing: .1em; white-space: nowrap; }
.icon-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; transition: transform 160ms; }
.icon-button:hover svg { transform: rotate(-18deg); }

.board-wrap { position: relative; padding: 28px; }
.play-area { display: block; }
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 540px;
  margin: 0 auto;
  transition: filter 220ms;
}
.matches-panel {
  max-width: 540px;
  margin: 20px auto 0;
  padding: 18px;
  background: rgba(16, 28, 59, .035);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.matches-heading {
  display: flex;
  flex-direction: column;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}
.matches-heading span {
  color: #9296a1;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .16em;
}
.matches-heading strong { margin-top: 3px; font-size: 12px; letter-spacing: .07em; }
.matches-empty { margin: 18px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.matches-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}
.matches-list li {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  min-height: 46px;
  padding: 5px 9px;
  background: var(--paper);
  border: 1px solid rgba(39, 84, 215, .15);
  border-radius: 4px;
  box-shadow: 0 3px 10px rgba(16, 28, 59, .04);
}
.matches-list li span { color: var(--blue); font-family: "GFS Didot", serif; font-size: 27px; }
.matches-list li strong { font-size: 12px; font-weight: 700; }
.matches-empty[hidden] { display: none; }

.card {
  position: relative;
  min-width: 0;
  aspect-ratio: 1.95;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 700px;
  cursor: pointer;
  user-select: none;
  transition: opacity 220ms, transform 220ms, visibility 0s 220ms;
}

.card:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 5px; }
.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 440ms cubic-bezier(.2, .72, .25, 1);
}
.card.is-flipped .card-inner, .card.is-matched .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 5px;
  backface-visibility: hidden;
}
.card-front {
  color: white;
  background:
    linear-gradient(135deg, transparent 46%, rgba(255,255,255,.05) 46%, rgba(255,255,255,.05) 48%, transparent 48%),
    var(--blue);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.045), 0 3px 7px rgba(29, 67, 179, .15);
}
.card-front::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 2px;
}
.card-number { font-family: "GFS Didot", serif; font-size: clamp(28px, 4vw, 40px); }
.card-back {
  transform: rotateY(180deg);
  color: var(--navy);
  background: #fffefa;
  border: 1px solid rgba(16, 28, 59, .2);
  box-shadow: inset 0 0 0 4px #f2eee4;
  font-family: "GFS Didot", serif;
  font-size: clamp(36px, 6vw, 54px);
}
.card-back.is-name { font-family: "DM Sans", sans-serif; font-size: clamp(15px, 2.5vw, 22px); font-weight: 700; letter-spacing: .04em; }
.card-back.is-decoy { color: var(--gold); font-size: clamp(42px, 6vw, 58px); }
.card.is-matched { cursor: default; }
.card.is-cleared { visibility: hidden; opacity: 0; transform: scale(.88); }
.card.is-matched .card-back {
  color: var(--blue);
  background: #f3fff8;
  border: 3px solid #2fa96f;
  animation: match-flash 500ms ease-in-out 2;
}
@keyframes match-flash {
  0%, 100% { box-shadow: inset 0 0 0 3px rgba(47, 169, 111, .12), 0 0 0 0 rgba(47, 169, 111, .38); }
  50% { box-shadow: inset 0 0 0 3px rgba(47, 169, 111, .2), 0 0 0 6px rgba(47, 169, 111, .26); }
}
.card.is-matched .card-back::after {
  content: "✓";
  position: absolute;
  right: 8px;
  top: 6px;
  font-family: "DM Sans", sans-serif;
  font-size: 11px;
  font-weight: 700;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: safe center;
  flex-direction: column;
  padding: 24px;
  background: rgba(255, 253, 248, .91);
  text-align: center;
  opacity: 1;
  overflow-y: auto;
  transition: opacity 220ms, visibility 220ms;
  backdrop-filter: blur(7px);
}
.start-overlay.is-hidden { visibility: hidden; opacity: 0; }
.start-overlay.is-opening { justify-content: flex-start; padding-top: 18px; }
.start-overlay.is-result { justify-content: flex-start; padding-top: 32px; }
.start-icon {
  display: grid;
  width: 52px;
  height: 52px;
  margin-bottom: 14px;
  place-items: center;
  color: var(--blue);
  background: #edf1ff;
  border: 1px solid #d5def8;
  border-radius: 50%;
  font-family: "GFS Didot", serif;
  font-size: 28px;
}
.start-overlay h2 { margin: 0 0 8px; font-family: "GFS Didot", serif; font-size: 28px; font-weight: 400; }
.start-overlay p { margin: 0 0 20px; color: var(--muted); font-size: 12px; }
.alphabet-reference {
  width: min(580px, 100%);
  margin: -2px 0 20px;
  padding: 14px;
  background: rgba(16, 28, 59, .035);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.alphabet-reference[hidden] { display: none; }
.alphabet-reference > span { color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .16em; }
.alphabet-reference ol {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.alphabet-reference li {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 7px;
  background: var(--paper);
  border: 1px solid rgba(16, 28, 59, .09);
  border-radius: 3px;
  text-align: left;
}
.alphabet-reference li span { color: var(--blue); font-family: "GFS Didot", serif; font-size: 21px; white-space: nowrap; }
.alphabet-reference li strong { overflow: hidden; font-size: 9px; text-overflow: ellipsis; }
.round-matches {
  width: min(500px, 100%);
  margin: -2px 0 20px;
  padding: 14px;
  background: rgba(39, 84, 215, .05);
  border: 1px solid rgba(39, 84, 215, .14);
  border-radius: 5px;
}
.round-matches[hidden] { display: none; }
.round-matches > span { color: var(--muted); font-size: 8px; font-weight: 700; letter-spacing: .16em; }
.round-matches ol {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}
.round-matches li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--paper);
  border: 1px solid rgba(39, 84, 215, .13);
  border-radius: 3px;
}
.round-matches li span { color: var(--blue); font-family: "GFS Didot", serif; font-size: 34px; }
.round-matches li strong { font-size: 15px; }
.game-footer {
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
}
.game-footer p { display: flex; align-items: center; gap: 7px; margin: 0; }
.legend-card, .legend-smile {
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  color: var(--blue);
  background: #edf1ff;
  border-radius: 2px;
  font-family: "GFS Didot", serif;
  font-size: 12px;
}
.legend-smile { color: var(--gold); background: #f8f0df; }
.progress-text { align-items: flex-end; margin-left: auto; }
.progress-text strong { color: var(--navy); font-size: 13px; }

footer {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 24px 0 36px;
  color: #96989e;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: .17em;
}
.footer-line { flex: 1; height: 1px; background: rgba(16, 28, 59, .1); }

@media (max-width: 700px) {
  .page-shell { width: min(100% - 24px, 560px); }
  .site-header { height: 74px; }
  .arcade-link { font-size: 8px; letter-spacing: 0.08em; }
  .best-badge > span { display: none; }
  main { padding-top: 14px; }
  .intro { margin-bottom: 28px; }
  .lede { font-size: 13px; }
  .game-toolbar { min-height: 65px; padding: 0 16px; }
  .round-label span:not(.status-dot) { display: none; }
  .icon-button { padding: 9px 11px; }
  .board-wrap { padding: 14px; }
  .board { gap: 7px; grid-template-columns: repeat(3, 1fr); }
  .card { aspect-ratio: 1.75; }
  .matches-panel { padding: 14px; }
  .matches-list { display: grid; grid-template-columns: repeat(2, 1fr); }
  .alphabet-reference ol { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .game-footer { padding: 12px 16px; }
  .game-footer p { display: none; }
  .progress-text { margin: auto; align-items: center; }
  footer { gap: 10px; }
  footer span:not(.footer-line) { white-space: nowrap; font-size: 7px; }
}

@media (max-width: 520px) {
  .game-toolbar {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 10px;
    padding: 9px 10px;
  }
  .timer-wrap { grid-column: 1 / -1; grid-row: 2; }
  .icon-button { grid-column: 2; grid-row: 1; padding: 8px 10px; }
  .icon-button span { font-size: 8px; }
}

@media (max-width: 420px) {
  .alphabet-reference ol { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

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