:root {
  --bg1: #1b1340;
  --bg2: #120c2b;
  --bg3: #0c1530;
  --txt: #f3f1ff;
  --dim: #b6b0e0;
  --gold: #ffd23f;
  --accent: #8a7bff;
  --panel: #1a1438;
  --line: rgba(255,255,255,0.14);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: radial-gradient(120% 80% at 50% -10%, #2a1d63 0%, var(--bg1) 38%, var(--bg2) 70%, var(--bg3) 100%);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", system-ui, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
body { display: flex; flex-direction: column; height: 100dvh; }

/* 상단바 */
#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: linear-gradient(180deg, rgba(26,20,56,0.92), rgba(18,12,43,0.7));
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  color: var(--txt); z-index: 10;
}
#topbar .back { color: var(--dim); text-decoration: none; font-size: 14px; font-weight: 600; }
#topbar .back:hover { color: #fff; }
#topbar .brand { font-weight: 800; letter-spacing: -0.02em; font-size: 16px; display: flex; align-items: center; gap: 5px; }
#topbar .brand .ic { font-size: 18px; }
#topbar .spacer { flex: 1; }
#topbar .stat {
  font-size: 12px; font-weight: 800; color: var(--gold);
  background: rgba(255,210,63,0.14); border: 1px solid rgba(255,210,63,0.35);
  padding: 4px 10px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
#topbar button {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255,255,255,0.08); color: var(--txt); font-size: 14px; font-weight: 700;
  cursor: pointer; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
#topbar button:hover { background: rgba(255,255,255,0.18); }
#topbar button:active { transform: scale(0.94); }

/* 본문 */
#app {
  flex: 1; display: flex; flex-direction: column; min-height: 0;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
}

/* HUD */
#hud {
  display: flex; align-items: stretch; justify-content: center; gap: 10px;
  margin: 2px auto 6px; width: 100%; max-width: 460px;
}
#hud .hcol {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 8px; border-radius: 13px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--line);
}
#hud .hcol.combo { background: rgba(138,123,255,0.18); border-color: rgba(138,123,255,0.5); }
#hud .hcol[hidden] { display: none; }
#hud .hl { font-size: 10.5px; font-weight: 700; color: var(--dim); letter-spacing: 0.02em; }
#hud .hv { font-size: 22px; font-weight: 900; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
#hud .hcol:nth-child(1) .hv { color: var(--gold); }
#hud .hcol.combo .hv { color: #c9beff; }
#hud .hcol:nth-child(3) .hv { color: #fff; }

#boardWrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board {
  touch-action: none; max-width: 100%; max-height: 100%;
  display: block;
}

/* 오버레이 */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 18px; background: rgba(8,6,22,0.66); -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
}
.overlay[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 400px; max-height: 90vh; overflow: auto;
  background: linear-gradient(180deg, #241a52, #160f33);
  border: 1px solid rgba(150,135,255,0.34); border-radius: 22px; padding: 24px 22px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55); text-align: center;
}
.sheet .emoji { font-size: 46px; line-height: 1; }
.sheet h2 { margin: 8px 0 2px; font-size: 26px; font-weight: 900; letter-spacing: -0.02em; }
.sheet .subt { margin: 0 0 14px; color: #b3a6ff; font-weight: 700; font-size: 14px; }
.rules { text-align: left; background: rgba(0,0,0,0.22); border-radius: 14px; padding: 13px 15px; margin: 0 0 16px; }
.rules p { font-size: 13.5px; line-height: 1.6; color: #e7e2ff; margin: 0 0 7px; }
.rules p:last-child { margin: 0; }
.rules b { color: #fff; }
.rules .k { color: var(--gold); font-weight: 800; }
.rules .d { color: #ff8f8f; font-weight: 800; }
.goscore { display: flex; justify-content: center; gap: 26px; margin: 4px 0 18px; }
.goscore .b { font-size: 12px; color: var(--dim); font-weight: 600; }
.goscore .v { font-size: 40px; font-weight: 900; color: var(--gold); letter-spacing: -0.02em; line-height: 1.05; }
.goscore .v.small { color: #fff; font-size: 32px; }
.primary {
  width: 100%; padding: 15px; border-radius: 15px; border: none;
  background: linear-gradient(180deg, #9d8cff, #6b4fe0); color: #fff;
  font-size: 17px; font-weight: 900; cursor: pointer; letter-spacing: -0.01em;
  box-shadow: 0 6px 0 #4a32b0, 0 10px 24px rgba(107,79,224,0.45);
}
.primary:active { transform: translateY(3px); box-shadow: 0 3px 0 #4a32b0, 0 6px 14px rgba(107,79,224,0.45); }
.ghost {
  margin-top: 10px; width: 100%; padding: 11px; border-radius: 13px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--txt);
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.ghost:active { transform: scale(0.98); }
.tip { margin-top: 13px; font-size: 12px; color: var(--dim); line-height: 1.5; }

@media (min-width: 620px) {
  #topbar .brand { font-size: 18px; }
}
