:root {
  --panel: rgba(20, 32, 24, 0.86);
  --panel-line: rgba(255, 255, 255, 0.12);
  --text: #f4f8ef;
  --muted: #a9bfa5;
  --accent: #7be04a;
  --gold: #ffd54a;
  --danger: #ff6b6b;
  --sidebar-w: 300px;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #79a85a;
  color: var(--text);
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#topbar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 5;
}

#mode-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 18px 0 14px;
  border-radius: 14px;
  border: 2px solid var(--panel-line);
  background: var(--panel);
  font-weight: 700;
  font-size: 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#mode-toggle:active {
  transform: translateY(1px);
}

.mode-icon {
  width: 26px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid var(--text);
  position: relative;
}

.mode-icon.desktop::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 3px;
  margin-left: -6px;
  background: var(--text);
  border-radius: 2px;
}

.mode-icon.touch {
  width: 16px;
  height: 24px;
  border-radius: 5px;
}

.mode-icon.touch::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  background: var(--text);
  border-radius: 50%;
}

.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.conn .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f0b429;
}

.conn.online .dot {
  background: var(--accent);
}

.conn.offline .dot {
  background: var(--danger);
}

.banner {
  position: fixed;
  top: max(72px, calc(env(safe-area-inset-top) + 60px));
  left: 0;
  right: var(--sidebar-w);
  margin: 0 auto;
  width: max-content;
  max-width: 80vw;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(255, 107, 107, 0.95);
  color: #2b0b0b;
  font-weight: 800;
  z-index: 6;
  pointer-events: none;
}

body.sidebar-closed .banner {
  right: 0;
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) 14px;
  background: var(--panel);
  border-left: 2px solid var(--panel-line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  z-index: 4;
  touch-action: pan-y;
}

#sidebar header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

#sidebar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0.3px;
  color: var(--accent);
  text-transform: uppercase;
}

#sidebar-toggle,
#sidebar-open {
  border: 2px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  position: relative;
}

#sidebar-toggle::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 12px;
  width: 8px;
  height: 8px;
  border-right: 3px solid var(--text);
  border-top: 3px solid var(--text);
  transform: rotate(45deg);
}

#sidebar-open {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: auto;
  padding: 0 16px;
  min-height: 48px;
  z-index: 5;
  background: var(--panel);
  font-weight: 800;
  font-size: 16px;
}

body.sidebar-closed #sidebar {
  display: none;
}

.card {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-line);
}

.label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.money {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.money strong {
  font-size: 34px;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  font-variant-numeric: tabular-nums;
}

.money.bump strong {
  animation: bump 0.4s ease;
}

@keyframes bump {
  40% {
    transform: scale(1.12);
  }
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.row.small {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 6px;
}

.bar {
  height: 14px;
  margin-top: 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

#basket-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7be04a, #d6f04a);
  border-radius: 8px;
  transition: width 0.12s linear, background 0.2s;
}

#basket-fill.full {
  background: linear-gradient(90deg, #ff9d4a, #ff6b6b);
}

#upgrades {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-title {
  margin: 8px 2px 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.upgrade {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 66px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 2px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
  touch-action: manipulation;
}

.upgrade.affordable {
  border-color: var(--accent);
  background: rgba(123, 224, 74, 0.14);
}

.upgrade.maxed {
  border-color: var(--gold);
  background: rgba(255, 213, 74, 0.1);
}

.upgrade.blocked {
  opacity: 0.72;
  border-style: dashed;
}

.upgrade:active {
  transform: translateY(1px);
}

.upgrade.flash {
  animation: flash 0.5s ease;
}

@keyframes flash {
  30% {
    background: rgba(255, 255, 255, 0.45);
  }
}

.upgrade .body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.upgrade .title {
  font-weight: 800;
  font-size: 14px;
}

.key {
  display: none;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.15);
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
}

body.mode-desktop .key {
  display: inline-block;
}

.upgrade .stat {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.25;
}

.upgrade .note {
  font-size: 11.5px;
  font-weight: 700;
  color: #ffb84a;
}

.upgrade .cost {
  font-weight: 800;
  font-size: 14px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.upgrade:not(.affordable):not(.maxed) .cost {
  color: #d59090;
}

.pips {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.pips i {
  width: 8px;
  height: 5px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.18);
}

.pips i.on {
  background: var(--accent);
}

.badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border-bottom: 4px solid rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.badge b {
  font-size: 17px;
}

.badge small {
  font-size: 9px;
  opacity: 0.85;
  margin-top: 2px;
}

.badge.g-cut {
  background: #e63946;
}

.badge.g-drive {
  background: #3b82f6;
}

.badge.g-store {
  background: #f59e0b;
}

.badge.g-gear {
  background: #8b5cf6;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chip #clock-label {
  color: var(--muted);
}

.chip.night {
  background: rgba(24, 30, 66, 0.92);
}

.chip.bonus #clock-label {
  color: var(--gold);
}

.clock-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffd54a;
  box-shadow: 0 0 8px #ffd54a;
}

.chip.night .clock-icon {
  background: transparent;
  box-shadow: inset -4px -2px 0 0 #cfd8ff;
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #10230a;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}

.account .who {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

#logout {
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

#wood-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b9814a, #e0aa63);
  border-radius: 8px;
  transition: width 0.12s linear;
}

#wood-fill.full {
  background: linear-gradient(90deg, #ff9d4a, #ff6b6b);
}

.hint {
  margin: 0;
  margin-top: auto;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

/* Joystick */
#joystick {
  position: fixed;
  left: max(28px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 170px;
  height: 170px;
  z-index: 3;
  touch-action: none;
}

#joy-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(20, 32, 24, 0.45);
  border: 3px solid rgba(255, 255, 255, 0.35);
}

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 74px;
  height: 74px;
  margin: -37px 0 0 -37px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  border: 3px solid rgba(0, 0, 0, 0.25);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  will-change: transform;
}

/* Compass: floats around the mower and points back to the SELL pad */
#compass {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 2;
  pointer-events: none;
  will-change: transform;
}

#compass-arrow {
  position: absolute;
  left: -19px;
  top: -19px;
  width: 38px;
  height: 38px;
  background: var(--gold);
  clip-path: polygon(50% 0, 100% 100%, 50% 75%, 0 100%);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.4));
}

#compass-label {
  position: absolute;
  left: -34px;
  top: -18px;
  width: 68px;
  padding: 3px 0;
  text-align: center;
  border-radius: 10px;
  background: var(--panel);
  border: 2px solid var(--gold);
  line-height: 1.1;
}

#compass-label span {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--muted);
}

#compass-label strong {
  font-size: 15px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* Toasts */
#toasts {
  position: fixed;
  left: 0;
  right: var(--sidebar-w);
  bottom: max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 7;
}

body.sidebar-closed #toasts {
  right: 0;
}

.toast {
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  font-weight: 800;
  animation: toast-in 0.2s ease, toast-out 0.4s ease 2.2s forwards;
}

.toast.error {
  border-color: var(--danger);
}

.toast.success {
  border-color: var(--gold);
  color: var(--gold);
  font-size: 22px;
}

@keyframes toast-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Overlay */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 30, 18, 0.88);
  transition: opacity 0.3s;
}

#overlay.done {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  font-weight: 700;
  text-align: center;
  padding: 0 24px;
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  animation: spin 1s infinite ease-in-out;
}

@keyframes spin {
  50% {
    transform: rotate(180deg) scale(0.6);
    border-radius: 50%;
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Narrow screens (iPad portrait and below) */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 260px;
  }

  .money strong {
    font-size: 28px;
  }

  #sidebar h1 {
    font-size: 18px;
  }
}

@media (max-width: 640px) {
  :root {
    --sidebar-w: 0px;
  }

  #sidebar {
    width: min(300px, 84vw);
    box-shadow: -12px 0 30px rgba(0, 0, 0, 0.4);
  }
}

/* Toolbar, players, guest note */
#toolbar {
  position: fixed;
  top: max(72px, calc(env(safe-area-inset-top) + 60px));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}

.tool {
  position: relative;
  width: 46px;
  height: 46px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  border: 2px solid var(--panel-line);
  background: var(--panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: manipulation;
}

.tool svg {
  width: 24px;
  height: 24px;
  fill: var(--text);
}

#btn-lobbies svg {
  fill: none;
  color: var(--text);
}

.tool:active {
  transform: translateY(1px);
}

#btn-sound .mute {
  display: none;
}

#btn-sound.muted .waves {
  display: none;
}

#btn-sound.muted .mute {
  display: block;
  stroke: var(--danger);
}

.badge-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid #1a2a1f;
}

.people {
  width: 14px;
  height: 10px;
  position: relative;
}

.people::before,
.people::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 7px;
  height: 7px;
  border-radius: 50% 50% 2px 2px;
  background: var(--accent);
}

.people::before {
  left: 0;
}

.people::after {
  right: 0;
  opacity: 0.6;
}

.guest-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed #ffb84a;
  background: rgba(255, 184, 74, 0.1);
  color: #ffd9a0;
  font-size: 12px;
  line-height: 1.35;
}

.badge.g-farm {
  background: #d6336c;
}

.badge.g-engine {
  background: #f76707;
}

.equip-toggle {
  min-height: 38px;
  margin-top: -4px;
  border-radius: 10px;
  border: 2px dashed var(--panel-line);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
  font-size: 13px;
}

.equip-toggle.on {
  border-style: solid;
  border-color: #8b5cf6;
  background: rgba(139, 92, 246, 0.22);
}

/* Engine shop */
.shopcard #shop-fill {
  height: 100%;
  width: 0%;
  border-radius: 8px;
  background: linear-gradient(90deg, #f76707, #ffd54a);
  transition: width 0.2s;
}

.shopcard #shop-fill.done {
  background: linear-gradient(90deg, #7be04a, #d6f04a);
}

.linkish {
  margin-top: 8px;
  width: 100%;
  min-height: 40px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  background: rgba(123, 224, 74, 0.14);
  font-weight: 800;
}

#shop-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  min-width: 280px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) 14px;
  background: linear-gradient(180deg, rgba(48, 26, 12, 0.94), rgba(20, 32, 24, 0.94));
  border-left: 2px solid #f76707;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  z-index: 6;
  touch-action: pan-y;
}

#shop-panel header,
#chat header,
.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

#shop-panel h2 {
  margin: 0;
  font-size: 20px;
  color: #ffa94d;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

#shop-panel header p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

#shop-panel .bonus {
  margin: 0;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--gold);
}

.money-mini {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.money-mini strong {
  font-size: 22px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

#shop-parts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.close-x {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 2px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.08);
  font-size: 22px;
  line-height: 1;
}

body.shop-open #sidebar,
body.shop-open #sidebar-open,
body.dealer-open #sidebar,
body.yard-open #sidebar,
body.dealer-open #sidebar-open,
body.yard-open #sidebar-open {
  display: none;
}

body.shop-open .banner,
body.shop-open #toasts,
body.dealer-open .banner,
body.yard-open .banner,
body.dealer-open #toasts,
body.yard-open #toasts {
  right: var(--sidebar-w);
}

#fuel-fill,
#temp-fill {
  height: 100%;
  width: 0%;
  border-radius: 8px;
}

#fuel-fill {
  background: linear-gradient(90deg, #f4a261, #7be04a);
}

#fuel-fill.low {
  background: #e4572e;
}

#temp-fill {
  background: linear-gradient(90deg, #4cc9f0, #f4a261);
}

#temp-fill.hot {
  background: #e4572e;
}

#dealer-panel,
#yard-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--sidebar-w);
  min-width: 280px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) 14px;
  background: linear-gradient(180deg, rgba(16, 36, 28, 0.96), rgba(20, 32, 24, 0.94));
  border-left: 2px solid #7dffa8;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  z-index: 6;
}

#yard-panel {
  border-left-color: #e0b040;
  background: linear-gradient(180deg, rgba(42, 28, 16, 0.96), rgba(28, 24, 18, 0.94));
}

#yard-panel .veh.on {
  border-color: #e0b040;
}

#yard-panel .veh-buy {
  border-color: #e0b040;
  background: rgba(224, 176, 64, 0.16);
}

#dealer-panel header,
#yard-panel header,
#ecu-box h3 {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#dealer-panel h2,
#yard-panel h2,
#ecu-box h3 {
  margin: 0;
  font-size: 22px;
}

#dealer-panel header p,
#yard-panel header p,
#ecu-box .fine,
.veh p {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.35;
}

.veh {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--panel-line);
  background: rgba(0, 0, 0, 0.22);
}

.veh.on {
  border-color: #7dffa8;
}

.veh h3 {
  margin: 0;
  font-size: 16px;
}

.veh .stats {
  opacity: 0.9;
}

.veh-buy {
  min-height: 40px;
  border-radius: 10px;
  border: 2px solid #7dffa8;
  background: rgba(125, 255, 168, 0.16);
  font-weight: 800;
}

.veh-buy:disabled {
  opacity: 0.55;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatches button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
}

.swatches button.on {
  border-color: #fff;
}

/* Chat */
#chat {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(340px, calc(100vw - var(--sidebar-w) - 40px));
  min-width: 250px;
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  border: 2px solid var(--panel-line);
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 6;
  touch-action: pan-y;
  -webkit-user-select: text;
  user-select: text;
}

#chat header strong {
  align-self: center;
}

#chat .close-x {
  width: 30px;
  height: 30px;
  font-size: 18px;
}

#chat-log {
  flex: 1;
  min-height: 90px;
  max-height: 30vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  line-height: 1.35;
}

#chat-log .empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 12.5px;
}

#chat-log .msg b {
  margin-right: 6px;
  color: var(--accent);
}

#chat-log .msg.mine b {
  color: var(--gold);
}

#chat-form {
  display: flex;
  gap: 6px;
}

#chat-form input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 2px solid var(--panel-line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}

#chat-form input:focus {
  outline: none;
  border-color: var(--accent);
}

#chat-form button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 2px solid var(--accent);
  background: rgba(123, 224, 74, 0.16);
  font-weight: 800;
}

/* Settings dialog */
.modal {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 16, 10, 0.6);
  touch-action: pan-y;
}

.modal-card {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 18px;
  border-radius: 18px;
  border: 2px solid var(--panel-line);
  background: rgba(24, 38, 28, 0.97);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-card h2 {
  margin: 0;
  font-size: 22px;
}

.preview-host {
  height: 168px;
  min-height: 168px;
  flex: none;
  border-radius: 12px;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #243628, #101810 70%);
  border: 2px solid var(--panel-line);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.links a {
  color: var(--accent);
}

.msg-tools {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.msg-tools button,
#account-export,
#account-delete {
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-line);
  background: transparent;
  color: inherit;
}

#account-delete {
  border-color: #e4572e;
  margin-top: 8px;
}

#account-delete-pw {
  width: 100%;
  margin: 6px 0;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-line);
  background: rgba(0, 0, 0, 0.25);
  color: inherit;
}

.preview-canvas {
  width: 100%;
  height: 168px;
  display: block;
}

.lobby-card,
.light-row {
  margin: 0 0 8px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.04);
}

.lobby-card.on,
.light-row.on,
.lobby-private.on {
  border-color: var(--accent);
}

.lobby-private {
  min-height: 42px;
  border-radius: 12px;
  border: 2px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 800;
}

.name-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0;
}

.chip-name {
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.board-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.board-row.on b {
  color: var(--accent);
}

#board-tabs button {
  flex: 1 1 30%;
  font-size: 12px;
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.seg {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.seg button {
  flex: 1 1 auto;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 2px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
  font-size: 14px;
}

.seg button.on {
  border-color: var(--accent);
  background: rgba(123, 224, 74, 0.2);
  color: #eaffd8;
}

.seg.five button {
  padding: 0 6px;
  font-size: 13px;
}

.desc {
  margin: 8px 0;
  min-height: 3.6em;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.fine {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--muted);
}

.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .track {
  flex: none;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  position: relative;
  transition: background 0.15s;
}

.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.switch input:checked + .track {
  background: var(--accent);
}

.switch input:checked + .track::after {
  transform: translateX(20px);
}

.switch input:focus-visible + .track {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.switch .text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.switch .text small {
  color: var(--muted);
  font-size: 12px;
}

.slider {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 600;
}

.slider input {
  width: 100%;
  accent-color: var(--accent);
  touch-action: pan-x;
}

/* Performance stats */
#perf {
  position: fixed;
  top: max(72px, calc(env(safe-area-inset-top) + 60px));
  left: max(70px, calc(env(safe-area-inset-left) + 58px));
  min-width: 170px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(8, 14, 10, 0.78);
  font: 600 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  z-index: 5;
  pointer-events: none;
}

#perf div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

#perf span {
  color: var(--muted);
}

#perf b.good {
  color: #7be04a;
}

#perf b.ok {
  color: #ffd54a;
}

#perf b.bad {
  color: #ff6b6b;
}

/* Nameplates of other players */
#nameplates {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.nameplate {
  position: absolute;
  left: 0;
  top: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(12, 20, 14, 0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  will-change: transform;
}

.nameplate.guest {
  font-style: italic;
  color: #ffd9a0;
}

/* Cinematic finish for the top graphics preset */
#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.32) 100%);
}

body.gfx-vignette #vignette {
  opacity: 1;
}

@media (max-width: 640px) {
  #shop-panel,
  #dealer-panel,
  #yard-panel {
    width: min(320px, 88vw);
  }

  body.shop-open .banner,
  body.shop-open #toasts,
  body.dealer-open .banner,
  body.yard-open .banner,
  body.dealer-open #toasts,
  body.yard-open #toasts {
    right: 0;
  }

  #chat {
    width: min(340px, calc(100vw - 24px));
  }

  .slider {
    grid-template-columns: 96px 1fr;
  }
}

body.mode-touch #chat {
  bottom: 220px;
}

#dash {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 4;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

body.dash-off #dash {
  display: none;
}

.dials {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.dial {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 58%, #1a221c 0 46%, transparent 47%),
    conic-gradient(from 220deg, #2a9d8f 0 150deg, #e9c46a 150deg 190deg, #e4572e 190deg 230deg, #121814 230deg 360deg);
  box-shadow: inset 0 0 0 4px #121814, 0 8px 18px rgba(0, 0, 0, 0.28);
  position: relative;
}

.dial .needle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 30px;
  margin-left: -1px;
  margin-top: -28px;
  background: #f4f1de;
  border-radius: 2px;
  transform-origin: 50% 28px;
  transform: rotate(-120deg);
}

.dial em,
.dial b,
.gear-badge span,
.gear-badge b {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-style: normal;
}

.dial em {
  top: 46px;
  font-size: 12px;
  font-weight: 700;
  color: #f4f1de;
}

.dial b {
  bottom: 8px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: #c9d4cc;
  font-weight: 600;
}

.gear-badge {
  min-width: 54px;
  padding: 4px 10px 5px;
  border-radius: 12px;
  background: rgba(18, 24, 20, 0.9);
  border: 2px solid #7dffa8;
  text-align: center;
  position: relative;
  height: 42px;
}

.gear-badge b {
  position: static;
  display: block;
  font-size: 18px;
  line-height: 1;
  color: #f4f1de;
}

.gear-badge span {
  position: static;
  display: block;
  font-size: 10px;
  color: #c9d4cc;
}

body.mode-touch #dash {
  bottom: 196px;
}

@media (max-width: 640px) {
  .dial {
    width: 68px;
    height: 68px;
  }

  .dial .needle {
    height: 22px;
    margin-top: -20px;
    transform-origin: 50% 20px;
  }

  .dial em {
    top: 34px;
    font-size: 11px;
  }
}

#demo-banner {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(560px, calc(100% - 24px));
  padding: 10px 10px 10px 16px;
  border-radius: 16px;
  background: #fffaf1;
  color: #1c2418;
  border: 2px solid #1c2418;
  box-shadow: 4px 4px 0 #1c2418;
}

#demo-banner p {
  margin: 0;
  flex: 1;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

#demo-banner a {
  flex: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: #2f7d32;
  color: #fffaf1;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

body.mode-touch #demo-banner {
  bottom: max(188px, calc(env(safe-area-inset-bottom) + 176px));
}

/* Phone fit. --ui is 1 on a tall screen and smaller when the phone is on its side.
   The settings slider multiplies it. */
:root {
  --ui: 1;
}

#mode-toggle {
  min-height: calc(48px * var(--ui));
  gap: calc(10px * var(--ui));
  padding: 0 calc(18px * var(--ui)) 0 calc(14px * var(--ui));
  font-size: calc(16px * var(--ui));
}

#toolbar {
  top: max(calc(72px * var(--ui)), calc(env(safe-area-inset-top) + 60px * var(--ui)));
  gap: calc(8px * var(--ui));
}

.tool {
  width: calc(46px * var(--ui));
  height: calc(46px * var(--ui));
}

.tool svg {
  width: calc(24px * var(--ui));
  height: calc(24px * var(--ui));
}

#sidebar-open {
  min-height: calc(48px * var(--ui));
  padding: 0 calc(16px * var(--ui));
  font-size: calc(16px * var(--ui));
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#joystick {
  width: calc(170px * var(--ui));
  height: calc(170px * var(--ui));
}

#joy-knob {
  width: calc(74px * var(--ui));
  height: calc(74px * var(--ui));
  margin: calc(-37px * var(--ui)) 0 0 calc(-37px * var(--ui));
}

.dial {
  width: calc(86px * var(--ui));
  height: calc(86px * var(--ui));
}

body.mode-touch #dash {
  bottom: calc(196px * var(--ui));
}

body.mode-touch #chat {
  bottom: calc(220px * var(--ui));
}

@media (max-width: 640px) {
  .dial {
    width: calc(68px * var(--ui));
    height: calc(68px * var(--ui));
  }
}

@media (max-width: 520px) {
  #conn-text,
  #players-text {
    display: none;
  }

  #conn,
  #players {
    padding: 0 10px;
  }
}

/* Phone on its side: the button column is taller than the screen. */
body.layout-landscape #toolbar {
  flex-direction: row;
  top: max(8px, env(safe-area-inset-top));
  left: auto;
  right: max(8px, env(safe-area-inset-right));
}

body.layout-landscape #topbar {
  max-width: 48vw;
}

body.layout-landscape #conn-text,
body.layout-landscape #players-text {
  display: none;
}

body.layout-landscape #sidebar-open {
  top: auto;
  bottom: max(8px, env(safe-area-inset-bottom));
  right: max(8px, env(safe-area-inset-right));
}

body.layout-landscape.mode-touch #dash,
body.layout-landscape.mode-touch #chat,
body.layout-landscape.mode-touch #demo-banner {
  bottom: max(8px, env(safe-area-inset-bottom));
}

body.layout-landscape.mode-touch #chat {
  left: calc(36px + 170px * var(--ui));
  width: min(280px, 42vw);
  max-height: 50vh;
}
