* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f7c3cf; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: #3b2238; }
body { touch-action: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
canvas#c { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
.hidden { display: none !important; }

.screen { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; }
.card { background: #fff; border-radius: 28px; padding: 28px 32px; box-shadow: 0 10px 0 #b84866, 0 18px 40px rgba(80,0,30,.25); width: min(92vw, 460px); text-align: center; border: 4px solid #3b2238; }
.logo { font-size: 46px; margin: 0; letter-spacing: 1px; font-weight: 900; color: #ff4d6d; -webkit-text-stroke: 2px #3b2238; }
.logo span { color: #3a86ff; }
.sub { margin: 4px 0 18px; font-weight: 700; color: #8a4a6e; }
label { display: block; text-align: left; font-weight: 800; margin: 12px 0; font-size: 15px; }
input { display: block; width: 100%; font-size: 26px; padding: 10px 14px; border: 3px solid #3b2238; border-radius: 14px; margin-top: 6px; font-weight: 800; text-align: center; touch-action: manipulation; }
#code { text-transform: uppercase; letter-spacing: 8px; }
button { font: inherit; font-weight: 900; font-size: 22px; padding: 14px 26px; border-radius: 16px; border: 3px solid #3b2238; background: #ffb703; color: #3b2238; box-shadow: 0 5px 0 #3b2238; cursor: pointer; touch-action: manipulation; }
button:active { transform: translateY(3px); box-shadow: 0 2px 0 #3b2238; }
button:disabled { opacity: .45; }
form button { width: 100%; margin-top: 10px; }
.err { color: #d00040; font-weight: 800; min-height: 1.2em; }

#msg h2 { margin: 6px 0 10px; font-size: 30px; }
#msg p { font-size: 18px; font-weight: 600; line-height: 1.35; }
#msg .big { font-size: 64px; font-weight: 900; margin: 0; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 3px solid #3b2238; vertical-align: -4px; }
.stats { text-align: left; margin: 12px auto 0; font-size: 17px; font-weight: 700; }
.stats td { padding: 3px 10px; }

/* Race HUD */
#hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#place { position: absolute; left: 14px; top: 12px; font-size: 40px; font-weight: 900; color: #fff; -webkit-text-stroke: 2px #3b2238; }
#place small { font-size: 22px; }
#segbox { position: absolute; left: 14px; top: 62px; max-width: min(60vw, 420px); background: rgba(255,255,255,.88); border: 3px solid #3b2238; border-radius: 14px; padding: 6px 12px; font-size: 14px; font-weight: 600; }
#segbox b { display: block; font-size: 18px; font-weight: 900; }
#mini { position: absolute; right: 14px; top: 16px; width: min(36vw, 260px); height: 18px; border: 3px solid #3b2238; border-radius: 10px; background: #fff; overflow: hidden; }
#miniFill { height: 100%; width: 0; background: linear-gradient(90deg, #ff4d6d, #ffb703); }
#boost { pointer-events: auto; position: absolute; right: 18px; bottom: 22px; width: 118px; height: 118px; border-radius: 50%; padding: 0; background: #ff9f1c; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 34px; line-height: 1; }
#boost small { font-size: 13px; letter-spacing: 1px; }
#boost .ico { width: 44px; height: 22px; border-radius: 12px; background: #ffd27a; border: 3px solid #a85a00; margin-bottom: 3px; }
#boost.on { background: #ffe066; box-shadow: 0 0 0 8px rgba(255,170,40,.5), 0 5px 0 #3b2238; }
#alert { position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%); font-size: 24px; font-weight: 900; color: #fff; background: #d00040; border: 3px solid #3b2238; padding: 6px 16px; border-radius: 14px; white-space: nowrap; }
#alert:empty { display: none; }
#net { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 20; background: #3b2238; color: #fff; padding: 6px 14px; border-radius: 10px; font-weight: 800; }

/* Host */
body.host { touch-action: auto; }
.host-top { position: fixed; left: 0; right: 0; top: 0; z-index: 4; pointer-events: none; }
.host-panel { position: fixed; z-index: 5; }
#lobby { width: min(94vw, 1100px); }
#lobby .join-line { font-size: 30px; font-weight: 800; margin: 6px 0; }
#lobby .code { font-size: 110px; font-weight: 900; letter-spacing: 14px; color: #3a86ff; -webkit-text-stroke: 3px #3b2238; line-height: 1; margin: 6px 0 14px; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0; }
.slot { border: 3px dashed #c99; border-radius: 18px; padding: 14px; min-height: 74px; font-size: 24px; font-weight: 900; display: flex; align-items: center; gap: 12px; justify-content: center; position: relative; }
.slot.full { border-style: solid; border-color: #3b2238; background: #fff7f9; }
.slot .kick { position: absolute; right: 6px; top: 4px; font-size: 14px; padding: 2px 8px; box-shadow: none; border-width: 2px; background: #fff; }
.slot.off { opacity: .45; }
.btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hbar { position: fixed; z-index: 6; right: 18px; bottom: 18px; display: flex; gap: 10px; }
.hbar button { font-size: 18px; padding: 10px 18px; }
#results { width: min(94vw, 1150px); max-height: 92vh; overflow: auto; }
#results table { width: 100%; border-collapse: collapse; font-size: 20px; margin: 10px 0 18px; }
#results th { background: #3b2238; color: #fff; padding: 8px; font-size: 16px; }
#results td { padding: 8px; border-bottom: 2px solid #f0d0da; font-weight: 700; }
#results tr.win td { background: #fff3c4; }
#results h2 { font-size: 40px; margin: 4px 0; }
