/* ===========================================================
   Luna Mini4WD Workshop 3D — UI (밝은 실버 + 레이싱 레드/옐로)
   =========================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
    font-family: 'Space Grotesk', 'Pretendard Variable', -apple-system, sans-serif;
    background: #f3f5f9;
    color: #1c222e;
    -webkit-user-select: none; user-select: none;
}

#app3d { position: fixed; inset: 0; }
#app3d canvas { display: block; }

/* ── 부트 로더 ── */
#boot {
    position: fixed; inset: 0; z-index: 100;
    background: #f3f5f9;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; transition: opacity .6s;
}
#boot.off { opacity: 0; pointer-events: none; }
#boot .car-ico { font-size: 58px; animation: vroom 1.2s ease-in-out infinite; }
@keyframes vroom {
    0%, 100% { transform: translateX(-14px) rotate(-2deg); }
    50% { transform: translateX(14px) rotate(2deg); }
}
#boot .bar { width: 220px; height: 8px; border-radius: 4px; background: #dde3ec; overflow: hidden; }
#boot .bar i { display: block; height: 100%; width: 40%; border-radius: 4px;
    background: linear-gradient(90deg, #e04545, #f5a623); animation: load 1.1s ease-in-out infinite; }
@keyframes load { 0% { transform: translateX(-100%); } 100% { transform: translateX(560%); } }
#boot small { color: #6a7486; font-size: 14px; }

/* ── 상단바 ── */
#topbar {
    position: fixed; top: 0; left: 0; right: 0; height: 50px; z-index: 40;
    display: flex; align-items: center; gap: 8px; padding: 0 12px;
    background: rgba(255,255,255,0.86);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #dfe4ec;
}
.tb-title { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 7px; }
.tb-title .beta {
    font-size: 10px; font-weight: 700; letter-spacing: .08em; color: #fff;
    background: linear-gradient(90deg, #e04545, #f5a623);
    padding: 2px 7px; border-radius: 20px;
}
.tb-sp { flex: 1; }
.tb-btn {
    height: 34px; padding: 0 12px; border-radius: 9px; border: 1px solid #d5dce6;
    background: #fff; color: #2a3242; font: 600 13px 'Space Grotesk', sans-serif;
    cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
    text-decoration: none; transition: all .15s;
}
.tb-btn:hover { border-color: #aab6c8; transform: translateY(-1px); }
.tb-btn.icon { width: 34px; padding: 0; justify-content: center; }
.tb-btn.on { background: #223252; color: #ffd257; border-color: #223252; }

/* ── 패널 공통 ── */
.panel {
    position: fixed; z-index: 30; width: 268px;
    background: rgba(255,255,255,0.94);
    backdrop-filter: blur(8px);
    border: 1px solid #dfe4ec; border-radius: 14px;
    box-shadow: 0 10px 32px rgba(28,34,46,0.12);
    overflow: hidden;
}
#panelDash { width: 300px; }
.p-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 9px 13px; font-weight: 700; font-size: 13.5px;
    background: linear-gradient(180deg, #f7f9fc, #eef1f6);
    border-bottom: 1px solid #e4e9f0; cursor: grab; touch-action: none;
}
.p-head:active { cursor: grabbing; }
.p-fold {
    width: 22px; height: 22px; border: none; border-radius: 6px; cursor: pointer;
    background: #e4e9f0; color: #4a5468; font-weight: 700;
}
.panel.folded .p-body { display: none; }
.p-body { padding: 11px 13px; max-height: calc(100vh - 140px); overflow-y: auto; }
.p-body::-webkit-scrollbar { width: 5px; }
.p-body::-webkit-scrollbar-thumb { background: #cdd5e0; border-radius: 3px; }

/* ── 조립 단계 ── */
.prog { height: 8px; border-radius: 4px; background: #e4e9f0; overflow: hidden; }
.prog i { display: block; height: 100%; width: 0; border-radius: 4px;
    background: linear-gradient(90deg, #2a9d5c, #7fd0a0); transition: width .35s; }
.prog-label { text-align: right; font-size: 11px; color: #6a7486; margin: 3px 0 7px; }
#stepList { list-style: none; display: flex; flex-direction: column; gap: 3px; }
#stepList li {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 8px; border-radius: 8px; font-size: 12.5px; color: #8a94a6;
}
#stepList li .ic { width: 20px; text-align: center; }
#stepList li.done { color: #2a9d5c; }
#stepList li.cur {
    background: #fff6df; color: #1c222e; font-weight: 700;
    outline: 1.5px solid #f0c65a;
    animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { outline-color: #f0c65a; } 50% { outline-color: #ffdf9a; } }
.p-sub { margin: 12px 0 6px; font-weight: 700; font-size: 12.5px; color: #4a5468; }
#missionList { list-style: none; display: flex; flex-direction: column; gap: 4px; }
#missionList li { display: flex; gap: 8px; font-size: 12px; color: #8a94a6; padding: 3px 6px; }
#missionList li.done { color: #b8860b; font-weight: 600; }

/* ── 계기판 ── */
#scm { width: 100%; background: #fbfcfe; border: 1px solid #e4e9f0; border-radius: 10px; margin-bottom: 10px; }
.ro-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.ro {
    background: #f4f6fa; border: 1px solid #e4e9f0; border-radius: 9px;
    padding: 6px 9px; display: flex; flex-direction: column; gap: 1px;
}
.ro.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; }
.ro-name { font-size: 10.5px; color: #6a7486; }
.ro-val { font-size: 14.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ro-val.big { color: #b8860b; }
.ro-val.hot1 { color: #d97a2b; }
.ro-val.hot2 { color: #d92b2b; animation: blink .8s step-end infinite; }
@keyframes blink { 50% { opacity: 0.45; } }

.rh-row { display: flex; align-items: center; gap: 9px; margin-bottom: 5px; }
.rh-label { font-size: 12px; font-weight: 600; color: #4a5468; white-space: nowrap; }
.rh-row input[type=range] { flex: 1; accent-color: #e04545; }
.rh-row b { font-size: 12.5px; min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.formula {
    text-align: center; font-size: 12px; color: #7a5a18;
    background: #fff6df; border-radius: 8px; padding: 4px; margin-bottom: 10px;
}

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.act {
    height: 40px; border-radius: 10px; border: 1px solid #d5dce6; background: #fff;
    font: 600 12.5px 'Space Grotesk', sans-serif; color: #2a3242; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    transition: all .15s;
}
.act:hover:not(:disabled) { transform: translateY(-1px); border-color: #aab6c8; }
.act:disabled { opacity: 0.4; cursor: not-allowed; }
.act.big { grid-column: 1 / -1; height: 46px; font-size: 15px; }
.act.big.on { background: #2a9d5c; border-color: #2a9d5c; color: #fff; }
.act.on { background: #223252; border-color: #223252; color: #ffd257; }
.act.danger { color: #c03030; }
.act.danger-on { background: #c03030; border-color: #c03030; color: #fff; animation: blink .5s step-end infinite; }
.act.race.on { background: #e04545; border-color: #e04545; color: #fff; }
.act.body.on { background: #8f5ad6; border-color: #8f5ad6; color: #fff; }

/* ── 개러지 ── */
#panelGarage { width: 320px; }
.g-sec { margin-bottom: 9px; }
.g-label { font-size: 11.5px; font-weight: 700; color: #4a5468; margin-bottom: 4px; }
.g-opts { display: flex; flex-wrap: wrap; gap: 4px; }
.g-opt {
    padding: 4px 9px; border-radius: 8px; border: 1.5px solid #d5dce6; background: #fff;
    font: 600 11.5px 'Space Grotesk', sans-serif; color: #4a5468; cursor: pointer;
    display: inline-flex; align-items: center; gap: 5px;
}
.g-opt .sw { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.g-opt.sel { border-color: #223252; background: #223252; color: #ffd257; }
.g-stats {
    background: #f4f6fa; border: 1px solid #e4e9f0; border-radius: 10px;
    padding: 8px 10px; margin: 10px 0; font-size: 11.5px;
}
.g-bar-row { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.g-bar-row .nm { width: 74px; color: #6a7486; font-weight: 600; }
.g-bar { flex: 1; height: 7px; border-radius: 4px; background: #e4e9f0; overflow: hidden; }
.g-bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, #2b6fb3, #59c7ff); }
.g-bar i.warn { background: linear-gradient(90deg, #d97a2b, #d92b2b); }
.g-bar-row .vv { width: 66px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.g-verdict { margin-top: 6px; font-size: 11px; font-weight: 700; }
.g-verdict.ok { color: #2a9d5c; }
.g-verdict.risk { color: #d92b2b; }
.g-duel { border-top: 1px dashed #d5dce6; padding-top: 8px; }
.g-code-row { display: flex; gap: 6px; margin: 5px 0; }
.g-code-row code {
    flex: 1; background: #1c222e; color: #ffd257; border-radius: 7px;
    padding: 5px 8px; font-size: 11.5px; overflow: hidden; white-space: nowrap;
}
.g-code-row input {
    flex: 1; border: 1.5px solid #d5dce6; border-radius: 7px; padding: 5px 8px;
    font: 600 11.5px 'Space Grotesk', sans-serif;
}
.mini {
    padding: 4px 10px; border-radius: 7px; border: 1px solid #d5dce6; background: #fff;
    font: 700 11px 'Space Grotesk', sans-serif; cursor: pointer;
}
.g-code-msg { font-size: 11px; color: #2a9d5c; min-height: 14px; }

/* ── 오버레이/모달 ── */
.overlay {
    position: fixed; inset: 0; z-index: 60; display: none;
    align-items: center; justify-content: center;
    background: rgba(28,34,46,0.45); backdrop-filter: blur(3px);
}
.overlay.show { display: flex; }
.modal {
    width: min(480px, 92vw); background: #fff; border-radius: 18px;
    padding: 22px 24px; box-shadow: 0 24px 60px rgba(28,34,46,0.35);
}
.modal h2 { font-size: 19px; margin-bottom: 14px; }
.modal-note { font-size: 12px; color: #6a7486; line-height: 1.5; margin: 10px 0 14px; }
.modal-btns { display: flex; gap: 8px; }
.modal-btns .act.big { flex: 1; }
.rival-card {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 12px; margin-bottom: 6px; border-radius: 12px;
    border: 2px solid #e4e9f0; background: #f8fafc; cursor: pointer;
    font: 600 13.5px 'Space Grotesk', sans-serif; text-align: left;
}
.rival-card.sel { border-color: #e04545; background: #fff2f0; }
.rival-card .rv-spec { margin-left: auto; font-size: 11px; color: #8a94a6; font-weight: 500; }
#resultTable { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
#resultTable td, #resultTable th {
    padding: 7px 8px; font-size: 13px; border-bottom: 1px solid #eef1f6; text-align: left;
    font-variant-numeric: tabular-nums;
}
#resultTable tr.me { background: #fff6df; font-weight: 700; }

/* ── 레이스 HUD ── */
#raceHUD { display: none; }
body.racing #raceHUD { display: block; }
body.racing .panel, body.racing #noteCard { display: none !important; }
.hud-top {
    position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
    display: flex; gap: 8px; z-index: 45;
}
.hud-chip {
    background: rgba(28,34,46,0.88); color: #fff; border-radius: 20px;
    padding: 7px 14px; font: 600 13.5px 'Space Grotesk', sans-serif;
}
.hud-chip b { color: #ffd257; }
.hud-speed {
    position: fixed; left: 22px; bottom: 22px; z-index: 45;
    background: rgba(28,34,46,0.88); color: #fff; border-radius: 16px;
    padding: 12px 20px; text-align: center; min-width: 130px;
}
.hud-speed b { font-size: 38px; font-variant-numeric: tabular-nums; }
.hud-speed small { margin-left: 5px; color: #8a94a6; }
.hud-speed #hudWarn {
    display: none; margin-top: 3px; font-size: 12px; font-weight: 700; color: #ff7a6a;
    animation: blink .4s step-end infinite;
}
.hud-speed.warn #hudWarn { display: block; }
.hud-standings {
    position: fixed; right: 18px; top: 108px; z-index: 45;
    display: flex; flex-direction: column; gap: 5px;
}
.stand-row {
    background: rgba(28,34,46,0.85); color: #fff; border-radius: 10px;
    padding: 6px 12px; font: 600 12.5px 'Space Grotesk', sans-serif;
    display: flex; gap: 8px; align-items: center; min-width: 170px;
}
.stand-row.me { outline: 2px solid #ffd257; }
.stand-row .gap { margin-left: auto; color: #8a94a6; font-size: 11px; }
#raceExit { position: fixed; right: 18px; bottom: 22px; z-index: 45; }

#countdown {
    position: fixed; inset: 0; z-index: 55; display: none;
    align-items: center; justify-content: center; pointer-events: none;
    font: 800 120px 'Space Grotesk', sans-serif; color: #ffd257;
    text-shadow: 0 8px 40px rgba(0,0,0,0.4);
}
#countdown.show { display: flex; }

#shortAlarm {
    position: fixed; top: 110px; left: 50%; transform: translateX(-50%); z-index: 36;
    background: #c03030; color: #fff; font: 700 14px 'Space Grotesk', sans-serif;
    padding: 10px 20px; border-radius: 12px; opacity: 0; pointer-events: none;
    box-shadow: 0 8px 26px rgba(192,48,48,0.4);
    transition: opacity .2s; animation: shake .35s linear infinite;
}
#shortAlarm.show { opacity: 1; }
@keyframes shake { 0%,100% { margin-left: 0; } 25% { margin-left: -4px; } 75% { margin-left: 4px; } }

#noteCard {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
    z-index: 35; max-width: min(620px, 92vw);
    background: rgba(28,34,46,0.92); color: #f2f5fa;
    font-size: 13.5px; line-height: 1.55;
    padding: 12px 18px; border-radius: 14px;
    display: flex; gap: 10px; align-items: flex-start;
    opacity: 0; pointer-events: none; transition: all .35s;
    backdrop-filter: blur(6px);
}
#noteCard.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#noteCard .bulb { font-size: 18px; }

/* 좁은 화면 */
@media (max-width: 860px) {
    .panel { width: 230px; }
    #panelDash { width: 266px; }
    .tb-btn span { display: none; }
    .tb-btn { padding: 0 9px; }
}
