/* 반응속도 테스트 — 세 개의 무대(서부 결투·레이싱 출발·상자 고양이). 신호는 한 프레임에 바뀌고, 반응 뒤 연출만 움직인다. */
:root {
  --display: "Black Han Sans", "Pretendard Variable", system-ui, sans-serif;
  --body: "Pretendard Variable", system-ui, -apple-system, "Apple SD Gothic Neo", sans-serif;
  --dock-h: 104px;
}
body[data-theme="duel"] { --bg: #2a1b47; --panel: #efd6a6; --ink: #2a1610; --ink-2: rgba(42, 22, 16, .66); --accent: #c9461c; --on-stage: #fff4dc; --sil: #1d0e17; }
body[data-theme="race"] { --bg: #2c2f34; --panel: #eceef0; --ink: #16181b; --ink-2: rgba(22, 24, 27, .62); --accent: #d9261a; --on-stage: #ffffff; --sil: #121315; }
body[data-theme="cat"]  { --bg: #1d2747; --panel: #f1dfbd; --ink: #1c2040; --ink-2: rgba(28, 32, 64, .64); --accent: #d9701f; --on-stage: #fff6e0; --sil: #120f1c; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body);
  height: auto; overflow-x: hidden; overflow-y: visible;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #ffd84d; outline-offset: 2px; }

.app { position: relative; height: 100svh; min-height: 520px; display: flex; flex-direction: column; overflow: hidden; }

/* 머리줄: 무대 위에 겹친다 */
.top {
  position: absolute; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  color: var(--on-stage); pointer-events: none;
}
.top > * { pointer-events: auto; }
.logo { font: 400 22px/1 var(--display); color: inherit; text-decoration: none; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.top h1 { margin: 0; font: 700 15px/1 var(--body); opacity: .92; flex: 1; text-shadow: 0 1px 2px rgba(0,0,0,.45); }
.chip {
  border: 1.5px solid currentColor; background: rgba(0,0,0,.22); color: inherit;
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.chip[aria-pressed="false"] { opacity: .6; }

/* 무대 */
.stage {
  position: relative; flex: 1; min-height: 0; overflow: hidden; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
body:not([data-state="idle"]) .stage { touch-action: none; }
.scene, .scene > * { position: absolute; }
.scene { inset: 0; }
.scene svg { display: block; width: 100%; height: 100%; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 8; }
.flash.on { animation: flash .45s ease-out; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

/* ── 서부 결투 ── */
.d-sky { inset: 0 0 38% 0; background: linear-gradient(#2a1b47 0%, #5a2550 30%, #b8413a 62%, #e9773a 84%, #f7b955 100%); }
.d-sun { left: 50%; bottom: 38%; width: min(64vw, 56vh); aspect-ratio: 1; transform: translate(-50%, 50%); border-radius: 50%;
  background: radial-gradient(circle, #fff1c2 0%, #ffd27a 42%, #f7a24a 62%, rgba(247, 162, 74, 0) 70%); }
.d-mesa { left: 0; right: 0; bottom: 38%; height: 20%; }
.d-ground { inset: 62% 0 0 0; background: linear-gradient(#a4532d, #7d3a20 55%, #5e2a17); }
.d-ground::after { content: ""; position: absolute; inset: 0; opacity: .35;
  background-image: radial-gradient(rgba(255, 210, 150, .5) 1px, transparent 1.4px); background-size: 9px 7px; }
.d-shadow { left: 50%; bottom: 28.5%; width: 34%; max-width: 300px; height: 3.2%; transform: translateX(-12%) skewX(-40deg); background: rgba(40, 10, 20, .45); border-radius: 50%; }
.d-opp { left: 50%; bottom: 29%; height: 40%; aspect-ratio: 2 / 3; transform: translateX(-50%); fill: var(--sil); }
.d-opp .opp-body, .d-opp .opp-hat { transform-box: fill-box; }
.d-opp .opp-body { transform-origin: 50% 100%; transition: transform .55s cubic-bezier(.5, 0, .9, .5); }
.d-opp .opp-hat { transform-origin: 50% 50%; transition: transform .7s cubic-bezier(.2, .7, .3, 1), opacity .7s; }
.d-opp .opp-flash { opacity: 0; fill: #ffe9a8; }
.d-opp .opp-draw { display: none; }
.scene.lost .d-opp .opp-draw { display: inline; }
.scene.lost .d-opp .arm-r { display: none; }
.scene.won .d-opp .opp-body { transform: rotate(-84deg) translateY(10%); }
.scene.won .d-opp .opp-hat { transform: translate(60%, -120%) rotate(200deg); opacity: 0; }
.scene.lost .d-opp .opp-flash { animation: muzzle .3s ease-out; }
.d-tumble { left: -12%; bottom: 30%; width: 9%; max-width: 70px; aspect-ratio: 1; fill: none; stroke: #4a2216; stroke-width: 3; opacity: 0; }
.scene.waiting .d-tumble { animation: tumble 6.5s linear .6s infinite; }
@keyframes tumble { 0% { opacity: 1; transform: translateX(0) rotate(0); } 50% { transform: translateX(70vw) translateY(-14%) rotate(420deg); } 100% { opacity: 1; transform: translateX(140vw) rotate(900deg); } }
.d-hand { right: -3%; bottom: -3%; height: 46%; aspect-ratio: 1; fill: var(--sil); }
.d-hand .drawn { display: none; }
.scene.fired .d-hand .idle { display: none; }
.scene.fired .d-hand .drawn { display: inline; }
.d-hand .muzzle { fill: #fff3b0; opacity: 0; }
.scene.fired .d-hand .muzzle { animation: muzzle .25s ease-out; }
@keyframes muzzle { 0% { opacity: 1; } 100% { opacity: 0; } }
.scene.lost::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 50% 60%, transparent 35%, rgba(150, 0, 0, .55)); animation: hurt .9s ease-out forwards; }
@keyframes hurt { from { opacity: 1; } to { opacity: .55; } }
/* 신호: 하늘이 한 프레임에 하얗게 */
.scene.go .d-sky { background: #fff3cf; }
.scene.go .d-sun { background: radial-gradient(circle, #fff 0%, #fff6d8 60%, rgba(255, 246, 216, 0) 70%); }

/* ── 레이싱 출발 ── */
.r-sky { inset: 0 0 50% 0; background: linear-gradient(#aebbc5, #d6dde2 70%, #e7ebee); }
.r-stand { left: 0; right: 0; bottom: 50%; height: 22%; }
.r-track { left: 0; right: 0; top: 50%; bottom: 0; }
.r-gantry { left: 50%; top: 13%; width: min(92%, 620px); aspect-ratio: 600 / 150; transform: translateX(-50%); }
.r-gantry .lamp { fill: #2a1210; }
.r-gantry .halo { opacity: 0; }
.r-gantry .pod.on .lamp { fill: url(#lampOn); }
.r-gantry .pod.on .halo { opacity: 1; }
.r-car { left: 50%; bottom: 3%; width: min(78%, 56vh); aspect-ratio: 400 / 260; transform: translateX(-50%); transform-origin: 50% 100%; }
.r-car .rain { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }
.scene.launched .r-car { transition: transform .9s cubic-bezier(.45, 0, .2, 1); transform: translateX(-50%) translateY(-38%) scale(.32); }
.r-smoke { left: 50%; bottom: 2%; width: min(90%, 64vh); aspect-ratio: 400 / 120; transform: translateX(-50%); opacity: 0; fill: #eef0f2; }
.scene.launched .r-smoke { animation: smoke 1.1s ease-out forwards; }
@keyframes smoke { 0% { opacity: .95; transform: translateX(-50%) scale(.7); } 100% { opacity: 0; transform: translateX(-50%) scale(1.5) translateY(-10%); } }

/* ── 상자 고양이 ── */
.c-wall { inset: 0 0 30% 0; background-color: #1d2747;
  background-image: repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 18px, transparent 18px 46px); }
.c-wall::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at 24% 22%, rgba(244, 231, 176, .22), transparent 55%); }
.c-window { left: 8%; top: 11%; width: min(30%, 200px); aspect-ratio: 200 / 220; }
.c-floor { inset: 70% 0 0 0; background: repeating-linear-gradient(90deg, #5b3d2c 0 74px, #4f3426 74px 77px); }
.c-floor::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 10px; background: #2c1d24; }
.c-box { left: 50%; bottom: 8%; width: min(92%, 60vh); aspect-ratio: 320 / 300; transform: translateX(-50%); transform-origin: 50% 100%; }
.c-box .cat { visibility: hidden; }
.scene.go .c-box .cat { visibility: visible; }
.c-box .cat.blur { filter: url(#catBlur); }
.scene.shake .c-box { animation: wiggle .42s ease-in-out; }
@keyframes wiggle { 20% { transform: translateX(-50%) rotate(-3deg); } 45% { transform: translateX(-50%) rotate(2.6deg); } 70% { transform: translateX(-50%) rotate(-1.6deg); } 100% { transform: translateX(-50%) rotate(0); } }
.c-photo { inset: 9% max(7%, calc(50% - 40vh)) 8%; border: 14px solid #fbf8f1; border-bottom-width: 64px; box-shadow: 0 18px 40px rgba(0,0,0,.45), 0 0 0 9999px rgba(10, 12, 26, .5);
  opacity: 0; transform: rotate(-2.4deg) scale(1.08); pointer-events: none; }
.c-photo span { position: absolute; left: 0; right: 0; bottom: -54px; text-align: center; font: 400 clamp(22px, 6.4vw, 34px)/1.2 var(--display); color: #2b2a33; }
.scene.snapped .c-photo { opacity: 1; transform: rotate(-2.4deg) scale(1); transition: transform .35s cubic-bezier(.2, .8, .3, 1.2), opacity .15s; }
.scene.empty-snap .c-photo { opacity: 1; transform: rotate(2deg) scale(1); transition: opacity .15s; }

/* HUD */
.hud { position: absolute; inset: 0; z-index: 10; pointer-events: none; color: var(--on-stage); text-align: center; }
.hud > * { pointer-events: none; }
.rounds { position: absolute; top: max(58px, calc(env(safe-area-inset-top) + 50px)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px; margin: 0; padding: 0; list-style: none; }
.rounds li { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--on-stage); opacity: .85; }
.rounds li.done { background: var(--on-stage); }
.rounds li.now { box-shadow: 0 0 0 4px rgba(255,255,255,.25); }
body[data-theme="race"] .rounds li { border-radius: 3px; border-color: #16181b; background: #3a3d42; }
body[data-theme="race"] .rounds li.done { background: #d9261a; }
body[data-theme="cat"] .rounds li { border-radius: 50% 50% 45% 45%; }
.msg { position: absolute; top: 25%; left: 16px; right: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.cue { margin: 0; font: 400 clamp(22px, 6.4vw, 40px)/1.15 var(--display); text-shadow: 0 2px 0 rgba(0,0,0,.4), 0 0 18px rgba(0,0,0,.35); word-break: keep-all; }
body[data-theme="race"] .msg { top: auto; bottom: 52%; }
body[data-theme="race"] .cue { color: #16181b; text-shadow: 0 1px 0 rgba(255,255,255,.7); font-size: clamp(18px, 5vw, 30px); }
body[data-theme="race"] .hud { color: #16181b; }
body[data-theme="race"] .top { color: #16181b; }
body[data-theme="race"] .logo, body[data-theme="race"] .top h1 { text-shadow: none; }
body[data-theme="race"] .chip { background: rgba(255,255,255,.45); }
body[data-theme="race"] .cue, body[data-theme="race"] .sub { width: max-content; max-width: 100%;
  background: #16181b; color: #f4f4f0; padding: 7px 14px 6px; border-radius: 4px; text-shadow: none; }
body[data-theme="race"] .sub { background: #f4f4f0; color: #16181b; border: 2px solid #16181b; font-size: 14px; }
.cue:empty, .sub:empty { display: none; }
body[data-theme="duel"][data-state="go"] { --on-stage: #2a1610; }
body[data-theme="duel"][data-state="go"] .top, body[data-theme="duel"][data-state="go"] .sub { text-shadow: none; }
.sub { margin: 0; font-weight: 700; font-size: 15px; line-height: 1.45; text-shadow: 0 1px 3px rgba(0,0,0,.6); word-break: keep-all; overflow-wrap: anywhere; }
.sub .hint { display: block; font-weight: 600; font-size: 13px; opacity: .85; }
body[data-theme="race"] .sub { text-shadow: none; }
body[data-theme="cat"] .msg { left: 40px; right: 40px; }
body[data-theme="cat"] .cue:not(:empty), body[data-theme="cat"] .sub:not(:empty) { background: rgba(14, 18, 40, .78); padding: 6px 12px; border-radius: 6px; text-shadow: none; }
.go-word { position: absolute; top: 11%; left: 0; right: 0; font: 400 clamp(84px, 30vw, 220px)/1 var(--display); color: #b3200f; display: none; letter-spacing: -.02em; }
.scene.go ~ .hud .go-word, body[data-state="go"] .go-word { display: block; }
body[data-theme="race"] .go-word, body[data-theme="cat"] .go-word { display: none !important; }
.stamp { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) rotate(-7deg); display: none; align-items: baseline; gap: 4px;
  padding: 6px 22px 10px; border: 6px solid currentColor; border-radius: 10px; color: #fff4dc; background: rgba(20, 8, 12, .38);
  font: 400 clamp(64px, 22vw, 150px)/1 var(--display); }
.stamp span { font-size: .36em; }
.stamp.show { display: inline-flex; animation: stamp .32s cubic-bezier(.2, 1.6, .4, 1); }
.stamp.bad { color: #ffb4a0; }
@keyframes stamp { from { transform: translate(-50%, -50%) rotate(-16deg) scale(1.9); opacity: 0; } to { transform: translate(-50%, -50%) rotate(-7deg) scale(1); opacity: 1; } }
body[data-theme="race"] .stamp { color: #16181b; background: rgba(255,255,255,.72); top: 66%; }
body[data-theme="cat"] .stamp { display: none !important; }
.stamp-note { display: block; }
.challenge { position: absolute; left: 50%; bottom: calc(15% + 74px); transform: translateX(-50%) rotate(-1.5deg); width: min(88%, 420px);
  background: #fbf3e2; color: #2a1610; padding: 12px 16px; border: 2px solid #2a1610; box-shadow: 4px 4px 0 #2a1610; font-size: 15px; line-height: 1.45; text-align: left; }
.challenge b { font: 400 20px/1.2 var(--display); display: block; }
.challenge span { word-break: keep-all; overflow-wrap: anywhere; }
.start {
  position: absolute; left: 50%; bottom: 13%; transform: translateX(-50%); pointer-events: auto;
  font: 400 clamp(22px, 6vw, 30px)/1 var(--display); color: var(--ink); background: var(--panel);
  border: 3px solid var(--ink); box-shadow: 0 6px 0 var(--ink); border-radius: 12px; padding: 16px 30px 14px; cursor: pointer; white-space: nowrap;
}
.start:active { transform: translateX(-50%) translateY(4px); box-shadow: 0 2px 0 var(--ink); }
body:not([data-state="idle"]) .start { display: none; }
body:not([data-state="idle"]) .challenge { display: none; }

/* 무대 고르기 */
.dock { flex: none; height: var(--dock-h); background: var(--panel); color: var(--ink); border-top: 3px solid var(--ink); padding: 8px 12px calc(6px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 620px; width: 100%; margin: 0 auto; }
.themes button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px 6px; border: 2px solid transparent; border-radius: 10px; background: none; cursor: pointer; font-weight: 700; font-size: 14px; }
.themes svg { width: 36px; height: 24px; fill: var(--ink); }
.themes svg .l { fill: var(--panel); }
.themes button[aria-checked="true"] { border-color: var(--ink); background: rgba(255,255,255,.4); }
.themes button[aria-checked="true"] svg .l { fill: var(--accent); }
body:not([data-state="idle"]) .themes button { opacity: .45; pointer-events: none; }
.device { margin: 0; text-align: center; font-size: 12px; color: var(--ink-2); }

/* 결과 시트 */
.result { position: absolute; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; animation: rise .38s cubic-bezier(.2, .8, .3, 1); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.result[hidden] { display: none; }
.result-in { max-width: 980px; margin: 0 auto; padding: 60px 16px 28px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.card-wrap { width: min(100%, 46svh * .8, 420px); }
.card-wrap canvas { display: block; width: 100%; height: auto; border-radius: 6px; box-shadow: 0 16px 40px rgba(0,0,0,.45); }
.result-side { width: 100%; max-width: 440px; color: var(--on-stage); }
.r-title { margin: 0 0 4px; font: 400 26px/1.1 var(--display); }
.r-line { margin: 0 0 6px; font-size: 16px; line-height: 1.5; }
.r-vs { margin: 0 0 6px; font-weight: 800; font-size: 16px; color: #ffd84d; }
.ages { border: 0; padding: 0; margin: 10px 0 0; }
.ages legend { font-size: 13px; opacity: .8; margin-bottom: 6px; padding: 0; }
.age-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.age-chips button { border: 1.5px solid rgba(255,255,255,.55); background: transparent; color: var(--on-stage); border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 700; cursor: pointer; }
.age-chips button[aria-checked="true"] { background: var(--on-stage); color: var(--bg); border-color: var(--on-stage); }
.name { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 13px; }
.name span { opacity: .8; }
.name input { font: 600 16px var(--body); padding: 10px 12px; border-radius: 8px; border: 2px solid rgba(255,255,255,.4); background: rgba(0,0,0,.25); color: var(--on-stage); }
.r-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.btn { border: 2.5px solid var(--on-stage); background: transparent; color: var(--on-stage); border-radius: 10px; padding: 13px 10px; font-weight: 800; font-size: 16px; cursor: pointer; }
.btn.primary { grid-column: 1 / -1; background: var(--panel); color: var(--ink); border-color: var(--panel); font: 400 21px/1 var(--display); padding: 16px 10px 14px; }
.r-env { margin: 12px 0 0; font-size: 12px; line-height: 1.5; opacity: .72; }
.toast { position: absolute; z-index: 40; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: #fff; color: #111; border: 2px solid #111; font-weight: 700; font-size: 14px; padding: 9px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 860px) {
  .top { padding: 18px 28px; }
  .top h1 { font-size: 17px; }
  .result-in { flex-direction: row; align-items: flex-start; justify-content: center; gap: 40px; padding-top: 80px; }
  .card-wrap { width: min(420px, calc((100svh - 120px) * .8)); flex: none; }
  .result-side { padding-top: 12px; }
  .msg { top: 12%; }
  body[data-theme="race"] .msg { bottom: 42%; }
  body[data-theme="race"] .stamp { top: 78%; }
  .go-word { top: 20%; }
  .d-hand { height: 58%; }
  .d-opp { height: 44%; }
}
@media (min-width: 860px) and (min-height: 700px) { :root { --dock-h: 112px; } }

@media (prefers-reduced-motion: reduce) {
  .scene.waiting .d-tumble, .scene.shake .c-box, .r-car .rain { animation: none; }
  .scene.launched .r-car, .d-opp .opp-body, .d-opp .opp-hat { transition: none; }
  .stamp.show, .result { animation: none; }
}

/* 아래 안내 본문 */
.guide { position: relative; background: var(--panel); color: var(--ink); border-top: 3px solid var(--ink); content-visibility: auto; contain-intrinsic-size: auto 2200px; }
.guide-in { max-width: 700px; margin: 0 auto; padding: 44px 20px 56px; }
.guide h2 { font: 400 26px/1.25 var(--display); margin: 0 0 14px; }
.guide h3 { font: 800 19px/1.35 var(--body); margin: 34px 0 10px; }
.guide p, .guide li, .guide dd { font-size: 16px; line-height: 1.75; word-break: keep-all; }
.guide p { margin: 0 0 12px; }
.guide a { color: var(--ink); text-underline-offset: 3px; }
.guide ul, .guide ol { padding-left: 1.2em; margin: 0; }
.guide li { margin-bottom: 8px; }
.guide .facts { list-style: none; padding: 0; }
.guide .facts li { padding: 10px 0 10px 14px; border-left: 4px solid var(--accent); margin-bottom: 10px; }
.guide .facts b, .guide-steps b { display: block; font-size: 17px; }
.guide .facts a { font-size: 14px; color: var(--ink-2); display: inline-block; }
.guide dl { margin: 0; }
.guide .qa { padding: 12px 0; border-bottom: 1.5px solid rgba(0,0,0,.14); }
.guide dt { font-weight: 800; font-size: 17px; margin-bottom: 4px; }
.guide dd { margin: 0; }
.guide-more ul { list-style: none; padding: 0; }
.guide-more a { display: block; text-decoration: none; padding: 10px 0; border-bottom: 1.5px solid rgba(0,0,0,.14); }
.guide-more b { display: block; font-size: 17px; }
.site-foot { margin-top: 36px; font-size: 14px; color: var(--ink-2); }
.site-foot a { color: inherit; }
.site-foot .sep { margin: 0 8px; }
.fallback { position: fixed; inset: auto 0 0 0; padding: 14px; background: #fff; color: #111; text-align: center; margin: 0; z-index: 50; }
