:root {
  --primary: rgb(89, 198, 241);
  --purple-950: #053348;
  --purple-900: #075472;
  --purple-800: #0d6f91;
  --purple-700: #289fc9;
  --purple-600: #59c6f1;
  --purple-100: #dff6ff;
  --yellow: rgb(250, 233, 34);
  --yellow-soft: #fff3c8;
  --ink: #102d3a;
  --muted: #58717c;
  --paper: #fff;
  --line: #dbeaf0;
  --shadow: 0 16px 45px rgba(5, 75, 103, .14);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 2%, rgba(89, 198, 241, .26), transparent 22rem),
    radial-gradient(circle at 93% 25%, rgba(40, 159, 201, .14), transparent 26rem),
    #f4fbfe;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.game-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 20px;
}

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

.brand {
  display: inline-flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-title {
  color: rgb(40, 68, 85);
  font-family: "Montserrat", Arial, sans-serif;
  font-size: clamp(1.35rem, 2.8vw, 2.2rem);
  font-weight: 800;
  letter-spacing: .025em;
  line-height: 1;
  white-space: nowrap;
}

.reset-button, .play-again {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 13px;
  padding: 0 18px;
  color: #fff;
  background: var(--purple-800);
  box-shadow: 0 8px 18px rgba(5, 84, 114, .22);
  font-weight: 750;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}

.reset-button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reset-button:hover, .play-again:hover {
  transform: translateY(-1px);
  background: var(--purple-700);
  box-shadow: 0 11px 22px rgba(5, 84, 114, .28);
}

.game-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--purple-700);
  font-size: .78rem;
  font-weight: 850;
  letter-spacing: .11em;
  text-transform: uppercase;
}

h1, h2 { margin: 0; color: var(--purple-950); line-height: 1.04; letter-spacing: -.045em; }
h1 { font-size: clamp(1.9rem, 4vw, 3.4rem); }
h2 { font-size: clamp(1.75rem, 5vw, 2.5rem); }

.instructions {
  width: min(360px, 42%);
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 6px 26px rgba(5, 75, 103, .07);
  backdrop-filter: blur(12px);
}

.score-item {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 20px;
  border-right: 1px solid var(--line);
}

.score-item:last-child { border-right: 0; }
.score-label { color: var(--muted); font-size: .82rem; font-weight: 650; }
.score-item strong { color: var(--purple-900); font-size: 1.42rem; font-variant-numeric: tabular-nums; }
.score-item small { margin-left: 2px; color: var(--muted); font-size: .78rem; font-weight: 650; }

.board-wrap {
  overflow: hidden;
  border: 1px solid rgba(40, 159, 201, .2);
  border-radius: 24px;
  padding: 13px;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
}

.progress-track { height: 4px; overflow: hidden; margin-bottom: 12px; border-radius: 99px; background: var(--purple-100); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--purple-700)); transition: width .35s ease; }

.memory-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(7px, 1vw, 13px);
}

.memory-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 4 / 4.75;
  border: 0;
  border-radius: clamp(10px, 1.4vw, 17px);
  padding: 0;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
}

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 5px 13px rgba(5, 51, 72, .14);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform .38s cubic-bezier(.2, .75, .25, 1), box-shadow .2s ease;
}

.memory-card:hover .card-inner { box-shadow: 0 10px 20px rgba(5, 51, 72, .22); }
.memory-card.is-open .card-inner, .memory-card.is-matched .card-inner { transform: rotateY(180deg); }
.memory-card.is-matched { cursor: default; }

.card-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  display: grid;
  place-items: center;
  border: 1px solid rgba(40, 68, 85, .12);
  color: rgb(40, 68, 85);
  background: rgb(88, 194, 240);
  transform: rotateY(0deg) translateZ(1px);
}

.card-back-message {
  position: relative;
  display: flex;
  width: 88%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: rgb(40, 68, 85);
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.card-vote {
  font-size: clamp(.5rem, 1.1vw, .84rem);
  line-height: 1;
  letter-spacing: .14em;
}

.card-back-message strong {
  margin: .02em 0 .04em;
  font-size: clamp(1.6rem, 4vw, 3.55rem);
  line-height: .9;
  letter-spacing: -.07em;
}

.card-party {
  max-width: 100%;
  font-size: clamp(.42rem, .96vw, .76rem);
  line-height: 1.08;
  letter-spacing: .035em;
  overflow-wrap: normal;
}

.card-front {
  display: grid;
  grid-template-rows: 1fr auto;
  border: 2px solid #fff;
  background: var(--paper);
  transform: rotateY(180deg) translateZ(1px);
  -webkit-backface-visibility: hidden;
}

.portrait {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  color: #fff;
  background: #f4f8fa;
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center top;
  background: #fff;
  transform: none;
}
.portrait .initials { font-size: clamp(1rem, 3.1vw, 2.45rem); font-weight: 900; letter-spacing: -.07em; }

.candidate-number {
  position: absolute;
  top: 7px;
  left: 7px;
  display: grid;
  min-width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 8px;
  color: var(--purple-950);
  background: var(--yellow);
  box-shadow: 0 3px 9px rgba(0,0,0,.18);
  font-size: .68rem;
  font-weight: 900;
}

.candidate-info { min-width: 0; padding: clamp(5px, .7vw, 9px); text-align: left; }
.candidate-info strong { display: block; min-height: 2.5em; overflow: visible; padding-top: .08em; color: var(--purple-950); font-size: clamp(.55rem, 1.05vw, .84rem); line-height: 1.25; white-space: normal; }
.candidate-info span { display: block; overflow: hidden; margin-top: 2px; color: var(--muted); font-size: clamp(.48rem, .86vw, .68rem); line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }

.memory-card.is-matched .card-inner { box-shadow: 0 0 0 3px var(--primary), 0 8px 20px rgba(5, 51, 72, .16); }
.memory-card.is-matched .card-front::after {
  position: absolute;
  right: 7px;
  top: 7px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #218b63;
  content: "✓";
  font-size: .72rem;
  font-weight: 900;
}

.memory-card:focus-visible { outline: 4px solid var(--primary); outline-offset: 3px; }

.live-status { min-height: 1.25rem; margin: 10px 0 0; color: var(--muted); font-size: .85rem; text-align: center; }

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding-top: 12px;
  color: var(--muted);
  font-size: .75rem;
}

.footer-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--yellow); }

.result-dialog {
  width: min(480px, calc(100% - 28px));
  border: 0;
  border-radius: 26px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  box-shadow: 0 28px 90px rgba(5, 51, 72, .38);
}

.result-dialog::backdrop { background: rgba(4, 42, 58, .72); backdrop-filter: blur(6px); }
.result-card { position: relative; overflow: hidden; padding: 38px; border-radius: inherit; background: #fff; text-align: center; }
.result-card::before { position: absolute; inset: 0 0 auto; height: 7px; background: linear-gradient(90deg, var(--purple-800), var(--primary)); content: ""; }
.dialog-close { position: absolute; right: 15px; top: 14px; display: grid; width: 38px; height: 38px; place-items: center; border: 0; border-radius: 50%; color: var(--muted); background: #f3eff5; font-size: 1.55rem; cursor: pointer; }
.result-icon { display: grid; width: 68px; height: 68px; margin: 0 auto 20px; place-items: center; border-radius: 50%; color: var(--purple-950); background: var(--primary); font-size: 2rem; font-weight: 900; box-shadow: 0 10px 26px rgba(89, 198, 241, .4); }
.result-text { margin: 18px 0 14px; color: var(--muted); }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; margin: 0 0 18px; border: 1px solid var(--line); border-radius: 16px; }
.result-stats div { padding: 14px; }
.result-stats div + div { border-left: 1px solid var(--line); }
.result-stats strong, .result-stats span { display: block; }
.result-stats strong { color: var(--purple-900); font-size: 1.65rem; }
.result-stats span { margin-top: 2px; color: var(--muted); font-size: .75rem; }
.new-record { color: #177652; font-weight: 800; }
.play-again { width: 100%; margin-top: 4px; }

@media (max-width: 760px) {
  .game-shell { width: min(100% - 20px, 620px); padding-top: 12px; }
  .topbar { padding-bottom: 22px; }
  .game-heading { display: block; }
  .instructions { width: 100%; margin-top: 10px; font-size: .92rem; }
  .scoreboard { grid-template-columns: repeat(3, 1fr); }
  .best-score { display: none !important; }
  .score-item { min-height: 62px; padding: 9px 13px; }
  .score-item:nth-child(3) { border-right: 0; }
  .score-label { font-size: .72rem; }
  .score-item strong { font-size: 1.18rem; }
  .board-wrap { border-radius: 18px; padding: 9px; }
  .memory-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .candidate-info span { display: none; }
  .candidate-number { top: 4px; left: 4px; min-width: 19px; height: 19px; border-radius: 6px; font-size: .55rem; }
  .memory-card.is-matched .card-front::after { top: 4px; right: 4px; width: 19px; height: 19px; font-size: .58rem; }
}

@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .brand-title { font-size: 1.12rem; }
  .reset-button { min-height: 42px; padding: 0 13px; font-size: .82rem; }
  .reset-button svg { width: 17px; }
  h1 { font-size: 1.72rem; }
  .eyebrow { font-size: .7rem; }
  .instructions { font-size: .82rem; line-height: 1.4; }
  .score-item { display: grid; gap: 2px; }
  .result-card { padding: 34px 22px 24px; }
}

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