:root {
  --ink: #1a1240; --cream: #fff3d6; --gold: #ffc62e; --pink: #ff5c8a; --cyan: #35d6f2;
  --l0: #ff6b8b; --l1: #ffc83d; --l2: #4cd9a0; --l3: #5aa9ff;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; color: #fff; font-family: 'Fredoka', 'Jua', system-ui, sans-serif; user-select: none; -webkit-user-select: none; touch-action: none; background: linear-gradient(180deg, #5b3fd0 0%, #3a2a9a 45%, #1d1456 100%); }
canvas { position: fixed; display: block; }
#c { inset: 0; width: 100%; height: 100%; z-index: 0; touch-action: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
i { display: inline-block; flex: none; }
.em { font-size: 1.15em; line-height: 1; }
.i-play { width: 0; height: 0; border-left: 22px solid currentColor; border-top: 14px solid transparent; border-bottom: 14px solid transparent; margin-left: 4px; }
.i-pause { width: 16px; height: 18px; border-left: 5px solid currentColor; border-right: 5px solid currentColor; }
.i-x { width: 18px; height: 18px; background: linear-gradient(45deg, transparent 42%, currentColor 42% 58%, transparent 58%), linear-gradient(-45deg, transparent 42%, currentColor 42% 58%, transparent 58%); }
.i-back { width: 16px; height: 16px; border-left: 5px solid currentColor; border-bottom: 5px solid currentColor; transform: rotate(45deg); margin-left: 6px; }
.i-out { width: 12px; height: 12px; border-top: 2.5px solid currentColor; border-right: 2.5px solid currentColor; margin-left: 4px; }
.i-grid { width: 20px; height: 20px; background: radial-gradient(circle, currentColor 2.4px, transparent 3px) 0 0 / 10px 10px; }

.big-btn { display: flex; align-items: center; justify-content: center; gap: 12px; min-width: 240px; height: 72px; padding: 0 34px; border-radius: 999px; font-size: 30px; font-weight: 700; color: #fff; background: linear-gradient(180deg, #ff8fb1, #ff4f86); box-shadow: 0 7px 0 #b42a5a, 0 14px 26px rgba(10,5,40,.45); text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 #b42a5a; }
.mid-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 56px; min-width: 56px; padding: 0 20px; border-radius: 18px; font-size: 20px; font-weight: 700; color: var(--ink); background: #fff; box-shadow: 0 5px 0 rgba(10,5,40,.3), 0 8px 18px rgba(10,5,40,.3); }
.mid-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(10,5,40,.3); }
.ic-btn { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 15px; color: var(--ink); background: rgba(255,255,255,.92); box-shadow: 0 4px 0 rgba(10,5,40,.25); }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; z-index: 10; }
.screen.dim { background: rgba(14, 8, 50, .6); justify-content: center; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.row { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.row.col { flex-direction: column; gap: 18px; }

/* 곡 목록 */
#songs { background: linear-gradient(180deg, #4b34b8, #20165e); justify-content: flex-start; padding-top: var(--safe-t); }
.songs-h { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.diffs { flex: 1; display: flex; gap: 8px; justify-content: center; }
.diffs button { height: 48px; padding: 0 10px; border-radius: 16px; background: rgba(255,255,255,.16); font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.diffs button.on { background: #fff; color: var(--ink); box-shadow: 0 4px 0 rgba(10,5,40,.3); }
.tot { display: flex; gap: 4px; align-items: center; font-size: 22px; font-weight: 700; min-width: 56px; justify-content: flex-end; }
#songList { width: 100%; max-width: 520px; flex: 1; overflow-y: auto; padding: 4px 14px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.song { display: flex; align-items: center; gap: 14px; min-height: 88px; padding: 10px 16px; border-radius: 24px; background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 55%, #20165e)); box-shadow: 0 6px 0 rgba(10,5,40,.35); text-align: left; width: 100%; }
.song:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(10,5,40,.35); }
.song .ic { font-size: 40px; width: 52px; text-align: center; }
.song .nm { flex: 1; min-width: 0; }
.song .nm b { display: block; font-size: 22px; line-height: 1.1; text-shadow: 0 2px 0 rgba(0,0,0,.25); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song .nm small { font-size: 15px; opacity: .85; }
.song .st { display: flex; gap: 2px; font-size: 24px; }
.song .st .o { opacity: .28; filter: grayscale(1); }
.song.lock { filter: grayscale(.85) brightness(.7); }
.song.lock .st { display: none; }
.song .lk { font-size: 30px; }

/* 게임 화면 */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud > * { pointer-events: auto; }
#btnPause { position: absolute; left: 12px; top: calc(12px + var(--safe-t)); width: 46px; height: 46px; }
#score { position: absolute; left: 0; right: 0; top: calc(12px + var(--safe-t)); text-align: center; font-size: 44px; font-weight: 700; text-shadow: 0 3px 0 rgba(10,5,40,.55), 0 0 14px rgba(10,5,40,.5); pointer-events: none; font-variant-numeric: tabular-nums; }
#hearts { position: absolute; right: 12px; top: calc(16px + var(--safe-t)); font-size: 24px; letter-spacing: 2px; pointer-events: none; }
#prog { position: absolute; left: 70px; right: 70px; top: calc(66px + var(--safe-t)); height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; pointer-events: none; }
#prog span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--l1), var(--l0)); }
#combo { position: absolute; left: 0; right: 0; top: min(calc(80% + 90px), calc(100% - 78px)); display: flex; justify-content: center; align-items: baseline; gap: 10px; text-align: center; pointer-events: none; opacity: 0; transition: opacity .15s; }
#combo.on { opacity: .8; }
#combo b { font-size: 46px; font-weight: 700; display: block; line-height: 1; color: #fff; text-shadow: 0 4px 0 var(--ink), 0 0 20px rgba(255,255,255,.6); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
#combo small { font-size: 18px; letter-spacing: 3px; font-weight: 700; text-shadow: 0 2px 0 var(--ink); }
#combo.pop b { animation: cpop .16s ease-out; }
@keyframes cpop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
#mood { position: fixed; z-index: 4; left: 50%; font-size: 40px; transform: translate(48px, 0); pointer-events: none; transition: top .2s; filter: drop-shadow(0 3px 4px rgba(10,5,40,.4)); }

/* 자유 연주 */
#free { background: transparent; justify-content: flex-start; z-index: 8; pointer-events: none; padding-top: var(--safe-t); }
#free > * { pointer-events: auto; }
.free-h { width: 100%; display: flex; gap: 10px; align-items: center; padding: 12px 14px; }
.inst { flex: 1; display: flex; gap: 8px; justify-content: center; }
.inst button { width: 56px; height: 52px; border-radius: 16px; background: rgba(255,255,255,.18); font-size: 28px; }
.inst button.on { background: #fff; box-shadow: 0 4px 0 rgba(10,5,40,.3); }
#keys { position: absolute; left: 0; right: 0; bottom: 0; top: 60%; display: flex; gap: 4px; padding: 0 6px calc(8px + var(--safe-b)); touch-action: none; }
#keys .key { flex: 1; border-radius: 16px 16px 24px 24px; background: linear-gradient(180deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c)); box-shadow: 0 8px 0 rgba(10,5,40,.35); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 14px; font-size: 26px; transition: transform .05s; pointer-events: none; }
#keys .key.on { transform: translateY(8px); box-shadow: 0 0 0 rgba(10,5,40,.35); filter: brightness(1.25); }

/* 설정 */
.sheet { width: min(92vw, 420px); background: #fff; color: var(--ink); border-radius: 28px; padding: 18px 20px 24px; display: flex; flex-direction: column; gap: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.4); }
.sheet-h { display: flex; justify-content: space-between; align-items: center; font-size: 24px; font-weight: 700; }
.sheet .ic-btn { background: #eee; box-shadow: 0 4px 0 rgba(0,0,0,.12); }
.slider { display: flex; align-items: center; gap: 12px; font-size: 30px; }
.slider input { flex: 1; height: 44px; accent-color: var(--pink); touch-action: pan-x; }
.calrow { display: flex; align-items: center; gap: 8px; font-size: 24px; font-weight: 700; }
.calrow .mid-btn { background: var(--ink); color: #fff; box-shadow: 0 5px 0 rgba(0,0,0,.25); }
.calrow small { font-size: 14px; opacity: .6; margin-left: -4px; }
.calrow .lat { margin-left: auto; font-size: 18px; opacity: .75; }
#calib { z-index: 20; }
.calx { position: absolute; right: 14px; top: calc(14px + var(--safe-t)); }
#calDots { display: flex; gap: 14px; margin-bottom: 30px; }
#calDots i { width: 26px; height: 26px; border-radius: 50%; background: rgba(255,255,255,.25); }
#calDots i.on { background: var(--gold); box-shadow: 0 0 14px var(--gold); }
#calPad { width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ff9ec0, #ff3f7f); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 56px; box-shadow: 0 10px 0 #a3194f, 0 0 0 0 rgba(255,255,255,.6); }
#calPad.beat { animation: beat .25s ease-out; }
@keyframes beat { 0% { box-shadow: 0 10px 0 #a3194f, 0 0 0 0 rgba(255,255,255,.8); } 100% { box-shadow: 0 10px 0 #a3194f, 0 0 0 50px rgba(255,255,255,0); } }
#calPad b { font-size: 34px; }
#calRes { margin-top: 26px; font-size: 46px; font-weight: 700; min-height: 56px; }
#toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); background: rgba(10,5,40,.8); padding: 10px 18px; border-radius: 14px; font-size: 18px; z-index: 40; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.on { opacity: 1; }
#nogl { display: none; }

#pops { position: fixed; inset: 0; z-index: 6; pointer-events: none; overflow: hidden; }
.fxpop { position: absolute; transform: translate(-50%, -50%); font-weight: 700; white-space: nowrap; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; animation: popUp .85s ease-out forwards; }
@keyframes popUp { 0% { transform: translate(-50%, -30%) scale(.4); opacity: 0; } 15% { transform: translate(-50%, -60%) scale(1.25); opacity: 1; } 100% { transform: translate(-50%, -150%) scale(1); opacity: 0; } }
#cut { position: fixed; left: 0; right: 0; top: 30%; z-index: 7; text-align: center; font-size: 96px; font-weight: 700; color: #ffe45e; -webkit-text-stroke: 12px var(--ink); paint-order: stroke fill; pointer-events: none; opacity: 0; transform: rotate(-7deg); }
#cut::before { content: ''; position: fixed; left: 0; right: 0; top: 18%; height: 40%; background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255,255,255,.55) 0 4deg, transparent 4deg 15deg); mask: radial-gradient(circle, transparent 22%, #000 70%); -webkit-mask: radial-gradient(circle, transparent 22%, #000 70%); z-index: -1; }
#cut.on { animation: cutIn .9s ease-out; }
@keyframes cutIn { 0% { opacity: 0; transform: rotate(-7deg) scale(.3); } 15% { opacity: 1; transform: rotate(-7deg) scale(1.25); } 30% { transform: rotate(-7deg) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

