:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", Arial, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 500px at 50% 0%, #ffffff, var(--bg));
}
body { -webkit-tap-highlight-color: transparent; }

.wrap {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 18px;
  max-width: 980px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.title {
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 18px;
}
.hud {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.hud-item {
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 10px;
}
.hud-item .label {
  color: var(--muted);
  font-size: 12px;
  margin-right: 8px;
}

.stage {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.06);
}
canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(to bottom, rgba(255,255,255,0.70), rgba(255,255,255,0.35));
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }
.overlay-card {
  width: min(520px, calc(100% - 24px));
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,0.9);
  padding: 16px 16px 14px;
}
.overlay-title {
  font-weight: 900;
  letter-spacing: -0.03em;
  font-size: 18px;
}
.overlay-sub {
  margin-top: 6px;
  color: var(--muted);
}
.overlay-cta{
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.start-btn{
  width: 100%;
  border: 1px solid rgba(255,255,255,0.75);
  background: linear-gradient(135deg, #c4f1f9, #a5b4fc);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 14px 34px rgba(79, 70, 229, 0.18), 0 10px 24px rgba(14, 165, 233, 0.14);
}
.start-btn:active{ transform: translateY(1px); }
.start-hint{
  color: var(--muted);
  font-size: 12px;
}
.overlay-help {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  color: #374151;
  font-size: 13px;
}
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 7px;
  background: #fff;
}

.leaderboard {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.leaderboard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.leaderboard-title {
  font-weight: 800;
  letter-spacing: -0.02em;
}
.tabs {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.tab {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}
.tab.active {
  border-color: #c7d2fe;
  background: #eef2ff;
}
.board {
  margin: 10px 0 0;
  padding-left: 18px;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.board li {
  padding: 8px 10px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}
.board li:last-child { border-bottom: 0; }
.board .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
.board .score { font-weight: 800; }

.submit-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
}
.input:focus {
  border-color: #c7d2fe;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { background: #f9fafb; }
.btn.primary {
  border-color: #c7d2fe;
  background: #eef2ff;
}
.btn.primary:hover { background: #e0e7ff; }

.net-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  min-height: 16px;
}

.footer {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding-bottom: 6px;
}

.mobile-controls {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: none;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  z-index: 60;
  pointer-events: none;
}
.mc-btn {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 12px 12px;
  text-align: left;
  box-shadow: 0 12px 30px rgba(17, 24, 39, 0.12);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.mc-btn.primary {
  background: linear-gradient(135deg, #c4f1f9, #a5b4fc);
  border-color: rgba(255, 255, 255, 0.8);
}
.mc-btn.ghost {
  background: rgba(255, 255, 255, 0.72);
}
.mc-title {
  font-weight: 900;
  display: block;
}
.mc-sub {
  color: rgba(17, 24, 39, 0.7);
  font-size: 12px;
  display: block;
  margin-top: 2px;
}

.cta-button {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #0b152a;
  text-decoration: none;
  background: linear-gradient(135deg, #c4f1f9, #a5b4fc);
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.25), 0 8px 20px rgba(14, 165, 233, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}
.cta-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(79, 70, 229, 0.3), 0 10px 24px rgba(14, 165, 233, 0.22);
  filter: saturate(1.05);
}
.cta-button:active {
  transform: translateY(0);
}
.cta-label {
  font-size: 14px;
}
.cta-arrow {
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(12, 23, 52, 0.08);
}
@media (max-width: 640px) {
  .cta-button {
    left: 12px;
    right: 12px;
    justify-content: center;
  }
  .mobile-controls {
    display: grid;
  }
  .wrap {
    padding-bottom: 96px; /* 모바일 컨트롤 공간 */
  }
}
