:root {
  color-scheme: dark;
  --ink: #f8f5ff;
  --muted: #bcb6d4;
  --night: #131223;
  --accent: #e1ff80;
  --line: #7d70ab55;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  background: var(--night);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 75% 38%, #30204a 0%, #17142a 48%, #10121f 86%);
}

button, a { touch-action: manipulation; }
button { font: inherit; cursor: pointer; }
a { color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.top {
  width: min(100% - 56px, 1240px);
  margin: auto;
  min-height: 73px;
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.home {
  display: flex;
  gap: 10px;
  align-items: center;
  width: fit-content;
  min-height: 44px;
  padding: 2px 4px;
  text-decoration: none;
}
.home > span { color: var(--accent); font-size: 21px; }
.home img { display: block; width: 95px; height: auto; }
.game {
  display: grid;
  grid-template-columns: minmax(250px, .8fr) minmax(320px, 1fr);
  align-items: center;
  gap: clamp(35px, 7vw, 112px);
  width: min(100% - 80px, 1050px);
  margin: auto;
  padding: clamp(38px, 8vh, 115px) 0 36px;
}
.intro { align-self: center; }
h1 {
  margin: 0;
  font-family: "Avenir Next Condensed", "Arial Narrow", Arial, sans-serif;
  font-size: clamp(59px, 8.6vw, 112px);
  line-height: .93;
  font-weight: 900;
  letter-spacing: -.045em;
}
.instructions {
  margin: 19px 0 27px;
  max-width: 32ch;
  color: var(--muted);
  font-size: clamp(.91rem, 1.55vw, 1.13rem);
  line-height: 1.45;
}
.score {
  display: flex;
  gap: 24px;
  width: fit-content;
  margin: 0 0 25px;
  padding: 13px 19px;
  border-block: 1px solid var(--line);
}
.score div + div { padding-left: 24px; border-left: 1px solid var(--line); }
.score dt { color: var(--muted); font-size: .72rem; }
.score dd {
  margin: 3px 0 0;
  color: var(--accent);
  font-size: 1.54rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score dd > span { color: #ded7f1; font-size: .85rem; font-weight: 650; }
.action {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 152px;
  min-height: 48px;
  padding: 11px 15px;
  border: 1px solid #e8ff9733;
  border-radius: 6px;
  color: #1b2417;
  background: var(--accent);
  font-weight: 810;
}
.action:hover { background: #efffae; }
.status { margin: 13px 0 0; min-height: 2.6em; max-width: 38ch; color: #ded6f4; line-height: 1.35; font-size: .85rem; }
.game[data-phase=won] .status { color: var(--accent); }
.playfield { min-width: 0; }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(7px, 1.1vw, 13px);
  padding: clamp(10px, 1.7vw, 19px);
  border: 1px solid #8c7eaf6e;
  border-radius: clamp(12px, 2.1vw, 24px);
  background: linear-gradient(130deg, #251c3a, #18172d);
  box-shadow: 0 20px 75px #0b081970, inset 0 1px #cfb2ff10;
}
.card {
  --symbol: #f2c5ff;
  position: relative;
  padding: 0;
  border: 1px solid #7e68ab83;
  border-radius: clamp(5px, 1.1vw, 11px);
  background: #2b2042;
  color: var(--ink);
  aspect-ratio: 1;
  min-width: 0;
}
.card[aria-disabled=true] { cursor: default; }
.card:focus-visible { z-index: 1; }
.card[aria-disabled=false]:hover { border-color: #cbb5ff; }
.card[aria-disabled=false]:active { transform: translateY(2px); }
.back, .face { position: absolute; inset: 0; border-radius: inherit; display: grid; place-items: center; pointer-events: none; }
.back {
  background:
    radial-gradient(circle at 50% 50%, #b8a1f314 0 58%, transparent 58%),
    repeating-linear-gradient(135deg, #8f79d611 0 1px, transparent 1px 10px),
    linear-gradient(155deg, #513875, #282447);
  box-shadow: inset 0 1px 0 #d0b4fc32, inset 0 -4px #18162e54;
}
.back::before {
  content: "";
  width: 40%;
  aspect-ratio: 1;
  border: 1px solid #c6aff78c;
  border-radius: 25%;
  transform: rotate(45deg);
}
.back::after {
  content: "";
  position: absolute;
  width: 12.5%;
  aspect-ratio: 1;
  border: 1px solid #d9c8ffa1;
  transform: rotate(45deg);
  border-radius: 25%;
}
.face {
  opacity: 0;
  background: radial-gradient(ellipse at 55% 45%, color-mix(in srgb, var(--symbol) 26%, #211938), #26203b 70%);
  box-shadow: inset 0 1px 0 #ecd9ff4f, inset 0 -5px #17132f47;
}
.card[data-state=up], .card[data-state=matched] { border-color: color-mix(in srgb, var(--symbol) 64%, #211a33); }
.card[data-state=up] .face, .card[data-state=matched] .face { opacity: 1; }
.card[data-state=up] .back, .card[data-state=matched] .back { opacity: 0; }
.card[data-state=matched] { border-color: #bbef7dac; }
.card[data-state=matched] .face {
  box-shadow: inset 0 0 0 2px #c9ff8b30;
}
.card[data-state=matched] .face::after {
  content: "";
  position: absolute;
  top: 10%;
  right: 12%;
  width: 8%;
  height: 13%;
  border: solid #e3ffa1;
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}
.game[data-phase=checking] .card[data-state=up] { border-color: #ff997cc7; }
.symbol {
  position: relative;
  width: 57%;
  height: 57%;
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--symbol) 64%, transparent));
}
.symbol::before, .symbol::after { content: ""; position: absolute; }
.card[data-symbol=sun] { --symbol: #ffe16d; }
.card[data-symbol=sun] .symbol {
  background: repeating-conic-gradient(from -9deg, var(--symbol) 0 18deg, transparent 18deg 45deg);
  border-radius: 50%;
}
.card[data-symbol=sun] .symbol::before {
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--symbol) 0 52%, #694c37 54% 63%, var(--symbol) 65%);
}
.card[data-symbol=moon] { --symbol: #bda7ff; }
.card[data-symbol=moon] .symbol {
  border-radius: 50%;
  background: radial-gradient(circle at 71% 28%, transparent 0 49%, var(--symbol) 51% 100%);
}
.card[data-symbol=star] { --symbol: #ff9cbb; }
.card[data-symbol=star] .symbol { background: var(--symbol); clip-path: polygon(50% 0%, 64% 35%, 100% 50%, 64% 65%, 50% 100%, 36% 65%, 0 50%, 36% 35%); }
.card[data-symbol=planet] { --symbol: #9acafc; }
.card[data-symbol=planet] .symbol::before { inset: 14%; border-radius: 50%; background: linear-gradient(170deg, var(--symbol) 22%, #5d7dc2 24% 33%, var(--symbol) 35% 59%, #7995d5 60% 74%, var(--symbol) 76%); }
.card[data-symbol=planet] .symbol::after { inset: 36% -8%; border: solid var(--symbol); border-width: 0 3px 3px; border-radius: 50%; transform: rotate(-25deg); }
.card[data-symbol=bolt] { --symbol: #ffb88d; }
.card[data-symbol=bolt] .symbol { background: var(--symbol); clip-path: polygon(53% 0, 85% 0, 61% 38%, 87% 38%, 29% 100%, 40% 57%, 13% 57%); }
.card[data-symbol=gem] { --symbol: #85edbb; }
.card[data-symbol=gem] .symbol { clip-path: polygon(50% 0%, 91% 28%, 91% 72%, 50% 100%, 9% 72%, 9% 28%); background: conic-gradient(from -30deg, #4bb888 0 60deg, #74dba4 60deg 120deg, #3eac84 120deg 180deg, #82edb8 180deg 240deg, #66cfa0 240deg 300deg, #a9ffd0 300deg); }
.card[data-symbol=comet] { --symbol: #ff8d9e; }
.card[data-symbol=comet] .symbol::before { inset: 10% 8% 12%; background: var(--symbol); clip-path: polygon(0 0, 84% 43%, 94% 84%, 47% 100%, 9% 57%, 38% 64%); }
.card[data-symbol=comet] .symbol::after { inset: 43% 7% 8% 45%; border-radius: 50%; background: #ffd1ca; }
.card[data-symbol=satellite] { --symbol: #7fe9ef; }
.card[data-symbol=satellite] .symbol { transform: rotate(-38deg); }
.card[data-symbol=satellite] .symbol::before {
  inset: 36% -4%;
  border: 1px solid var(--symbol);
  background: repeating-linear-gradient(90deg, var(--symbol) 0 18%, #357985 19% 23%);
  border-radius: 4px;
}
.card[data-symbol=satellite] .symbol::after { inset: 15% 35%; border-radius: 25%; background: var(--symbol); box-shadow: 0 0 0 2px #357985; }
.keyboard { margin: 14px 0 0; color: var(--muted); font-size: .73rem; text-align: center; }
kbd { font: inherit; color: var(--ink); }
noscript { display: block; padding: 14px; color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .card, .face, .back { transition: opacity 130ms linear, border-color 130ms linear, transform 80ms ease; }
  .card[data-state=matched] .symbol { animation: paired 200ms ease-out; }
  @keyframes paired { 50% { scale: 1.13; } }
}
@media (max-width: 700px) {
  .top { width: calc(100% - 36px); min-height: 54px; }
  .game {
    grid-template-columns: 1fr;
    width: min(100% - 36px, 480px);
    gap: 10px;
    padding: 22px 0 max(16px, env(safe-area-inset-bottom));
  }
  .intro { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
  h1, .instructions, .status { grid-column: 1 / -1; }
  h1 { font-size: clamp(50px, 13vw, 69px); }
  .instructions { margin: 0 0 2px; max-width: 46ch; }
  .score { gap: 12px; padding: 6px 8px; margin: 0; }
  .score div + div { padding-left: 12px; }
  .score dd { font-size: 1.34rem; }
  .action { min-width: 0; justify-self: end; }
  .status { margin: 0; font-size: .78rem; min-height: 2.6em; }
}
@media (max-width: 390px) {
  .board { gap: 7px; padding: 9px; }
  .card { aspect-ratio: 1.045; }
}
@media (pointer: coarse) {
  .keyboard { display: none; }
}
