#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

/* ---------- 공통 화면 ---------- */
.screen {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  z-index: 10;
}
.screen.active { display: flex; animation: fadeIn 0.35s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 28px;
  box-shadow: 0 10px 0 rgba(42, 28, 22, 0.25);
  padding: 28px 32px;
}
.eyebrow { margin: 0 0 6px; color: var(--red); font-size: 20px; }
h1 { margin: 0 0 10px; font-size: 64px; line-height: 1.05; font-weight: normal; }
h2 { margin: 0 0 14px; font-size: 40px; font-weight: normal; }
h3 { margin: 0 0 12px; font-size: 24px; font-weight: normal; }
.key-hint { margin: 16px 0 0; font-size: 20px; color: var(--ink-2); }
.key-hint.center { text-align: center; }
.key-hint.big { font-size: 26px; }
.red { color: var(--red); font-weight: normal; }

/* ---------- 타이틀 ---------- */
#screen-title { background: linear-gradient(180deg, rgba(77,147,220,0.55), rgba(214,234,249,0.35)); }
.title-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) minmax(0, 0.7fr);
  gap: 24px; align-items: center;
  width: min(1400px, 100%);
}
.hero { width: 100%; max-width: 520px; display: block; margin: 0 auto; filter: drop-shadow(0 10px 0 rgba(42,28,22,0.2)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-1.5deg); } }
.desc { font-size: 22px; color: var(--ink-2); margin: 0 0 22px; line-height: 1.45; }
.name-label { display: block; font-size: 20px; margin-bottom: 8px; }
#nameInput {
  width: 100%;
  font-family: var(--font);
  font-size: 34px;
  padding: 14px 18px;
  border: 4px solid var(--ink);
  border-radius: 18px;
  outline: none;
  background: #fff;
  color: var(--ink);
}
#nameInput:focus { border-color: var(--red); box-shadow: 0 0 0 6px rgba(224,49,46,0.15); }
.name-tip { font-size: 16px; color: var(--ink-2); margin: 10px 0 0; }
.error { color: var(--red); font-size: 18px; min-height: 1.2em; margin: 8px 0 0; }
.title-rank ol { margin: 0; padding: 0; list-style: none; }
.title-rank li, .result-top li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 4px;
  border-bottom: 2px dashed var(--line);
  font-size: 20px;
}
.title-rank li:last-child, .result-top li:last-child { border-bottom: 0; }
.rk { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #eee3d4; flex: none; font-size: 18px; }
.rk.r1 { background: var(--gold); } .rk.r2 { background: #cfd6de; } .rk.r3 { background: #e3a36d; }
.mini-face { width: 36px; height: 36px; flex: none; }
.nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm { font-variant-numeric: tabular-nums; color: var(--blue); }
.empty { color: var(--ink-2); font-size: 18px; padding: 8px 0; }

/* ---------- 캐릭터 선택 ---------- */
#screen-select { flex-direction: column; justify-content: space-between; padding: 28px 24px 28px; }
.select-bottom { display: flex; flex-direction: column; gap: 4px; }
.select-head { text-align: center; background: rgba(255,250,242,0.92); border: 4px solid var(--ink); border-radius: 24px; padding: 14px 30px; }
.select-head h2 { margin: 0; font-size: 34px; }
.select-cards { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.sel-card {
  width: 150px; padding: 10px 10px 8px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 24px;
  text-align: center; font-size: 26px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s;
  box-shadow: 0 6px 0 rgba(42,28,22,0.25);
}
.sel-card img { width: 104px; height: 104px; display: block; margin: 0 auto 4px; }
.sel-card.on { transform: translateY(-14px) scale(1.06); background: #fff; border-color: var(--red); box-shadow: 0 14px 0 rgba(224,49,46,0.35); }
.sel-card.on::after { content: "▲"; display: block; color: var(--red); font-size: 18px; margin-top: 2px; }

/* ---------- 게임 방법 ---------- */
#screen-guide { background: rgba(42, 28, 22, 0.25); }
.guide { width: min(720px, 100%); }
.guide ul { list-style: none; padding: 0; margin: 0; }
.guide li { display: flex; gap: 18px; align-items: center; padding: 12px 0; border-bottom: 2px dashed var(--line); font-size: 20px; line-height: 1.45; color: var(--ink-2); }
.guide li b { color: var(--ink); font-weight: normal; font-size: 24px; }
.guide .ico { width: 96px; flex: none; text-align: center; font-size: 44px; }
.guide .ico.keys { font-size: 22px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hud-hearts { position: absolute; top: 22px; left: 26px; display: flex; gap: 8px; }
.heart { width: 52px; height: 48px; transition: transform 0.2s; }
.heart.lost { filter: grayscale(1) opacity(0.55); transform: scale(0.85); }
.heart.pop { animation: pop 0.45s ease; }
@keyframes pop { 30% { transform: scale(1.45) rotate(-12deg); } }
.hud-timer {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  background: #3a2f33; color: #fff;
  border: 4px solid #8cc0ee; border-top: 0;
  border-radius: 0 0 26px 26px;
  padding: 8px 34px 12px;
  font-size: 46px; font-variant-numeric: tabular-nums; letter-spacing: 1px;
}
.hud-gifts {
  position: absolute; top: 22px; right: 26px;
  background: rgba(255,255,255,0.92); border-radius: 999px;
  padding: 8px 26px 8px 16px; display: flex; align-items: center; gap: 10px;
  font-size: 40px; box-shadow: 0 4px 0 rgba(42,28,22,0.18);
}
.hud-gifts.pop { animation: pop 0.35s ease; }
.gift-ico { width: 46px; height: 46px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Crect x='6' y='20' width='36' height='24' rx='3' fill='%23e0312e'/%3E%3Crect x='3' y='13' width='42' height='10' rx='3' fill='%23f04a46'/%3E%3Crect x='21' y='13' width='6' height='31' fill='%23ffd447'/%3E%3Cpath d='M24 13c-4-9-14-9-12-2 1 3 7 3 12 2zm0 0c4-9 14-9 12-2-1 3-7 3-12 2z' fill='%23ffd447'/%3E%3C/svg%3E") center/contain no-repeat; }
.hud-progress { position: absolute; right: 34px; top: 120px; bottom: 120px; width: 16px; display: flex; flex-direction: column; align-items: center; }
.hud-progress .flag { position: absolute; top: -40px; font-size: 30px; }
.hud-progress .track { position: relative; flex: 1; width: 12px; border-radius: 6px; background: rgba(255,255,255,0.55); border: 2px solid rgba(42,28,22,0.25); }
.hud-progress .fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 6px; background: var(--red); }
.hud-progress img { position: absolute; left: 50%; width: 46px; height: 46px; transform: translate(-50%, 50%); background: #fff; border-radius: 50%; border: 3px solid #3aa7e8; }

#countdown {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 20;
  font-size: 220px; color: #fff; -webkit-text-stroke: 8px var(--ink); paint-order: stroke fill;
}
#countdown span { animation: countPop 0.75s ease forwards; }
@keyframes countPop { 0% { transform: scale(2.2); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(0.85); opacity: 0; } }
#banner {
  position: fixed; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none; z-index: 20;
  font-size: 120px; color: #fff; -webkit-text-stroke: 7px var(--ink); paint-order: stroke fill;
}
#banner.show { animation: bannerIn 0.5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes bannerIn { from { transform: scale(0.3); opacity: 0; } to { transform: none; opacity: 1; } }

#flash { position: fixed; inset: 0; pointer-events: none; z-index: 4; box-shadow: inset 0 0 160px 40px rgba(224,49,46,0.75); opacity: 0; }
#flash.on { animation: flash 0.6s ease; }
@keyframes flash { 15% { opacity: 1; } 100% { opacity: 0; } }
#speedlines {
  position: fixed; inset: -20%; pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.25s;
  background: repeating-conic-gradient(from 0deg at 50% 45%, rgba(255,255,255,0) 0deg 5deg, rgba(255,255,255,0.55) 5.4deg 5.8deg);
  -webkit-mask: radial-gradient(circle at 50% 45%, transparent 28%, #000 62%);
          mask: radial-gradient(circle at 50% 45%, transparent 28%, #000 62%);
}
#speedlines.on { opacity: 1; animation: spin 0.4s linear infinite; }
@keyframes spin { to { transform: rotate(4deg); } }

/* ---------- 결과 ---------- */
#screen-result { background: rgba(42, 28, 22, 0.3); }
.result { width: min(640px, 100%); text-align: center; position: relative; padding-top: 70px; }
.result-img { position: absolute; width: 150px; top: -90px; left: 50%; transform: translateX(-50%); }
.result h2 { font-size: 52px; margin: 0; }
.result-time { font-size: 76px; color: var(--blue); font-variant-numeric: tabular-nums; margin: 4px 0; }
.result-rank { font-size: 30px; min-height: 1.3em; }
.result-rank b { color: var(--red); font-size: 44px; font-weight: normal; }
.result-stats { font-size: 20px; color: var(--ink-2); margin: 6px 0 14px; }
.result-top { list-style: none; margin: 0 auto; padding: 0; text-align: left; max-width: 460px; }
.result-top li.me { background: #fff1c9; border-radius: 12px; }

#deviceTag { position: fixed; left: 12px; bottom: 8px; font-size: 14px; color: rgba(42,28,22,0.55); z-index: 30; }
#netTag { position: fixed; right: 12px; bottom: 8px; font-size: 15px; z-index: 30; background: #fff3c4; border: 2px solid var(--ink); border-radius: 10px; padding: 4px 10px; }

@media (max-width: 1100px) {
  .title-wrap { grid-template-columns: 1fr 1fr; }
  .title-rank { display: none; }
  h1 { font-size: 48px; }
}
