@import url('https://fonts.googleapis.com/css2?family=Jua&family=Gowun+Dodum&display=swap');

:root {
  --bg1: #1b1347; --bg2: #3a1c71;
  --card: #ffffff; --ink: #24203b; --muted: #6e6a86;
  --pink: #ff5fa2; --yellow: #ffd23f; --mint: #3ddc97; --sky: #4cc9f0; --purple: #7b5cff;
  --radius: 28px;
  --font-title: 'Jua', 'Gowun Dodum', 'Malgun Gothic', sans-serif;
  --font-body: 'Gowun Dodum', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { background: #1b1347; }
body {
  font-family: var(--font-body); color: var(--ink);
  background: radial-gradient(ellipse at 20% 10%, #5b2a9e 0%, transparent 55%),
              radial-gradient(ellipse at 90% 90%, #0e4d92 0%, transparent 50%),
              linear-gradient(160deg, var(--bg1), var(--bg2));
  overflow: hidden; user-select: none;
}
button { font-family: var(--font-title); cursor: pointer; border: 0; }

/* 배경 음표 */
#notes { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#notes span { position: absolute; bottom: -60px; font-size: 42px; opacity: .25; animation: float linear infinite; color: #fff; }
@keyframes float { to { transform: translateY(-115vh) rotate(25deg); } }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 56px; z-index: 1; }
.screen.active { display: flex; animation: pop .35s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }

h1, h2 { font-family: var(--font-title); font-weight: 400; color: #fff; text-align: center; margin: 0 0 16px; }
h1 { font-size: clamp(44px, 6vw, 92px); line-height: 1.15; text-shadow: 0 6px 0 rgba(0,0,0,.18); }
h2 { font-size: clamp(30px, 3.4vw, 54px); }
.sub { color: #e6defc; font-size: clamp(18px, 1.8vw, 28px); text-align: center; margin: 0 0 28px; }

.step { position: fixed; top: 22px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; z-index: 2; }
.step i { width: 46px; height: 10px; border-radius: 10px; background: rgba(255,255,255,.22); }
.step i.on { background: var(--yellow); }

.btn { font-size: clamp(24px, 2.4vw, 38px); padding: 20px 52px; border-radius: 999px; color: var(--ink);
  background: var(--yellow); box-shadow: 0 8px 0 #c99a00; transition: transform .08s; }
.btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #c99a00; }
.btn.ghost { background: rgba(255,255,255,.14); color: #fff; box-shadow: 0 8px 0 rgba(0,0,0,.2); }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 8px 0 #c2306f; }
.btn:disabled { opacity: .45; }
.nav { display: flex; gap: 24px; margin-top: 30px; }

/* 시작 화면 */
#welcome .big-note { font-size: 140px; animation: bounce 1.4s ease-in-out infinite; }
@keyframes bounce { 50% { transform: translateY(-24px) rotate(-8deg); } }
#welcome .btn { font-size: clamp(30px, 3vw, 48px); padding: 28px 80px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* 가사 쓰기 */
.panel { background: var(--card); border-radius: var(--radius); padding: 30px 36px; width: min(1200px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.row { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.row label { font-family: var(--font-title); font-size: 26px; white-space: nowrap; }
input.nick { flex: 1; min-width: 0; width: 100%; box-sizing: border-box; font: inherit; font-size: 28px; padding: 14px 20px; border: 3px solid #e3def5; border-radius: 18px; outline: none; }
textarea { width: 100%; box-sizing: border-box; display: block; height: 32vh; min-height: 200px; font: inherit; font-size: clamp(24px, 2.2vw, 34px); line-height: 1.6;
  padding: 20px 24px; border: 3px solid #e3def5; border-radius: 22px; resize: none; outline: none; }
input.nick:focus, textarea:focus { border-color: var(--purple); }
.counter { text-align: right; color: var(--muted); font-size: 20px; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.chip { font-size: 22px; padding: 10px 20px; border-radius: 999px; background: #f1edff; color: var(--purple); }
.err { color: #fff; background: #ff4d6d; border-radius: 16px; padding: 12px 22px; font-size: 22px; margin-top: 18px; display: none; }
.err.show { display: block; animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* 장르 카드 */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; width: min(1300px, 100%); }
.card { background: rgba(255,255,255,.95); border-radius: 26px; padding: 22px 10px; text-align: center; font-family: var(--font-title);
  font-size: clamp(22px, 2vw, 32px); border: 6px solid transparent; transition: transform .12s; }
.card .e { font-size: clamp(44px, 4.4vw, 70px); display: block; margin-bottom: 6px; }
.card.sel { border-color: var(--yellow); transform: scale(1.05); box-shadow: 0 0 0 6px rgba(255,210,63,.35); }
.voices { display: flex; gap: 18px; margin-top: 22px; }
.voices .card { padding: 14px 30px; display: flex; align-items: center; gap: 12px; }
.voices .card .e { font-size: 40px; margin: 0; }

/* 가사 비교 */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; width: min(1400px, 100%); }
.lyric-card { background: #fff; border-radius: var(--radius); padding: 22px 28px; border: 7px solid transparent; text-align: left;
  font-family: var(--font-body); max-height: 56vh; overflow: auto; }
.lyric-card.sel { border-color: var(--yellow); }
.lyric-card h3 { font-family: var(--font-title); font-weight: 400; font-size: 30px; margin: 0 0 4px; }
.lyric-card .tag { display: inline-block; font-family: var(--font-title); font-size: 18px; padding: 4px 14px; border-radius: 99px;
  background: #f1edff; color: var(--purple); margin-bottom: 10px; }
.lyric-card .sec { font-family: var(--font-title); color: var(--pink); font-size: 18px; margin-top: 10px; }
.lyric-card p { margin: 2px 0; font-size: clamp(19px, 1.6vw, 25px); line-height: 1.5; }
.loading { color: #fff; font-family: var(--font-title); font-size: 34px; text-align: center; }
.loading .pen { font-size: 90px; display: block; animation: write 1s ease-in-out infinite; }
@keyframes write { 50% { transform: translateX(30px) rotate(12deg); } }

/* 대기 화면 */
.eq { display: flex; gap: 12px; align-items: flex-end; height: 160px; margin: 20px 0 30px; }
.eq b { width: 30px; border-radius: 12px; background: linear-gradient(var(--pink), var(--yellow)); animation: eq 1s ease-in-out infinite; }
@keyframes eq { 0%,100% { height: 20%; } 50% { height: 100%; } }
.queue-badge { font-family: var(--font-title); font-size: 34px; color: var(--ink); background: var(--mint); border-radius: 999px; padding: 12px 36px; }
.fact { margin-top: 36px; background: rgba(255,255,255,.12); color: #fff; border-radius: 24px; padding: 22px 34px;
  font-size: clamp(22px, 2vw, 30px); max-width: 1100px; text-align: center; min-height: 100px; }
.fact b { color: var(--yellow); font-family: var(--font-title); font-weight: 400; display: block; margin-bottom: 4px; }

/* 결과 화면 */
.result { display: grid; grid-template-columns: 1.3fr 1fr; gap: 30px; width: min(1400px, 100%); align-items: stretch; }
.player { background: #fff; border-radius: var(--radius); padding: 28px 34px; display: flex; flex-direction: column; }
.player .title { font-family: var(--font-title); font-size: clamp(34px, 3.2vw, 52px); margin: 0; }
.player .by { color: var(--muted); font-size: 22px; margin-bottom: 14px; }
.play { width: 120px; height: 120px; border-radius: 50%; background: var(--pink); color: #fff; font-size: 54px; box-shadow: 0 8px 0 #c2306f; flex: none; }
.play:active { transform: translateY(6px); box-shadow: 0 2px 0 #c2306f; }
.ctrl { display: flex; align-items: center; gap: 24px; }
.bar { flex: 1; height: 16px; background: #eee9fb; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--purple), var(--pink)); }
.lyrics-view { margin-top: 18px; overflow: auto; max-height: 32vh; font-size: clamp(20px, 1.7vw, 26px); line-height: 1.55; }
.lyrics-view p { margin: 2px 0; }
.compare.single { grid-template-columns: 1fr; width: min(760px, 100%); }
.lyrics-view .sec { font-family: var(--font-title); color: var(--pink); font-size: 18px; margin-top: 8px; }
.qr-box { background: #fff; border-radius: var(--radius); padding: 26px; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.qr-box img { width: min(300px, 100%); aspect-ratio: 1; image-rendering: pixelated; }
.qr-box p { font-family: var(--font-title); font-size: 28px; margin: 12px 0 0; }
.qr-box small { color: var(--muted); font-size: 18px; }
.demo-note { margin-top: 10px; font-size: 16px; color: var(--muted); }

.mobile-only { display: none; }
.save-btns { display: none; flex-direction: column; gap: 14px; width: 100%; }
.save-btns .btn { text-align: center; text-decoration: none; display: block; }
.btn.ghost-dark { background: #f1edff; color: var(--purple); box-shadow: 0 6px 0 #d6cdfa; }

/* ===== 휴대폰·좁은 화면 ===== */
@media (max-width: 900px) {
  html, body { height: auto; }
  body { background-attachment: fixed; overflow-x: hidden; overflow-y: auto; min-height: 100dvh; }
  .screen { position: relative; inset: auto; min-height: 100dvh; padding: 64px 16px calc(24px + env(safe-area-inset-bottom));
    justify-content: flex-start; }
  .screen.active { display: flex; }
  #welcome { justify-content: center; }
  #welcome .big-note { font-size: 90px; }
  #welcome .btn { padding: 22px 48px; font-size: 28px; }
  h1 { font-size: 40px; } h2 { font-size: 27px; margin-bottom: 8px; }
  .sub { font-size: 17px; margin-bottom: 16px; }
  .step { top: 16px; } .step i { width: 34px; height: 8px; }

  .panel { padding: 18px 16px; border-radius: 22px; }
  .row { flex-direction: column; align-items: stretch; gap: 6px; }
  .row label { font-size: 19px; }
  input.nick { font-size: 19px; padding: 12px 14px; }
  textarea { font-size: 20px; height: 34vh; min-height: 170px; padding: 14px 16px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .chip { font-size: 17px; white-space: nowrap; flex: none; }

  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card { font-size: 19px; padding: 14px 6px; border-width: 4px; border-radius: 20px; }
  .card .e { font-size: 40px; }
  .voices { gap: 8px; width: 100%; margin-top: 14px; }
  .voices .card { flex: 1; flex-direction: column; padding: 10px 4px; gap: 2px; font-size: 16px; }
  .voices .card .e { font-size: 30px; }

  .compare, .result { grid-template-columns: 1fr; gap: 16px; }
  .lyric-card { max-height: none; padding: 16px 18px; border-width: 5px; }
  .lyric-card h3 { font-size: 24px; }

  .nav { position: sticky; bottom: 0; width: calc(100% + 32px); margin: 20px -16px 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, rgba(27,19,71,.95) 30%); gap: 12px; z-index: 3; }
  .nav .btn { flex: 1; font-size: 21px; padding: 16px 10px; }
  .nav .btn.ghost { flex: 0 0 auto; padding: 16px 18px; }

  .eq { height: 110px; } .eq b { width: 18px; }
  .queue-badge { font-size: 22px; padding: 10px 24px; text-align: center; }
  .fact { font-size: 18px; padding: 16px 18px; }

  .player { padding: 20px 18px; }
  .player .title { font-size: 28px; }
  .play { width: 84px; height: 84px; font-size: 38px; }
  .lyrics-view { max-height: none; }
  .qr-box { padding: 18px; }
  .qr-box img { width: 220px; }
  #gearBtn { width: 44px; height: 44px; font-size: 22px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
}

@media (max-width: 900px) {
  .step { position: absolute; }
  .save-btns .btn { font-size: 21px; padding: 16px 12px; white-space: nowrap; }
}
@media (max-width: 420px) {
  #result .nav .btn.ghost { padding: 14px 10px; }
  .nav .btn { font-size: 18px; padding: 14px 8px; white-space: nowrap; }
  .nav .btn.ghost { padding: 14px 12px; }
  h2 { font-size: 24px; }
  .player .title { font-size: 24px; }
  .save-btns .btn { font-size: 19px; }
}
.short { display: none; }
@media (max-width: 420px) { .long { display: none; } .short { display: inline; } }

/* 개인 폰으로 접속한 경우: QR 대신 저장·공유 버튼 */
body.mobile .kiosk-only { display: none; }
body.mobile .mobile-only, body.mobile .save-btns { display: flex; }

/* 관리자 톱니바퀴 (시작 화면에서만 보임) */
#gearBtn { position: fixed; right: 18px; bottom: 18px; z-index: 5; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,.12); font-size: 28px; opacity: .55; display: none; }
#gearBtn:active { opacity: 1; }
body.on-welcome #gearBtn { display: block; }

/* 서버 연결 끊김 안내 */
#offline { position: fixed; inset: 0; z-index: 9000; display: none; align-items: center; justify-content: center; text-align: center;
  background: rgba(20,14,50,.92); }
body.is-offline #offline { display: flex; }

body.via-internet #gearBtn { display: none !important; }
