:root {
  --bg1: #d8f2d4;
  --bg2: #8cc9cf;
  --panel: #ffffffcc;
  --ink: #554f66;
  --muted: #8b86a2;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: "Nunito", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

body {
  background:
    radial-gradient(900px 420px at 20% -10%, #f6c7dc 0%, transparent 60%),
    radial-gradient(760px 360px at 90% 10%, #b3e8c8 0%, transparent 60%),
    radial-gradient(1000px 480px at 40% 100%, #b6d7ef 0%, transparent 68%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

.game-shell {
  width: min(860px, 100%);
  display: grid;
  grid-template-columns: 54px 1fr 130px;
  gap: 12px;
  align-items: start;
}

.left-tools {
  display: grid;
  gap: 12px;
  padding-top: 10px;
}

.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid #ece8f9;
  background: var(--panel);
  color: #6d6792;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 8px 20px #9f94bf30;
  transition: transform .15s, background .15s;
}
.tool-btn:hover {
  transform: translateY(-1px);
  background: #fff;
}

.board-wrap {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.glass {
  border-radius: 18px;
  padding: 8px;
  border: 2px solid #f3eeff;
  background: #ffffff55;
  box-shadow: inset 0 0 0 2px #ffffff90, 0 12px 28px #6b5ca433;
}

#board {
  border-radius: 12px;
  display: block;
  background: linear-gradient(180deg, #7d88a9cc, #6b7694cc);
}

.tip {
  font-size: 13px;
  color: #5a5570;
  text-align: center;
  background: #ffffffa8;
  border: 1px solid #efe8ff;
  border-radius: 12px;
  padding: 8px 14px;
  letter-spacing: .03em;
}

.right-panel {
  display: grid;
  gap: 10px;
}

.stat-card {
  border-radius: 16px;
  border: 2px solid #efebfb;
  background: var(--panel);
  padding: 10px;
  text-align: center;
  box-shadow: 0 8px 20px #9f94bf24;
}

.label {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 700;
}

.value {
  margin-top: 4px;
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
  color: #7a6ca7;
}
.value.score { color: #f59e0b; }
.value.chain { color: #ef4444; }

#nextCanvas {
  display: block;
  margin: 8px auto 0;
  border-radius: 8px;
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0,0,0,.45);
  display: grid;
  place-items: center;
}
.overlay.hidden { display: none; }

.overlay-box {
  background: #fff;
  border-radius: 20px;
  padding: 36px 44px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.overlay-box h2 {
  font-size: 26px;
  color: #7a6ca7;
  margin-bottom: 8px;
}
.overlay-box p {
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 20px;
}

.retry-btn {
  padding: 10px 32px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #c084fc, #818cf8);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px #a78bfa55;
  transition: transform .15s;
}
.retry-btn:hover { transform: scale(1.05); }

.mobile-controls {
  display: none;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  border: 2px solid #efebfb;
  background: var(--panel);
  color: #6d6792;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 12px #9f94bf20;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background .1s;
}
.ctrl-btn:active {
  background: #e8e0ff;
}
.ctrl-btn.ctrl-drop {
  background: linear-gradient(135deg, #c084fc88, #818cf888);
  font-size: 24px;
  font-weight: 700;
}
.ctrl-btn.ctrl-drop:active {
  background: linear-gradient(135deg, #c084fc, #818cf8);
  color: #fff;
}

@media (max-width: 700px) {
  body {
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
  }
  .game-shell {
    grid-template-columns: 1fr;
    gap: 6px;
    justify-items: center;
    width: 100%;
    max-width: 340px;
  }
  .board-wrap {
    grid-row: 1;
    width: 100%;
  }
  .glass {
    padding: 5px;
    width: 100%;
  }
  #board {
    width: 100%;
    height: auto;
    display: block;
  }
  .right-panel {
    grid-row: 2;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    width: 100%;
  }
  .left-tools {
    grid-row: 3;
    display: flex;
    gap: 8px;
    padding-top: 0;
    justify-content: center;
  }
  .tool-btn { width: 36px; height: 36px; font-size: 16px; }
  .value { font-size: 18px; }
  .label { font-size: 10px; }
  .stat-card { padding: 6px; }
  #nextCanvas { width: 50px; height: 50px; margin-top: 4px; }
  .tip { display: none; }
  .mobile-controls {
    display: flex;
    width: 100%;
    max-width: 340px;
    justify-content: center;
  }
  .ctrl-btn { width: 48px; height: 48px; font-size: 20px; }
  .overlay-box { padding: 28px 24px; }
}
