:root {
  --red: #e23b3b;
  --red-d: #a8202a;
  --yellow: #ffd23f;
  --pink: #ff4f9a;
  --teal: #38e0c8;
  --blue: #2f7de1;
  --purple: #7b4dff;
  --ink: #1d1530;
  --panel: rgba(255, 255, 255, 0.94);
  --muted: #6b6480;
  --radius: 18px;
  --shadow: 0 10px 0 rgba(0, 0, 0, 0.18), 0 20px 40px rgba(0, 0, 0, 0.25);
  --display: "Lilita One", "Arial Black", Impact, sans-serif;
  --body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a1030;
  font-family: var(--body);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
/* 100% rather than 100vh: iOS Safari's 100vh includes the area behind its toolbars. */
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------------------------------------------------------------- screens */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  z-index: 10;
  overflow-y: auto;
}
.screen.active { display: flex; animation: screenIn 0.28s ease-out; }
.screen.overlay { background: rgba(20, 8, 40, 0.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); z-index: 30; }
@keyframes screenIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }

#loading { background: radial-gradient(circle at 50% 40%, #ff6b4a, #b8203a 60%, #4a0f3a); flex-direction: column; gap: 22px; color: #fff; }
.loadbar { width: min(360px, 80vw); height: 16px; border-radius: 10px; background: rgba(0, 0, 0, 0.3); overflow: hidden; border: 3px solid #fff; }
#loadbar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), #fff3a0); transition: width 0.2s; }
#load-msg { font-weight: 800; margin: 0; opacity: 0.9; }

/* ---------------------------------------------------------------- logo */
.logo { display: flex; flex-direction: column; align-items: center; line-height: 0.85; transform: rotate(-4deg); filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.25)); }
.logo span { font-family: var(--display); letter-spacing: 2px; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.logo .l1 { font-size: clamp(48px, min(13vw, 21vh), 150px); color: var(--yellow); text-shadow: 0 6px 0 #c47a00; }
.logo .l2 { font-size: clamp(40px, min(11vw, 18vh), 128px); color: #fff; background: var(--red); padding: 4px 28px 10px; border-radius: 18px; border: 6px solid var(--ink); -webkit-text-stroke: 3px var(--ink); margin-top: 6px; transform: rotate(3deg); }
.logo.small .l1 { font-size: 54px; }
.logo.small .l2 { font-size: 44px; padding: 2px 16px 6px; border-width: 4px; border-radius: 12px; }

#title { flex-direction: column; background: linear-gradient(180deg, rgba(10, 5, 30, 0.1), rgba(10, 5, 30, 0.35)); }
.title-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.tagline { font-family: var(--display); color: #fff; font-size: clamp(22px, 4vw, 34px); margin: 0; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; transform: rotate(-2deg); }
.footer-note { position: absolute; bottom: max(14px, env(safe-area-inset-bottom)); left: 16px; right: 16px; text-align: center; color: #fff; font-weight: 800; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); margin: 0; font-size: 14px; }

/* ---------------------------------------------------------------- panels */
.panel {
  background: var(--panel);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  --pad: 22px;
  padding: var(--pad);
  width: min(460px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel.wide { width: min(1040px, 100%); }
.panel.small-panel { width: min(340px, 100%); }
.screen-title { font-family: var(--display); font-size: 34px; margin: 0; letter-spacing: 1px; color: var(--ink); }
.sub-title { font-family: var(--display); font-size: 22px; margin: 4px 0 -4px; letter-spacing: 0.5px; }
h3 { font-family: var(--display); font-weight: 400; font-size: 21px; margin: 0 0 8px; letter-spacing: 0.5px; }
.muted { color: var(--muted); font-weight: 700; }
.card { background: #fff; border: 3px solid #e7e2f2; border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
/* Keep each panel's action buttons (Back / OK / Race!) in reach when its content scrolls. */
.panel:has(> .row:last-child) { padding-bottom: 0; }
.panel > .row:last-child { position: sticky; bottom: 0; margin: 0 calc(-1 * var(--pad)); padding: 10px var(--pad) var(--pad); background: linear-gradient(rgba(255, 255, 255, 0), #fff 12px); z-index: 2; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font-family: var(--body);
  font-weight: 900;
  font-size: 17px;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, background 0.15s;
  outline: none;
}
.btn:hover, .btn:focus-visible { background: #fff6cc; }
.btn:focus-visible { box-shadow: 0 4px 0 var(--ink), 0 0 0 4px var(--yellow); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--red); color: #fff; }
.btn.primary:hover, .btn.primary:focus-visible { background: #f04a4a; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.05); }
.btn.small { font-size: 14px; padding: 6px 12px; }
.btn.big { font-family: var(--display); font-weight: 400; font-size: 34px; padding: 12px 40px; letter-spacing: 1px; background: var(--yellow); }
.btn.big-ish { font-size: 22px; padding: 14px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.on { background: var(--yellow); }
.btn.primary.on { color: var(--ink); }
.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.menu-panel { align-items: center; width: min(480px, 100%); }
.menu-list { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.menu-list .row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; align-items: stretch; }
.menu-list .row .btn { padding: 10px 6px; font-size: 15px; }
.btn.mode { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 12px 18px 12px 70px; position: relative; }
.btn.mode b { font-family: var(--display); font-weight: 400; font-size: 26px; letter-spacing: 0.5px; }
.btn.mode small { font-weight: 700; color: var(--muted); font-size: 14px; }
.btn.mode::before { content: ""; position: absolute; left: 14px; top: 50%; width: 42px; height: 42px; margin-top: -21px; border-radius: 12px; border: 3px solid var(--ink); background-size: 70%; background-position: center; background-repeat: no-repeat; }
.btn.mode.gp::before { background-color: var(--yellow); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 3h12v3a6 6 0 0 1-12 0zM6 5H3a3 3 0 0 0 3 3M18 5h3a3 3 0 0 1-3 3M10 12h4v4h-4zM7 19h10v2H7z' fill='%23fff' stroke='%231d1530' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.btn.mode.vs::before { background-color: var(--red); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 3v18M5 4h13l-3 4 3 4H5' fill='%23fff' stroke='%231d1530' stroke-width='1.8' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.btn.mode.tt::before { background-color: var(--teal); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='13' r='8' fill='%23fff' stroke='%231d1530' stroke-width='1.8'/%3E%3Cpath d='M12 13V9M10 2h4' stroke='%231d1530' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.btn.mode.daily::before { background-color: var(--pink); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='3' y='5' width='18' height='16' rx='2' fill='%23fff' stroke='%231d1530' stroke-width='1.8'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4' stroke='%231d1530' stroke-width='1.8' stroke-linecap='round'/%3E%3Cpath d='M12 12.5l1.1 2.2 2.4.3-1.8 1.7.5 2.4-2.2-1.2-2.2 1.2.5-2.4-1.8-1.7 2.4-.3z' fill='%23ffd23f' stroke='%231d1530' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E"); }
/* Not raced today's challenge yet */
.btn.mode.daily.fresh::after { content: "NEW"; position: absolute; top: -9px; right: -6px; background: var(--red); color: #fff; font-family: var(--display); font-size: 13px; letter-spacing: 1px; padding: 2px 9px; border-radius: 10px; border: 2px solid var(--ink); transform: rotate(4deg); }
.btn.mode.online::before { background-color: var(--purple); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='%23fff' stroke='%231d1530' stroke-width='1.8'/%3E%3Cpath d='M3 12h18M12 3c3 3 3 15 0 18M12 3c-3 3-3 15 0 18' fill='none' stroke='%231d1530' stroke-width='1.5'/%3E%3C/svg%3E"); }

/* ---------------------------------------------------------------- select */
#select { justify-content: flex-start; padding-left: max(16px, 3vw); }
.select-panel { width: min(560px, 100%); }
.char-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.char-card { border: 3px solid var(--ink); border-radius: 14px; background: linear-gradient(180deg, #fff, #efe9fb); padding: 4px 4px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; box-shadow: 0 3px 0 var(--ink); transition: transform 0.1s; font-family: var(--body); color: var(--ink); }
.char-card img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.char-card span { font-weight: 900; font-size: 13px; max-width: 100%; overflow-wrap: anywhere; text-align: center; line-height: 1.1; }
.char-card.sel { background: linear-gradient(180deg, #fff3b0, var(--yellow)); transform: translateY(-3px) scale(1.04); }
.char-card:focus-visible { outline: 4px solid var(--pink); }
.sel-detail { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.sel-detail h3 { font-size: 30px; margin: 0; }
.sel-detail p { margin: 0; }
.stats { display: grid; grid-template-columns: auto 150px; gap: 4px 10px; align-items: center; font-weight: 800; font-size: 13px; }
.bar { height: 10px; border-radius: 6px; background: #e7e2f2; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--yellow)); border-radius: 6px; transition: width 0.25s; }
.kart-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kart-card { border: 3px solid var(--ink); border-radius: 12px; background: #fff; padding: 8px; cursor: pointer; text-align: left; box-shadow: 0 3px 0 var(--ink); font-family: var(--body); color: var(--ink); }
.kart-card b { font-family: var(--display); font-weight: 400; font-size: 20px; display: block; }
.kart-card small { color: var(--muted); font-weight: 700; }
.kart-card.sel { background: var(--yellow); }
.cc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; box-shadow: 0 3px 0 var(--ink); }
.seg button { font-family: var(--body); font-weight: 900; font-size: 15px; border: 0; border-right: 2px solid var(--ink); background: #fff; padding: 8px 14px; cursor: pointer; color: var(--ink); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--red); color: #fff; }
.seg button:focus-visible { outline: 3px solid var(--yellow); outline-offset: -3px; }

/* ---------------------------------------------------------------- tracks */
.track-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.track-card { border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; cursor: pointer; background: #fff; box-shadow: 0 4px 0 var(--ink); padding: 0; text-align: left; font-family: var(--body); color: var(--ink); transition: transform 0.1s; }
.track-card canvas { width: 100%; aspect-ratio: 1.3; display: block; }
.track-card .tinfo { padding: 8px 10px; }
.track-card b { font-family: var(--display); font-weight: 400; font-size: 19px; display: block; }
.track-card small { color: var(--muted); font-weight: 700; display: block; }
.track-card .best { color: var(--blue); }
.track-card .best { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-card .best.mine { color: var(--muted); }
.track-card .best:empty { display: none; }
.track-card.sel { outline: 5px solid var(--yellow); transform: translateY(-3px); }
.track-card.random canvas { background: linear-gradient(135deg, var(--pink), var(--purple)); }

/* ---------------------------------------------------------------- online */
.online-grid, .lobby-grid, .howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.lobby-grid { grid-template-columns: 1.1fr 1fr 1fr; }
.howto-grid { grid-template-columns: 1.2fr 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field input[type="range"] { accent-color: var(--red); width: 100%; }
.field .seg { align-self: flex-start; }
.player-box { grid-column: 1 / -1; border-bottom: 2px solid rgba(0, 0, 0, 0.08); padding-bottom: 12px; }
.player-code { font-size: 20px; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.player-code small { font-size: 12px; letter-spacing: 0; color: var(--muted); margin-right: 6px; }
.player-note { font-size: 13px; margin: 0; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.row.wrap { flex-wrap: wrap; gap: 8px; }
.code-input { font-size: 22px; letter-spacing: 2px; text-transform: uppercase; text-align: center; width: 100%; }
.link-error { color: var(--red); font-weight: 800; min-height: 1.2em; margin: 6px 0; }
.menu-list .row .feedback-btn { grid-column: 1 / -1; }
#feedback-text { width: 100%; resize: vertical; min-height: 110px; font: 700 16px var(--body); padding: 10px 12px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; color: var(--ink); }
#feedback-text:focus { outline: none; box-shadow: 0 0 0 4px var(--yellow); }
.feedback-panel .field.check { font-size: 14px; margin: 8px 0; }
#link #link-confirm { display: none; }
#link.confirm #link-enter { display: none; }
#link.confirm #link-confirm { display: block; }
.field input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--red); flex: none; }
.field.check { min-height: 36px; cursor: pointer; }
input[type="text"], input:not([type]), #code-input, #name-input, #chat-input {
  font-family: var(--body); font-weight: 800; font-size: 17px; border: 3px solid var(--ink); border-radius: 10px; padding: 9px 12px; outline: none; background: #fff; color: var(--ink); min-width: 0;
  user-select: text; -webkit-user-select: text;
}
input:focus { box-shadow: 0 0 0 4px var(--yellow); }
#code-input { width: 110px; text-transform: uppercase; letter-spacing: 4px; text-align: center; font-family: var(--display); font-size: 22px; }
.join-row { flex-wrap: nowrap; }
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.room { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 2px solid #e7e2f2; border-radius: 10px; }
.room .code { font-family: var(--display); font-size: 22px; letter-spacing: 2px; }
.room .info { flex: 1; font-weight: 700; font-size: 14px; color: var(--muted); }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.code { font-family: var(--display); color: var(--red); letter-spacing: 3px; }
.lobby-players { display: flex; flex-direction: column; gap: 6px; }
.lp { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 10px; background: #f5f2fb; font-weight: 800; }
.lp img { width: 42px; height: 42px; }
.lp .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lp .tag { font-size: 12px; padding: 2px 8px; border-radius: 8px; background: #e7e2f2; }
.lp .tag.ready { background: #3ccf6e; color: #fff; }
.lp .tag.host { background: var(--yellow); }
.lp .pts { font-family: var(--display); font-size: 18px; color: var(--purple); }
.lp.me { outline: 3px solid var(--yellow); }
.lobby-settings { display: flex; flex-direction: column; gap: 10px; }
.lobby-settings .ls { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 800; flex-wrap: wrap; }
.lobby-settings select { font-family: var(--body); font-weight: 800; font-size: 16px; border: 3px solid var(--ink); border-radius: 10px; padding: 6px 8px; background: #fff; color: var(--ink); }
.chat-card { min-height: 260px; }
.chat-log { flex: 1; overflow-y: auto; max-height: 240px; min-height: 140px; font-size: 14px; display: flex; flex-direction: column; gap: 3px; user-select: text; -webkit-user-select: text; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log b { color: var(--purple); }
#chat-form { flex-wrap: nowrap; }
#chat-input { flex: 1; font-size: 16px; padding: 7px 10px; }

.keys { border-collapse: collapse; font-weight: 700; }
.keys td { padding: 5px 6px; vertical-align: middle; }
kbd { display: inline-block; font-family: var(--body); font-weight: 900; font-size: 13px; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 7px; padding: 1px 7px; margin: 1px; background: #fff; }
.tips { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-weight: 700; font-size: 15px; }
.c-blue { color: #2f8fff; } .c-orange { color: #ff8a1a; } .c-purple { color: #b04aff; }
.howto-items { display: grid; grid-template-columns: 1fr; gap: 6px; }
.hi { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.hi svg { width: 34px; height: 34px; flex: none; }

/* ---------------------------------------------------------------- what's new */
.whatsnew-panel { width: min(560px, 100%); }
.whatsnew-list { display: flex; flex-direction: column; gap: 12px; }
.wn-entry { position: relative; }
.wn-entry h3 { margin: 0; }
.wn-entry.new h3 { padding-right: 56px; }
.wn-date { font-family: var(--body); font-size: 13px; letter-spacing: 0; white-space: nowrap; }
.wn-entry.new { border-color: var(--red); }
.wn-entry.new::after { content: "NEW"; position: absolute; top: 12px; right: 12px; background: var(--red); color: #fff; font-family: var(--display); font-size: 13px; letter-spacing: 1px; padding: 2px 9px; border-radius: 10px; border: 2px solid var(--ink); transform: rotate(4deg); }

/* ---------------------------------------------------------------- best times (fastest lap / full race) */
.records-panel { width: min(600px, 100%); }
.records-board { display: grid; grid-template-columns: 1fr 1fr; flex: none; }
.records-tracks { display: grid; grid-template-columns: repeat(8, 1fr); flex: none; }
.records-tracks button { padding: 8px 6px; line-height: 1.15; }
.records-status { margin: 0; }
.records-status:empty { display: none; }
/* The whole panel scrolls (Back stays pinned), not just the list. */
.results-table.records-table { flex: none; overflow: visible; }
.records-table .rr .pts { min-width: 90px; font-variant-numeric: tabular-nums; }
.records-note { margin: 0; font-size: 14px; }

/* ---------------------------------------------------------------- daily challenge */
.daily-when { margin: -6px 0 0; }
.daily-card { display: grid; grid-template-columns: 180px 1fr; gap: 14px; align-items: center; background: #fff; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; box-shadow: 0 4px 0 var(--ink); flex: none; }
.daily-card canvas { width: 100%; height: 100%; aspect-ratio: 1.3; object-fit: cover; display: block; border-right: 3px solid var(--ink); }
.daily-info { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 10px 0; min-width: 0; }
.daily-info > b { font-family: var(--display); font-weight: 400; font-size: 24px; letter-spacing: 0.5px; line-height: 1.1; }
.daily-racer { display: flex; align-items: center; gap: 8px; }
.daily-racer img { width: 46px; height: 46px; flex: none; }
.daily-racer span { display: flex; flex-direction: column; min-width: 0; }
.daily-racer b { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.daily-racer small { color: var(--muted); font-weight: 800; }
.daily-best { margin: 0; font-weight: 900; }
.daily-best:empty { display: none; }
#daily-prev:empty { display: none; }
.records-table .rr.gap { background: none; animation: none; justify-content: center; display: flex; color: var(--muted); padding: 0; line-height: 1; }

/* ---------------------------------------------------------------- invites and share cards */
.invite-row { gap: 8px; flex-wrap: nowrap; }
.btn.whatsapp { background: #25d366; color: #fff; }
.btn.whatsapp::before { content: ""; display: inline-block; width: 1.1em; height: 1.1em; margin-right: 6px; vertical-align: -0.2em; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 0 0-8.6 15.1L2 22l5-1.3A10 10 0 1 0 12 2z' fill='%23fff'/%3E%3Cpath d='M8.6 7.3c.3-.6.6-.6.9-.6h.6c.2 0 .5 0 .7.6l.9 2.1c.1.2.1.5 0 .7l-.5.7c-.2.2-.2.4 0 .7.9 1.5 2 2.5 3.5 3.2.3.1.5.1.7-.1l.7-.9c.2-.3.5-.3.7-.2l2 1c.3.1.4.3.4.5 0 .6-.3 1.6-1.6 2.1-1 .4-2.4.3-4.6-.8-2.5-1.3-4.1-3.8-4.4-4.3-.5-.8-1-2-1-3 0-1 .4-1.6.9-2.1z' fill='%2325d366'/%3E%3C/svg%3E") center / contain no-repeat; }
.sharecard-panel { width: min(520px, 100%); align-items: center; }
.share-img { width: 100%; max-width: 440px; aspect-ratio: 1; border-radius: 14px; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); background: #1d1530; flex: none; }
.sharecard-panel .row.end { flex-wrap: wrap; justify-content: center; }

/* ---------------------------------------------------------------- highlights replay */
.replay-ui { display: none; position: fixed; inset: 0; z-index: 8; pointer-events: none; font-family: var(--display); color: #fff; }
body.replaying .replay-ui { display: block; }
body.replaying .hud { display: none !important; }
/* Letterbox bars for the TV look */
.replay-ui::before, .replay-ui::after { content: ""; position: absolute; left: 0; right: 0; height: 7vh; background: #000; }
.replay-ui::before { top: 0; }
.replay-ui::after { bottom: 0; }
.replay-badge { position: absolute; top: calc(7vh + 14px); left: max(18px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 8px; font-size: 24px; letter-spacing: 2px; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
.replay-badge i { width: 14px; height: 14px; border-radius: 50%; background: #ff2a2a; animation: recBlink 1s steps(2) infinite; }
.replay-badge span { font-size: 16px; opacity: 0.8; }
@keyframes recBlink { 50% { opacity: 0; } }
.replay-caption { position: absolute; left: 50%; bottom: calc(7vh + 24px); transform: translateX(-50%); max-width: 90vw; padding: 8px 22px; border-radius: 14px; background: rgba(20, 8, 40, 0.72); border: 3px solid var(--yellow); font-size: clamp(20px, 3.4vw, 34px); text-align: center; letter-spacing: 0.5px; animation: captionIn 0.35s ease-out; }
@keyframes captionIn { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translateX(-50%); } }
.replay-skip { position: absolute; top: calc(7vh + 10px); right: max(18px, env(safe-area-inset-right)); pointer-events: auto; padding: 8px 16px; font-size: 16px; }

/* ---------------------------------------------------------------- the Custom racer's editor */
#custom { justify-content: flex-start; padding-left: max(16px, 3vw); }
#sel-edit[hidden] { display: none; }
.custom-panel { gap: 10px; }
.custom-head { display: flex; flex-direction: column; gap: 10px; }
.custom-tabs { align-self: flex-start; }
.custom-body { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.cz-group { display: flex; flex-direction: column; gap: 6px; }
.cz-label { font-weight: 900; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.cz-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cz-chip { font-family: var(--body); font-weight: 800; font-size: 13px; color: var(--ink); background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 5px 10px; cursor: pointer; box-shadow: 0 2px 0 var(--ink); }
.cz-chip.on { background: var(--yellow); }
.cz-chip:focus-visible, .cz-sw:focus-visible { outline: 3px solid var(--pink); outline-offset: 1px; }
.cz-colors { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.cz-sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink); cursor: pointer; padding: 0; box-shadow: 0 2px 0 var(--ink); }
.cz-sw.on { outline: 3px solid var(--ink); outline-offset: 2px; }
.cz-sw.off { background: repeating-linear-gradient(45deg, #fff 0 4px, #e7e2f2 4px 8px); }
.cz-pick { position: relative; width: 28px; height: 28px; border-radius: 50%; border: 2px dashed var(--ink); overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); cursor: pointer; }
.cz-pick.on { outline: 3px solid var(--ink); outline-offset: 2px; border-style: solid; }
.cz-pick input { position: absolute; inset: -8px; width: 48px; height: 48px; opacity: 0; cursor: pointer; }
.cz-num { width: 80px; font: 800 15px var(--body); padding: 5px 8px; border: 2px solid var(--ink); border-radius: 10px; }
.cz-stats { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px 10px; align-items: center; font-weight: 900; }
.cz-pips { display: flex; gap: 4px; }
.cz-pips i { width: 22px; height: 14px; border-radius: 4px; background: #e7e2f2; border: 2px solid var(--ink); }
.cz-pips i.on { background: linear-gradient(90deg, var(--red), var(--yellow)); }
.cz-stats .btn { padding: 2px 12px; font-size: 18px; }
.cz-left { font-weight: 900; }
.cz-left.bad { color: var(--red); }
@media (max-width: 600px) and (orientation: portrait) {
  /* Phones held upright: the editor sits at the bottom, the kart spins above it */
  #custom { align-items: flex-end; justify-content: center; padding-left: 10px; padding-right: 10px; }
  .custom-panel { width: 100%; max-height: 56%; }
  .custom-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .custom-head .screen-title { font-size: 22px; }
  .custom-tabs button { padding: 6px 8px; font-size: 13px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .custom-panel { width: min(470px, 58%); }
  .custom-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .custom-head .screen-title { font-size: 22px; }
}

/* ---------------------------------------------------------------- the tutorial */
.tutorial-ui { display: none; position: fixed; left: 0; right: 0; top: calc(12px + env(safe-area-inset-top)); z-index: 6; pointer-events: none; }
.tutorial-ui.on { display: block; }
body.replaying .tutorial-ui { display: none; }
.tut-card { width: min(520px, calc(100vw - 260px)); margin: 0 auto; padding: 10px 14px 10px; border-radius: 18px; background: rgba(255, 255, 255, 0.94); border: 4px solid var(--ink); box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35); color: var(--ink); pointer-events: auto; transition: background 0.2s, transform 0.2s; }
.tutorial-ui.done .tut-card { background: #c9f7d4; transform: scale(1.04); }
.tut-top { display: flex; align-items: center; gap: 8px; font-weight: 900; font-size: 12px; color: var(--muted); }
.tut-dots { display: flex; gap: 4px; }
.tut-dots i { width: 9px; height: 9px; border-radius: 50%; background: #e7e2f2; border: 2px solid var(--ink); }
.tut-dots i.ok { background: #3bd16f; }
.tut-dots i.cur { background: var(--yellow); }
.tut-title { font-size: 24px; margin: 2px 0 2px; }
.tut-text { margin: 0; font-weight: 800; font-size: 15px; line-height: 1.35; }
.tut-text em { display: block; margin-top: 4px; font-style: normal; color: var(--red); }
.tut-text kbd { font-size: 13px; }
.tut-text .tk { height: 22px; min-width: 0; font-size: 12px; vertical-align: 1px; }
.tut-text .c-blue { color: #2f7bff; } .tut-text .c-orange { color: #ff7a1a; }
.tut-bar { margin-top: 6px; height: 12px; }
.tut-foot { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.tut-where { flex: 1; font-weight: 900; font-size: 13px; color: #d4246e; }
.tut-foot .btn { padding: 4px 10px; font-size: 13px; }
.panel.tut-panel { width: min(480px, 100%); }
.tut-panel p { margin: 0; font-weight: 700; }
/* Laps, the clock and your place don't matter in the tutorial */
body.tutorial .hud-lap, body.tutorial #hud-time, body.tutorial #hud-splits { display: none; }
@media (max-width: 760px) {
  .tut-card { width: calc(100vw - 20px); }
  .tutorial-ui { top: calc(112px + env(safe-area-inset-top)); }
  body.tutorial .hud-minimap { display: none; }
}

/* ---------------------------------------------------------------- watching races live */
.watch-ui { display: none; position: fixed; inset: 0; z-index: 7; pointer-events: none; color: #fff; }
body.watching .watch-ui { display: block; }
body.watching .touch, body.watching .pause-btn, body.watching .hud-social, body.watching .hud-watchers, body.watching .players-chip { display: none !important; }
.hud.spect-other .hud-item, .hud.spect-other .hud-coins { display: none; }
.watch-bar { position: absolute; left: 12px; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); width: fit-content; max-width: calc(100vw - 24px); margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 12px; border-radius: 18px; background: rgba(20, 8, 40, 0.78); border: 3px solid #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); pointer-events: auto; }
.watch-live { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 16px; letter-spacing: 1px; color: #ff5b5b; flex: none; }
.watch-live i { width: 11px; height: 11px; border-radius: 50%; background: #ff2a2a; animation: recBlink 1s steps(2) infinite; }
.watch-bar.off .watch-live { color: #aaa; }
.watch-bar.off .watch-live i { background: #888; animation: none; }
.watch-portrait { width: 40px; height: 40px; flex: none; }
.watch-portrait:not([src]), .watch-portrait[src=""] { display: none; }
.watch-who { display: flex; flex-direction: column; min-width: 0; font-weight: 900; line-height: 1.15; }
.watch-who b { font-family: var(--display); font-weight: 400; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-who small { font-size: 13px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-bar .btn { flex: none; padding: 7px 12px; font-size: 14px; }
.watch-bar .btn[hidden] { display: none; }
.watch-msg { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); max-width: min(560px, 88vw); padding: 14px 24px; border-radius: 18px; background: rgba(20, 8, 40, 0.78); border: 3px solid var(--yellow); font-family: var(--display); font-size: clamp(20px, 3vw, 28px); text-align: center; }
.watch-msg:empty { display: none; }
/* Chatting with the racer you're watching: the feed and the message box sit above the bar */
.watch-chat { position: absolute; left: max(12px, env(safe-area-inset-left)); bottom: calc(max(14px, env(safe-area-inset-bottom)) + 66px); width: min(380px, calc(100vw - 24px)); display: flex; flex-direction: column; gap: 6px; font-family: var(--body); font-weight: 900; }
.watch-chat .hud-feed div.racer { border: 2px solid var(--yellow); }
.watch-chat-form { display: flex; gap: 6px; pointer-events: auto; }
#watch-chat-input { flex: 1; min-width: 0; font-size: 16px; padding: 7px 10px; border-radius: 10px; border: 3px solid #fff; background: rgba(20, 10, 40, 0.7); color: #fff; font-family: var(--body); font-weight: 800; outline: none; }
#watch-chat-input::placeholder { color: rgba(255, 255, 255, 0.7); }
.watch-chat-form .btn { flex: none; padding: 7px 12px; font-size: 14px; }
.watch-reacts { display: flex; gap: 6px; pointer-events: auto; }
.react-btn { flex: none; width: 46px; height: 46px; padding: 0; border-radius: 50%; border: 3px solid #fff; background: rgba(20, 10, 40, 0.6); font-size: 24px; line-height: 1; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: transform 0.08s; }
.react-btn:hover { background: rgba(20, 10, 40, 0.85); }
.react-btn:active, .react-btn.pop { transform: scale(1.25); }
@media (max-width: 400px) { .react-btn { width: 42px; height: 42px; font-size: 22px; } }
.reactions { position: fixed; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.react { position: absolute; bottom: 30%; display: flex; flex-direction: column; align-items: center; animation: reactUp 2.6s ease-out forwards; }
.react i { font-style: normal; font-size: 46px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45)); }
.react small { margin-top: 2px; padding: 1px 7px; border-radius: 8px; background: rgba(20, 10, 40, 0.6); color: #fff; font: 900 12px var(--body); white-space: nowrap; }
@keyframes reactUp {
  0% { transform: translate(0, 0) scale(0.3); opacity: 0; }
  12% { transform: translate(calc(var(--dx) * 0.2), -30px) scale(1.2); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), -280px) scale(1); opacity: 0; }
}
.hud-social.watch-only .hud-mic:not(.hud-chat), .hud-social.watch-only .hud-talkers { display: none; }
.hud-watchers { position: absolute; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); padding: 3px 14px; border-radius: 14px; background: rgba(20, 10, 40, 0.55); border: 3px solid #fff; font-size: 18px; white-space: nowrap; }
.hud-watchers:empty { display: none; }
@media (max-width: 560px) {
  .watch-live { display: none; }
  .watch-bar { gap: 8px; }
  .watch-who b { font-size: 17px; }
}

/* ---------------------------------------------------------------- players and challenges */
.beta-chip { left: max(14px, env(safe-area-inset-left)); right: auto !important; background: #ffe9f6; }
.beta-panel { width: min(560px, 100%); }
.beta-panel > p { margin: 0; }
.beta-list { display: flex; flex-direction: column; gap: 10px; }
.beta-card { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; padding: 12px 14px; border-radius: 14px; border: 3px solid var(--ink); background: linear-gradient(135deg, #fff6d8, #ffe2b0); box-shadow: 0 3px 0 var(--ink); }
.beta-card h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.beta-card h3 small { font-family: var(--body); font-weight: 900; font-size: 11px; letter-spacing: 1px; color: #fff; background: #d4246e; border-radius: 6px; padding: 2px 6px; }
.beta-card p { margin: 0; grid-column: 1; font-weight: 700; font-size: 14px; }
.beta-card .beta-best { grid-column: 1; font-weight: 900; font-size: 13px; color: var(--muted); }
.beta-card .btn { grid-column: 2; grid-row: 1 / span 3; }
.hud-warn { margin-top: 6px; display: inline-block; padding: 4px 10px; border-radius: 8px; background: #ffd21f; color: #1a1a1a; border: 3px solid #1a1a1a; font-size: 17px; letter-spacing: 0.5px; text-shadow: none; }
.hud-warn:empty { display: none; }
.hud-warn.live { animation: warnBlink 0.5s steps(2) infinite; background: #ff5a2a; color: #fff; }
@keyframes warnBlink { 50% { opacity: 0.45; } }
.players-chip { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); z-index: 3; padding: 7px 14px; font-size: 15px; }
.players-chip.live { background: #3bd16f; color: #fff; }
.players-list .rr { grid-template-columns: 40px 1fr auto; padding: 4px 8px 4px 12px; }
.players-list .rr .nm small { display: block; color: var(--muted); font-weight: 700; font-size: 13px; }
.players-list .rr .btn { padding: 7px 12px; font-size: 14px; }
.players-list .pl-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.notify-card { flex: none; gap: 8px; }
.notify-card h3 { margin: 0; }
.notify-text { margin: 0; font-size: 14px; }
.challenge-panel { align-items: center; text-align: center; }
.challenge-portrait { width: 120px; height: 120px; }
.challenge-text { margin: 0; font-weight: 800; font-size: 18px; }
.panel.beaten-panel { width: min(460px, 100%); }
.beaten-note { margin: 0; }
.beaten-list { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; min-height: 0; }
.beaten-list .rr .nm { white-space: normal; }
.panel.gchal-panel { width: min(420px, 100%); }
#gchal .gchal-panel { align-items: center; }
#gchal .gchal-panel .row { align-self: stretch; }
.gchal-tries .rr .time { display: none; }
.gchal-panel .challenge-text { text-align: center; }
.gchal-tries { display: flex; flex-direction: column; gap: 5px; width: 100%; overflow-y: auto; min-height: 0; }
.gchal-tries .rr { grid-template-columns: 34px 36px 1fr auto; }
.gchal-tries .rr img { width: 32px; height: 32px; }
.gchal-tries .rr .pos { font-size: 20px; }
.gchal-name { width: 100%; }
.gchal-share-text { margin: 0; }
.gchal-link { width: 100%; font-size: 14px; }

/* ---------------------------------------------------------------- results */
.results-table { display: flex; flex-direction: column; gap: 5px; overflow-y: auto; min-height: 0; flex: 1 1 auto; padding: 2px; }
.results-panel { overflow: hidden; }
#results-actions { flex: none; }
.rr { display: grid; grid-template-columns: 44px 48px 1fr auto auto; gap: 10px; align-items: center; padding: 2px 12px; flex: none; border-radius: 12px; background: #f5f2fb; font-weight: 800; animation: rowIn 0.35s backwards; }
.rr .pos { font-family: var(--display); font-size: 26px; text-align: center; }
.rr img { width: 40px; height: 40px; }
.rr .time { font-variant-numeric: tabular-nums; color: var(--muted); }
.rr .nm, .pod .nm { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rr .pts { font-family: var(--display); font-size: 20px; color: var(--purple); min-width: 60px; text-align: right; }
.rr.me { background: var(--yellow); }
.rr.p1 .pos { color: #d4a000; } .rr.p2 .pos { color: #8a93a6; } .rr.p3 .pos { color: #b86a2a; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-20px); } }
.results-panel { width: min(640px, 100%); }
.podium-panel { width: min(720px, 100%); align-items: stretch; }
.podium-panel .results-table { flex: none; overflow: visible; }
.podium-stage { display: flex; justify-content: center; align-items: flex-end; gap: 12px; height: 220px; flex: none; }
.pod { display: flex; flex-direction: column; align-items: center; width: 150px; min-width: 0; flex: 0 1 auto; }
.pod img { width: 110px; height: 110px; animation: bob 1.4s ease-in-out infinite; }
.pod .blk { width: 100%; border: 4px solid var(--ink); border-radius: 12px 12px 0 0; display: flex; align-items: flex-start; justify-content: center; font-family: var(--display); font-size: 40px; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; padding-top: 6px; }
.pod.p1 .blk { height: 110px; background: linear-gradient(#ffe066, #e0a800); }
.pod.p2 .blk { height: 80px; background: linear-gradient(#e6e9f0, #9aa3b5); }
.pod.p3 .blk { height: 55px; background: linear-gradient(#f0b27a, #b86a2a); }
.pod .nm { font-weight: 900; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.podium-msg { font-family: var(--display); font-size: 28px; text-align: center; margin: 0; color: var(--red); }

/* ---------------------------------------------------------------- HUD */
.hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 5; font-family: var(--display); color: #fff; }
.hud.active { display: block; }
.hud * { -webkit-text-stroke: 0; }
.hud-item { position: absolute; left: max(16px, env(safe-area-inset-left)); top: calc(16px + env(safe-area-inset-top)); width: 92px; height: 92px; border-radius: 20px; background: rgba(20, 10, 40, 0.45); border: 4px solid #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); display: flex; align-items: center; justify-content: center; }
.hud-item #hud-item-icon { width: 70px; height: 70px; }
.hud-item #hud-item-icon svg { width: 100%; height: 100%; }
.hud-item.rolling { animation: shake 0.1s infinite; }
.hud-item.has { background: rgba(255, 210, 63, 0.35); animation: pop 0.3s; }
#hud-item-count { position: absolute; right: -8px; bottom: -8px; font-size: 22px; background: var(--red); border: 3px solid #fff; border-radius: 12px; padding: 0 6px; }
#hud-item-count:empty { display: none; }
.hud-item::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: 6px; height: 6px; border-radius: 3px; background: #ffd23f; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); transform-origin: left; transform: scaleX(var(--t, 0)); display: none; }
.hud-item.timed::after { display: block; }
@keyframes shake { 50% { transform: rotate(3deg); } }
@keyframes pop { 50% { transform: scale(1.15); } }
.hud-coins { position: absolute; left: max(16px, env(safe-area-inset-left)); top: calc(118px + env(safe-area-inset-top)); font-size: 26px; display: flex; align-items: center; gap: 6px; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5); }
.coin-ico { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff6b0, #ffcc22 45%, #c88a00); border: 3px solid #7a5200; display: inline-block; }
.hud-topright { position: absolute; right: max(16px, env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top)); text-align: right; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55); }
.hud-time { font-size: 30px; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.hud-lap { font-size: 34px; }
.hud-lap small { font-size: 20px; opacity: 0.9; }
.hud-splits { font-family: var(--body); font-weight: 900; font-size: 14px; opacity: 0.9; }
.hud-records { margin-top: 6px; font-family: var(--body); font-weight: 900; font-size: 15px; line-height: 1.35; }
.hud-records small { font-size: 11px; opacity: 0.85; letter-spacing: 0.5px; }
.hud-records b { color: #ffd23f; font-variant-numeric: tabular-nums; }
.hud-standings { position: absolute; left: max(16px, env(safe-area-inset-left)); top: 170px; width: 170px; height: 240px; font-family: var(--body); font-weight: 900; font-size: 13px; }
.st-row { position: absolute; left: 0; top: 0; height: 27px; width: 100%; display: flex; align-items: center; gap: 5px; background: rgba(20, 10, 40, 0.45); border-radius: 14px; padding: 0 8px 0 4px; transition: transform 0.35s ease; }
.st-row.me { background: rgba(226, 59, 59, 0.85); }
.st-row img { width: 24px; height: 24px; }
.st-pos { width: 16px; text-align: center; font-family: var(--display); font-size: 16px; }
.st-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-minimap { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: 110px; width: 190px; height: 190px; opacity: 0.95; }
.hud-place { position: absolute; right: max(22px, env(safe-area-inset-right)); bottom: 8px; font-size: 96px; line-height: 1; -webkit-text-stroke: 5px var(--ink) !important; paint-order: stroke fill; color: #fff; transform: rotate(-4deg); }
.hud-place #hud-place-suf { font-size: 48px; -webkit-text-stroke: 4px var(--ink) !important; paint-order: stroke fill; }
.hud-place.p1 { color: #ffd23f; } .hud-place.p2 { color: #e6e9f0; } .hud-place.p3 { color: #f0a060; } .hud-place.p4, .hud-place.p5 { color: #7ad0ff; }
.hud-place.last { color: #ff6b6b; }
.hud-place.hidden { display: none; }
.hud-drift { position: absolute; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); width: 150px; height: 12px; margin-left: -75px; border-radius: 8px; background: rgba(0, 0, 0, 0.35); border: 3px solid #fff; opacity: 0; transition: opacity 0.2s; overflow: hidden; }
.hud-drift.on { opacity: 0.9; }
.hud-drift::after { content: ""; position: absolute; inset: 0; width: 0; background: #fff2b0; transition: width 0.2s, background 0.2s; }
.hud-drift.l1::after { width: 33%; background: #4aa8ff; }
.hud-drift.l2::after { width: 66%; background: #ff8a1a; }
.hud-drift.l3::after { width: 100%; background: #d060ff; }
#hud-center { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 110px; color: var(--yellow); -webkit-text-stroke: 6px var(--ink) !important; paint-order: stroke fill; opacity: 0; transform: scale(0.5); transition: opacity 0.15s, transform 0.25s cubic-bezier(0.3, 1.8, 0.5, 1); pointer-events: none; }
#hud-center.show { opacity: 1; transform: scale(1); }
#hud-center.count { font-size: 150px; }
#hud-center.go { color: #3cff7a; }
#hud-center.final { color: #ff5b5b; font-size: 80px; }
#hud-center.finish { color: #fff; font-size: 100px; }
#hud-center.info { font-size: 56px; color: #fff; }
#hud-sub { position: absolute; left: 0; right: 0; top: calc(30% + 130px); text-align: center; font-size: 30px; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.6); }
#hud-wrong { position: absolute; left: 0; right: 0; top: 18%; text-align: center; font-size: 56px; color: #ff4040; -webkit-text-stroke: 4px #fff !important; paint-order: stroke fill; display: none; animation: blink 0.5s steps(2) infinite; }
#hud-wrong.show { display: block; }
@keyframes blink { 50% { opacity: 0.2; } }
#hud-speedlines { position: absolute; inset: 0; opacity: 0; transition: opacity 0.25s; background: repeating-conic-gradient(from 0deg at 50% 55%, rgba(255, 255, 255, 0.16) 0deg 1.2deg, transparent 1.2deg 9deg); -webkit-mask-image: radial-gradient(circle at 50% 55%, transparent 32%, #000 75%); mask-image: radial-gradient(circle at 50% 55%, transparent 32%, #000 75%); animation: spinlines 0.35s linear infinite; }
@keyframes spinlines { to { transform: rotate(3deg) scale(1.02); } }
#hud-splat { position: absolute; inset: -5%; opacity: 0; transition: opacity 0.4s; background:
  radial-gradient(circle at 22% 30%, #9a0f28 0 11%, transparent 11.5%),
  radial-gradient(circle at 70% 40%, #b3122e 0 15%, transparent 15.5%),
  radial-gradient(circle at 45% 70%, #8a0c22 0 13%, transparent 13.5%),
  radial-gradient(circle at 85% 80%, #b3122e 0 9%, transparent 9.5%),
  radial-gradient(circle at 12% 78%, #a3102a 0 8%, transparent 8.5%),
  radial-gradient(circle at 55% 22%, #c0183a 0 7%, transparent 7.5%); }
#hud-flash { position: absolute; inset: 0; opacity: 0; background: #fff; }
.pause-btn { position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); pointer-events: auto; background: rgba(20, 10, 40, 0.4); color: #fff; border: 3px solid #fff; border-radius: 12px; font-size: 18px; padding: 4px 12px; cursor: pointer; display: none; }
body.touch-on .pause-btn { display: block; }
/* Time Trial's instant restart: top centre, beside the pause button on touch screens */
.hud-restart { position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); pointer-events: auto; background: rgba(20, 10, 40, 0.4); color: #fff; border: 3px solid #fff; border-radius: 12px; font-size: 20px; line-height: 1; padding: 5px 12px 6px; cursor: pointer; display: none; }
body.tt-race .hud-restart { display: block; }
body.touch-on.tt-race .hud-restart { transform: translateX(calc(-50% + 58px)); }
body.watching .hud-restart, body.replaying .hud-restart { display: none !important; }
.fps { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); font-family: var(--body); font-size: 12px; font-weight: 900; text-shadow: 0 1px 2px #000; }

.touch { display: none; }
body.touch-on .touch { display: block; }
.touch-stick { position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom)); width: 200px; height: 110px; border-radius: 60px; background: rgba(255, 255, 255, 0.15); border: 3px solid rgba(255, 255, 255, 0.6); pointer-events: auto; touch-action: none; display: flex; align-items: center; justify-content: center; }
#touch-knob { width: 76px; height: 76px; border-radius: 50%; background: rgba(255, 255, 255, 0.8); border: 3px solid var(--ink); transition: transform 0.05s; }
.touch-btns { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: 80px 100px; grid-template-rows: 80px 100px; gap: 10px; pointer-events: auto; }
body.touch-on .hud-place { bottom: auto; top: 110px; font-size: 70px; }
body.touch-on .hud-minimap { bottom: auto; top: 200px; width: 130px; height: 130px; }
.tbtn { border-radius: 50%; border: 4px solid #fff; background: rgba(20, 10, 40, 0.45); color: #fff; font-family: var(--display); font-size: 18px; touch-action: none; padding: 0; -webkit-user-select: none; user-select: none; }
.tbtn.down { background: rgba(255, 210, 63, 0.75); color: var(--ink); }
.tbtn.item { grid-column: 2; grid-row: 1; }
.tbtn.brake { grid-column: 1; grid-row: 2; font-size: 20px; }
.tbtn.drift { grid-column: 2; grid-row: 2; font-size: 22px; background: rgba(226, 59, 59, 0.6); }

/* ---------------------------------------------------------------- voice + race chat */
.voice-bar { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
#mute-btn { display: none; }
.voice-on #mute-btn { display: inline-block; }
.voice-hint { font-size: 13px; margin: 6px 0 0; }
.lp .vc { border: 0; background: none; font-size: 18px; padding: 0 2px; cursor: pointer; line-height: 1; opacity: 0.85; }
.lp .vc.off { opacity: 0.45; }
.lp .vc.wait { animation: blink 1s steps(2) infinite; }
.lp .vc:disabled { cursor: default; }
.lp.talking { box-shadow: 0 0 0 3px #3ccf6e, 0 0 12px rgba(60, 207, 110, 0.7); }
.hud-social { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: 18px; width: min(380px, 60vw); display: none; flex-direction: column; gap: 6px; font-family: var(--body); font-weight: 900; }
.hud-social.on { display: flex; }
body.touch-on .hud-social { bottom: 150px; }
.hud-feed { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.hud-feed div { align-self: flex-start; max-width: 100%; background: rgba(20, 10, 40, 0.55); border-radius: 10px; padding: 3px 9px; text-shadow: 0 1px 2px #000; overflow-wrap: anywhere; transition: opacity 0.6s; }
.hud-feed div.sys { font-style: italic; opacity: 0.85; }
.hud-feed div.fade { opacity: 0; }
.hud-feed b { color: var(--yellow); }
.hud-voice { display: flex; align-items: center; gap: 8px; min-height: 38px; }
.hud-mic { pointer-events: auto; width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; background: rgba(20, 10, 40, 0.45); font-size: 17px; cursor: pointer; padding: 0; }
.hud-mic.live { background: rgba(60, 207, 110, 0.75); }
.hud-mic.muted { background: rgba(226, 59, 59, 0.75); }
.hud-mic.talk { box-shadow: 0 0 0 3px #3cff7a; }
.hud-talkers { font-size: 14px; text-shadow: 0 1px 3px #000; }
.race-chat { display: none; pointer-events: auto; }
.race-chat.open { display: block; }
#race-chat-input { width: 100%; font-size: 16px; padding: 7px 10px; border-radius: 10px; border: 3px solid #fff; background: rgba(20, 10, 40, 0.8); color: #fff; font-family: var(--body); font-weight: 800; outline: none; }
.hud-social-hint { font-size: 12px; opacity: 0.7; text-shadow: 0 1px 2px #000; }
body.touch-on .hud-social-hint { display: none; }

/* ---------------------------------------------------------------- quick volume sliders */
.vols { display: flex; flex-direction: column; gap: 4px; }
.lobby-panel .vols { margin-top: 4px; padding-top: 8px; border-top: 2px solid #f0edf7; }
.vol { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 14px; }
.vol span { width: 84px; flex: none; white-space: nowrap; }
.vol input[type="range"] { flex: 1; min-width: 0; accent-color: var(--red); }
#pause .vols { margin-bottom: 6px; }
#pause:not(.online) .vol.online-only { display: none; }

/* ---------------------------------------------------------------- toasts */
.notify-prefs { display: flex; flex-direction: column; gap: 2px; }
.notify-prefs[hidden], .notify-ask[hidden] { display: none; }
.notify-ask { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 12px; border-radius: 14px; background: #fff7d6; border: 3px solid var(--yellow); animation: toastIn 0.3s ease-out; }
.notify-ask p { margin: 0; flex: 1 1 220px; font-weight: 800; color: var(--ink); }
.toasts { position: fixed; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; font-weight: 800; padding: 10px 16px; border-radius: 12px; border: 3px solid #fff; box-shadow: var(--shadow); animation: toastIn 0.25s ease-out; max-width: 90vw; }
.toast.err { background: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .online-grid, .lobby-grid, .howto-grid { grid-template-columns: 1fr; }
  #select { justify-content: center; }
}
@media (max-width: 600px) {
  .panel { padding: 16px; }
  .screen-title { font-size: 28px; }
  .char-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .char-card span { font-size: 11px; }
  .stats { grid-template-columns: auto 110px; }
  .hud-item { width: 70px; height: 70px; }
  .hud-item #hud-item-icon { width: 52px; height: 52px; }
  .hud-coins { top: 92px; font-size: 20px; }
  .hud-standings { display: none; }
  .hud-time { font-size: 20px; }
  .hud-lap { font-size: 24px; }
  .hud-splits { display: none; }
  .hud-records { font-size: 12px; margin-top: 2px; }
  .hud-records small { font-size: 9px; }
  #hud-center { font-size: 70px; }
  #hud-center.count { font-size: 100px; }
  .rr { grid-template-columns: 34px 38px 1fr auto; }
  .rr .time { display: none; }
  .rr img { width: 36px; height: 36px; }
  .podium-stage { height: 200px; }
  .pod img { width: 80px; height: 80px; }
}
@media (max-height: 520px) {
  .hud-standings { display: none; }
  .hud-minimap { width: 130px; height: 130px; bottom: 90px; }
  .hud-place { font-size: 64px; }
}

/* Short screens: tighten the main menu so its last button row fits without scrolling. */
@media (max-height: 720px) {
  .menu-list { gap: 10px; }
  .btn.mode { padding-top: 8px; padding-bottom: 8px; }
}
@media (max-height: 720px) and (orientation: portrait) {
  .menu-panel { gap: 10px; }
  .menu-list { gap: 8px; }
  .logo.small .l1 { font-size: 42px; }
  .logo.small .l2 { font-size: 34px; }
  .btn.mode { padding-top: 5px; padding-bottom: 5px; }
  .btn.mode b { font-size: 23px; }
  .btn.mode small { font-size: 13px; }
}

/* ---------------------------------------------------------------- touch vs keyboard content */
.touch-only { display: none; }
body.touch-on .touch-only { display: flex; }
body.touch-on .no-touch { display: none; }
.touch-keys td:first-child { text-align: center; }
.tk { display: inline-flex; align-items: center; justify-content: center; min-width: 54px; height: 30px; padding: 0 8px; border-radius: 15px; border: 2px solid var(--ink); background: var(--ink); color: #fff; font-family: var(--display); font-size: 14px; letter-spacing: 0.5px; }
.tk.sm { min-width: 0; height: 22px; font-size: 11px; padding: 0 6px; vertical-align: middle; }
.tk.stick { width: 70px; background: #efe9fb; position: relative; }
.tk.stick::after { content: ""; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); }
.pause-btns { display: flex; flex-direction: column; gap: 14px; }
.hud-chat { display: none; }
/* Tilt steering: the pad still works as an override and its knob shows the wheel angle. */
body.tilt-on .touch-stick { opacity: 0.6; }
body.tilt-on .touch-stick::before { content: "TILT"; position: absolute; top: -22px; left: 0; right: 0; text-align: center; font-family: var(--display); font-size: 14px; letter-spacing: 1px; color: #fff; text-shadow: 0 2px 3px rgba(0, 0, 0, 0.6); }
body.touch-on .hud-chat { display: block; }

/* ---------------------------------------------------------------- phones, portrait */
@media (max-width: 500px) {
  .panel { --pad: 14px; gap: 12px; }
  .track-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .track-card canvas { aspect-ratio: 1.5; }
  .track-card b { font-size: 16px; }
  .track-card small { font-size: 12px; }
  .row.between { gap: 8px; }
  .lobby-panel > .row.between .row { gap: 8px; }
  .lobby-panel > .row.between .btn { padding: 9px 12px; font-size: 15px; }
  .chat-card { min-height: 0; }
  .keys td { padding: 4px 3px; }
  .records-tracks { grid-template-columns: repeat(4, 1fr); } /* eight tabs in two rows */
  .records-tracks button:nth-child(-n + 4) { border-bottom: 2px solid var(--ink); }
  .records-tracks button:nth-child(4) { border-right: 0; }
  .records-tracks button { font-size: 12px; padding: 6px 2px; }
  .daily-card { grid-template-columns: 120px 1fr; gap: 10px; }
  .daily-info > b { font-size: 20px; }
  .daily-racer img { width: 38px; height: 38px; }
  .daily-racer small { font-size: 13px; }
  /* Stick + buttons must share ~375px without overlapping. */
  .touch-stick { width: 150px; height: 100px; }
  #touch-knob { width: 64px; height: 64px; }
  .touch-btns { grid-template-columns: 70px 84px; grid-template-rows: 70px 84px; }
  body.touch-on .hud-social { bottom: calc(140px + env(safe-area-inset-bottom)); }
}

/* ---------------------------------------------------------------- phones, landscape */
@media (max-height: 500px) and (orientation: landscape) {
  .screen { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .panel { --pad: 14px; gap: 8px; border-width: 3px; }
  .screen-title { font-size: 24px; }
  .sub-title { font-size: 18px; margin: 0; }
  h3 { font-size: 18px; margin-bottom: 4px; }
  .card { padding: 10px; gap: 8px; }
  .btn { font-size: 15px; padding: 8px 16px; }

  /* title */
  .title-wrap { gap: 10px; }
  .btn.big { font-size: 26px; padding: 8px 32px; }
  .tagline { font-size: 20px; }
  .footer-note { font-size: 12px; bottom: max(6px, env(safe-area-inset-bottom)); }

  /* main menu: logo on the left, modes in a 2x2 grid */
  .menu-panel { flex-direction: row; width: min(760px, 100%); gap: 16px; }
  .menu-panel .logo.small { flex: none; }
  .logo.small .l1 { font-size: 40px; }
  .logo.small .l2 { font-size: 32px; }
  .menu-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .menu-list .row { grid-column: 1 / -1; }
  .menu-list .row .btn { flex: 1; }
  .menu-list .row { grid-template-columns: repeat(4, 1fr); }
  /* Daily Challenge gets its own slim row under the 2x2 grid. */
  .btn.mode.daily { grid-column: 1 / -1; order: 1; min-height: 0; }
  .menu-list .row { order: 2; }
  .btn.mode { padding: 8px 12px 8px 60px; min-height: 72px; justify-content: center; }
  .btn.mode b { font-size: 21px; }
  .btn.mode small { font-size: 12px; line-height: 1.25; }
  .btn.mode::before { left: 10px; width: 38px; height: 38px; margin-top: -19px; }

  /* racer select: panel on the left, the spinning kart stays visible on the right */
  #select { justify-content: flex-start; }
  .select-panel { width: min(470px, 58%); }
  .char-grid { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .char-card { padding: 2px; border-radius: 10px; }
  .char-card span { display: none; }
  .char-card.sel { transform: translateY(-2px); }
  .sel-detail { gap: 8px; }
  .sel-detail h3 { font-size: 22px; }
  .stats { grid-template-columns: auto 110px; font-size: 12px; gap: 2px 8px; }
  .kart-grid { gap: 6px; }
  .kart-card { padding: 5px 8px; }
  .kart-card b { font-size: 16px; }
  .kart-card small { font-size: 11px; line-height: 1.2; display: block; }
  .seg button { padding: 7px 12px; font-size: 14px; }
  .panel > p, .lobby-head p { margin: 0; }
  .settings-panel .field.check { min-height: 32px; }

  /* tracks: all eight in one row */
  .track-grid { grid-template-columns: repeat(8, 1fr); gap: 8px; }
  .track-card canvas { aspect-ratio: 1.6; }
  .track-card .tinfo { padding: 5px 7px; }
  .track-card b { font-size: 14px; }
  .track-card small { font-size: 11px; }

  /* online, lobby, how to play: use the width */
  .online-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .lobby-grid { grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
  .howto-grid { grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
  .btn.big-ish { font-size: 18px; padding: 10px; }
  .room-list { max-height: none; }
  .chat-card { min-height: 0; }
  .chat-log { min-height: 90px; max-height: 160px; }
  .lp img { width: 34px; height: 34px; }
  .keys td { padding: 3px 4px; font-size: 13px; }
  .tips { font-size: 13px; gap: 5px; }
  .whatsnew-panel { width: min(640px, 100%); }
  .records-panel { width: min(640px, 100%); }
  .records-tracks button { font-size: 13px; padding: 6px 4px; }
  .whatsnew-list { gap: 8px; }
  .hi { font-size: 12px; }
  .hi svg { width: 26px; height: 26px; }

  /* settings in two columns */
  .settings-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; width: min(640px, 100%); align-items: start; }
  .settings-panel > .screen-title, .settings-panel > .row:last-child { grid-column: 1 / -1; }

  /* pause */
  #pause .small-panel { width: min(460px, 100%); }
  .pause-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

  /* results + podium */
  .results-panel .screen-title { font-size: 22px; }
  #results-sub { margin: -4px 0 0; }
  .rr { padding: 0 10px; }
  .rr img { width: 32px; height: 32px; }
  .rr .pos { font-size: 20px; }
  .podium-panel .screen-title { font-size: 22px; }
  .podium-stage { height: 150px; }
  .pod { width: 120px; }
  .pod img { width: 64px; height: 64px; }
  .pod .nm { font-size: 13px; }
  .pod .blk { font-size: 28px; padding-top: 2px; }
  .pod.p1 .blk { height: 64px; } .pod.p2 .blk { height: 46px; } .pod.p3 .blk { height: 32px; }
  .podium-msg { font-size: 20px; }

  /* HUD with touch controls: pack the info around the top, controls along the bottom */
  body.touch-on .hud-item { top: 10px; width: 62px; height: 62px; border-radius: 16px; border-width: 3px; }
  body.touch-on .hud-item #hud-item-icon { width: 46px; height: 46px; }
  body.touch-on #hud-item-count { font-size: 16px; }
  body.touch-on .hud-coins { top: 26px; left: calc(max(16px, env(safe-area-inset-left)) + 74px); font-size: 22px; }
  body.touch-on .hud-topright { top: 6px; }
  body.touch-on .hud-time { font-size: 18px; }
  body.touch-on .hud-lap { font-size: 22px; }
  body.touch-on .hud-lap small { font-size: 14px; }
  body.touch-on .hud-splits { display: none; }
  body.touch-on .hud-place { top: 56px; bottom: auto; right: max(20px, env(safe-area-inset-right)); font-size: 46px; -webkit-text-stroke: 4px var(--ink) !important; }
  body.touch-on .hud-place #hud-place-suf { font-size: 24px; -webkit-text-stroke: 3px var(--ink) !important; }
  body.touch-on .hud-minimap { top: 82px; bottom: auto; left: max(12px, env(safe-area-inset-left)); right: auto; width: 110px; height: 110px; }
  body.touch-on .pause-btn { top: 8px; }
  body.touch-on .touch-stick { bottom: max(12px, env(safe-area-inset-bottom)); width: 170px; height: 90px; }
  body.touch-on #touch-knob { width: 62px; height: 62px; }
  body.touch-on .touch-btns { bottom: max(12px, env(safe-area-inset-bottom)); grid-template-columns: 64px 80px; grid-template-rows: 64px 80px; gap: 8px; }
  body.touch-on .tbtn { font-size: 15px; }
  body.touch-on .hud-social { top: 50px; bottom: auto; left: 50%; transform: translateX(-50%); width: min(340px, 42vw); align-items: center; }
  body.touch-on .hud-feed div { align-self: center; }
  #hud-center { font-size: 64px; top: 24%; }
  #hud-center.count { font-size: 96px; }
  #hud-center.final, #hud-center.finish { font-size: 60px; }
  #hud-center.info { font-size: 36px; }
  #hud-sub { top: calc(24% + 90px); font-size: 22px; }
  #hud-wrong { font-size: 40px; }
}
@media (max-height: 500px) and (orientation: landscape) and (max-width: 760px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; }
  .lobby-grid .chat-card { grid-column: 1 / -1; }
}
