:root {
  --ink: #0b1530;
  --ink-2: #13224a;
  --glass: rgba(10, 20, 48, 0.62);
  --glass-2: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f2f6ff;
  --muted: #a9b7d6;
  --ice: #7fd8ff;
  --hot: #ff5a36;
  --hot-2: #ffb000;
  --good: #3ddc84;
  --bad: #ff4a5a;
  --radius: 16px;
  --display: 'Bebas Neue', Impact, 'Arial Narrow', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: 'Noto Sans KR', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas#c { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ── 공통 ─────────────────────────────────────── */
.logo {
  font-family: var(--display);
  font-size: clamp(56px, 9vw, 104px);
  line-height: 0.85;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 6px 30px rgba(0, 30, 90, 0.45);
}
.logo span {
  display: block;
  background: linear-gradient(90deg, var(--ice), #fff 60%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo.small { font-size: 54px; text-align: center; }
.logo.small span { display: inline; margin-left: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--glass-2);
  font-weight: 700;
  font-size: 15px;
  transition: transform 0.12s, background 0.2s, border-color 0.2s;
  backdrop-filter: blur(6px);
}
.btn:hover { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.35); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--hot), #ff7d2e);
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(255, 90, 54, 0.35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.big { padding: 16px 26px; font-size: 18px; }

.screen { position: fixed; inset: 0; z-index: 10; }
.screen-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.screen-head h2 { margin: 0; font-family: var(--display); font-size: 40px; letter-spacing: 1px; font-weight: 400; }

/* ── 로딩 ─────────────────────────────────────── */
.loading {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; gap: 22px; justify-items: center;
  background: radial-gradient(circle at 50% 30%, #1d3a7a, var(--ink) 70%);
}
.loading p { color: var(--muted); margin: 0; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--ice);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 메인 ─────────────────────────────────────── */
#screen-main {
  background: linear-gradient(90deg, rgba(6, 14, 36, 0.78) 0%, rgba(6, 14, 36, 0.35) 38%, transparent 60%);
  display: flex; align-items: center;
  padding: max(24px, env(safe-area-inset-top)) 6vw;
}
.main-panel { width: min(420px, 100%); display: flex; flex-direction: column; gap: 18px; }
.tagline { margin: -4px 0 6px; color: var(--muted); font-size: 16px; letter-spacing: 0.5px; }
.track-pill {
  display: grid; text-align: left; gap: 2px;
  padding: 14px 18px; border-radius: var(--radius);
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px);
}
.track-pill:hover { border-color: var(--ice); }
.pill-label { font-size: 12px; color: var(--muted); letter-spacing: 1px; }
.pill-name { font-size: 20px; font-weight: 900; }
.pill-best { font-size: 13px; color: var(--ice); }
.menu-buttons { display: grid; gap: 10px; }
.mode-toggle { display: grid; gap: 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); }
.seg button { padding: 9px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 700; }
.seg button.on { background: var(--ice); color: var(--ink); }
.mode-desc { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; min-height: 2.6em; }
.keys-title { margin: 6px 0 -4px; font-size: 15px; color: #fff; }
.keys-title span { font-size: 11px; font-weight: 700; color: var(--ink); background: var(--ice); border-radius: 99px; padding: 2px 8px; margin-left: 6px; vertical-align: 2px; }
.menu-buttons .btn { justify-content: flex-start; }

/* ── 트랙 선택 ────────────────────────────────── */
#screen-tracks {
  background: rgba(6, 14, 36, 0.72);
  backdrop-filter: blur(4px);
  padding: max(24px, env(safe-area-inset-top)) 5vw 24px;
  overflow-y: auto;
}
.track-list {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  max-width: 1200px; margin: 0 auto;
}
.track-card {
  display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden;
  border-radius: 20px; border: 2px solid var(--line); background: var(--glass);
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.track-card:hover { transform: translateY(-4px); }
.track-card.selected { border-color: var(--ice); box-shadow: 0 0 0 4px rgba(127, 216, 255, 0.2), 0 14px 40px rgba(0, 0, 0, 0.35); }
.tc-art {
  height: 130px; position: relative;
  background:
    linear-gradient(160deg, transparent 55%, rgba(255, 255, 255, 0.95) 55.5%),
    linear-gradient(200deg, transparent 62%, rgba(235, 243, 255, 0.92) 62.5%),
    linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
}
.tc-en {
  position: absolute; left: 16px; top: 12px;
  font-family: var(--display); font-size: 30px; letter-spacing: 1px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.tc-body { padding: 16px 18px 18px; display: grid; gap: 10px; }
.tc-title { display: flex; justify-content: space-between; align-items: center; }
.tc-title h3 { margin: 0; font-size: 20px; font-weight: 900; }
.tc-body p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; min-height: 66px; }
.diff { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; }
.diff.d1 { background: rgba(61, 220, 132, 0.2); color: var(--good); }
.diff.d2 { background: rgba(33, 166, 255, 0.2); color: #6cc4ff; }
.diff.d3 { background: rgba(20, 20, 20, 0.6); color: #fff; border: 1px solid #fff4; }
.tc-meta { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tc-meta li { display: grid; font-size: 11px; color: var(--muted); text-align: center; background: var(--glass-2); border-radius: 10px; padding: 8px 4px; }
.tc-meta b { font-size: 17px; color: var(--text); }
.tc-best { font-size: 13px; color: var(--hot-2); font-weight: 700; }
.track-actions { grid-column: 1 / -1; display: flex; justify-content: center; padding: 6px 0 20px; }

/* ── 꾸미기 ───────────────────────────────────── */
#screen-locker { pointer-events: none; }
.locker-panel {
  pointer-events: auto;
  position: absolute; left: 0; top: 0; bottom: 0;
  width: min(440px, 100%);
  padding: max(20px, env(safe-area-inset-top)) 22px 18px;
  background: linear-gradient(180deg, rgba(8, 18, 44, 0.9), rgba(8, 18, 44, 0.78));
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; background: var(--glass-2); border-radius: 12px; margin-bottom: 12px; }
.tab { padding: 10px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--muted); }
.tab.active { background: #fff; color: var(--ink); }
.locker-options { flex: 1; overflow-y: auto; display: grid; gap: 14px; align-content: start; padding-right: 4px; }
.opt-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; letter-spacing: 0.5px; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 8px; }
.swatch {
  aspect-ratio: 1; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.25); transition: transform 0.12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.on { border-color: #fff; box-shadow: 0 0 0 3px var(--ice), inset 0 -4px 8px rgba(0, 0, 0, 0.25); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--glass-2); font-size: 14px; font-weight: 500; }
.chip.on { background: var(--ice); color: var(--ink); border-color: var(--ice); font-weight: 700; }
.board-info { background: var(--glass-2); border-radius: 12px; padding: 12px 14px; display: grid; gap: 7px; margin-top: -4px; }
.board-info p { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.bar { display: grid; grid-template-columns: 70px 1fr; align-items: center; font-size: 12px; }
.bar i { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); position: relative; overflow: hidden; }
.bar i::after { content: ''; position: absolute; inset: 0; width: calc(var(--v) * 100%); background: linear-gradient(90deg, var(--ice), #fff); border-radius: inherit; }
.locker-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding-top: 14px; }
.locker-actions .primary { grid-column: 1 / -1; }
.drag-hint { position: absolute; right: 24px; bottom: 20px; margin: 0; color: rgba(255, 255, 255, 0.75); font-size: 13px; text-shadow: 0 1px 6px #0006; }

/* ── 모달 ─────────────────────────────────────── */
.modal { display: grid; place-items: center; background: rgba(4, 10, 28, 0.6); backdrop-filter: blur(6px); padding: 16px; }
.modal-card {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: linear-gradient(180deg, #14254f, #0d1a3a);
  border: 1px solid var(--line); border-radius: 22px; padding: 26px;
  display: grid; gap: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: pop 0.25s ease-out;
}
.modal-card.narrow { width: min(340px, 100%); }
.modal-card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 42px; letter-spacing: 1px; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; }
.keys th { text-align: left; white-space: nowrap; padding: 8px 12px 8px 0; color: var(--ice); font-weight: 700; }
.keys td { padding: 8px 0; color: var(--text); border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.keys tr th { border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.row .btn { flex: 1; }

.result-head .hud-label { color: var(--hot-2); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--glass-2); border-radius: 14px; padding: 12px; display: grid; gap: 2px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat b { font-size: 20px; font-weight: 900; word-break: keep-all; }
.stat em { font-style: normal; font-size: 11px; color: var(--hot-2); font-weight: 700; min-height: 14px; }
.res-best { margin: 0; color: var(--muted); font-size: 13px; }

/* ── HUD ──────────────────────────────────────── */
.hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.hud-label { font-size: 12px; font-weight: 700; letter-spacing: 2px; color: rgba(255, 255, 255, 0.7); }
.hud-big { font-family: var(--display); font-size: 40px; line-height: 1; letter-spacing: 1px; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.hud-tl, .hud-tr {
  position: absolute; top: max(16px, env(safe-area-inset-top));
  padding: 12px 16px; border-radius: 14px;
  background: rgba(8, 18, 44, 0.45); backdrop-filter: blur(6px);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.hud-tl { left: 16px; min-width: 150px; }
.hud-tr { right: 16px; text-align: right; display: grid; gap: 4px; justify-items: end; }
.speed { font-family: var(--display); font-size: 64px; line-height: 0.9; font-variant-numeric: tabular-nums; }
.unit { font-size: 13px; font-weight: 700; margin-left: 6px; color: rgba(255, 255, 255, 0.7); letter-spacing: 1px; }
.hud-small { font-size: 13px; font-weight: 700; color: var(--ice); }
.charge { width: 120px; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.charge div { height: 100%; width: 0; background: linear-gradient(90deg, var(--hot-2), var(--hot)); }
.combo { font-family: var(--display); font-size: 26px; color: var(--hot-2); min-height: 26px; letter-spacing: 1px; }
.hud-btn {
  pointer-events: auto; position: absolute; top: max(16px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(8, 18, 44, 0.45); font-size: 14px; letter-spacing: -2px;
}
.progress {
  position: absolute; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(460px, 60vw); height: 8px; border-radius: 99px; background: rgba(8, 18, 44, 0.45);
}
.progress div { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--ice), #fff); box-shadow: 0 0 12px var(--ice); }
.progress .flag { position: absolute; right: -26px; top: -9px; font-size: 18px; }

.trick {
  position: absolute; left: 50%; top: 24%; transform: translate(-50%, 0);
  text-align: center; opacity: 0; pointer-events: none;
}
.trick.show { animation: trick 2.2s ease-out forwards; }
.trick .tname { font-family: var(--display); font-size: clamp(38px, 6vw, 64px); letter-spacing: 2px; text-shadow: 0 4px 24px rgba(0, 40, 120, 0.6), 0 0 2px #000; }
.trick .tpts { font-family: var(--display); font-size: 32px; color: var(--hot-2); letter-spacing: 1px; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); }
.trick .tpts b { color: #fff; font-weight: 400; }
.trick .tperfect { font-size: 13px; font-weight: 900; letter-spacing: 3px; color: var(--good); }
@keyframes trick {
  0% { opacity: 0; transform: translate(-50%, 20px) scale(0.8); }
  10% { opacity: 1; transform: translate(-50%, 0) scale(1.06); }
  20% { transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(1); }
}
.msg {
  position: absolute; left: 50%; top: 40%; transform: translateX(-50%);
  padding: 10px 22px; border-radius: 99px; font-weight: 900; font-size: 20px;
  background: rgba(8, 18, 44, 0.6); opacity: 0; transition: opacity 0.2s; white-space: nowrap;
}
.msg.show { opacity: 1; }
.msg.bad { color: #fff; background: rgba(255, 74, 90, 0.75); }
.msg.good { color: var(--ink); background: var(--hot-2); font-family: var(--display); font-weight: 400; font-size: 40px; letter-spacing: 2px; }
.countdown {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-family: var(--display); font-size: 160px; opacity: 0; text-shadow: 0 8px 40px rgba(0, 30, 90, 0.6);
}
.countdown.show { animation: count 0.95s ease-out forwards; }
@keyframes count {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
}

/* ── 터치 ─────────────────────────────────────── */
.touch { display: none; }
body.touch-device .touch { display: block; }
body.touch-device .progress { bottom: auto; top: max(5px, env(safe-area-inset-top)); width: calc(100vw - 120px); height: 5px; }
body.touch-device .progress .flag { font-size: 13px; top: -6px; right: -20px; }
body.touch-device .hud-btn { top: calc(max(16px, env(safe-area-inset-top)) + 4px); }
.pad { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 12px; pointer-events: auto; }
.pad.left { left: 18px; }
.pad.right { right: 18px; display: grid; grid-template-columns: 64px 64px 92px; grid-template-rows: 64px 64px; gap: 10px; }
.pad button {
  width: 78px; height: 78px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(8, 18, 44, 0.42); font-size: 24px; font-weight: 900; touch-action: none;
}
.pad.right button { width: 64px; height: 64px; font-size: 14px; }
.pad.right [data-key='up'] { grid-column: 1; grid-row: 1; }
.pad.right [data-key='down'] { grid-column: 1; grid-row: 2; }
.pad.right [data-key='grab'] { grid-column: 2; grid-row: 2; }
.pad.right .jump { grid-column: 3; grid-row: 1 / 3; width: 92px; height: 92px; align-self: end; background: rgba(255, 90, 54, 0.55); }
.pad button.on { background: rgba(127, 216, 255, 0.5); border-color: #fff; }

.corner { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 20; display: flex; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: rgba(8, 18, 44, 0.5); backdrop-filter: blur(6px); font-size: 17px; }
body[data-screen='play'] .corner,
body[data-screen='locker'] .corner { display: none; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ink); margin: 0; }

/* ── 반응형 ───────────────────────────────────── */
@media (max-width: 820px) {
  #screen-main { background: linear-gradient(0deg, rgba(6, 14, 36, 0.85) 0%, rgba(6, 14, 36, 0.4) 55%, transparent 80%); align-items: flex-end; padding-bottom: 76px; }
  .main-panel { gap: 12px; }
  .locker-panel {
    top: auto; width: 100%; height: 58vh; border-right: 0; border-top: 1px solid var(--line);
    border-radius: 22px 22px 0 0; padding-top: 14px;
  }
  .locker-panel .screen-head { margin-bottom: 8px; }
  .locker-panel .screen-head h2 { font-size: 30px; }
  .drag-hint { top: 18px; bottom: auto; right: 16px; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
  .hud-big { font-size: 30px; }
  .speed { font-size: 46px; }
  .hud-tl { min-width: 0; padding: 10px 12px; }
  .msg.good { font-size: 30px; }
}
@media (max-width: 480px) {
  .pad.left { left: 10px; gap: 8px; }
  .pad.left button { width: 62px; height: 62px; }
  .pad.right { right: 10px; grid-template-columns: 52px 52px 74px; grid-template-rows: 52px 52px; gap: 8px; }
  .pad.right button { width: 52px; height: 52px; font-size: 12px; }
  .pad.right .jump { width: 74px; height: 74px; }
  .hud-tl, .hud-tr { top: calc(max(16px, env(safe-area-inset-top)) + 4px); }
  .hud-tl { left: 10px; }
  .hud-tr { right: 10px; }
  .hud-btn { width: 40px; height: 40px; }
  .countdown { font-size: 110px; }
}
@media (max-height: 520px) {
  .pad button { width: 64px; height: 64px; }
  .pad.right { grid-template-columns: 56px 56px 80px; grid-template-rows: 56px 56px; }
  .pad.right button { width: 56px; height: 56px; }
  .pad.right .jump { width: 80px; height: 80px; }
  .trick { top: 16%; }
}
