*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --bg-soft: #020617;
  --board-bg: #020617;
  --tile-bg: #0b1120;
  --tile-accent: rgba(148, 163, 184, 0.4);
  --tile-text: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  --primary: #38bdf8;
  --primary-soft: rgba(56, 189, 248, 0.15);
  --shadow-soft: 0 18px 45px rgba(15, 23, 42, 0.85);
}

:root.light {
  --bg: #f3f4f6;
  --bg-soft: #e5e7eb;
  --board-bg: #e5e7eb;
  --tile-bg: #ffffff;
  --tile-accent: rgba(148, 163, 184, 0.45);
  --tile-text: #111827;
  --muted: #6b7280;
  --border: #d1d5db;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --shadow-soft: 0 14px 35px rgba(148, 163, 184, 0.55);
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1e293b, #020617);
  color: #e5e7eb;
}

:root.light body {
  background: radial-gradient(circle at top, #e5e7eb, #f9fafb);
  color: #111827;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.header {
  text-align: center;
  padding-top: 0.25rem;
}

.header h1 {
  font-size: clamp(1.6rem, 4vw, 1.9rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  font-weight: 700;
}

.subtitle {
  margin-top: 0.35rem;
  margin-bottom: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.controls {
  background: linear-gradient(135deg, rgba(15,23,42,0.96), rgba(15,23,42,0.9));
  border-radius: 18px;
  padding: 0.7rem 0.9rem;
  border: 1px solid rgba(148,163,184,0.18);
  box-shadow: 0 10px 30px rgba(15,23,42,0.85);
}

:root.light .controls {
  background: linear-gradient(135deg, rgba(243,244,246,0.96), rgba(229,231,235,0.96));
  border: 1px solid rgba(209,213,219,0.9);
  box-shadow: 0 10px 25px rgba(156,163,175,0.35);
}

.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.value {
  font-size: 1.1rem;
  font-weight: 600;
}

.buttons {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.65rem;
}

.btn {
  flex: 1;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  border: 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s ease-out, box-shadow 0.12s ease-out,
    background 0.12s ease-out, color 0.12s ease-out;
  white-space: nowrap;
}

.btn.primary {
  background: var(--primary);
  color: #0b1120;
  box-shadow: 0 10px 25px var(--primary-soft);
}

.btn.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(148,163,184,0.4);
}

.btn:active {
  transform: scale(0.97) translateY(1px);
  box-shadow: none;
}

.board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  width: min(90vw, 460px);
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at top, rgba(15,23,42,1), #020617);
  border-radius: 24px;
  padding: 0.85rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 0.55rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148,163,184,0.35);
}

:root.light .board {
  background: radial-gradient(circle at top, #f3f4f6, #e5e7eb);
  border: 1px solid rgba(209,213,219,0.9);
}

.tile {
  border-radius: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 700;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background: radial-gradient(circle at top, #1f2937, #020617);
  color: var(--tile-text);
  border: 1px solid rgba(148,163,184,0.4);
  box-shadow: 0 10px 26px rgba(15,23,42,0.75);
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out,
    background 0.15s ease-out, border-color 0.15s ease-out;
}

:root.light .tile {
  background: radial-gradient(circle at top, #ffffff, #e5e7eb);
  border-color: rgba(209,213,219,0.95);
  box-shadow: 0 10px 24px rgba(156,163,175,0.7);
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--tile-accent), transparent 55%);
  opacity: 0.9;
  pointer-events: none;
}

.tile-number {
  position: relative;
  z-index: 1;
}

.tile.movable {
  cursor: pointer;
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(56,189,248,0.45);
  border-color: var(--primary-soft);
}

:root.light .tile.movable {
  box-shadow: 0 12px 26px rgba(37,99,235,0.45);
}

.tile.movable::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top, var(--primary-soft), transparent 70%);
  opacity: 0.65;
}

.tile:active {
  transform: translateY(2px);
  box-shadow: 0 4px 14px rgba(15,23,42,0.6);
}

.tile.empty {
  background: radial-gradient(circle at top, #020617, #020617);
  border-style: dashed;
  border-color: rgba(148,163,184,0.35);
  box-shadow: inset 0 0 0 1px rgba(15,23,42,0.9);
}

:root.light .tile.empty {
  background: radial-gradient(circle at top, #e5e7eb, #e5e7eb);
  border-color: rgba(209,213,219,0.9);
  box-shadow: inset 0 0 0 1px rgba(229,231,235,1);
}

.tile.empty::before {
  opacity: 0.1;
}

.options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0;
}

.option-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.option-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.chip {
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
  font-size: 0.78rem;
  border: 1px solid rgba(148,163,184,0.5);
  background: rgba(15,23,42,0.1);
  color: var(--muted);
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

:root.light .chip {
  background: rgba(249,250,251,0.9);
  border-color: rgba(209,213,219,0.95);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%) translateY(100%);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: rgba(15,23,42,0.96);
  color: #e5e7eb;
  border: 1px solid rgba(148,163,184,0.6);
  box-shadow: 0 16px 38px rgba(15,23,42,0.9);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s ease-out, opacity 0.18s ease-out;
  max-width: 90vw;
  text-align: center;
}

:root.light .toast {
  background: rgba(17,24,39,0.96);
  color: #f9fafb;
  border-color: rgba(31,41,55,0.9);
  box-shadow: 0 16px 35px rgba(55,65,81,0.9);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0%);
}

@media (max-width: 480px) {
  .app {
    padding-inline: 1rem;
  }
  .controls {
    padding: 0.6rem 0.8rem;
  }
  .buttons {
    gap: 0.5rem;
  }
  .btn {
    font-size: 0.78rem;
    padding-block: 0.5rem;
  }
  .board {
    padding: 0.75rem;
    gap: 0.45rem;
  }
  .tile {
    border-radius: 16px;
  }
}

@media (min-width: 768px) {
  .app {
    padding-top: 1.5rem;
  }
}