/* Balltris — 밤하늘 남색 바탕 + 사탕색 공 */
:root {
  --bg: #14163A;
  --bg-2: #1B1E4B;
  --panel: #23275C;
  --panel-2: #2C3170;
  --line: rgba(255, 255, 255, 0.1);
  --ink: #F4F5FF;
  --ink-soft: #A9ADD6;
  --sun: #FFC83D;
  --pink: #FF6FA5;
  --cyan: #3FD3FF;
  --grape: #A77BFF;
  --red: #FF5D6C;
  --radius: 18px;
  --font: 'Fredoka', 'Jua', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-ko: 'Jua', 'Fredoka', system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #262A6B 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
html[lang="ko"] body { font-family: var(--font-ko); }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── 공통 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 24px; border-radius: 999px; border: 0;
  font-size: 18px; font-weight: 600; text-decoration: none;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--sun); color: #2A1E00; box-shadow: 0 5px 0 #C9921A; }
.btn-ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); }

/* ── 홈 ── */
.home {
  max-width: 480px; margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.home-hero { text-align: center; padding-top: 12px; }
.logo-mark { width: 120px; height: 72px; animation: hop 2.4s ease-in-out infinite; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14px); }
  55% { transform: translateY(0) scale(1.06, .92); }
  65% { transform: translateY(-5px); }
}
.logo {
  margin: 4px 0 0; font-family: 'Fredoka', sans-serif; font-size: 48px; font-weight: 700; letter-spacing: -1px;
}
.logo span { color: var(--sun); }
.tagline { margin: 4px 0 0; color: var(--ink-soft); font-size: 16px; }

.btn-play {
  min-height: 64px; font-size: 24px; background: var(--sun); color: #2A1E00;
  box-shadow: 0 6px 0 #C9921A, 0 12px 30px rgba(255, 200, 61, .25);
}
.btn-play-icon { font-size: 18px; }
.best-line { margin: -6px 0 0; text-align: center; color: var(--ink-soft); }
.best-line strong { color: var(--ink); font-family: 'Fredoka', sans-serif; font-size: 20px; margin-left: 4px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; color: var(--ink-soft); font-weight: 600; }

.ball-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ball-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px;
  background: var(--bg-2); border: 2px solid transparent; border-radius: 14px; text-align: center;
}
.ball-card strong { font-size: 16px; }
.ball-card small { color: var(--ink-soft); font-size: 12.5px; }
.ball-card.is-on { border-color: var(--sun); background: #2A2E66; }
.ball-card.is-locked { opacity: .45; cursor: default; }
.ball-swatch {
  width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 12%, var(--c) 45%, color-mix(in srgb, var(--c) 60%, #000) 100%);
}
.ball-swatch--basic { --c: #F07A22; }
.ball-swatch--bouncy { --c: #FF6FA5; }
.ball-swatch--heavy { --c: #8C90B8; }
.ball-swatch--feather { --c: #4CD98A; }

.skin-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.skin-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px;
  background: var(--bg-2); border: 2px solid transparent; border-radius: 14px;
}
.skin-card strong { font-size: 15px; }
.skin-card.is-on { border-color: var(--sun); background: #2A2E66; }
.skin-preview { width: 48px; height: 48px; }

.howto { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.howto li { display: flex; gap: 10px; align-items: flex-start; line-height: 1.45; font-size: 15px; }
.howto-ico { flex: none; font-size: 18px; line-height: 1.3; }
.hint { margin: 12px 0 0; color: var(--ink-soft); font-size: 13.5px; line-height: 1.45; }
.hint--keys { margin-top: 6px; }
@media (hover: none) { .hint--keys { display: none; } }

.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 48px; border-top: 1px solid var(--line);
}
.card h2 + .setting { border-top: 0; }
.segmented { display: inline-flex; background: var(--bg-2); border-radius: 999px; padding: 3px; }
.segmented button, .segmented a {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 999px;
  font-size: 14px; color: var(--ink-soft); text-decoration: none;
}
.segmented .is-on { background: var(--panel-2); color: var(--ink); }

.switch {
  appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 999px;
  background: var(--bg-2); position: relative; cursor: pointer; transition: background .15s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--ink-soft); transition: transform .15s, background .15s;
}
.switch:checked { background: var(--grape); }
.switch:checked::after { transform: translateX(20px); background: #fff; }

.home-foot { text-align: center; font-size: 13px; color: var(--ink-soft); }

/* ── 게임 화면 ── */
body.is-game { overflow: hidden; overscroll-behavior: none; }
.game {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: calc(8px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

.hud { display: flex; align-items: center; gap: 6px; max-width: 520px; width: 100%; margin: 0 auto; }
.icon-btn {
  flex: none; width: 42px; height: 42px; border-radius: 12px; border: 0;
  background: var(--panel); display: grid; place-items: center;
}
.icon-btn svg { fill: var(--ink); }
.hud-chip {
  flex: 1 1 0; min-width: 0; background: var(--panel); border-radius: 12px; padding: 4px 8px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.1;
}
.hud-chip--score { flex-grow: 1.8; }
.hud-chip small, .hud-next small { font-size: 11px; color: var(--ink-soft); }
.hud-chip strong { font-family: 'Fredoka', sans-serif; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hud-next {
  flex: none; background: var(--panel); border-radius: 12px; padding: 3px 6px;
  display: flex; flex-direction: column; align-items: center; line-height: 1;
}
#nextCanvas { width: 58px; height: 32px; display: block; }

.stage {
  flex: 1 1 auto; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  margin: 8px 0;
}
#board {
  display: block; border-radius: 12px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .06), 0 18px 40px rgba(0, 0, 0, .35);
}

.popups {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.popup {
  font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 26px; color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .35); animation: pop 1.1s ease-out forwards;
  max-width: 94%; text-align: center; white-space: pre-line; line-height: 1.1;
}
.popup--points { color: var(--sun); }
.popup--bounce { color: var(--cyan); font-size: 30px; }
.popup--combo { color: var(--pink); }
.popup--big { color: var(--sun); font-size: clamp(28px, 9vw, 40px); }
.popup--level { color: var(--grape); font-size: 34px; }
.popup--goal { color: #fff; font-size: 32px; text-shadow: 0 0 14px rgba(255, 200, 61, .9), 0 3px 0 rgba(0, 0, 0, .35); }
.popup--fire { font-size: 32px; color: #FF7A59; text-shadow: 0 0 16px rgba(255, 93, 108, .9), 0 3px 0 rgba(0, 0, 0, .35); }

/* 점수·레벨이 바뀔 때 톡 튀는 효과 */
.is-bump { display: inline-block; animation: bump .28s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); } }

/* 튜토리얼 안내 카드 */
.coach {
  flex: none; position: relative; z-index: 5; margin: 6px auto 0;
  width: min(100%, 420px); padding: 10px 14px 8px; border-radius: 16px;
  background: rgba(20, 22, 58, .92); border: 2px solid var(--sun);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); text-align: center;
}
.coach.is-pop { animation: coachIn .35s ease-out; }
@keyframes coachIn { 0% { transform: translateY(-8px); opacity: 0; } 100% { transform: none; opacity: 1; } }
.coach-step {
  display: inline-block; font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 13px;
  color: #2A1E00; background: var(--sun); border-radius: 999px; padding: 1px 10px;
}
.coach-text { margin: 6px 0 2px; font-size: 15px; line-height: 1.4; }
.coach-skip { background: none; border: 0; color: var(--ink-soft); font-size: 13px; text-decoration: underline; padding: 4px 8px; }
.coach-go { margin-top: 4px; min-height: 44px; padding: 0 22px; }
.coach.is-done { border-color: var(--cyan); }
.is-tutorial .hud-chip--score { opacity: .4; }

.tut-link { display: block; text-align: center; margin: -6px 0 18px; color: var(--cyan); font-size: 14.5px; }
@keyframes pop {
  0% { transform: scale(.4); opacity: 0; }
  18% { transform: scale(1.15); opacity: 1; }
  30% { transform: scale(1); }
  75% { opacity: 1; transform: translateY(-12px); }
  100% { opacity: 0; transform: translateY(-36px); }
}

/* 아래 조작부: 기울기 모드 = 회전 · 기울기 표시 · 내려찍기 / 버튼 모드 = ◀ 회전 내려찍기 ▶ */
.dock {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 10px;
  max-width: 520px; width: 100%; margin: 0 auto;
}
.pad-btn {
  flex: none; width: 64px; height: 56px; border-radius: 16px; border: 0;
  background: var(--panel); font-size: 24px; box-shadow: 0 4px 0 #15184A;
  touch-action: none;
}
.pad-btn:active, .pad-btn.is-down { transform: translateY(3px); box-shadow: 0 1px 0 #15184A; background: var(--panel-2); }
.pad-btn--move { flex: 1 1 0; max-width: 110px; }
.is-tilt .pad-btn--move { display: none; }
.is-touch .tilt-meter { display: none; }

.tilt-meter {
  flex: 1 1 auto; max-width: 260px; height: 14px; border-radius: 999px; position: relative;
  background: linear-gradient(90deg, rgba(63, 211, 255, .35), rgba(255, 255, 255, .06) 45% 55%, rgba(255, 111, 165, .35));
}
.tilt-meter::after {
  content: ''; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 2px; margin-left: -1px;
  background: rgba(255, 255, 255, .3);
}
/* 튕긴 블록 → 지금 기울이면 굴러감 */
.tilt-meter { transition: box-shadow .15s, opacity .15s; opacity: .55; }
.can-roll .tilt-meter { opacity: 1; box-shadow: 0 0 0 2px var(--sun), 0 0 16px rgba(255, 200, 61, .45); }
.tilt-dot {
  position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 15%, var(--sun) 50%, #C9921A 100%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

/* ── 오버레이 ── */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px 16px;
}
.overlay--dim { background: rgba(10, 11, 34, .72); backdrop-filter: blur(3px); }
#startOverlay { background: rgba(10, 11, 34, .45); }
.start-btn {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: transparent; border: 0; font-size: 22px; font-weight: 600;
}
.start-play {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  font-size: 34px; padding-left: 6px; color: #2A1E00;
  background: radial-gradient(circle at 35% 30%, #fff 0 10%, var(--sun) 45%, #C9921A 100%);
  box-shadow: 0 10px 30px rgba(255, 200, 61, .35); animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.07); } }
.overlay-hint { margin: 0; color: var(--ink-soft); text-align: center; max-width: 300px; line-height: 1.45; }
.is-touch .overlay-hint { visibility: hidden; }

.countdown {
  font-family: 'Fredoka', sans-serif; font-size: 120px; font-weight: 700; color: var(--sun);
  text-shadow: 0 6px 0 rgba(0, 0, 0, .3); animation: count .55s ease-out;
}
@keyframes count { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.sheet {
  width: 100%; max-width: 340px; background: var(--panel); border-radius: 24px; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.sheet h2 { margin: 0 0 4px; font-size: 26px; }
.result-score { font-family: 'Fredoka', sans-serif; font-size: 52px; font-weight: 700; color: var(--sun); line-height: 1; }
.new-best { margin: 0; color: var(--pink); font-weight: 600; animation: pulse 1s ease-in-out infinite; }
.result-stats { margin: 4px 0; display: grid; gap: 2px; }
.result-stats div { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.result-stats dt { color: var(--ink-soft); }
.result-stats dd { margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 600; }
.result-row { display: flex; gap: 10px; }
.result-row .btn { flex: 1; padding: 0 12px; }

/* ── 토스트 ── */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%); max-width: calc(100% - 32px); width: max-content;
  background: #0C0D26; color: var(--ink); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 14px; font-size: 14px; text-align: center;
  animation: toastIn .25s ease-out;
}
.toast.is-out { opacity: 0; transition: opacity .3s; }
@keyframes toastIn { from { transform: translate(-50%, 10px); opacity: 0; } }

/* ── 문서 · 오류 ── */
.page { max-width: 640px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top)) 16px 40px; }
.page--center { min-height: 100dvh; display: flex; align-items: center; justify-content: center; }
.error-code { margin: 0; font-family: 'Fredoka', sans-serif; font-size: 56px; color: var(--sun); }
.doc { line-height: 1.6; font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif; }
.doc h1 { font-size: 26px; }
.doc h2 { font-size: 18px; margin-top: 28px; }
.doc p { color: var(--ink-soft); }
.back-link { color: var(--ink-soft); text-decoration: none; }

@media (prefers-reduced-motion: reduce) {
  .logo-mark, .start-play, .new-best { animation: none; }
}
