:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  color: #edf3ff;
  background-color: #080c20;
  --muted: #aebee5;
  --ice: #dcf8ff;
  --gold: #ffe4a0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 34rem 26rem at 50% 14%, #2b3979 0%, #18234e 44%, transparent 100%),
    radial-gradient(ellipse 50rem 36rem at 50% 75%, #152047, transparent 90%),
    #080c20;
}

.game {
  width: min(100%, 35rem);
  width: min(100%, clamp(28rem, calc(100svh - 15rem), 35rem));
  margin-inline: auto;
  padding: clamp(12px, 2.5vh, 28px) 12px 18px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-bottom: 10px;
}

.masthead img {
  width: clamp(34px, 9vw, 46px);
  height: auto;
  filter: drop-shadow(0 0 12px #9d7bff80);
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.5rem, 10vw, 3.8rem);
  line-height: 1;
  letter-spacing: -.055em;
  color: #fff0be;
  background: linear-gradient(#fff9ed 20%, #ffe8aa 55%, #d6a553);
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 #513469) drop-shadow(0 0 13px #8c79e669);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto;
  gap: 7px;
  align-items: stretch;
  margin-bottom: 8px;
}

.counter {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3px;
  border: 1px solid #4b6299;
  border-radius: 8px;
  background: linear-gradient(#080e27, #111b40);
  box-shadow: inset 0 1px 3px #030719, 0 1px #748bc455;
}

.counter span { color: var(--muted); font-size: .875rem; }
.counter strong {
  font-size: clamp(1rem, 4.9vw, 1.45rem);
  line-height: 1.12;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.best strong { color: var(--gold); }

button {
  min-height: 46px;
  border: 1px solid #8098d0;
  border-radius: 8px;
  padding: 5px clamp(8px, 2.6vw, 16px);
  background: linear-gradient(#566eae, #33477d 47%, #263763 48%, #243963);
  color: #fff;
  font-family: inherit;
  font-size: .94rem;
  font-weight: 700;
  line-height: 1.15;
  text-shadow: 0 1px 2px #090c23;
  box-shadow: inset 0 1px #c3d7ff70, 0 2px 4px #03071985;
  cursor: pointer;
}

button[aria-disabled="true"] { opacity: .65; cursor: default; }
button:active { background: #263961; }
@media (hover: hover) {
  button:hover:not([aria-disabled="true"]) { border-color: #d8e9ff; filter: brightness(1.13); }
  .cell:hover { background-color: #263e77; }
}

.restart {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid #748abe;
  border-radius: 8px;
  background: #121c3d;
}
.restart p { flex-basis: 100%; margin: 0; line-height: 1.35; }

.frame {
  position: relative;
  padding: clamp(5px, 1.7vw, 10px);
  border: 1px solid #a8bcf5;
  border-radius: 13px;
  background: linear-gradient(155deg, #8398d5, #293b6b 19%, #556fbb 45%, #1e2b56 70%, #7389ca);
  box-shadow: inset 0 1px 2px #d9e5ff85, 0 8px 28px #030511b8, 0 0 32px #5778d94d;
}

.board {
  position: relative;
  display: grid;
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid #060a1b;
  border-radius: 7px;
  background: #0a1029;
  box-shadow: 0 0 0 1px #adc4ff65, inset 0 0 22px #04081c;
  touch-action: none;
  user-select: none;
}

.row { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); min-height: 0; }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid #7894df1c;
  border-bottom: 1px solid #7894df1c;
  background-color: #111b3c;
  cursor: pointer;
}

.row:nth-child(even) .cell:nth-child(odd),
.row:nth-child(odd) .cell:nth-child(even) { background-color: #182449; }

.gem {
  display: block;
  width: 87%;
  height: 87%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px #000a);
}

.board[aria-busy="true"] .gem { position: relative; z-index: 1; }
.cell[aria-selected="true"] { box-shadow: inset 0 0 0 2px var(--ice), inset 0 0 14px #8fdcfc70; }
.cell.hinted {
  box-shadow: inset 0 0 0 2px var(--gold), inset 0 0 14px #ffd56e75;
  background-color: #53415d !important;
}

:focus-visible { outline: 2px solid #fff0a9; outline-offset: 3px; }
.cell:focus-visible { outline-offset: -4px; }

.sparkle {
  position: absolute;
  z-index: 2;
  width: 80%;
  aspect-ratio: 1;
  background: radial-gradient(circle, #fff 2%, #dcf5ff 9%, #bad9ff99 20%, transparent 70%);
  pointer-events: none;
}
.sparkle::after {
  content: "";
  position: absolute;
  inset: 10%;
  background: #fff4dc;
  clip-path: polygon(50% 0, 58% 41%, 100% 50%, 58% 59%, 50% 100%, 42% 59%, 0 50%, 42% 41%);
}

.status, .instructions, .keyboard, footer { text-align: center; }
.status { color: var(--gold); font-size: .94rem; min-height: 1.25em; margin: 7px 0 3px; }
.instructions { color: #e2eaff; margin: 0 0 3px; }
.keyboard { color: var(--muted); margin: 0; font-size: .875rem; }
footer { margin-top: 9px; }
a { color: #bcd7ff; text-underline-offset: 3px; }

@media (pointer: coarse) { .keyboard { display: none; } }
@media (max-width: 360px) {
  .game { padding-inline: 8px; }
  .toolbar { gap: 5px; }
}
