:root {
  --blue: #0740E4; --navy: #0B1B3F; --red: #D9262B; --gold: #F7C844; --snow: #F6F9FF; --ink: #0B1B3F;
  --sans: "Pretendard Variable", Pretendard, -apple-system, system-ui, sans-serif;
  --disp: "Bagel Fat One", "Pretendard Variable", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #BFD3F0; color: var(--ink); font-family: var(--sans); -webkit-tap-highlight-color: transparent; }
body { touch-action: none; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font: 700 12px/1 var(--sans); background: #fff; border: 1px solid #C9D3E6; border-bottom-width: 2px; border-radius: 5px; padding: 2px 5px; margin: 0 1px; }

/* 화면들 */
.screen { position: fixed; inset: 0; display: none; place-items: center; padding: 16px; z-index: 20; background: radial-gradient(120% 90% at 50% 10%, rgba(11,27,63,.15), rgba(11,27,63,.55)); overflow: auto; }
.screen.show { display: grid; }
.card, .title-card, .load-card { background: var(--snow); border-radius: 22px; box-shadow: 0 20px 60px rgba(11,27,63,.35), inset 0 0 0 1px rgba(255,255,255,.7); padding: 26px 24px; width: min(460px, 100%); text-align: center; }

#loading { background: linear-gradient(180deg, #2E5FA8, #9CC1EE 70%, #F2E6E4); }
.load-title { font: 400 64px/1 var(--disp); color: var(--blue); letter-spacing: .02em; }
.load-bar { height: 10px; background: #DDE6F5; border-radius: 99px; overflow: hidden; margin: 18px 0 10px; }
.load-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--red), var(--gold)); transition: width .2s; }
#loadText { margin: 0; color: #4A5878; font-size: 14px; }

#title { background: linear-gradient(180deg, rgba(11,27,63,.05), rgba(11,27,63,.45)); }
.title-card { width: min(520px, 100%); padding: 22px 22px 18px; }
.brand-row { display: inline-flex; align-items: center; gap: 8px; font-weight: 900; font-size: 18px; color: var(--blue); background: #fff; padding: 6px 14px 6px 8px; border-radius: 99px; box-shadow: 0 2px 10px rgba(7,64,228,.15); }
.brand-row { padding: 8px 16px; }
.brand-logo { display: block; height: 22px; width: auto; }
.brand-x { color: #9AA6BD; font-weight: 500; }
.brand-ppl { color: var(--ink); letter-spacing: .04em; }
h1 { margin: 12px 0 6px; line-height: 1; }
h1 .t1 { display: block; font: 400 clamp(64px, 18vw, 96px)/.95 var(--disp); color: var(--red); text-shadow: 0 4px 0 #8E1418, 0 10px 24px rgba(217,38,43,.35); letter-spacing: .03em; }
h1 .t2 { display: block; font-weight: 900; font-size: 20px; margin-top: 10px; color: var(--ink); }
.lead { margin: 8px auto 14px; max-width: 34em; color: #3D4A66; font-size: 15px; line-height: 1.55; word-break: keep-all; }
.paint { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; margin-bottom: 14px; }
.paint-label { font-size: 13px; color: #5B6886; margin-right: 2px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid #D2DBEC; background: #fff; border-radius: 99px; padding: 6px 12px 6px 7px; font-size: 13px; font-weight: 700; }
.chip i { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.chip.on { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(7,64,228,.15); }
.big-btn { display: block; width: 100%; border: 0; border-radius: 16px; padding: 16px; font-weight: 900; font-size: 20px; color: #fff; background: linear-gradient(180deg, #2B66FF, var(--blue)); box-shadow: 0 6px 0 #04269A, 0 12px 24px rgba(7,64,228,.35); margin: 6px 0 12px; transition: transform .08s, box-shadow .08s; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #04269A, 0 6px 14px rgba(7,64,228,.3); }
.big-btn:focus-visible, .ghost-btn:focus-visible, .chip:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.ghost-btn { display: block; width: 100%; border: 1.5px solid #D2DBEC; background: #fff; border-radius: 14px; padding: 12px; font-weight: 800; font-size: 15px; margin-top: 8px; text-decoration: none; color: var(--ink); }
.howto { text-align: left; background: #fff; border-radius: 14px; padding: 10px 14px; font-size: 13px; color: #33405C; }
.howto summary { font-weight: 800; cursor: pointer; }
.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.howto ul { margin: 6px 0 0; padding-left: 16px; line-height: 1.75; }
.tips { border-top: 1px dashed #D2DBEC; padding-top: 6px; }
.best { margin: 10px 0 0; font-weight: 800; color: var(--blue); font-size: 14px; min-height: 1em; }
.fine { margin: 6px 0 0; font-size: 11.5px; color: #7A86A0; line-height: 1.6; }
.fine a { color: inherit; }
@media (max-width: 420px) { .howto-grid { grid-template-columns: 1fr; } }

/* HUD */
#hud, #pad { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 10; }
body.racing #hud { display: block; }
body.racing.touch #pad { display: block; }
.hud-tl { position: absolute; left: calc(14px + var(--safe-l)); top: calc(12px + var(--safe-t)); }
.lap { font: 400 30px/1 var(--disp); color: #fff; text-shadow: 0 2px 0 rgba(11,27,63,.6), 0 0 12px rgba(11,27,63,.4); }
.lap .k { font-size: 16px; margin-right: 6px; }
.lap .of { font-size: 18px; opacity: .85; }
.board { list-style: none; margin: 10px 0 0; padding: 0; font-weight: 800; font-size: 13px; }
.board li { display: flex; align-items: center; gap: 6px; background: rgba(11,27,63,.55); color: #fff; padding: 3px 10px 3px 4px; border-radius: 99px; margin-bottom: 3px; width: max-content; min-width: 112px; transition: transform .25s; }
.board li .p { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: rgba(255,255,255,.18); font-size: 12px; }
.board li .c { width: 9px; height: 9px; border-radius: 50%; }
.board li.me { background: var(--red); }
.board li.me .p { background: #fff; color: var(--red); }
.hud-tr { position: absolute; right: calc(14px + var(--safe-r)); top: calc(12px + var(--safe-t)); text-align: right; }
.time { font: 400 28px/1 var(--disp); color: #fff; text-shadow: 0 2px 0 rgba(11,27,63,.6); font-variant-numeric: tabular-nums; }
.laps { font-weight: 800; font-size: 12px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); margin-top: 4px; min-height: 14px; }
.laps div.new { color: var(--gold); }
#minimap { width: 128px; height: 128px; margin-top: 8px; filter: drop-shadow(0 2px 6px rgba(11,27,63,.35)); }
.item-slot { position: absolute; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%); width: 76px; height: 76px; border-radius: 20px; background: rgba(255,255,255,.88); box-shadow: 0 0 0 4px rgba(11,27,63,.25), 0 6px 18px rgba(11,27,63,.3); display: grid; place-items: center; }
.item-slot[data-empty="1"] { background: rgba(255,255,255,.35); }
.item-icon { width: 56px; height: 56px; background-size: contain; background-repeat: no-repeat; background-position: center; }
.item-name { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-weight: 800; font-size: 12px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.item-slot.spin .item-icon { animation: roul .12s steps(1) infinite; }
@keyframes roul { 50% { filter: hue-rotate(160deg) saturate(1.4); transform: scale(.9); } }
.hud-bottom { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); width: min(360px, 60vw); text-align: center; }
.speed { color: #fff; text-shadow: 0 2px 0 rgba(11,27,63,.55); }
.speed b { font: 400 40px/1 var(--disp); font-variant-numeric: tabular-nums; }
.speed span { font-weight: 800; font-size: 13px; margin-left: 4px; }
.gauge { height: 12px; border-radius: 99px; background: rgba(11,27,63,.45); box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); overflow: hidden; margin-top: 4px; }
.gauge i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #47B4FF, #8F7BFF, #FF4FA0); border-radius: 99px; }
.nitros { display: flex; justify-content: center; gap: 8px; margin-top: 6px; align-items: center; }
.nitros .n { width: 34px; height: 16px; border-radius: 6px; background: rgba(11,27,63,.35); box-shadow: inset 0 0 0 2px rgba(255,255,255,.5); }
.nitros .n.on { background: linear-gradient(90deg, #47B4FF, #FF4FA0); box-shadow: 0 0 10px #8F7BFF; }
.nitros .candy { color: #fff; font-weight: 900; text-shadow: 0 1px 3px rgba(0,0,0,.6); margin-left: 6px; font-size: 14px; }
.rank { position: absolute; right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); font: 400 72px/1 var(--disp); color: #fff; -webkit-text-stroke: 3px var(--navy); paint-order: stroke; text-shadow: 0 5px 0 var(--navy); }
.rank span { font-size: 30px; margin-left: 2px; }
.rank.r1 { color: var(--gold); }
.center-msg { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font: 400 clamp(54px, 14vw, 120px)/1 var(--disp); color: #fff; -webkit-text-stroke: 4px var(--red); paint-order: stroke; text-shadow: 0 8px 0 #8E1418; opacity: 0; transform: scale(.6); transition: opacity .15s, transform .25s cubic-bezier(.2,1.6,.4,1); }
.center-msg.show { opacity: 1; transform: scale(1); }
.center-msg.small { font-size: clamp(30px, 7vw, 54px); -webkit-text-stroke-width: 3px; }
.toast { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); font-weight: 900; font-size: 20px; color: #fff; text-shadow: 0 2px 0 rgba(11,27,63,.7), 0 0 14px rgba(11,27,63,.5); opacity: 0; transition: opacity .2s; white-space: nowrap; }
.toast.show { opacity: 1; }
.wrong { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); font: 400 44px/1 var(--disp); color: #FFE14A; -webkit-text-stroke: 3px #A11; paint-order: stroke; display: none; animation: blink .5s steps(1) infinite; }
.wrong.show { display: block; }
@keyframes blink { 50% { opacity: 0; } }
.speedlines { position: absolute; inset: 0; opacity: 0; background: repeating-conic-gradient(from 0deg at 50% 55%, rgba(255,255,255,.0) 0deg 4deg, rgba(255,255,255,.55) 4.4deg 4.8deg, rgba(255,255,255,0) 5.2deg 9deg); -webkit-mask: radial-gradient(circle at 50% 55%, transparent 32%, #000 70%); mask: radial-gradient(circle at 50% 55%, transparent 32%, #000 70%); transition: opacity .2s; }
.pause-btn { pointer-events: auto; position: absolute; right: calc(156px + var(--safe-r)); top: calc(14px + var(--safe-t)); width: 38px; height: 38px; border-radius: 12px; border: 0; background: rgba(11,27,63,.45); color: #fff; font-weight: 900; letter-spacing: -2px; }

/* 휴대폰 조작 버튼: 엄지가 닿기 쉽게 크게, 화면 가장자리(제스처 영역)에서 안쪽으로 */
#pad { --pad-x: calc(22px + var(--safe-l)); --pad-xr: calc(22px + var(--safe-r)); --pad-b: calc(26px + var(--safe-b)); }
.pad-left, .pad-right { position: absolute; bottom: var(--pad-b); pointer-events: auto; }
.pad-left { left: var(--pad-x); display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.pad-right { right: var(--pad-xr); display: grid; grid-template-columns: auto auto; gap: 12px; justify-items: center; align-items: end; }
.pad-right .drift { grid-column: 1 / span 2; grid-row: 2; }
.pbtn { width: 80px; height: 80px; border-radius: 50%; border: 0; background: rgba(255,255,255,.28); box-shadow: inset 0 0 0 2.5px rgba(255,255,255,.75), 0 4px 12px rgba(11,27,63,.25); color: #fff; font-weight: 900; font-size: 26px; text-shadow: 0 1px 3px rgba(0,0,0,.4); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); touch-action: none; padding: 0; }
.pbtn.on { background: rgba(255,255,255,.6); transform: scale(.95); }
.pbtn.small { width: 64px; height: 64px; font-size: 13px; }
.pbtn.small.brake { width: 108px; height: 46px; border-radius: 23px; font-size: 14px; }
.pbtn.drift { width: 112px; height: 112px; font-size: 17px; background: rgba(217,38,43,.55); }
.pbtn.drift.on { background: rgba(217,38,43,.85); }
.pbtn.nitro { background: rgba(143,123,255,.5); }
/* 조향 패드: 누른 채 좌우로 밀면 그만큼 꺾인다(가운데는 직진) */
.steerpad { position: relative; width: min(260px, 50vw); height: 96px; border-radius: 48px; background: rgba(255,255,255,.22); box-shadow: inset 0 0 0 2.5px rgba(255,255,255,.75), 0 4px 12px rgba(11,27,63,.25); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); touch-action: none; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; color: #fff; font-size: 24px; text-shadow: 0 1px 3px rgba(0,0,0,.4); }
.steerpad.on { background: rgba(255,255,255,.34); }
.steerpad .arr { pointer-events: none; opacity: .9; }
.steerpad .knob { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 2px 8px rgba(11,27,63,.35); pointer-events: none; transition: transform .08s; }
.steerpad.on .knob { transition: none; background: #fff; }
body.touch .hud-bottom { bottom: calc(196px + var(--safe-b)); width: min(220px, 56vw); }
body.touch .rank { bottom: auto; top: calc(178px + var(--safe-t)); font-size: 52px; }
body.touch .rank span { font-size: 22px; }
body.touch #minimap { width: 100px; height: 100px; }
body.touch .board { display: none; }
body.touch .pause-btn { right: auto; left: calc(14px + var(--safe-l)); top: calc(52px + var(--safe-t)); }
/* 좁은 휴대폰 */
@media (max-width: 380px) {
  #pad { --pad-x: calc(14px + var(--safe-l)); --pad-xr: calc(14px + var(--safe-r)); }
  .steerpad { width: 52vw; height: 92px; } .pbtn.drift { width: 100px; height: 100px; } .pbtn.small { width: 58px; height: 58px; }
}
/* 가로로 눕힌 휴대폰: 양손 엄지 자리. 가장자리에서 더 안쪽, 브레이크는 패드 옆 위 */
@media (orientation: landscape) and (max-height: 520px) {
  #pad { --pad-x: calc(40px + var(--safe-l)); --pad-xr: calc(40px + var(--safe-r)); --pad-b: calc(20px + var(--safe-b)); }
  .steerpad { width: min(260px, 30vw); height: 88px; }
  .pbtn.drift { width: 100px; height: 100px; } .pbtn.small { width: 56px; height: 56px; } .pbtn.brake { height: 40px; }
  body.touch .hud-bottom { bottom: calc(10px + var(--safe-b)); width: min(200px, 26vw); }
  body.touch .rank { top: calc(98px + var(--safe-t)); right: auto; left: calc(14px + var(--safe-l)); font-size: 44px; }
}

/* 결과 */
.result-card h2 { margin: 2px 0 0; font: 400 86px/1 var(--disp); color: var(--red); }
.result-card h2 small { font-size: 32px; margin-left: 4px; }
.r-kicker { margin: 0; font: 400 18px/1 var(--disp); color: var(--blue); letter-spacing: .2em; }
.r-time { margin: 6px 0 0; font: 400 26px/1.2 var(--disp); }
.r-best { margin: 4px 0 10px; font-weight: 800; color: var(--blue); min-height: 1.2em; }
.r-table { list-style: none; padding: 0; margin: 0 0 12px; text-align: left; font-size: 14px; }
.r-table li { display: grid; grid-template-columns: 26px 12px 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 10px; }
.r-table li:nth-child(odd) { background: #EEF2FA; }
.r-table li.me { background: #FFE3E3; font-weight: 900; }
.r-table .c { width: 10px; height: 10px; border-radius: 50%; }
.r-table .t { font-variant-numeric: tabular-nums; font-weight: 700; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: #fff; margin: 0; }
