:root {
  color-scheme: dark;
  --bg: #10151f;
  --panel: #17202d;
  --ink: #edf4ff;
  --muted: #90a0b6;
  --line: rgba(255, 255, 255, 0.12);
  --good: #58e6ad;
  --hint: #ffffff;
  --tile: #223044;
  --art-url: url("./art.svg?v=5");
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: radial-gradient(circle at 50% 0%, #263247 0, var(--bg) 52%);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  touch-action: manipulation;
  user-select: none;
}

body {
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

button {
  border: 1px solid var(--line);
  background: #1d2838;
  color: var(--ink);
  min-height: 46px;
  border-radius: 8px;
  font: 700 15px/1 system-ui, sans-serif;
  padding: 0 16px;
}

button:active {
  transform: translateY(1px);
}

.app {
  width: min(100%, 520px);
  display: grid;
  gap: 12px;
}

.topbar,
.status,
.controls,
.gallery,
.legend,
.message {
  background: rgba(23, 32, 45, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--good);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 9vw, 42px);
  line-height: 0.98;
}

.version {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.preview {
  width: 66px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  border: 2px solid rgba(88, 230, 173, 0.72);
  border-radius: 8px;
  background: var(--art-url) center / cover;
  box-shadow: 0 0 18px rgba(88, 230, 173, 0.34);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px;
}

.art-choice {
  min-height: 54px;
  padding: 0;
  border-radius: 8px;
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.art-choice.active {
  border-color: var(--good);
  box-shadow: 0 0 0 3px rgba(88, 230, 173, 0.26), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 62px;
}

.status div {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
}

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

.status span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.status strong {
  font-size: 22px;
}

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(40, 51, 70, 0.98), rgba(13, 18, 28, 0.98));
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), 0 18px 46px rgba(0, 0, 0, 0.35);
}

.board {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 7px;
  z-index: 2;
}

#pulseCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.85;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background-color: var(--tile);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 8px 18px rgba(0, 0, 0, 0.28);
  transition: transform 130ms ease, filter 130ms ease, border-color 130ms ease;
  overflow: hidden;
}

.tile.matched {
  border-color: rgba(88, 230, 173, 0.78);
  box-shadow: 0 0 15px rgba(88, 230, 173, 0.86);
}

.piece-label {
  position: absolute;
  left: 6px;
  top: 6px;
  z-index: 2;
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: rgba(237, 244, 255, 0.92);
  background: rgba(10, 15, 23, 0.48);
  font-size: 11px;
  font-weight: 900;
  backdrop-filter: blur(5px);
}

.tile.hint {
  transform: scale(0.94);
  border-color: var(--hint);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.28), 0 8px 18px rgba(0, 0, 0, 0.28);
}

.empty {
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 9px;
}

.legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  min-height: 40px;
  padding: 8px 10px;
  gap: 8px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #c9d8ea;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.message {
  min-height: 48px;
  display: grid;
  align-items: center;
  padding: 11px 14px;
  color: #c9d8ea;
  font-size: 14px;
  line-height: 1.45;
}

.message.win {
  color: var(--good);
  font-weight: 800;
}

@media (max-width: 360px) {
  .board {
    gap: 5px;
    inset: 8px;
  }

  .controls {
    gap: 6px;
  }

  button {
    padding: 0 8px;
    font-size: 13px;
  }
}
