:root {
  --ink: #4a3a35;
  --ink2: #7b6a62;
  --bg: #dff3e4;
  --cream: #fffaf0;
  --pink: #ff8fb4;
  --pink-soft: #ffe3ec;
  --blue: #7fbef5;
  --blue-soft: #e2f1ff;
  --yellow: #ffd45e;
  --yellow-soft: #fff4cc;
  --lilac: #b79cf2;
  --lilac-soft: #f0e8ff;
  --line: #e9dccf;
  --font: "Jua", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #cfe9d6 radial-gradient(circle at 20% 20%, #e8f7ec 0 40%, transparent 41%) 0 0 / 46px 46px;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: min(100vw, calc(100dvh * 9 / 16));
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 0 0 1px #bcd9c3, 0 10px 40px rgba(60, 90, 70, .18);
}
@supports not (height: 100dvh) { #app { width: min(100vw, calc(100vh * 9 / 16)); } }
/* 세로 폰(사파리 툴바로 9:16 보다 길쭉하지 않은 화면 포함)은 가로를 꽉 채운다. 9:16 기둥은 넓은 화면에서만 */
@media (max-aspect-ratio: 3/4) { #app { width: 100vw; } }
body.playing, body.playing #app { touch-action: none; }
/* 가로로 눕힌 폰: 9:16 기둥이 200px 남짓이라 글자·게이지가 찌그러진다. 세로로 돌려 달라고 덮는다(게임 중이면 일시정지) */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  #rotate { display: flex; position: fixed; inset: 0; z-index: 50; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    background: var(--bg); color: var(--ink); text-align: center; padding: 16px; }
  #rotate .ph { width: 34px; height: 58px; border: 4px solid var(--ink); border-radius: 9px; margin-bottom: 8px; box-shadow: inset 0 -8px 0 -4px var(--ink); }
  #rotate p { margin: 0; font-size: 24px; }
  #rotate small { font-size: 15px; color: var(--ink2); }
  #app { visibility: hidden; }
}
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#probe { position: absolute; visibility: hidden; pointer-events: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.hidden { display: none !important; }
button { font-family: var(--font); color: var(--ink); cursor: pointer; touch-action: manipulation; border: 0; }

#pauseBtn {
  position: absolute; z-index: 5;
  top: calc(env(safe-area-inset-top) + 14px); right: 10px;
  width: 44px; height: 44px; border-radius: 14px;
  background: #fff; border: 3px solid var(--ink); font-size: 15px; letter-spacing: -1px;
  box-shadow: 0 3px 0 var(--ink);
}

.screen {
  position: absolute; inset: 0; z-index: 10;
  overflow-y: auto; overscroll-behavior: contain;
  background: linear-gradient(180deg, #dff3e4 0%, #fdf6e7 70%, #ffe9f0 100%);
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 18px);
}
.screen.dim { background: rgba(74, 58, 53, .55); display: grid; place-items: center; }
.inner { max-width: 440px; margin: 0 auto; display: flex; flex-direction: column; align-items: stretch; gap: 12px; }

.badge {
  align-self: center; margin: 0; padding: 5px 12px; border-radius: 999px;
  background: #fff; border: 2px solid var(--line); font-size: 13px; color: var(--ink2);
}
.logo { margin: 2px 0 0; display: flex; flex-direction: column; align-items: center; line-height: 1; font-weight: 400; }
.logo .l1 { font-size: 46px; color: #fff; -webkit-text-stroke: 7px var(--ink); paint-order: stroke fill; letter-spacing: 2px; text-shadow: 0 5px 0 var(--ink); }
.logo .l2 {
  margin-top: -6px; font-size: 40px; color: var(--ink); background: var(--yellow);
  padding: 4px 16px 2px; border: 3px solid var(--ink); border-radius: 16px; transform: rotate(-5deg);
  box-shadow: 0 4px 0 var(--ink);
}
.logo .l3 { margin-top: 8px; font-size: 26px; color: var(--pink); -webkit-text-stroke: 5px #fff; paint-order: stroke fill; }

.hero { position: relative; height: 150px; display: flex; justify-content: center; align-items: flex-end; }
.hero::before { content: ""; position: absolute; bottom: 0; left: 50%; width: 220px; height: 26px; transform: translateX(-50%); background: #ffc9da; border: 3px solid var(--ink); border-radius: 50%; }
.hero-rapper { position: relative; height: 150px; transform-origin: 50% 100%; animation: bop .571s ease-in-out infinite alternate; }
.hero-prop { position: absolute; bottom: 14px; height: 52px; }
.hero-prop.left { left: calc(50% - 150px); transform: rotate(-8deg); }
.hero-prop.right { right: calc(50% - 150px); bottom: 70px; height: 40px; animation: floaty 1.14s ease-in-out infinite alternate; }

.gone { display: none !important; }
/* 곡 고르기 */
.songs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.songs button {
  display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 10px 7px; border-radius: 18px;
  background: #fff; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); min-width: 0;
}
.songs img { width: 40px; height: 40px; flex: none; border-radius: 50%; background: #fff; border: 2px solid var(--ink); object-fit: cover; }
.songs span { min-width: 0; display: flex; flex-direction: column; }
.songs b { font-size: 17px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.songs small { font-size: 11px; color: var(--ink2); line-height: 1.3; }
.songs button[aria-checked="true"] { background: var(--yellow); transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
body[data-song="keroro"] .songs button[aria-checked="true"] { background: #b9ec9c; }
body[data-song="keroro"] .logo .l2 { background: #9fe37f; }
body[data-song="keroro"] .logo .l3 { color: #3aa85c; }
body[data-song="keroro"] .hero::before { background: #bfeaa6; }
body[data-song="keroro"] .big { background: #4cc36f; }
/* 리더 고르기: 세카이식 캐릭터 카드 */
.leader .h { margin: 0 0 8px; font-size: 17px; }
.leader .h small { font-size: 12px; color: var(--ink2); }
.crew { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.crew button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px 5px;
  border-radius: 14px; background: #fff; border: 2px solid var(--line); min-width: 0;
}
.crew img { height: 52px; max-width: 100%; object-fit: contain; animation: hop .571s ease-in-out infinite alternate; animation-delay: var(--d); transform-origin: 50% 100%; }
.crew .fb { display: none; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--ink); color: #fff; font-size: 22px; place-items: center; margin: 3px 0; }
.crew img.gone + .fb { display: grid; }
.crew b { font-size: 14px; font-weight: 400; }
.crew small { font-size: 10px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.crew button[aria-checked="true"] { background: var(--lc); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); }
.crew button[aria-checked="true"]::after {
  content: "리더"; position: absolute; top: -8px; right: -4px; font-size: 10px; padding: 1px 6px; border-radius: 999px;
  background: var(--yellow); border: 2px solid var(--ink);
}
.skill-desc { margin: 8px 0 0; font-size: 13px; color: var(--ink2); text-align: center; }
.skill-desc b { font-weight: 400; color: var(--ink); }

.card { background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 12px 14px; box-shadow: 0 4px 0 var(--ink); }

.diffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.diffs button {
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 9px 4px 7px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; box-shadow: 0 4px 0 var(--ink);
}
.diffs button b { font-size: 20px; font-weight: 400; }
.diffs button small { font-size: 11px; color: var(--ink2); line-height: 1.3; text-align: center; }
.diffs button[aria-checked="true"][data-diff="easy"] { background: #c9f0d2; }
.diffs button[aria-checked="true"][data-diff="normal"] { background: var(--yellow); }
.diffs button[aria-checked="true"][data-diff="hard"] { background: var(--pink); color: #fff; }
.diffs button[aria-checked="true"][data-diff="hard"] small { color: #fff; }
.diffs button[aria-checked="true"] { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.diffs.small button { padding: 7px 4px 5px; }
.diffs.small button b { font-size: 16px; }

.big {
  font-size: 26px; padding: 14px 10px 12px; border-radius: 20px; background: var(--pink); color: #fff;
  border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; letter-spacing: 1px;
}
.big:active, .ghost:active, .diffs button:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.big[disabled] { filter: saturate(.4); }
.ghost { font-size: 17px; padding: 11px 8px 9px; border-radius: 16px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.how .h { margin: 0 0 6px; font-size: 17px; }
.how ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.7; color: var(--ink2); }
.how .fever { color: var(--pink); font-weight: 400; }
.keys { display: inline-flex; gap: 3px; vertical-align: 1px; }
kbd { font-family: var(--font); font-size: 12px; min-width: 20px; padding: 1px 5px; border: 2px solid var(--ink); border-bottom-width: 3px; border-radius: 6px; background: #fff; color: var(--ink); text-align: center; }

.settings { display: flex; flex-direction: column; gap: 8px; }
.settings .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 15px; }
.settings small { color: var(--ink2); font-size: 12px; }
.settings output { font-size: 15px; min-width: 56px; text-align: right; white-space: nowrap; }
.speed-row { display: flex; gap: 8px; align-items: center; }
.mini { flex: none; font-size: 13px; padding: 4px 10px 3px; border-radius: 10px; background: #fff; border: 2px solid var(--ink); }
.settings .check { justify-content: flex-start; }
.settings input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--pink); }
input[type=range] { width: 100%; accent-color: var(--pink); touch-action: pan-x; }

.legal { margin: 2px 0 6px; text-align: center; font-size: 12px; color: var(--ink2); }

.sheet { width: min(86%, 340px); background: var(--cream); border: 3px solid var(--ink); border-radius: 24px; padding: 18px 16px 16px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 6px 0 var(--ink); text-align: center; }
.sheet-img { height: 96px; align-self: center; }
.sheet-title { margin: 0; font-size: 24px; }

/* result */
.r-top { position: relative; display: flex; justify-content: center; align-items: flex-end; height: 190px; }
.r-top img { height: 180px; transform-origin: 50% 100%; animation: bop .571s ease-in-out infinite alternate; }
.rank {
  position: absolute; left: 6%; top: 6px; width: 104px; height: 104px; border-radius: 30px;
  display: grid; place-items: center; font-size: 76px; line-height: 1; padding-top: 6px;
  background: var(--yellow); border: 4px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  transform: rotate(-10deg); animation: stamp .5s cubic-bezier(.3, 1.6, .5, 1) both;
}
.rank.S { background: linear-gradient(135deg, #ffd45e, #ff9fc2); color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.rank.A { background: var(--pink); color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.rank.B { background: var(--blue); color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.rank.C { background: #c9f0d2; }
.rank.D { background: #e8e2dc; }
.r-line { margin: 0; text-align: center; font-size: 20px; background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 8px 12px 6px; position: relative; }
.r-line::before { content: ""; position: absolute; top: -10px; left: 50%; width: 16px; height: 16px; background: #fff; border-left: 3px solid var(--ink); border-top: 3px solid var(--ink); transform: translateX(-50%) rotate(45deg); }
.r-score { margin: 4px 0 0; text-align: center; font-size: 46px; line-height: 1; }
.r-score em { font-style: normal; font-size: 16px; vertical-align: 22px; background: var(--pink); color: #fff; padding: 3px 8px 1px; border-radius: 10px; border: 2px solid var(--ink); }
.r-fc { margin: 0 auto -4px; font-size: 18px; padding: 2px 14px 0; border-radius: 999px; background: linear-gradient(90deg, #ffd45e, #ff9fc2); border: 2px solid var(--ink); }
.r-bonus { margin: -2px 0 0; text-align: center; font-size: 13px; color: #b97a00; }
.r-best { margin: 0; text-align: center; font-size: 14px; color: var(--ink2); }
.r-best b { font-weight: 400; color: var(--ink); }
.r-counts { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.r-counts li { background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 2px 4px; text-align: center; }
.r-counts span { display: block; font-size: 11px; }
.r-counts b { font-weight: 400; font-size: 22px; }
.r-counts .p { background: var(--pink-soft); } .r-counts .g { background: var(--blue-soft); }
.r-counts .o { background: #e3f6e8; } .r-counts .m { background: #f1ece8; }
.r-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.r-stats div { background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px 4px; display: flex; justify-content: space-between; align-items: baseline; }
.r-stats span { font-size: 14px; color: var(--ink2); }
.r-stats b { font-weight: 400; font-size: 22px; }

.r-crew { display: flex; justify-content: center; align-items: flex-end; gap: 2px; height: 70px; }
.r-crew img { height: 62px; transform-origin: 50% 100%; animation: hop .571s ease-in-out infinite alternate; animation-delay: var(--d); }
.r-crew img.extra { height: 54px; display: none; }
.r-crew.cheer img.extra { display: block; }
.r-crew.sulk img { animation: none; transform: rotate(-8deg) translateY(4px); filter: saturate(.55); }
@keyframes bop { from { transform: scale(1.03, .96); } to { transform: translateY(-6px) scale(.98, 1.03); } }
@keyframes hop { from { transform: translateY(0); } to { transform: translateY(-7px); } }
@keyframes floaty { from { transform: translateY(0) rotate(-6deg); } to { transform: translateY(-8px) rotate(6deg); } }
@keyframes stamp { from { transform: rotate(-10deg) scale(2.2); } to { transform: rotate(-10deg) scale(1); } }

@media (prefers-reduced-motion: reduce) {
  .hero-rapper, .hero-prop.right, .crew img, .r-top img, .rank, .r-crew img { animation: none; }
  .rank { transform: rotate(-10deg); }
}
@media (max-height: 700px) {
  .hero { height: 86px; } .hero-rapper { height: 86px; } .hero-prop { height: 40px; } .hero-prop.right { bottom: 46px; height: 32px; }   /* 시작 버튼까지 첫 화면 안으로 */
  .logo .l1 { font-size: 38px; } .logo .l2 { font-size: 32px; }
  /* 짧은 화면: 난이도·시작 버튼을 첫 화면 안으로 (친구들·트랙 카드는 그 아래) */
  /* 곡 -> 리더(무슨 스킬인지 보이게) -> 난이도 -> 시작 순서. 리더 카드는 납작하게 */
  #title .songs, #title .leader, #title .diffs, #startBtn { order: 1; } #title .how, #title .settings, #title .legal, #rankBtn, #visits { order: 3; }
  .leader .h { margin-bottom: 4px; } .leader .h small { display: none; } .crew img { height: 38px; } .skill-desc { margin-top: 4px; }
  .badge { padding: 3px 10px; } .logo .l3 { margin-top: 4px; font-size: 22px; }
  .r-top { height: 150px; } .r-top img { height: 140px; } .rank { width: 86px; height: 86px; font-size: 60px; }
}

/* 접속수·랭킹 */
.visits { margin: -2px 0 0; text-align: center; font-size: 13px; color: var(--ink2); }
.entry { display: flex; flex-direction: column; gap: 8px; }
.entry .h { margin: 0; font-size: 17px; }
.nick-row { display: flex; gap: 8px; margin: 0; }
.nick-row input {
  flex: 1; min-width: 0; font-family: var(--font); font-size: 17px; color: var(--ink); padding: 9px 12px 7px;
  border: 3px solid var(--ink); border-radius: 14px; background: var(--cream); user-select: text; -webkit-user-select: text;
}
.nick-row input:focus { outline: 3px solid var(--yellow); outline-offset: 1px; }
.nick-row button { flex: none; font-size: 17px; padding: 9px 16px 7px; border-radius: 14px; background: var(--yellow); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); }
.nick-row button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.nick-row button[disabled], .nick-row input[disabled] { filter: saturate(.4); opacity: .7; }
.entry-msg { margin: 0; font-size: 14px; color: var(--ink2); min-height: 1em; line-height: 1.45; }
.entry-msg:empty { display: none; }
.entry-msg b { font-weight: 400; color: var(--pink); }
.link { align-self: center; background: none; font-size: 14px; color: var(--ink2); text-decoration: underline; text-underline-offset: 3px; padding: 4px 8px; }
.b-title { margin: 0; text-align: center; font-size: 40px; font-weight: 400; color: #fff; -webkit-text-stroke: 7px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); }
.btabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btabs button { background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 7px 4px 5px; box-shadow: 0 4px 0 var(--ink); }
.btabs button b { font-size: 16px; font-weight: 400; }
.btabs button[aria-selected="true"] { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.btabs button[aria-selected="true"][data-bd="easy"] { background: #c9f0d2; }
.btabs button[aria-selected="true"][data-bd="normal"] { background: var(--yellow); }
.btabs button[aria-selected="true"][data-bd="hard"] { background: var(--pink); color: #fff; }
.b-sum { margin: 0; text-align: center; font-size: 14px; color: var(--ink2); }
.b-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.b-list:empty { display: none; }
.b-list li, .b-me {
  display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 8px;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px 4px; margin: 0;
}
.b-list .pl { font-size: 18px; text-align: center; }
.b-list .nm, .b-me .nm { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-list .rk, .b-me .rk { font-size: 13px; color: var(--ink2); }
.b-list .sc, .b-me .sc { font-size: 18px; }
.b-list li:nth-child(1) { background: linear-gradient(90deg, #fff4cc, #fff); }
.b-list li:nth-child(1) .pl { color: #d9a520; font-size: 22px; }
.b-list li:nth-child(2) .pl { color: #8a9bb0; font-size: 20px; }
.b-list li:nth-child(3) .pl { color: #c4855a; font-size: 20px; }
.b-list li.me, .b-me { background: var(--pink-soft); border-color: var(--pink); box-shadow: 0 3px 0 var(--ink); }
.b-me .pl { font-size: 15px; text-align: center; }
.sheet-sub { margin: -4px 0 2px; font-size: 14px; color: var(--ink2); }
.bsongs { grid-template-columns: 1fr 1fr; }
.bseason { grid-template-columns: 1fr 1fr; }
.bseason button[aria-selected="true"] { background: #e3dcff; }
.bsongs button[aria-selected="true"] { background: var(--yellow); }
body[data-song="keroro"] .bsongs button[aria-selected="true"][data-song="keroro"] { background: #b9ec9c; }
/* 결과 화면 잊혀진 도로로: 작게, 말풍선 */
.r-crew .peek { position: relative; display: block; }
.r-crew .peek img { height: 50px; opacity: .85; }
.r-crew .peek::after { content: attr(data-say); position: absolute; right: -4px; bottom: calc(100% + 2px); white-space: nowrap; font-size: 12px; color: #6b7f99; background: #eef2f7; border: 2px solid #4a3a35; border-radius: 12px; padding: 2px 8px; }
/* 케로로: 연한 군복 초록 + 우주 별 점 */
body[data-song="keroro"] .screen {
  background: radial-gradient(circle, rgba(255, 214, 90, .45) 0 2px, transparent 3px) 0 0 / 58px 58px,
    radial-gradient(circle, rgba(255, 255, 255, .7) 0 1.5px, transparent 2.5px) 29px 29px / 58px 58px,
    linear-gradient(180deg, #d3edcb 0%, #eef6df 60%, #fbf3d9 100%);
}
