* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-1: #1a1a2e;
  --bg-2: #16213e;
  --accent: #e94560;
  --accent-2: #ffd369;
  --text: #f5f5f5;
  --muted: #a0a0b8;
  --tile-border: rgba(255, 255, 255, 0.12);
  --board-size: min(92vw, 520px);
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, var(--bg-2), var(--bg-1) 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
}

.app {
  width: 100%;
  max-width: 600px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

header {
  text-align: center;
  margin-top: 8px;
}

header h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 40px);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 1px;
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
  user-select: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #c63651);
  border-color: transparent;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ff556f, var(--accent));
}

select.btn {
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text) 50%), linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  width: 100%;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat span:last-child {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  background: rgba(0, 0, 0, 0.35);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  overflow: hidden;
  touch-action: none;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 10px;
  text-align: center;
  padding: 20px;
}

.placeholder p {
  margin: 0;
  font-size: 15px;
}

.tile {
  position: absolute;
  background-size: cover;
  background-repeat: no-repeat;
  border-radius: 6px;
  cursor: pointer;
  transition: left 0.18s ease, top 0.18s ease, opacity 0.2s ease;
  box-shadow: inset 0 0 0 1px var(--tile-border), 0 2px 4px rgba(0, 0, 0, 0.25);
  user-select: none;
  -webkit-user-drag: none;
}

.tile.empty {
  background: transparent;
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}

.tile.win {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  cursor: default;
}

.tile.win-flash {
  animation: flash 0.6s ease;
}

@keyframes flash {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.6); }
}

.tile .num {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fade 0.3s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-inner {
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 30px 40px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  max-width: 90vw;
}

.overlay-inner h2 {
  margin: 0 0 8px;
  font-size: 28px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-inner p {
  color: var(--muted);
  margin: 0 0 20px;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

footer {
  margin-top: auto;
  padding: 10px 0 20px;
  text-align: center;
}

footer p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 420px) {
  .app { padding: 10px; gap: 10px; }
  .btn { padding: 9px 12px; font-size: 13px; }
  .stat { min-width: 70px; padding: 4px 10px; }
  .stat span:last-child { font-size: 18px; }
}
