@import url("https://fonts.googleapis.com/css2?family=Black+Han+Sans&family=Nunito:wght@600;800;900&display=swap");

:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #38bdf8;
  --accent-2: #fb7185;
  --accent-3: #22c55e;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.12);
  --mobile-controls-height: 104px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Nunito", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 520px at 50% -80px, #e0f2fe 0%, #fff7ed 60%, #f8fafc 100%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.55) 0 10px, rgba(255, 255, 255, 0) 10px 20px);
  position: relative;
  overflow-x: hidden;
}
body { -webkit-tap-highlight-color: transparent; }
body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(0px);
  opacity: 0.25;
}
body::before {
  top: -140px;
  left: -120px;
  background: radial-gradient(circle at 30% 30%, #38bdf8, transparent 60%);
}
body::after {
  bottom: -160px;
  right: -120px;
  background: radial-gradient(circle at 70% 70%, #fb7185, transparent 60%);
}

.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-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.title {
  font-family: "Black Han Sans", "Nunito", sans-serif;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-size: 20px;
}
.lang-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.lang-switch button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.08em;
}
.lang-switch button.active {
  background: #111827;
  color: #ffffff;
}
.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;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
.hud-item .label {
  color: var(--muted);
  font-size: 12px;
  margin-right: 8px;
}

.stage {
  position: relative;
  background: linear-gradient(180deg, #ecfeff 0%, #fff7ed 52%, #fde68a 100%);
  border: 1px solid rgba(148, 163, 184, 0.5);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
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.80), 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 rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  padding: 16px 16px 14px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  animation: floatIn 380ms ease-out;
}
.overlay-title {
  font-family: "Black Han Sans", "Nunito", sans-serif;
  font-weight: 900;
  letter-spacing: -0.03em;
  font-size: 20px;
}
.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.85);
  background: linear-gradient(135deg, #38bdf8, #fb7185);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  color: #0f172a;
  box-shadow: 0 16px 32px rgba(14, 165, 233, 0.2), 0 10px 26px rgba(251, 113, 133, 0.22);
  animation: pulseGlow 1.8s ease-in-out infinite;
}
.start-btn[disabled]{
  opacity: 0.6;
  cursor: not-allowed;
  animation: none;
  box-shadow: none;
}
.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;
}
.overlay-ad{
  margin-top: 12px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(226,232,240,0.9);
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
}
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: #f8fafc;
}

.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: #bae6fd;
  background: #e0f2fe;
}
.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: #bae6fd;
  background: #e0f2fe;
}
.btn.primary:hover { background: #bae6fd; }

.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;
  animation: fadeUp 420ms ease-out;
}
.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, #38bdf8, #fb7185);
  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, #fef08a, #fda4af);
  box-shadow: 0 10px 30px rgba(251, 113, 133, 0.25), 0 8px 20px rgba(253, 224, 71, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
  animation: floatIn 420ms ease-out;
}
.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);
}
@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes pulseGlow {
  0%, 100% {
    transform: translateY(0);
    filter: saturate(1);
  }
  50% {
    transform: translateY(-1px);
    filter: saturate(1.15);
  }
}
@media (max-width: 640px) {
  .cta-button {
    left: 12px;
    right: 12px;
    justify-content: center;
    bottom: calc(12px + var(--mobile-controls-height));
  }
  .mobile-controls {
    display: grid;
  }
  .wrap {
    padding-bottom: calc(var(--mobile-controls-height) + 120px);
  }
}
