:root {
  --bg: #050a16;
  --glass: rgba(8, 14, 30, 0.72);
  --glass-2: rgba(20, 32, 64, 0.65);
  --line: rgba(120, 170, 255, 0.18);
  --text: #eef3ff;
  --muted: #8fa0c8;
  --blue: #00a2e9;
  --blue-2: #39c2ff;
  --volt: #ffd400;
  --good: #3ddc84;
  --bad: #ff5a5f;
  --purple: #b36bff;
  --hd: 'Orbitron', 'Rajdhani', system-ui, sans-serif;
  --tx: 'Rajdhani', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--tx); overflow: hidden; overscroll-behavior: none; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }

/* judul */
.brand { margin: 0; font-family: var(--hd); font-weight: 900; font-size: clamp(34px, 6vw, 72px); letter-spacing: .02em; font-style: italic; line-height: 1; text-shadow: 0 0 30px rgba(0,162,233,.55); }
.brand span { color: var(--blue-2); }
.brand em { color: var(--volt); font-style: italic; }
.brand.small { font-size: clamp(20px, 2.6vw, 30px); }

/* loading */
#loading { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: radial-gradient(ellipse at 50% 35%, #0d2650, #050a16 70%); padding: 24px; text-align: center; }
#loading .logo { height: 56px; opacity: .9; }
.bar { width: min(420px, 80vw); height: 6px; border-radius: 3px; background: rgba(255,255,255,.1); overflow: hidden; }
.bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--volt)); transition: width .2s; }
#loadText { margin: 0; color: var(--muted); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; font-size: 14px; }
.tip { margin: 0; max-width: 520px; color: var(--text); opacity: .75; font-size: 16px; }

/* menu */
#menu { position: fixed; inset: 0; z-index: 20; pointer-events: none; display: flex; flex-direction: column; }
.mhead { pointer-events: auto; display: flex; align-items: center; gap: 24px; padding: max(16px, env(safe-area-inset-top)) 24px 12px; background: linear-gradient(180deg, rgba(5,10,22,.85), transparent); }
#tabs { display: flex; gap: 4px; flex-wrap: wrap; }
#tabs button { background: transparent; border: 0; color: var(--muted); font-weight: 700; font-size: 17px; letter-spacing: .08em; text-transform: uppercase; padding: 8px 14px; transform: skewX(-12deg); border-bottom: 3px solid transparent; }
#tabs button.on { color: var(--text); border-color: var(--volt); background: rgba(255,255,255,.06); }
.panel { pointer-events: auto; margin: 8px 24px 24px; width: min(460px, calc(100% - 48px)); max-height: calc(100% - 110px); overflow-y: auto; touch-action: pan-y; background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px 20px; backdrop-filter: blur(12px); display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 6px 0 0; font-family: var(--hd); font-size: 13px; letter-spacing: .18em; color: var(--blue-2); text-transform: uppercase; }
.modes, .tracks { display: flex; flex-direction: column; gap: 8px; }
.mode, .track { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass-2); color: var(--text); }
.mode b, .track b { font-family: var(--hd); font-size: 15px; letter-spacing: .06em; font-style: italic; }
.mode span, .track span { color: var(--muted); font-size: 14px; font-weight: 600; }
.mode.on, .track.on { border-color: var(--volt); box-shadow: inset 4px 0 0 var(--volt); }
.locked { opacity: .45; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-weight: 700; font-size: 14px; letter-spacing: .04em; }
.field input[type=text], .field input:not([type]) { font: inherit; font-size: 18px; font-weight: 700; color: var(--text); background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; user-select: text; -webkit-user-select: text; }
.field input:focus { outline: 2px solid var(--blue); }
input[type=range] { accent-color: var(--volt); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.check input { width: 20px; height: 20px; accent-color: var(--volt); }
.pbline { color: var(--muted); font-weight: 600; font-size: 15px; min-height: 1.2em; }
.pbline b { color: var(--volt); }
.go { font-family: var(--hd); font-weight: 900; font-style: italic; letter-spacing: .08em; font-size: 18px; padding: 15px; border: 0; border-radius: 8px; color: #04121f; background: linear-gradient(90deg, var(--volt), #ffe970); clip-path: polygon(4% 0, 100% 0, 96% 100%, 0 100%); box-shadow: 0 0 30px rgba(255,212,0,.35); }
.go:active { transform: translateY(2px); }
.ghostbtn { font-weight: 700; font-size: 16px; letter-spacing: .06em; padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass-2); color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass-2); color: var(--text); font-weight: 700; font-size: 15px; text-transform: capitalize; }
.chips button.on { border-color: var(--volt); color: var(--volt); }
.hint { margin: 0; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg button { padding: 10px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--glass-2); color: var(--text); font-weight: 700; font-size: 15px; }
.seg button.on { background: var(--volt); color: #04121f; border-color: var(--volt); }
.board { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.board li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; background: var(--glass-2); font-weight: 700; font-size: 17px; }
.board li b { font-family: var(--hd); color: var(--muted); font-size: 14px; }
.board li:nth-child(1) b { color: var(--volt); }
.board li .t { font-variant-numeric: tabular-nums; color: var(--blue-2); }
.board li.me { outline: 2px solid var(--volt); }
.board .empty { color: var(--muted); padding: 10px; }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; font-family: var(--tx); }
.htl { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.lapbox, .timebox { background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 6px 14px; backdrop-filter: blur(6px); transform: skewX(-10deg); }
.lapbox small, .timebox small { display: block; color: var(--muted); font-weight: 700; letter-spacing: .14em; font-size: 12px; }
.lapbox b { font-family: var(--hd); font-size: 28px; font-style: italic; }
.timebox b { font-family: var(--hd); font-size: 30px; font-variant-numeric: tabular-nums; font-style: italic; }
.timebox span { color: var(--volt); }
.sectors { display: flex; gap: 4px; }
.sec { width: 54px; text-align: center; padding: 3px 0; border-radius: 4px; background: rgba(255,255,255,.12); font-weight: 800; font-size: 13px; color: rgba(255,255,255,.7); transform: skewX(-10deg); }
.sec.green { background: var(--good); color: #032b14; }
.sec.yellow { background: var(--volt); color: #2a2100; }
.sec.purple { background: var(--purple); color: #fff; }
.delta { font-family: var(--hd); font-size: 22px; font-weight: 900; padding: 4px 12px; border-radius: 8px; opacity: 0; transition: opacity .3s; font-variant-numeric: tabular-nums; }
.delta.show { opacity: 1; }
.delta.good { background: rgba(61,220,132,.2); color: var(--good); }
.delta.bad { background: rgba(255,90,95,.2); color: var(--bad); }
#minimap { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px; width: 150px; height: 150px; border-radius: 14px; background: rgba(5,10,22,.45); }
#speedo { position: absolute; right: 12px; bottom: max(10px, env(safe-area-inset-bottom)); width: 200px; height: 182px; }
.hmsg { position: absolute; top: 30%; left: 0; right: 0; text-align: center; font-family: var(--hd); font-weight: 900; font-style: italic; font-size: clamp(36px, 9vw, 96px); color: var(--volt); text-shadow: 0 4px 0 rgba(0,0,0,.5), 0 0 40px rgba(255,212,0,.5); opacity: 0; transition: opacity .2s, transform .2s; transform: scale(.9); }
.hmsg.show { opacity: 1; transform: scale(1); }
.hmsg.small { font-size: clamp(22px, 5vw, 44px); }
.hmsg.blue { color: var(--blue-2); text-shadow: 0 0 30px rgba(57,194,255,.6); }
.pausebtn { pointer-events: auto; position: absolute; top: max(14px, env(safe-area-inset-top)); right: 178px; width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass); color: var(--text); font-size: 15px; }
#rtouch { position: absolute; inset: 0; pointer-events: none; }
.rbtn { position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); background: rgba(8,14,30,.5); color: #fff; font-weight: 800; font-size: 22px; backdrop-filter: blur(4px); }
.rbtn.down { background: rgba(0,162,233,.75); }
.rbtn.left { left: 18px; bottom: max(26px, env(safe-area-inset-bottom)); width: 86px; height: 86px; }
.rbtn.right { left: 114px; bottom: max(26px, env(safe-area-inset-bottom)); width: 86px; height: 86px; }
.rbtn.drift { right: 220px; bottom: max(30px, env(safe-area-inset-bottom)); width: 90px; height: 90px; font-size: 15px; background: rgba(0,162,233,.45); }
.rbtn.brake { right: 230px; bottom: calc(max(30px, env(safe-area-inset-bottom)) + 104px); width: 62px; height: 62px; font-size: 13px; }
@media (pointer: fine) { #rtouch { display: none; } }

/* modal */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(3,6,14,.6); backdrop-filter: blur(6px); }
.card { width: min(380px, 100%); background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 10px; max-height: 100%; overflow-y: auto; touch-action: pan-y; }
.card.wide { width: min(560px, 100%); }
.card h2 { margin: 0 0 4px; font-family: var(--hd); font-style: italic; letter-spacing: .06em; color: var(--volt); }
.resgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.resgrid > div { background: var(--glass-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.resgrid small { color: var(--muted); font-weight: 700; letter-spacing: .12em; font-size: 12px; }
.resgrid b { font-family: var(--hd); font-size: 26px; font-style: italic; }
.resgrid span { color: var(--good); font-weight: 700; font-size: 14px; }
.laps { width: 100%; border-collapse: collapse; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.laps th { text-align: left; color: var(--muted); font-size: 12px; letter-spacing: .12em; padding: 4px 6px; }
.laps td { padding: 6px; border-top: 1px solid var(--line); }
.laps tr.best td:last-child { color: var(--purple); }
.row { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; font-weight: 700; opacity: 0; transition: opacity .3s; pointer-events: none; }
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  .mhead { flex-direction: column; align-items: flex-start; gap: 6px; padding: max(12px, env(safe-area-inset-top)) 16px 6px; }
  #tabs button { font-size: 14px; padding: 6px 9px; }
  .panel { margin: auto 12px max(12px, env(safe-area-inset-bottom)); width: calc(100% - 24px); max-height: 62%; }
  #minimap { width: 104px; height: 104px; }
  #speedo { width: 150px; height: 136px; }
  .pausebtn { right: 128px; }
  .timebox b { font-size: 22px; }
  .lapbox b { font-size: 20px; }
  .sec { width: 40px; font-size: 11px; }
  .rbtn.drift { right: 172px; width: 76px; height: 76px; }
  .rbtn.brake { right: 180px; bottom: calc(max(30px, env(safe-area-inset-bottom)) + 88px); }
}
