* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #10131a; color: #eef1f6; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 5px; margin: 0 1px; border-radius: 5px; background: rgba(255,255,255,.14); font-family: inherit; font-size: .9em; text-align: center; }
small { display: block; font-size: 12px; color: #b8c0cc; letter-spacing: .02em; }

/* Start screen: the map picture fills the window, the text and buttons sit over its dark left side
   (on phones, over its dark bottom). The picture stays put while a long card scrolls. */
.start {
  --start-inset: clamp(22px, 5.5vw, 78px);
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding: clamp(96px, 13vh, 140px) var(--start-inset) 58px;
  background: #10131a;
}
.start-map { position: fixed; inset: 0; background: #212730; }
.start-map canvas { width: 100%; height: 100%; display: block; }
.start-map::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, #10131a 0%, #10131af0 18%, #10131aaf 38%, #10131a1a 61%, transparent 80%),
    linear-gradient(0deg, #10131a 0%, transparent 29%);
}
.start-top {
  position: absolute; top: clamp(23px, 4vw, 47px); left: var(--start-inset); right: var(--start-inset);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.start-top .brand { display: block; width: clamp(178px, 22vw, 256px); height: auto; }
.start-settings { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.language-select { min-height: 40px; max-width: 100%; padding: 4px 6px; font: inherit; font-size: 13px; font-weight: 650; color: #eef1f6; background: #151d29; border: 1px solid #687483; border-radius: 5px; color-scheme: dark; cursor: pointer; }
.language-select:focus-visible { outline: 2px solid #ffc53d; outline-offset: 2px; }
.start-legend {
  position: fixed; z-index: 1; right: var(--start-inset); bottom: 41px;
  display: grid; gap: 6px; padding: 11px 13px;
  background: #10131a; border: 1px solid #384355; border-radius: 5px;
  font-size: 12px; line-height: 1.5;
}
.start-caption { font-size: 13px; font-weight: 740; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; color: #c9d0db; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { width: 8px; height: 8px; border-radius: 1px; background: #ffc53d; }
.legend b.rival { background: #65c5ee; }
.start-legend a { color: #aab3c0; font-size: 11px; text-underline-offset: 2px; }
.start-card { position: relative; width: min(46%, 530px); margin: auto 0; display: grid; gap: 14px; }
.start-card h1 { margin: 0; font-size: clamp(44px, 7.4vw, 106px); font-weight: 850; line-height: .94; letter-spacing: -.065em; text-wrap: balance; }
.start-card h1 b { font-weight: inherit; }
:lang(en) .start-card h1, :lang(pt) .start-card h1 { font-size: clamp(39px, 5.7vw, 81px); }
.start-card h1 span { display: block; color: #ffc53d; }
.start-card p { margin: 0; line-height: 1.5; color: #c9d0db; }
.start-card .lead { margin-top: 5px; font-size: clamp(15px, 1.65vw, 19px); max-width: 30ch; }
.start-actions { display: grid; gap: 9px; justify-items: start; margin: 12px 0 6px; }
.start .primary, .start .secondary { min-height: 48px; padding: 0 16px; border-radius: 5px; font-size: 14px; }
.start .secondary { background: #10131aee; border: 1px solid #687483; }
.start .secondary:hover { background: #1c212bee; }
.start .primary:focus-visible, .start .secondary:focus-visible { outline: 2px solid #eef1f6; outline-offset: 3px; }
.start .search input, .start .places button, .start .geo-help, .start .ad-box { border-radius: 5px; }
.start .search input { background: #10131aee; border-color: #687483; }
@media (max-width: 700px) {
  /* The picture keeps the top of the screen, the card starts under it. */
  .start { padding: 40vh var(--start-inset) 28px; }
  .start-map::after { background: linear-gradient(180deg, #10131ac7 0%, #10131a00 19%, #10131a00 39%, #10131aba 56%, #10131a 73%); }
  .start-top { top: 20px; gap: 8px; }
  .start-top .brand { width: min(49vw, 196px); }
  .start-card { width: 100%; margin: auto 0 0; }
  .start-card h1, :lang(en) .start-card h1, :lang(pt) .start-card h1 { font-size: clamp(39px, 9vw, 65px); }
  .start-legend { position: absolute; top: calc(40vh - 84px); bottom: auto; left: var(--start-inset); right: auto; padding: 6px 9px; }
  .start-legend .legend { display: none; }
}
.primary, .secondary { min-height: 52px; border-radius: 14px; border: 0; font-size: 17px; font-weight: 700; padding: 0 20px; }
.primary { background: #ffc53d; color: #1d1606; }
.primary:hover { background: #ffd469; }
.secondary { background: rgba(255,255,255,.1); color: #eef1f6; border: 1px solid rgba(255,255,255,.18); }
.secondary:hover { background: rgba(255,255,255,.16); }
button:disabled { opacity: .55; cursor: progress; }
.start-status { min-height: 1.5em; font-weight: 600; }
.start-status.error { color: #ff9aa9 !important; }
.search { display: grid; gap: 8px; }
.search label { font-size: 14px; color: #c7ced8; }
.search div { display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.06); color: #eef1f6; font: inherit; font-size: 16px; }
.search input:focus { outline: 2px solid #ffc53d; outline-offset: 1px; }
.search .secondary { min-height: 48px; font-size: 15px; }
.places { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.places button { width: 100%; min-height: 44px; padding: 8px 12px; text-align: left; border-radius: 10px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); color: #eef1f6; font-size: 14px; line-height: 1.35; }
.places button:hover { background: rgba(255,255,255,.12); }
.places button.approximate { border-color: rgba(255,197,61,.6); background: rgba(255,197,61,.14); font-weight: 700; }
.geo-help { display: grid; gap: 10px; padding: 14px 16px; border-radius: 14px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); }
.geo-help strong { font-size: 16px; }
.geo-help ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; line-height: 1.45; color: #dfe4ea; }
.fine { font-size: 13px; color: #9aa4b2 !important; }

:root {
  --hud-panel: rgba(16, 21, 31, .94);
  --hud-border: #3a4556;
  --hud-muted: #bbc4d1;
  --hud-accent: #ffc53d;
  --hud-inset: 16px;
  --hud-left: max(var(--hud-inset), env(safe-area-inset-left));
  --hud-right: max(var(--hud-inset), env(safe-area-inset-right));
  --hud-bottom: max(var(--hud-inset), env(safe-area-inset-bottom));
  --hud-players-width: 218px;
  --hud-map-width: 218px;
}
.bar {
  position: fixed;
  top: max(var(--hud-inset), env(safe-area-inset-top));
  left: var(--hud-left);
  right: calc(var(--hud-players-width) + var(--hud-right) + 8px);
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}
.overview, .drive-status, .players-panel, .map-panel, .turn, .keys-help, .toast, .loading-cells {
  background: var(--hud-panel);
  border: 1px solid var(--hud-border);
  border-radius: 8px;
  box-shadow: 0 3px 14px rgba(12, 17, 26, .24);
}
.overview { min-width: 190px; max-width: min(100%, 300px); border-top: 2px solid var(--hud-accent); }
.place { padding: 8px 12px; border-bottom: 1px solid var(--hud-border); }
.place strong { display: block; font-size: 14px; overflow-wrap: anywhere; }
.land { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 8px 12px 10px; }
.land strong { font-size: 26px; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--hud-accent); white-space: nowrap; }
.land span { max-width: 11ch; color: var(--hud-muted); font-size: 12px; line-height: 1.2; text-align: right; }
.drive-status { display: flex; max-width: 100%; }
.trail, .fuel {
  display: grid;
  align-content: center;
  gap: 5px;
  min-width: 0;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.fuel { border-left: 1px solid var(--hud-border); }
.trail[data-state="warning"] #trail-text { color: #ff9ca8; }
.meter { height: 4px; border-radius: 2px; background: #364151; overflow: hidden; }
.trail[data-state="home"] .meter, .trail[data-state="returning"] .meter { visibility: hidden; }
#trail-fill { height: 100%; width: 0; background: var(--hud-accent); transition: width .2s linear; }
.trail[data-state="warning"] #trail-fill { background: #ff5c6c; }
#fuel-fill { height: 100%; width: 100%; background: #3ccf7a; transition: width .3s linear; }
#fuel-fill.low { background: #ff9f3d; }
#fuel-fill.empty { background: #ff5c6c; }

.players-panel, .map-panel {
  position: fixed;
  padding: 8px;
  display: grid;
  gap: 8px;
}
.players-panel { top: max(var(--hud-inset), env(safe-area-inset-top)); right: var(--hud-right); width: var(--hud-players-width); }
.map-panel { bottom: var(--hud-bottom); left: var(--hud-left); width: var(--hud-map-width); }
.me-menu:not([hidden]) + .ranking { border-top: 1px solid var(--hud-border); padding-top: 8px; }
.ranking-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px; margin: 0 3px 5px; }
.ranking h2 { margin: 0; font-size: 13px; }
.ranking .language-select { min-height: 32px; font-size: 12px; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 13px; }
.board li { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 7px; align-items: center; padding: 5px 6px; border-radius: 4px; }
.board li.me { background: #3a3323; font-weight: 700; }
.board i { width: 8px; height: 8px; border-radius: 50%; }
.board span { overflow-wrap: anywhere; }
.board small { display: inline; color: var(--hud-muted); font-size: 11px; }
.board b { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.mini-map { position: relative; }
#mini-map { display: block; width: 100%; aspect-ratio: 1; border-radius: 5px; background: #161f2d; }
.mini-north { position: absolute; top: 6px; left: 6px; padding: 2px 5px; border-radius: 3px; background: var(--hud-panel); color: #eef1f6; font-size: 11px; font-weight: 800; }
.map-tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.map-tools button { min-height: 44px; min-width: 0; padding: 0; border-radius: 5px; border: 1px solid var(--hud-border); background: #222d3d; color: #eef1f6; font-size: 19px; }
.map-tools button:hover { background: #303e54; }
.map-tools .text { font-size: 13px; font-weight: 650; }
#hud button:focus-visible { outline: 2px solid var(--hud-accent); outline-offset: 2px; }

.turn, .toast, .loading-cells { position: fixed; left: 50%; transform: translateX(-50%); margin: 0; }
.turn { bottom: calc(var(--hud-bottom) + 100px); display: flex; align-items: center; gap: 10px; padding: 7px 12px 7px 7px; font-size: 14px; font-weight: 700; pointer-events: none; }
#turn-icon { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 4px; background: var(--hud-accent); color: #201807; font-size: 20px; line-height: 1; }
.turn[data-state="blocked"] #turn-icon { background: #ff9ca8; }
.keys-help { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 5px 13px; width: fit-content; margin: 0; padding: 7px 11px; font-size: 12px; color: var(--hud-muted); }
.keys-help span { white-space: nowrap; }
.toast, .loading-cells { left: calc((100% - var(--hud-players-width) - var(--hud-right) - 8px) / 2); }
.toast { top: 128px; padding: 10px 16px; font-size: 15px; font-weight: 700; width: max-content; max-width: min(560px, calc(100vw - var(--hud-players-width) - var(--hud-right) - 2 * var(--hud-left) - 8px)); text-align: center; pointer-events: none; }
.loading-cells { top: 198px; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--hud-muted); pointer-events: none; }
.recenter { position: fixed; left: 50%; bottom: calc(var(--hud-bottom) + 156px); transform: translateX(-50%); min-height: 44px; padding: 0 15px; border-radius: 6px; border: 0; background: var(--hud-accent); color: #1d1606; font-size: 14px; font-weight: 700; box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.recenter:hover { background: #ffd469; }
.world-map { position: fixed; inset: 0; z-index: 20; background: radial-gradient(circle at 50% 45%, #1b2740 0%, #070a12 75%); }
.world-map canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
/* MapLibre makes its container position: relative, so the size is set outright. */
.world-view { position: absolute; inset: 0; width: 100%; height: 100%; }
.world-view .maplibregl-canvas { cursor: grab; }
.world-map canvas:active { cursor: grabbing; }
.world-bar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; background: rgba(14,17,24,.78); border: 1px solid rgba(255,255,255,.08); }
.world-bar div { display: grid; gap: 2px; }
.world-bar strong { font-size: 17px; }
.world-bar span { font-size: 13px; color: #c7ced8; }
.world-bar .secondary { min-height: 44px; font-size: 15px; }
.pick-panel { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 10px 10px 10px 16px; border-radius: 16px; background: rgba(14,17,24,.85); border: 1px solid rgba(255,255,255,.1); font-weight: 600; white-space: nowrap; }
.pick-panel .primary { min-height: 46px; }
.toast.good { border-color: rgba(126,217,87,.6); }
.toast.bad { border-color: rgba(255,92,108,.7); color: #ffd3d8; }

.touch { position: fixed; left: 0; right: 0; bottom: 16px; display: flex; justify-content: center; gap: 12px; padding: 0 12px; }
.touch button { width: 68px; height: 68px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); background: rgba(14,17,24,.72); color: #fff; font-size: 24px; touch-action: none; }
.touch button:active { background: rgba(255,197,61,.4); }
.touch .gas { width: 84px; height: 84px; margin-left: 8px; background: rgba(255,197,61,.85); color: #1d1606; border-color: transparent; }
.touch .gas:active { background: #ffd469; }
.touch { align-items: center; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

.game-meta {
  position: fixed;
  right: var(--hud-right);
  bottom: calc(var(--hud-bottom) + 20px);
  display: grid;
  justify-items: end;
  gap: 5px;
  width: min(515px, calc(100vw - var(--hud-map-width) - var(--hud-left) - var(--hud-right) - 12px));
  pointer-events: none;
}
.credits { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; font-size: 12px; text-align: right; }
.credits a { color: #dfe4ea; background: rgba(14,17,24,.74); padding: 3px 7px; border-radius: 5px; text-decoration: none; pointer-events: auto; }
.credits a:hover { text-decoration: underline; }
/* The start screen credits its own map picture, so the game's credits wait for the game. */
body:has(#start:not([hidden])) .game-meta, body:has(#hud[hidden]) .keys-help { display: none; }

@media (max-width: 760px), (pointer: coarse) {
  :root { --hud-inset: 10px; --hud-map-width: 152px; --hud-players-width: clamp(142px, 31vw, 178px); }
  .overview { min-width: 0; }
  .place { padding: 6px 9px; }
  .place strong { font-size: 12px; }
  .land { padding: 6px 9px 8px; gap: 8px; }
  .land strong { font-size: 23px; }
  .trail, .fuel { padding: 7px 9px; font-size: 12px; }
  .players-panel, .map-panel { padding: 5px; gap: 5px; }
  .ranking h2 { font-size: 12px; }
  .board { font-size: 11px; }
  .board li { grid-template-columns: 6px minmax(0, 1fr) auto; gap: 4px; padding: 4px; }
  .board i { width: 6px; height: 6px; }
  .board small { font-size: 10px; }
  .map-tools { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .map-tools #reset { display: none; }
  .keys-help { display: none; }
  .turn { bottom: calc(var(--hud-bottom) + 88px); left: auto; right: var(--hud-right); max-width: calc(100vw - var(--hud-map-width) - var(--hud-left) - var(--hud-right) - 8px); transform: none; font-size: 12px; }
  #turn-icon { width: 26px; height: 26px; font-size: 17px; }
  .toast { top: 166px; left: 50%; max-width: calc(100vw - var(--hud-inset) * 2); }
  .loading-cells { top: 236px; left: 50%; }
  .recenter { bottom: calc(var(--hud-bottom) + var(--hud-map-width) + 64px); }
  .touch { bottom: calc(10px + env(safe-area-inset-bottom)); gap: clamp(6px, 3vw, 14px); }
  .touch button { width: clamp(48px, 16vw, 68px); height: clamp(48px, 16vw, 68px); border-radius: 12px; background: var(--hud-panel); border-color: var(--hud-border); }
  .touch .gas { width: clamp(58px, 19vw, 84px); height: clamp(58px, 19vw, 84px); background: var(--hud-accent); }
  .credits { flex-direction: column; align-items: flex-end; font-size: 11px; }
  .credits a:last-child { display: none; }
}

@media (max-width: 510px) {
  .drive-status { flex-direction: column; }
  .fuel { border-left: 0; border-top: 1px solid var(--hud-border); }
}

@media (pointer: coarse) {
  :root { --hud-bottom: calc(100px + env(safe-area-inset-bottom)); }
  .language-select, .ranking .language-select { min-height: 44px; }
}

/* The game version, bottom right. */
.build {
  position: fixed;
  right: var(--hud-right);
  bottom: var(--hud-bottom);
  z-index: 30;
  font: 600 11px/1.2 system-ui, sans-serif;
  color: rgba(255, 255, 255, .75);
  background: rgba(20, 24, 32, .55);
  padding: 2px 6px;
  border-radius: 6px;
  pointer-events: none;
  user-select: none;
}

/* Account line at the top of the start card: Google sign-in, or who is signed in. */
.account { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.account .google { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; background: #fff; color: #1f1f1f; font-weight: 600; text-decoration: none; }
.account .google::before { content: 'G'; font: 800 17px/1 system-ui, sans-serif; color: #4285f4; }
.account small { color: #aab3c0; }
.account .who { display: inline-flex; align-items: center; gap: 8px; color: #eef1f6; font-weight: 600; text-decoration: none; }
.account .who img { width: 28px; height: 28px; border-radius: 50%; }
.account .link { background: none; border: 0; color: #aab3c0; font-size: 14px; text-decoration: underline; cursor: pointer; min-height: 44px; }

/* Display ad on the start screen, always labelled. Hidden until a slot is configured. */
.ad-box { display: grid; gap: 4px; min-height: 100px; padding: 8px; border-radius: 12px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); }
.ad-box[hidden] { display: none; }
.ad-box small { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #8a93a0; }

/* The account menu over the game, at the top of the side panel. */
.me-menu { position: relative; }
.me-button { width: 100%; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 6px; border-radius: 10px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.08); color: #eef1f6; font: 600 14px/1.2 inherit; cursor: pointer; text-align: left; }
.me-button:hover, .me-button[aria-expanded="true"] { background: rgba(255,255,255,.14); }
.me-button span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-button::after { content: '▾'; color: #aab3c0; font-size: 12px; }
.me-avatar { width: 28px; height: 28px; border-radius: 50%; flex: none; object-fit: cover; background: #ffc53d; color: #1b1f27; display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.me-panel { position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; right: 0; display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: rgba(20, 24, 32, .96); border: 1px solid rgba(255,255,255,.12); box-shadow: 0 12px 32px rgba(0,0,0,.45); }
.me-panel[hidden] { display: none; }
.me-panel p { margin: 0; color: #aab3c0; font-size: 13px; line-height: 1.35; }
.me-panel strong { color: #eef1f6; font-size: 15px; }
.me-panel .google { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border-radius: 10px; background: #fff; color: #1f1f1f; font-weight: 600; text-decoration: none; }
.me-panel .google::before { content: 'G'; font: 800 17px/1 system-ui, sans-serif; color: #4285f4; }
.me-panel button { min-height: 40px; border-radius: 10px; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); color: #eef1f6; font: 600 14px inherit; cursor: pointer; }
