:root {
  --bg: #12131a;
  --card: rgba(20, 22, 32, 0.86);
  --ink: #f5f6fa;
  --muted: #9aa0b4;
  --accent: #ffcc00;
  --gas: #3ccf6e;
  --brake: #ff5a36;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border-radius: 16px; padding: 16px; backdrop-filter: blur(6px); }
.code { font-size: 56px; font-weight: 800; letter-spacing: 10px; color: var(--accent); }
.code.sm { font-size: 26px; letter-spacing: 4px; }

/* ---------- host ---------- */
.host canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.lobby { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; width: min(420px, 92vw); }
.lobby h1 { margin: 0 0 4px; font-size: 44px; font-weight: 900; letter-spacing: 2px; }
.lobby h1 span { color: var(--accent); margin-left: 8px; }
.lobby p { margin: 8px 0; }
.lobby img { width: 240px; height: 240px; background: #fff; border-radius: 12px; padding: 8px; }
.hud { position: fixed; bottom: 16px; left: 16px; z-index: 3; align-items: flex-start; display: none; flex-direction: column; gap: 10px; }
.hud.on { display: flex; }
.mini { display: flex; gap: 12px; align-items: center; padding: 10px; }
.mini img { width: 84px; height: 84px; background: #fff; border-radius: 8px; padding: 4px; }
.players { min-width: 220px; padding: 10px 14px; }
.prow { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 15px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.prow .lap { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.prow .ms { width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.ms.ok { color: var(--gas); } .ms.mid { color: var(--accent); } .ms.bad { color: var(--brake); }
.hint { padding-left: 4px; }

/* ---------- pad (HP) ---------- */
.pad { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.join { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; text-align: center; }
.join h1 { margin: 0; font-size: 34px; font-weight: 900; }
.join h1 span { color: var(--accent); margin-left: 6px; }
.join input { width: min(320px, 90vw); font-size: 22px; padding: 12px 14px; border-radius: 12px; border: 2px solid #343850; background: #1c1e2a; color: var(--ink); text-align: center; }
.join input#room { text-transform: uppercase; letter-spacing: 6px; font-weight: 800; }
.join button, .rotate button { font-size: 22px; font-weight: 800; padding: 14px 40px; border-radius: 14px; border: 0; background: var(--accent); color: #12131a; }
.err { color: var(--brake); min-height: 20px; }

.ctrl { position: fixed; inset: 0; display: none; }
.ctrl.on { display: block; }
.topbar { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; font-size: 15px; background: var(--card); padding: 6px 14px; border-radius: 999px; z-index: 2; }
.steer { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; }
.steer .track { position: absolute; left: 8%; right: 8%; top: 50%; height: 14px; margin-top: -7px; border-radius: 7px; background: #2a2d40; }
.steer .knob { position: absolute; top: 50%; left: 50%; width: 96px; height: 96px; margin: -48px 0 0 -48px; border-radius: 50%; background: #3a3f5c; border: 4px solid var(--ink); transition: background .1s; }
.steer .label { position: absolute; bottom: 18px; width: 100%; text-align: center; color: var(--muted); font-size: 14px; }
.btns { position: absolute; right: 0; top: 0; bottom: 0; width: 50%; }
.btn { position: absolute; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 900; font-size: 22px; color: #12131a; opacity: .85; }
.btn.down { opacity: 1; transform: scale(.94); }
#gas { width: 44vh; height: 44vh; max-width: 190px; max-height: 190px; right: 5%; bottom: 7%; background: var(--gas); }
#gas.auto { opacity: .45; }
#drift { width: 32vh; height: 32vh; max-width: 136px; max-height: 136px; right: calc(5% + min(44vh, 190px) + 12px); bottom: 9%; background: #8a6cff; font-size: 18px; }
#drift[data-lvl="1"] { box-shadow: 0 0 0 6px #3ab0ff; } #drift[data-lvl="2"] { box-shadow: 0 0 0 6px #ff9a1f; } #drift[data-lvl="3"] { box-shadow: 0 0 0 6px #c45cff; }
#item { width: 28vh; height: 28vh; max-width: 120px; max-height: 120px; right: 7%; top: 16%; background: #2a2d40; border: 3px dashed #555a78; font-size: 52px; }
#item.has { background: #ffcc00; border: 3px solid #fff; }
#brake { width: 22vh; height: 22vh; max-width: 96px; max-height: 96px; left: 4%; top: 18%; background: var(--brake); font-size: 16px; }
.rotate { position: fixed; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 16px; background: var(--bg); z-index: 5; }
@media (orientation: portrait) { .ctrl.on ~ .rotate { display: flex; } }
.via { font-size: 11px; font-weight: 800; letter-spacing: 1px; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; }
.via.ok { color: var(--gas); } .via.mid { color: var(--accent); }
.prow .via { margin-left: 4px; }

/* ---------- M1: split-screen, banner, hasil ---------- */
#views { position: fixed; inset: 0; pointer-events: none; }
.vhud { position: absolute; border: 2px solid rgba(0,0,0,.35); }
.vtag { position: absolute; top: 10px; left: 12px; display: flex; gap: 8px; align-items: center; background: var(--card); padding: 4px 12px; border-radius: 999px; font-size: 16px; }
.vpos { position: absolute; right: 16px; bottom: 8px; font-size: 44px; font-weight: 900; color: var(--accent); text-shadow: 0 2px 6px rgba(0,0,0,.6); }
.vlap { position: absolute; top: 10px; right: 14px; font-size: 18px; font-weight: 800; background: var(--card); padding: 4px 12px; border-radius: 999px; }
.vitem { position: absolute; top: 48px; left: 12px; font-size: 40px; }
.vhud.single .vtag { top: 16px; left: 50%; transform: translateX(-50%); }
.banner { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 4; pointer-events: none; text-align: center; }
.banner.hidden { display: none; }
.banner.hint { background: var(--card); padding: 8px 18px; border-radius: 999px; font-size: 16px; top: auto; bottom: 16px; }
.banner.timer { background: var(--card); padding: 4px 14px; border-radius: 999px; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; top: auto; bottom: 16px; }
.banner.big { top: 50%; transform: translate(-50%, -50%); font-size: 160px; font-weight: 900; color: var(--accent); text-shadow: 0 6px 20px rgba(0,0,0,.6); }
.banner.go { color: var(--gas); font-size: 140px; }
.results { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, 92vw); z-index: 5; text-align: center; }
.results h2 { margin: 0 0 12px; letter-spacing: 2px; color: var(--accent); }
.rrow { display: flex; align-items: center; gap: 10px; padding: 8px 6px; font-size: 18px; border-bottom: 1px solid #2a2d40; }
.rrow.top { font-size: 22px; font-weight: 700; }
.rrow .rname { flex: 1; text-align: left; }
.rrow .rtime { font-variant-numeric: tabular-nums; color: var(--muted); }

.toggle { font: inherit; font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--muted); background: transparent; color: var(--muted); }
.toggle.on { color: var(--gas); border-color: var(--gas); }
.startbox { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); z-index: 3; width: min(640px, 94vw); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; background: rgba(20,22,32,.96); }
#start { font-size: 22px; font-weight: 900; padding: 12px; border-radius: 14px; border: 0; background: var(--accent); color: #12131a; margin-top: 4px; }
.startbox .x { position: absolute; top: 4px; right: 8px; background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; }
.setrow { display: flex; align-items: center; gap: 10px; }
.setrow > span { width: 64px; flex: none; color: var(--muted); font-size: 13px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.seg button { flex: 1; font: inherit; font-size: 13px; font-weight: 700; padding: 8px 6px; border-radius: 10px; border: 1px solid #343850; background: #1c1e2a; color: var(--ink); white-space: nowrap; }
.seg button.sel { background: var(--accent); color: #12131a; border-color: var(--accent); }
.seg.dis { opacity: .35; pointer-events: none; }
.choose { position: fixed; inset: 0; z-index: 6; background: var(--bg); display: none; flex-direction: column; align-items: center; justify-content: center; padding: 10px 16px; gap: 8px; }
.choose.on { display: flex; }
.choose h2 { margin: 0; font-size: 20px; }
.chargrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(760px, 100%); }
.charcard { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px; border-radius: 12px; border: 2px solid #343850; background: #1c1e2a; color: var(--ink); font: inherit; }
.charcard.sel { border-color: var(--accent); }
.charcard .cicon { font-size: 30px; line-height: 1.1; }
.charcard b { font-size: 16px; }
.charcard small { color: var(--muted); font-size: 11px; }
.charcard .cstat { font-size: 10.5px; color: var(--muted); letter-spacing: .5px; }
@media (orientation: portrait) { .chargrid { grid-template-columns: repeat(2, 1fr); } }
.padmsg { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); color: var(--muted); font-size: 13px; white-space: nowrap; z-index: 2; }
.topbar, .topbar * { white-space: nowrap; }
.topbar { max-width: 96vw; }

/* ---------- M2 ---------- */
.banner .trackname { font-size: 26px; letter-spacing: 2px; color: var(--ink); margin-bottom: -10px; }
.results { max-height: 92vh; overflow-y: auto; }
.results h3 { margin: 14px 0 4px; color: var(--muted); font-size: 14px; letter-spacing: 2px; text-transform: uppercase; }
.rrow .pts { color: var(--gas); margin-left: 6px; }
.vchar { font-size: 18px; }

/* ---------- M3: sambung ulang ---------- */
.reconn { position: fixed; inset: 0; z-index: 7; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: rgba(18,19,26,.88); }
.reconn.on { display: flex; }
.spin { width: 40px; height: 40px; border-radius: 50%; border: 4px solid #343850; border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.soundbtn { position: fixed; top: 50%; right: 12px; transform: translateY(-50%); z-index: 6; font: inherit; font-size: 22px; width: 48px; height: 48px; padding: 0; border-radius: 50%; border: 0; background: var(--card); color: var(--ink); cursor: pointer; }
.results p { margin: 10px 0 0; }
.remote { color: var(--accent); max-width: 380px; margin: 6px auto 0; }

/* ======================================================================
   Online: layar pemain (menu, daftar room, room, HUD balapan)
   ====================================================================== */
.game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.view { position: fixed; inset: 0; z-index: 3; display: none; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.view.on { display: flex; }
.game button { font: inherit; cursor: pointer; }
.game button:disabled { cursor: not-allowed; opacity: .45; }
.big { font-size: 20px; font-weight: 900; letter-spacing: 1px; padding: 12px 28px; border-radius: 14px; border: 0; background: var(--accent); color: #12131a; }
.big.sm { font-size: 15px; padding: 9px 16px; }
.big.on { background: var(--gas); }
.ghostbtn { background: transparent; color: var(--ink); border: 1px solid #343850; border-radius: 10px; padding: 7px 12px; font-size: 14px; }
.ghostbtn:hover { border-color: var(--accent); }
.game input { font: inherit; font-size: 18px; padding: 11px 14px; border-radius: 12px; border: 2px solid #343850; background: #1c1e2a; color: var(--ink); width: 100%; }
.game input:focus { outline: none; border-color: var(--accent); }

.menu { width: min(440px, 100%); text-align: center; padding: 28px 24px; }
.logo { margin: 0; font-size: 54px; font-weight: 900; letter-spacing: 2px; }
.logo span { color: var(--accent); margin-left: 10px; }
.menuform { display: flex; gap: 10px; margin: 18px 0 8px; }
.menuform input { text-align: center; }
.howto { text-align: left; margin: 14px 0 0; padding-left: 20px; line-height: 1.6; }

.rooms { width: min(720px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 12px; }
.vhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.vhead h2 { margin: 0; flex: 1; font-size: 22px; }
.roomlist { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 120px; }
.roomrow { display: grid; grid-template-columns: 1fr auto auto auto; gap: 14px; align-items: center; text-align: left; padding: 14px 16px; border-radius: 12px; border: 1px solid #343850; background: #1c1e2a; color: var(--ink); font-size: 16px; }
.roomrow:hover { border-color: var(--accent); }
.roomrow .cnt { font-weight: 800; font-variant-numeric: tabular-nums; }
.pill { font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 999px; background: #22324a; color: #8cc8ff; }
.pill.race { background: #4a2a22; color: #ffb38a; }
.empty { text-align: center; padding: 28px 0; }

.roomgrid { width: min(1180px, 100%); display: grid; grid-template-columns: 1fr 1.25fr 1fr; grid-template-rows: auto 1fr; gap: 12px; align-items: start; max-height: 100%; }
.rhead { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 16px; }
.rhead h2 { margin: 0; font-size: 22px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.col h3 { margin: 0; font-size: 14px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
.mrow { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid #2a2d40; font-size: 15px; }
.mrow.me { background: rgba(255, 204, 0, .07); border-radius: 8px; }
.mrow b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.micon { font-size: 18px; }
.mpad { font-size: 12px; color: var(--brake); white-space: nowrap; }
.mpad.ok { color: var(--gas); }
.mready { font-size: 11px; font-weight: 900; letter-spacing: 1px; padding: 3px 8px; border-radius: 999px; background: #2a2d40; color: var(--muted); }
.mready.ok { background: var(--gas); color: #12131a; }
.kick { background: transparent; border: 1px solid #5a2a2a; color: var(--brake); border-radius: 8px; width: 28px; height: 28px; padding: 0; }
.kick:hover { background: var(--brake); color: #fff; }
.game .chargrid { grid-template-columns: repeat(3, 1fr); width: 100%; }
.game .charcard { cursor: pointer; padding: 8px 6px; }
.game .charcard:hover:not(:disabled) { border-color: #6a6f90; }
.game .charcard.sel { border-color: var(--accent); background: #2a2614; }
.charcard .bar { display: flex; align-items: center; gap: 6px; width: 100%; font-size: 10px; color: var(--muted); }
.charcard .bar em { font-style: normal; width: 34px; text-align: left; }
.charcard .bar > span { flex: 1; height: 5px; background: #2a2d40; border-radius: 3px; overflow: hidden; }
.charcard .bar i { display: block; height: 100%; background: var(--accent); }
.padbox { display: flex; gap: 14px; align-items: center; background: #1c1e2a; border: 1px dashed #4a4f70; border-radius: 12px; padding: 10px; }
.padbox img { width: 112px; height: 112px; background: #fff; border-radius: 8px; padding: 4px; flex: none; }
.padok { width: 100%; text-align: center; color: var(--gas); font-weight: 700; padding: 6px; }
.padbox .code.sm { margin-top: 4px; }
#readyBtn, #startBtn { width: 100%; }
#vRoom .setrow > span { width: 62px; }
#vRoom .seg button { cursor: pointer; }

.modal { position: fixed; inset: 0; z-index: 9; display: none; align-items: center; justify-content: center; background: rgba(10, 11, 16, .7); padding: 16px; }
.modal.on { display: flex; }
.modal form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; }
.modal h3 { margin: 0 0 4px; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; }
.padbadge { position: fixed; top: 12px; right: 12px; z-index: 4; background: var(--card); padding: 7px 14px; border-radius: 999px; font-size: 13px; border: 1px solid #4a3a1a; max-width: calc(100vw - 24px); }
.padbadge.ok { border-color: #1f5a35; color: var(--gas); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); z-index: 10; background: #2a2d40; padding: 10px 18px; border-radius: 12px; font-weight: 600; opacity: 0; transition: .25s; pointer-events: none; max-width: calc(100vw - 32px); text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* HUD balapan (layar penuh, satu pemain) */
.rhud { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 2; }
body.racing .rhud { display: block; }
.rh-tag { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; background: var(--card); padding: 5px 14px; border-radius: 999px; font-size: 16px; font-weight: 700; }
.rh-lap { position: absolute; top: 14px; right: 16px; font-size: 22px; font-weight: 900; background: var(--card); padding: 5px 14px; border-radius: 999px; }
.rh-item { position: absolute; top: 14px; left: 16px; width: 88px; height: 88px; display: flex; align-items: center; justify-content: center; font-size: 46px; border-radius: 18px; background: var(--card); border: 3px dashed #4a4f70; }
.rh-item.on { border: 3px solid var(--accent); }
.rh-pos { position: absolute; right: 22px; bottom: 14px; font-size: 64px; font-weight: 900; color: var(--accent); text-shadow: 0 3px 10px rgba(0,0,0,.6); }
.board { position: absolute; left: 16px; top: 120px; padding: 8px 12px; min-width: 190px; font-size: 14px; }
.brow { display: flex; align-items: center; gap: 7px; padding: 2px 0; }
.brow b { width: 16px; color: var(--muted); }
.brow .muted { margin-left: auto; }
.brow.me { color: var(--accent); font-weight: 800; }
.rh-warn { position: absolute; left: 50%; top: 58px; transform: translateX(-50%); color: #fff; background: #a3321f; padding: 6px 14px; border-radius: 10px; font-weight: 700; display: none; }
.rh-warn:not(:empty) { display: block; }
.wait { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; text-align: center; width: min(440px, 92vw); display: none; }
.wait.on { display: block; }
.wait h2 { margin: 0 0 6px; color: var(--accent); font-size: 30px; }
.wait p { margin: 6px 0; }
.rrow.me { background: rgba(255, 204, 0, .1); }
@media (max-width: 900px) {
  .roomgrid { grid-template-columns: 1fr; }
  .board { display: none; }
}
.rh-lap:empty, .rh-pos:empty { display: none; }
body.watching .rh-item { display: none; }
.game .toast { bottom: auto; top: 70px; transform: translate(-50%, -20px); }
.game .toast.on { transform: translate(-50%, 0); }
.steer.tilt .track { background: #22324a; }
.steer.tilt .knob { border-color: #3ab0ff; transition: none; }
