:root {
  --bg: #120c22;
  --ink: #f6eefe;
  --muted: #cbb9e8;
  --card: rgba(24, 16, 42, 0.82);
  --accent: #d7b4ff;
  --accent-2: #9b6dff;
  --gap: #1a1230;
  --ok: #7dffb3;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: auto;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, #2a1848 0%, transparent 55%),
    var(--bg);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 2px;
}

.top h1 {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.back, .icon-btn {
  color: var(--muted);
  text-decoration: none;
  background: var(--card);
  border: 1px solid rgba(215, 180, 255, 0.18);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.85rem;
  min-width: 44px;
  text-align: center;
}

.icon-btn {
  border: 1px solid rgba(215, 180, 255, 0.18);
  color: var(--ink);
  cursor: pointer;
}

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

.stat {
  background: var(--card);
  border: 1px solid rgba(215, 180, 255, 0.12);
  border-radius: 14px;
  padding: 8px 6px;
  text-align: center;
}

.stat .label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat .value {
  display: block;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  font-weight: 650;
}

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
/**/
.board {
  width: min(92vw, 420px, 100%, calc(100dvh - 230px));
  max-height: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
  background: var(--gap);
  border-radius: 18px;
  box-shadow: var(--shadow);
  user-select: none;
}

.tile {
  position: relative;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  font-size: clamp(1.15rem, 6vw, 1.7rem);
  color: #3a2412;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s ease;
}

.tile.empty {
  visibility: hidden;
  pointer-events: none;
}

.tile:active { transform: scale(0.96); }

/* Wood */
.skin-wood .tile {
  background:
    linear-gradient(160deg, rgba(255,255,255,0.2), transparent 40%),
    repeating-linear-gradient(90deg, #c68642 0 2px, #b87432 2px 5px, #c68642 5px 8px);
  background-color: #c68642;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.28),
    inset 0 -3px 8px rgba(80, 30, 0, 0.28),
    0 2px 0 #7a4318;
  color: #3b220e;
  text-shadow: 0 1px 0 rgba(255,255,255,0.25);
}

/* Digits */
.skin-digits .tile {
  background: #221635;
  color: var(--ink);
  border: 1px solid rgba(215, 180, 255, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.skin-digits .tile::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 8px;
  border: 1px dashed rgba(215, 180, 255, 0.22);
  pointer-events: none;
}

/* Neon */
.skin-neon .tile {
  background: #1a1030;
  color: #e9d7ff;
  box-shadow:
    0 0 0 1px rgba(215, 180, 255, 0.35),
    0 0 14px rgba(155, 109, 255, 0.35);
  text-shadow: 0 0 10px rgba(215, 180, 255, 0.8);
}

.skins,
.actions {
  flex-shrink: 0;
}

.skins {
  display: flex;
  gap: 8px;
}

.skin {
  flex: 1;
  border: 1px solid rgba(215, 180, 255, 0.18);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.skin.active {
  color: var(--bg);
  background: var(--accent);
  border-color: transparent;
  font-weight: 650;
}

.actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 8px;
}

.btn {
  border: 1px solid rgba(215, 180, 255, 0.2);
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 10px;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn.primary {
  background: linear-gradient(180deg, #e4c6ff, var(--accent-2));
  color: #1a1028;
  border: 0;
  font-weight: 700;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 5, 16, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.overlay.hidden { display: none; }

.modal {
  width: min(92vw, 360px);
  background: #1c1432;
  border: 1px solid rgba(215, 180, 255, 0.2);
  border-radius: 18px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal h2 { margin-bottom: 8px; }
.modal p { color: var(--muted); margin-bottom: 16px; line-height: 1.4; }
.modal .btn { width: 100%; }

.paused .board { filter: blur(3px) saturate(0.6); pointer-events: none; }
