:root {
  --yolk: #FFD234;        /* 브랜드 노랑 (매장 조명 같은 따뜻한 노랑) */
  --yolk-deep: #F2B705;
  --yolk-soft: #FFF1B8;
  --cream: #FFFDF6;       /* 카드 */
  --cocoa: #2B1A0E;       /* 글자 · 버튼 (구운 크러스트 가장 진한 색) */
  --crust: #9A5B13;       /* 타이머 링 · 라인 */
  --flame: #E8452C;       /* 찾음 표시 · 경고 */
  --ink-2: rgba(43, 26, 14, 0.62);
  --line: rgba(43, 26, 14, 0.14);
  --font-ui: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --font-display: 'Gowun Batang', 'AppleMyungjo', 'Nanum Myeongjo', serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--yolk);
  color: var(--cocoa);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cocoa); outline-offset: 2px; }

#app { min-height: 100dvh; }
.screen, .sheet { display: none; }
#app[data-screen="intro"] .intro { display: flex; }
#app:not([data-screen="intro"]) .game { display: flex; }
#app[data-screen="success"] .success,
#app[data-screen="done"] .done,
#app[data-screen="fail"] .fail { display: flex; }

/* ── 공통 버튼 ───────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 58px; padding: 0 20px;
  border: 0; border-radius: 16px;
  font-size: 18px; font-weight: 700; letter-spacing: -0.01em;
  transition: transform .08s ease, opacity .2s ease;
}
.btn:active { transform: translateY(1px) scale(.995); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-main { background: var(--cocoa); color: var(--yolk); }
.btn-text {
  display: block; margin: 10px auto 0; padding: 10px 14px;
  background: none; border: 0; color: var(--ink-2); font-size: 15px; text-decoration: underline; text-underline-offset: 3px;
}
.btn-chip {
  border: 1.5px solid var(--cocoa); background: var(--cream); color: var(--cocoa);
  border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 600;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none;
  background: rgba(43, 26, 14, 0.08) center / 22px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232B1A0E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 5 6 9H3v6h3l5 4z'/%3E%3Cpath d='M15.5 8.5a5 5 0 0 1 0 7M18.5 5.5a9 9 0 0 1 0 13'/%3E%3C/svg%3E");
}
.icon-btn.is-muted {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232B1A0E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M11 5 6 9H3v6h3l5 4z'/%3E%3Cpath d='m22 9-6 6M16 9l6 6'/%3E%3C/svg%3E");
}

/* ── 대기 화면 ───────────────────────────── */
.intro {
  flex-direction: column; align-items: stretch;
  max-width: 480px; margin: 0 auto; min-height: 100dvh;
  padding: calc(14px + var(--safe-t)) 20px calc(28px + var(--safe-b));
}
.topbar { display: flex; align-items: center; justify-content: space-between; height: 44px; }
.brand { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }

.hero { text-align: center; padding: 4px 0 18px; position: relative; }
.hero::before { /* 매장 조명처럼 은은한 빛 */
  content: ''; position: absolute; left: 50%; top: 0; width: 300px; height: 230px; transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(255, 252, 230, .95), rgba(255, 244, 190, .55) 55%, rgba(255, 210, 52, 0) 100%);
  z-index: 0; pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.hero-tart { width: 168px; height: 168px; margin: 6px auto 2px; animation: tart-float 4.5s ease-in-out infinite; }
.hero-tart svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 10px 14px rgba(120, 70, 0, .22)); }
@keyframes tart-float { 50% { transform: translateY(-6px) rotate(-1.5deg); } }
.title {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(34px, 9.6vw, 46px); line-height: 1.16; letter-spacing: -0.035em;
  margin: 6px 0 12px; word-break: keep-all;
}
.desc { margin: 0 auto; max-width: 21em; font-size: 16.5px; color: var(--ink-2); word-break: keep-all; }

.rules {
  display: grid; grid-template-columns: repeat(4, 1fr);
  margin: 6px 0 22px; padding: 14px 0;
  border-top: 1.5px solid var(--cocoa); border-bottom: 1.5px solid var(--cocoa);
  text-align: center;
}
.rules div + div { border-left: 1px solid var(--line); }
.rules dt { font-size: 12.5px; white-space: nowrap; color: var(--ink-2); }
.rules dd { margin: 2px 0 0; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.samples { margin: 0 0 18px; text-align: center; }
.sample-row { display: flex; justify-content: center; gap: 18px; }
.sample-row i { width: 46px; height: 46px; display: block; }
.sample-row svg { width: 100%; height: 100%; display: block; }
.samples figcaption { margin-top: 6px; font-size: 13.5px; color: var(--ink-2); word-break: keep-all; }
.prize { margin: 12px 4px 22px; text-align: center; font-size: 14px; color: var(--ink-2); word-break: keep-all; }
.demo-badge { margin: 16px 0 0; text-align: center; font-size: 12.5px; color: var(--ink-2); }

/* ── 랭킹 ───────────────────────────────── */
.rank-panel {
  background: var(--cream); border-radius: 20px; padding: 16px 16px 10px;
  box-shadow: 0 1px 0 rgba(43, 26, 14, .08), 0 10px 30px -18px rgba(90, 50, 0, .45);
}
.rank-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rank-head h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.live {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 800; color: var(--flame);
}
.live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--flame); animation: live 1.6s ease-in-out infinite; }
@keyframes live { 50% { opacity: .25; } }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-list li {
  display: grid; grid-template-columns: 30px 1fr auto auto; align-items: center; gap: 8px;
  padding: 9px 4px; border-top: 1px solid var(--line); font-size: 15px;
}
.rank-list li:first-child { border-top: 0; }
.rank-list .rk {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.rank-list li:nth-child(1) .rk { background: #F2B705; color: #fff; }
.rank-list li:nth-child(2) .rk { background: #B9B3A6; color: #fff; }
.rank-list li:nth-child(3) .rk { background: #C98A4B; color: #fff; }
.rank-list .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .tl { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rank-list .tm { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; }
.rank-list li.me { background: var(--yolk-soft); border-radius: 10px; border-top-color: transparent; }
.rank-list li.me + li { border-top-color: transparent; }
.rank-list .empty { display: block; padding: 18px 4px 14px; text-align: center; color: var(--ink-2); font-size: 14px; border: 0; }

/* ── 게임 화면 ───────────────────────────── */
.game {
  flex-direction: column; height: 100dvh; max-height: 100dvh; overflow: hidden;
  padding-top: var(--safe-t);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.hud {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; flex: none;
}
.dial {
  --p: 1;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--cream);
  box-shadow: 0 1px 0 rgba(43, 26, 14, .1);
}
.dial::before { /* 타르트 크러스트처럼 남은 시간만큼 남는 링 */
  content: ''; width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--crust) calc(var(--p) * 1turn), rgba(43, 26, 14, .12) 0);
  -webkit-mask: radial-gradient(circle, transparent 52%, #000 54%);
          mask: radial-gradient(circle, transparent 52%, #000 54%);
}
.dial-num { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; min-width: 3.4em; }
.dial.hurry::before { background: conic-gradient(var(--flame) calc(var(--p) * 1turn), rgba(232, 69, 44, .15) 0); }
.dial.hurry .dial-num { color: var(--flame); }
.dial.hurry { animation: hurry 1s ease-in-out infinite; }
@keyframes hurry { 50% { transform: scale(1.04); } }
.dial.hit { animation: hit .45s ease; }
@keyframes hit { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

.found { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.found-count { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.found-count b { font-size: 20px; }
.found-icons { display: flex; gap: 2px; }
.found-icons i { width: 15px; height: 15px; display: block; opacity: .28; filter: grayscale(1); transition: opacity .2s, filter .2s, transform .25s; }
.found-icons i.on { opacity: 1; filter: none; transform: scale(1.15); }
.found-icons svg { width: 100%; height: 100%; display: block; }

.stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  touch-action: none; background: #F5C518;
  box-shadow: inset 0 1px 0 rgba(43, 26, 14, .12), inset 0 -1px 0 rgba(43, 26, 14, .12);
}
.board { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.board img {
  display: block; width: 100%; height: 100%;
  pointer-events: none; -webkit-user-drag: none; user-select: none;
  transition: filter .5s ease;
}
.board.veil img { filter: blur(16px) saturate(.6); }
.board.gray img { filter: grayscale(1) brightness(.92); }
.overlay { position: absolute; inset: 0; pointer-events: none; }

.mark { position: absolute; aspect-ratio: 1; transform: translate(-50%, -50%); pointer-events: none; }
.mark-found {
  border-radius: 50%; border: 3px solid var(--flame);
  box-shadow: 0 0 0 1.5px #fff, inset 0 0 0 1.5px #fff;
  animation: ring-in .38s cubic-bezier(.2, 1.4, .4, 1) both;
}
.mark-found::after { /* 반짝임 */
  content: ''; position: absolute; inset: -40%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 244, 190, .9) 0 18%, rgba(255, 210, 52, 0) 60%);
  animation: sparkle .5s ease-out both;
}
@keyframes ring-in { from { transform: translate(-50%, -50%) scale(1.9); opacity: 0; } }
@keyframes sparkle { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }
.mark-wrong { animation: wrong-pop .9s ease both; }
.mark-wrong::before, .mark-wrong::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 100%; height: 18%;
  background: var(--flame); border-radius: 99px; box-shadow: 0 0 0 1.5px #fff;
  transform: translate(-50%, -50%) rotate(45deg);
}
.mark-wrong::after { transform: translate(-50%, -50%) rotate(-45deg); }
@keyframes wrong-pop { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }
.float-text {
  position: absolute; transform: translate(-50%, -120%); white-space: nowrap; pointer-events: none;
  font-weight: 800; font-size: 18px; color: var(--flame);
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff;
  animation: float-up .9s ease-out forwards;
}
@keyframes float-up { to { transform: translate(-50%, -260%); opacity: 0; } }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-family: var(--font-display); font-weight: 700; font-size: 120px; line-height: 1; color: var(--cocoa);
  text-shadow: 0 4px 0 var(--yolk), 0 0 30px rgba(255, 255, 255, .8);
}
.countdown:empty { display: none; }
.countdown span { animation: count-pop .7s ease-out both; }
.countdown .go { font-size: 64px; }
@keyframes count-pop { from { transform: scale(1.8); opacity: 0; } 30% { transform: scale(1); opacity: 1; } to { opacity: .9; } }

.stamp {
  position: absolute; left: 50%; top: 40%; pointer-events: none;
  padding: 8px 22px; border: 5px solid var(--flame); border-radius: 12px;
  color: var(--flame); font-size: 40px; font-weight: 900; letter-spacing: .02em; background: rgba(255, 253, 246, .88);
  transform: translate(-50%, -50%) rotate(-9deg); opacity: 0; white-space: nowrap;
}
.stamp.on { animation: slam .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes slam { from { transform: translate(-50%, -50%) rotate(-9deg) scale(2.4); opacity: 0; } to { transform: translate(-50%, -50%) rotate(-9deg) scale(1); opacity: 1; } }
.game.shake .stage { animation: hit .5s ease; }

.game-foot {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 48px; padding: 6px 14px calc(6px + var(--safe-b));
}
.hint { font-size: 13.5px; color: var(--ink-2); }

/* ── 결과 시트 ───────────────────────────── */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  align-items: flex-end; justify-content: center;
  background: rgba(43, 26, 14, .42);
}
.sheet-card {
  width: 100%; max-width: 480px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--cream); border-radius: 26px 26px 0 0;
  padding: 26px 22px calc(22px + var(--safe-b));
  text-align: center;
  animation: sheet-up .42s cubic-bezier(.2, .9, .3, 1) both;
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.result-badge {
  display: inline-block; margin: 0 0 8px; padding: 4px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 800;
}
.result-badge.win { background: var(--yolk); color: var(--cocoa); }
.result-badge.lose { background: var(--cocoa); color: var(--cream); }
.result-title { font-family: var(--font-display); font-weight: 700; font-size: 25px; line-height: 1.3; margin: 0 0 6px; letter-spacing: -0.03em; word-break: keep-all; }
.record { margin: 4px 0 0; font-size: 60px; font-weight: 900; letter-spacing: -0.04em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.record small { font-size: 22px; font-weight: 700; margin-left: 4px; letter-spacing: 0; }
.record.small { font-size: 40px; }
.record-note { margin: 4px 0 16px; color: var(--ink-2); font-size: 15px; min-height: 1.5em; }
.fail .record { margin-bottom: 22px; }

.entry { text-align: left; border-top: 1px solid var(--line); padding-top: 18px; }
.entry-lead { margin: 0 0 14px; font-size: 14.5px; color: var(--ink-2); word-break: keep-all; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13.5px; font-weight: 700; margin-bottom: 6px; }
.field input {
  width: 100%; height: 52px; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid rgba(43, 26, 14, .22); background: #fff; font-size: 17px;
}
.field input:focus { outline: none; border-color: var(--cocoa); box-shadow: 0 0 0 4px rgba(255, 210, 52, .55); }
.consent { margin: 4px 0 12px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--cocoa); flex: none; }
.consent details { margin: 6px 0 0 32px; color: var(--ink-2); }
.consent summary { cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.consent ul { margin: 8px 0 0; padding-left: 16px; font-size: 13px; line-height: 1.6; }
.form-error { min-height: 1.4em; margin: 0 0 10px; color: var(--flame); font-size: 14px; font-weight: 600; }

.code-box {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin: 14px 0 18px; padding: 14px; border-radius: 16px;
  border: 2px dashed var(--crust); background: #fff;
}
.code-box span { font-size: 13px; color: var(--ink-2); }
.code-box strong { font-size: 30px; font-weight: 900; letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.code-box em { font-style: normal; font-size: 13px; color: var(--ink-2); }
.done .rank-panel { text-align: left; margin-bottom: 18px; box-shadow: none; border: 1px solid var(--line); }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; display: none; }

@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 26px; max-width: 440px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ── 참가자 카드 ─────────────────────────── */
.player-card {
  background: var(--cream); border-radius: 20px; padding: 16px 16px 14px; margin: 0 0 14px;
  box-shadow: 0 1px 0 rgba(43, 26, 14, .08), 0 10px 30px -18px rgba(90, 50, 0, .45);
}
.player-card > * { display: none; }
.player-card[data-state="loading"] .pc-loading,
.player-card[data-state="new"] .pc-new,
.player-card[data-state="ready"] .pc-ready,
.player-card[data-state="out"] .pc-ready { display: block; }
.pc-loading { margin: 6px 0; text-align: center; color: var(--ink-2); font-size: 14.5px; }
.pc-label { display: block; font-weight: 800; font-size: 16px; margin-bottom: 8px; }
.pid-row { display: flex; gap: 8px; }
.pid-row input {
  flex: 1; min-width: 0; height: 52px; padding: 0 14px; border-radius: 12px;
  border: 1.5px solid rgba(43, 26, 14, .22); background: #fff; font-size: 17px;
}
.pid-row input:focus { outline: none; border-color: var(--cocoa); box-shadow: 0 0 0 4px rgba(255, 210, 52, .55); }
.btn-pid { flex: none; height: 52px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--cocoa); color: var(--yolk); font-weight: 800; font-size: 16px; }
.btn-pid:disabled { opacity: .55; }
.pc-help { margin: 8px 0 0; font-size: 13px; color: var(--ink-2); line-height: 1.55; word-break: keep-all; }
.pc-new .form-error { margin: 6px 0 0; min-height: 0; }
.pc-ready { text-align: center; }
.pc-hello { margin: 0; font-size: 15px; color: var(--ink-2); }
.pc-hello b { color: var(--cocoa); font-size: 19px; font-weight: 800; }
.pc-left { margin: 4px 0 0; font-size: 15px; font-weight: 700; }
.pc-left b { font-size: 34px; font-weight: 900; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 0 2px; }
.pc-of { color: var(--ink-2); font-weight: 600; }
.player-card[data-state="out"] .pc-left b { color: var(--flame); }
.pc-best { margin: 4px 0 0; font-size: 14px; color: var(--ink-2); }
.pc-best b { color: var(--cocoa); }
.start-error { text-align: center; margin: 0 0 8px; min-height: 0; }
.start-error:empty { display: none; }

/* ── 결과 시트 보조 ─────────────────────────── */
.out-note { margin: 0 0 14px; font-weight: 700; color: var(--flame); word-break: keep-all; }
.done #btnDoneRetry { margin-bottom: 4px; }
.rank-more { margin: 6px auto 0; font-size: 14px; }

/* ── 전체 랭킹 시트 ─────────────────────────── */
.rankall { display: none; z-index: 20; }
.rankall:not([hidden]) { display: flex; }
.rankall .sheet-card { text-align: left; }
.rankall .rank-list { margin-bottom: 16px; }

/* ── 새 1위 알림 ─────────────────────────── */
.toast {
  position: fixed; left: 50%; top: calc(14px + var(--safe-t)); z-index: 40;
  transform: translate(-50%, -160%); max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 999px; background: var(--cocoa); color: var(--yolk);
  font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .45);
  transition: transform .45s cubic-bezier(.2, 1.2, .4, 1);
  pointer-events: none;
}
.toast.on { transform: translate(-50%, 0); }

/* 도전 기회 제한이 없으면 규칙 3칸 */
.rules:has(#ruleMax[hidden]) { grid-template-columns: repeat(3, 1fr); }
.rules div[hidden] { display: none; }
/* 테스트 사이트 전용 */
.test-badge { display: inline-block; margin-left: 6px; padding: 2px 8px; border-radius: 999px; background: var(--flame); color: #fff; font-size: 11.5px; font-weight: 800; vertical-align: 1px; }
.test-badge[hidden] { display: none; }
.btn-test { margin-top: 10px; min-height: 48px; font-size: 15px; background: #fff; color: var(--cocoa); border: 2px dashed var(--flame); }
.btn-test[hidden] { display: none; }
.rank-list .tag { margin-left: 6px; padding: 1px 6px; border-radius: 6px; background: var(--yolk-soft); color: var(--crust); font-size: 11px; font-weight: 800; vertical-align: 1px; }
