:root {
  --panel: rgba(10, 12, 18, 0.62);
  --line: rgba(255, 255, 255, 0.09);
  --txt: #f2f4f8;
  --dim: #8f97a6;
  --red: #ff2d2d;
  --green: #1ed760;
  --purple: #b14dff;
  --yellow: #ffd21f;
  --teal: #19e3c5;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0d12; color: var(--txt);
  font-family: 'Titillium Web', 'Noto Sans Thai', system-ui, sans-serif; user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.panel { background: linear-gradient(180deg, rgba(14,16,24,.78), rgba(10,12,18,.58));
  border: 1px solid var(--line); border-radius: 10px; backdrop-filter: blur(8px);
  box-shadow: 0 8px 30px rgba(0,0,0,.35); }

#hud { position: fixed; inset: 0; pointer-events: none; }

/* timing tower */
#timing { position: absolute; top: 18px; left: 18px; width: 250px; padding: 12px 14px; border-left: 3px solid var(--red); }
#timing .row { display: flex; justify-content: space-between; font-size: 15px; color: var(--dim); font-weight: 600; letter-spacing: .06em; }
#timing .row b { color: var(--txt); font-variant-numeric: tabular-nums; }
#timing .head { font-size: 13px; }
#timing .head b { font-size: 18px; }
#timing .big { font-size: 38px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 2px 0 6px; }
.sectors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 10px; }
.sec { background: rgba(255,255,255,.06); border-radius: 5px; padding: 3px 6px; border-bottom: 3px solid #333a46; }
.sec i { display: block; font-style: normal; font-size: 11px; color: var(--dim); font-weight: 700; }
.sec b { font-size: 14px; font-variant-numeric: tabular-nums; }
.sec.purple { border-color: var(--purple); } .sec.purple b { color: #d7a8ff; }
.sec.green { border-color: var(--green); } .sec.green b { color: #8df5b4; }
.sec.yellow { border-color: var(--yellow); } .sec.yellow b { color: #ffe680; }
.sec.live { border-color: #fff; }

#map { position: absolute; top: 18px; right: 18px; width: 220px; height: 220px; }

/* start lights */
#lights { position: absolute; top: 26px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px;
  padding: 12px 16px; background: rgba(8,8,10,.8); border-radius: 12px; transition: opacity .3s; }
#lights i { width: 40px; height: 40px; border-radius: 50%; background: #2a0b0b; box-shadow: inset 0 3px 8px rgba(0,0,0,.7); }
#lights i.on { background: radial-gradient(circle at 40% 35%, #ffb3a8, #ff1a1a 45%, #a00000); box-shadow: 0 0 22px 6px rgba(255,30,30,.65); }
#lights.off { opacity: 0; }

#msg { position: absolute; top: 24%; left: 0; right: 0; text-align: center; font-size: 54px; font-weight: 900; font-style: italic;
  letter-spacing: .04em; text-shadow: 0 4px 24px rgba(0,0,0,.6); opacity: 0; transition: opacity .25s, transform .25s; transform: scale(.96); }
#msg.show { opacity: 1; transform: scale(1); }
#msg.green { color: #6dffa1; } #msg.red { color: #ff6b6b; } #msg.purple { color: #d59bff; } #msg.small { font-size: 30px; }

/* dashboard */
#dash { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); width: 470px; padding: 12px 16px 12px; }
#leds { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
#leds span { width: 18px; height: 18px; border-radius: 50%; background: #1b1e26; border: 1px solid #000; }
#leds span.g.on { background: #21e36b; box-shadow: 0 0 10px #21e36b; }
#leds span.r.on { background: #ff2b2b; box-shadow: 0 0 10px #ff2b2b; }
#leds span.b.on { background: #6a7bff; box-shadow: 0 0 10px #6a7bff; }
#leds.flash span { background: #6a7bff !important; box-shadow: 0 0 14px #6a7bff !important; }
.dashrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dashrow.small { margin-top: 8px; }
.spd, .rpm { width: 120px; text-align: center; }
.spd b, .rpm b { display: block; font-size: 40px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.rpm b { font-size: 26px; color: #c9d0dc; }
.spd span, .rpm span { font-size: 12px; color: var(--dim); font-weight: 700; letter-spacing: .12em; }
#gear { font-size: 72px; font-weight: 900; line-height: 1; width: 80px; text-align: center; color: #fff;
  text-shadow: 0 0 18px rgba(255,255,255,.25); }
.pedal { width: 10px; height: 64px; background: #1b1e26; border-radius: 5px; position: relative; overflow: hidden; }
.pedal div { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: var(--green); }
.pedal.brk div { background: var(--red); }
.pill { padding: 2px 12px; border-radius: 6px; font-weight: 900; letter-spacing: .1em; background: #1b1e26; color: #555d6c; border: 1px solid #2b303b; }
.pill.avail { color: #9cffbf; border-color: #1ed760; }
.pill.open { background: #1ed760; color: #04230f; border-color: #1ed760; box-shadow: 0 0 14px rgba(30,215,96,.6); }
.pill.aero:not(.open) { color: #8fb4ff; border-color: #2f4f8f; }
.pill.aero.avail:not(.open) { color: #9cffbf; border-color: #1ed760; }
.ers span.ot { color: #ff9be1; }
.chip.act { background: #ffb020; color: #2a1800; }
.ers { display: flex; align-items: center; gap: 8px; flex: 1; }
.ers span { font-size: 12px; font-weight: 700; color: var(--dim); letter-spacing: .1em; }
.ers span.on { color: #ffe066; }
.ers .bar { flex: 1; height: 9px; border-radius: 5px; background: #1b1e26; overflow: hidden; }
#ersFill { height: 100%; width: 100%; background: linear-gradient(90deg, #f7b500, #ffe066); }
.chips { display: flex; gap: 5px; }
.chip { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px; background: #1b1e26; color: #5c6473; }
.chip.on { background: #26364d; color: #9fc6ff; }

/* tyres */
#tyres { position: absolute; bottom: 20px; left: 18px; padding: 10px 14px; }
.tgrid { display: grid; grid-template-columns: 22px 22px; gap: 6px 26px; justify-content: center; }
.tgrid i { width: 22px; height: 34px; border-radius: 6px; background: #3a7bff; }
.tlbl { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 12px; color: var(--dim); font-weight: 700; }

#hint { position: absolute; bottom: 22px; right: 20px; font-size: 13px; color: rgba(255,255,255,.55); }

#help { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 18px 24px; width: 470px; max-width: calc(100% - 32px); }
#help h3 { margin: 0 0 10px; }
#help table { width: 100%; border-collapse: collapse; font-size: 14px; }
#help td { padding: 4px 0; border-bottom: 1px solid var(--line); }
#help td:first-child { width: 120px; font-weight: 700; color: #ffd8d8; }
#help p { font-size: 13px; color: var(--dim); margin: 12px 0 0; }

/* start overlay */
#overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse at center, rgba(5,6,10,.35), rgba(5,6,10,.85)); }
.card { width: 560px; max-width: 100%; padding: 30px 34px; text-align: center; border-radius: 16px;
  background: rgba(12,14,20,.72); border: 1px solid var(--line); backdrop-filter: blur(12px); }
.brand { font-size: 54px; font-weight: 900; font-style: italic; letter-spacing: .02em; line-height: 1; }
.brand .a { color: #fff; } .brand .f { color: var(--red); margin-left: 10px; }
.sub { color: var(--dim); margin: 10px 0 22px; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; text-align: left; font-size: 14px; margin-bottom: 24px; }
kbd { display: inline-block; min-width: 26px; padding: 1px 7px; margin-right: 4px; border-radius: 5px; text-align: center;
  background: #232835; border: 1px solid #3a4152; border-bottom-width: 3px; font-family: inherit; font-weight: 700; font-size: 13px; }
#startBtn { font: inherit; font-size: 20px; font-weight: 700; padding: 12px 44px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--red); color: #fff; box-shadow: 0 6px 24px rgba(255,45,45,.4); transition: transform .15s, filter .15s; }
#startBtn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.1); }
#startBtn:disabled { background: #3a3f4c; box-shadow: none; cursor: wait; }
.note { color: var(--dim); font-size: 13px; margin: 16px 0 0; }

/* menu options */
.opts { display: grid; gap: 10px; margin: 0 0 22px; text-align: left; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; color: #c9d0dc; }
.seg { display: flex; background: #171b24; border: 1px solid #2b3140; border-radius: 8px; padding: 3px; gap: 3px; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; color: #9aa3b2; background: transparent; border: 0; border-radius: 6px; padding: 4px 11px; cursor: pointer; }
.seg button.on { background: var(--red); color: #fff; }
.seg button:hover:not(.on) { background: #232938; }

/* timing tower */
#timing .head span { display: flex; gap: 6px; align-items: baseline; }
#pos { font-size: 22px !important; color: #fff; }
#tower { position: absolute; top: 236px; left: 18px; width: 250px; padding: 6px 0; font-size: 14px; }
.tw { display: grid; grid-template-columns: 26px 4px 1fr auto; align-items: center; gap: 8px; padding: 3px 12px; font-variant-numeric: tabular-nums; }
.tw b { text-align: right; color: var(--dim); }
.tw i { height: 16px; border-radius: 2px; }
.tw span { font-weight: 700; letter-spacing: .05em; }
.tw em { font-style: normal; color: #c9d0dc; font-size: 13px; }
.tw.me { background: rgba(255,255,255,.1); }
.tw.me span { color: #ffe066; }
.tw.fin em { color: #fff; }

/* results */
#results { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(5,6,10,.6); overflow-y: auto; overflow-x: hidden; }
.card.wide { width: 620px; }
.brand.small { font-size: 38px; margin-bottom: 18px; }
#resTable { width: 100%; border-collapse: collapse; font-size: 15px; text-align: left; font-variant-numeric: tabular-nums; }
#resTable td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
#resTable td:first-child { width: 36px; font-weight: 900; color: var(--dim); }
#resTable tr.me td { color: #ffe066; font-weight: 700; }
#resTable .sw { display: inline-block; width: 6px; height: 16px; border-radius: 2px; vertical-align: middle; margin-right: 8px; }
.btns { display: flex; gap: 12px; justify-content: center; margin-top: 22px; }
.btns button { font: inherit; font-size: 17px; font-weight: 700; padding: 10px 30px; border: 0; border-radius: 10px; cursor: pointer; background: var(--red); color: #fff; }
.btns button.ghost { background: #2a303d; }
.btns button:disabled { background: #3a3f4c; cursor: wait; }
.btns.col { flex-direction: column; align-items: stretch; }

/* tyre compounds */
.cmp { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 11px; font-weight: 900;
  text-decoration: none; background: #111; border: 3px solid #888; color: #fff; line-height: 1; box-sizing: content-box; }
.cmp.cS { border-color: #e0161e; } .cmp.cM { border-color: #f2c12e; } .cmp.cH { border-color: #eeeeee; }
#tyres .thead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
#tyres .thead b { font-size: 15px; font-variant-numeric: tabular-nums; }
#tyres .thead b.warn { color: #ffb020; } #tyres .thead b.bad { color: #ff3b30; }
.tgrid i { position: relative; overflow: hidden; background: #1b1e26 !important; }
.tgrid i b { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; border-radius: 6px; }
.tw { grid-template-columns: 26px 4px 1fr 24px auto; }
.tw .cmp { width: 12px; height: 12px; font-size: 8px; border-width: 2px; }
.tw q { quotes: none; color: #ffe066; font-weight: 700; }
#resTable .cmp { width: 13px; height: 13px; font-size: 9px; border-width: 2px; margin-right: 3px; }
#resTable .pen { color: #ff6b6b; }

/* damage diagram */
#damage { position: absolute; bottom: 20px; left: 142px; padding: 10px 12px 8px; text-align: center; }
#damage .car { position: relative; width: 56px; height: 96px; margin: 0 auto; }
#damage .d { position: absolute; display: block; border-radius: 3px; transition: background .2s; }
#damage .fw { left: 4px; right: 4px; top: 0; height: 7px; }
#damage .rw { left: 12px; right: 12px; bottom: 0; height: 8px; }
#damage .bd { left: 20px; right: 20px; top: 11px; bottom: 12px; border-radius: 8px; }
#damage .fl, #damage .fr, #damage .rl, #damage .rr { width: 13px; height: 22px; border-radius: 4px; }
#damage .fl { left: 0; top: 13px; } #damage .fr { right: 0; top: 13px; }
#damage .rl { left: 0; bottom: 14px; } #damage .rr { right: 0; bottom: 14px; }
#damage .g { background: #2c6e45; } #damage .y { background: #e8c21d; } #damage .o { background: #ff8a1f; }
#damage .r { background: #ff3b30; }
#damage .x { background: repeating-linear-gradient(45deg, #ff3b30 0 3px, #3a0b0b 3px 6px); animation: dmgBlink .6s steps(2) infinite; }
@keyframes dmgBlink { 50% { opacity: .35; } }
#damage .lbl { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--dim); letter-spacing: .08em; }

/* pit panel */
#pitbox { position: absolute; bottom: 130px; left: 50%; transform: translateX(-50%); min-width: 260px; padding: 10px 18px; text-align: center; border-top: 3px solid #ffe066; }
#pitbox.lim { box-shadow: 0 0 0 2px #ffe066, 0 8px 30px rgba(0,0,0,.35); }
#pitbox .ph { font-weight: 900; font-size: 20px; letter-spacing: .08em; color: #ffe066; }
#pitbox .ph.small { font-size: 13px; font-weight: 600; color: #c9d0dc; letter-spacing: 0; margin-top: 4px; }
#pitbox .tm { display: block; font-size: 34px; font-variant-numeric: tabular-nums; }
#pitbox .tsel { display: flex; justify-content: center; gap: 14px; margin-top: 8px; font-weight: 700; color: var(--dim); }
#pitbox .tsel span { display: flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 6px; }
#pitbox .tsel span.sel { background: rgba(255,255,255,.12); color: #fff; }
#pitbox kbd { font-size: 12px; }

/* pause + settings */
#pause, #settings { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: auto; background: rgba(5,6,10,.55); }
#settings { z-index: 5; }
.card.narrow { width: 340px; }
#settings h4 { margin: 18px 0 8px; text-align: left; font-size: 13px; letter-spacing: .12em; color: var(--dim); text-transform: uppercase; }
#settings .opts { margin-bottom: 8px; }
#settings small { color: var(--dim); font-size: 12px; }
.slider { display: grid; grid-template-columns: 170px 1fr 40px; align-items: center; gap: 12px; margin: 6px 0; font-size: 14px; color: #c9d0dc; text-align: left; }
.slider b { text-align: right; font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--red); }

/* pit repairs */
#pitbox .rep { margin-top: 8px; font-size: 13px; font-weight: 700; padding: 3px 8px; border-radius: 6px; }
#pitbox .rep.on { background: rgba(255,138,31,.18); color: #ffc58a; }
#pitbox .rep.off { background: rgba(255,255,255,.06); color: var(--dim); }
#pitbox .jobs { margin: 8px 0 2px; text-align: left; min-width: 250px; }
#pitbox .job { font-size: 13px; margin: 4px 0; color: var(--dim); }
#pitbox .job.s1 { color: #fff; } #pitbox .job.s2 { color: #8df5b4; }
#pitbox .job i { display: block; height: 4px; margin-top: 2px; border-radius: 2px; background: #1b1e26; overflow: hidden; }
#pitbox .job i b { display: block; height: 100%; background: #ff8a1f; }
#pitbox .job.s2 i b { background: #1ed760; }

/* next corner hint */
#corner { position: absolute; top: 102px; left: 50%; transform: translateX(-50%); padding: 5px 14px; border-radius: 8px;
  font-size: 15px; font-weight: 700; letter-spacing: .04em; background: rgba(10,12,18,.7); border: 1px solid var(--line); white-space: nowrap; }
#corner b { font-size: 20px; margin: 0 2px; font-variant-numeric: tabular-nums; }
#corner.green { color: #8df5b4; border-color: rgba(30,215,96,.45); }
#corner.yellow { color: #ffe066; border-color: rgba(255,210,31,.6); }
#corner.red { color: #fff; background: rgba(200,20,20,.85); border-color: #ff3b30; animation: dmgBlink .5s steps(2) infinite; }

/* rain tyres */
.cmp.cI { border-color: #1ed760; } .cmp.cW { border-color: #2f7bff; }

/* live weather panel */
#weather { position: absolute; top: 250px; right: 18px; width: 220px; padding: 10px 12px; font-size: 12px; }
#weather .wtop { display: flex; gap: 10px; align-items: center; }
#weather .wi { font-size: 26px; line-height: 1; }
#weather .wtop b { display: block; font-size: 14px; }
#weather small { color: var(--dim); }
#weather .wtrack { margin-top: 8px; color: var(--dim); }
#weather .wtrack b { color: #cfe3ff; }
#weather .wtrack i { display: block; height: 6px; margin-top: 3px; border-radius: 3px; background: #1b1e26; overflow: hidden; }
#weather .wtrack i b { display: block; height: 100%; background: linear-gradient(90deg, #4aa3ff, #2f5bff); }
#weather .wfc { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 10px; align-items: end; text-align: center; height: 62px; }
#weather .wfc div { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
#weather .wfc i { width: 12px; border-radius: 3px 3px 0 0; background: #3a4a62; }
#weather .wfc i.mid { background: #4aa3ff; } #weather .wfc i.hi { background: #2f5bff; }
#weather .wfc b { font-size: 10px; margin-top: 2px; } #weather .wfc span { font-size: 10px; color: var(--dim); }
#weather .wlbl { text-align: center; font-size: 10px; color: var(--dim); margin-top: 2px; }

/* briefing */
#briefing { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow-y: auto; overflow-x: hidden; background: rgba(5,6,10,.55); z-index: 4; }
#briefing h4 { margin: 16px 0 8px; text-align: left; font-size: 13px; letter-spacing: .12em; color: var(--dim); }
.bnow { display: flex; gap: 14px; align-items: center; text-align: left; }
.bnow .big { font-size: 44px; }
.bnow b { display: block; font-size: 16px; } .bnow small { color: var(--dim); font-size: 13px; }
.chart { display: flex; gap: 6px; height: 120px; align-items: stretch; padding: 6px 4px; background: rgba(255,255,255,.04); border-radius: 8px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; font-size: 11px; min-width: 0; }
.chart .bar i { width: 70%; border-radius: 4px 4px 0 0; background: #3a4a62; }
.chart .bar i.mid { background: #4aa3ff; } .chart .bar i.hi { background: #2f5bff; }
.chart .bar b { font-size: 11px; margin-bottom: 2px; } .chart .bar span { color: var(--dim); font-size: 10px; margin-top: 3px; white-space: nowrap; }
.tyrepick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tyrepick button { font: inherit; font-weight: 700; font-size: 13px; padding: 10px 4px 8px; border-radius: 10px; border: 2px solid #2b3140;
  background: #171b24; color: #c9d0dc; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tyrepick button.on { border-color: var(--red); background: #2a1518; color: #fff; }
.tyrepick em { font-style: normal; font-size: 10px; color: #8df5b4; }

/* 20-car tower: compact rows */
#tower { padding: 4px 0; font-size: 12.5px; }
#tower .tw { padding: 1px 10px; gap: 6px; line-height: 1.35; }
#tower .tw i { height: 12px; }
#tower .tw.ko { background: rgba(255,59,48,.14); }
#tower .tw.ko b { color: #ff8a80; }
#tower .tw.out { opacity: .45; }
#resTable tr.ko td { background: rgba(255,59,48,.10); }
#resTable tr.out td { opacity: .55; }
#resTable { font-size: 13.5px; }
#resTable td { padding: 4px 8px; }
.kotag { font-size: 11px; font-weight: 900; color: #fff; background: #d92b2b; padding: 1px 6px; border-radius: 4px; }
.outtag { font-size: 11px; color: var(--dim); }
#results .card.wide { max-height: calc(100vh - 32px); overflow-y: auto; }

/* online lobby */
.online { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.online #hostBtn { font: inherit; font-size: 15px; font-weight: 700; padding: 9px 18px; border-radius: 10px; border: 1px solid #3a4152; background: #1b2030; color: #dfe6f3; cursor: pointer; }
.online #hostBtn:hover { background: #242b3e; }
.roomrow { display: flex; gap: 8px; }
.roomrow input { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 8px; border: 1px solid #3a4152; background: #10131b; color: #cfe3ff; }
.roomrow button { font: inherit; font-weight: 700; padding: 8px 14px; border-radius: 8px; border: 0; background: var(--red); color: #fff; cursor: pointer; }
#netStatus { margin-top: 8px; font-weight: 700; color: #ffe066; font-size: 14px; }
/* a guest only waits: the host sets up the race */
body.guest-lobby .opts, body.guest-lobby #startBtn, body.guest-lobby .hostonly { display: none !important; }

/* circuit picker: wraps onto two rows on narrow screens */
.seg.wrap { flex-wrap: wrap; }
#circuitInfo { display: block; font-weight: 400; color: #8f98a8; font-size: 12px; margin-top: 2px; }

.deltag { font-size: 11px; font-weight: 800; color: #ff6b6b; }
#resTable s { color: var(--dim); }
