:root {
  --mana-primary: #2F6FED;
  --mana-text: #1B1B1F;
  --mana-text-secondary: #5F6368;
  --mana-surface: #FFFFFF;
  --mana-divider: #ECEDF0;
  --mana-positive: #137333;
  --mana-danger: #CE1126;
  --mana-danger-text: #CE1126; /* red words (Exit); lighter at night to read on the dark pill */
  --mana-accent: #2F6FED;  /* filled buttons; --mana-primary is for blue text and icons */
  --mana-surface-variant: #F1F3F4;
  --mana-primary-container: #E8F0FE;
  --mana-selected: #F2F6FF;
  --mana-field-line: #DADCE0;
  --mana-page: #F4F1EC;
  /* Driving screen, on the Mana palette: navy turn banner, red Report, a calm Exit with a red label. */
  --mana-turn-banner: #002B7F;
  --mana-turn-banner-pill: #001A57;
  --mana-report: #CE1126;
  /* On the map (read by app.js when the map loads). */
  --mana-route: #2457E6;
  --mana-route-casing: #12358F;
  --mana-route-night: #5B87FF;
  --mana-route-casing-night: #2457E6;
  --mana-route-alt: #9AA0A6;
  --mana-route-driven: #9AA0A6;
  --mana-via: #002B7F;
  --mana-destination: #CE1126;
  --mana-cluster: #5F6368;
}
/* Night colours, switched on with the map's between sunset and sunrise (as in the Android app). */
:root.night {
  --mana-primary: #8AB4F8;
  --mana-text: #E8EAED;
  --mana-text-secondary: #AEB4BC;
  --mana-surface: #2A2F36;
  --mana-divider: #3A4048;
  --mana-positive: #81C995;
  --mana-surface-variant: #3A4048;
  --mana-primary-container: #24375A;
  --mana-selected: #24375A;
  --mana-field-line: #4A5058;
  --mana-page: #1E2227;
  --mana-danger-text: #FF9AA2;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--mana-page); }
body { font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--mana-text); }
button { font: inherit; cursor: pointer; }
.ico { width: 24px; height: 24px; fill: currentColor; vertical-align: middle; flex: none; }
.fab { display: grid; place-items: center; }
#reportButton { color: #fff; background: var(--mana-report); }
.row .pin { color: var(--mana-primary); }
#searchBox .lead { color: var(--mana-text-secondary); display: flex; align-items: center; justify-content: center; }
.icon { display: grid; place-items: center; }
#map { position: fixed; inset: 0; }

.card { background: var(--mana-surface); border-radius: 22px; box-shadow: 0 2px 10px rgba(0, 0, 0, .18); }
#top { position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 12px; right: 12px; z-index: 2; }

#searchBox { position: relative; display: flex; flex-wrap: wrap; align-items: center; padding: 4px 6px 4px 14px; }
#searchBox .lead { opacity: .7; }
#submitSearch, #menuButton { flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; }
#search { flex: 1; min-width: 0; border: 0; outline: 0; font-size: 17px; padding: 12px 10px; background: transparent; color: var(--mana-text); }
#search::-webkit-search-cancel-button { display: none; }
.icon { border: 0; background: var(--mana-surface-variant); border-radius: 50%; width: 38px; height: 38px; color: var(--mana-text-secondary); }
/* A moving bar across the box while a search or route is on its way. */
#progress { position: absolute; left: 16px; right: 16px; bottom: 0; height: 3px; overflow: hidden; border-radius: 2px; }
#progress::after { content: ""; position: absolute; width: 35%; height: 100%; background: var(--mana-accent); animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { left: -35%; } to { left: 100%; } }
/* The input has no outline of its own, so the whole box shows where keyboard focus is. */
#searchBox:focus-within { box-shadow: 0 0 0 3px var(--mana-primary), 0 2px 10px rgba(0, 0, 0, .18); }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 3px solid var(--mana-primary); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  #progress::after { animation: none; left: 0; width: 100%; opacity: .6; }
}
#results { flex-basis: 100%; max-height: 55vh; overflow-y: auto; }
#results.submitted { max-height: 24vh; }
#results:not(:empty) { border-top: 1px solid var(--mana-divider); margin-top: 4px; padding: 4px 0; }
.row { display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px 6px; border: 0; background: none; text-align: left; color: var(--mana-text); }
.row .pin { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--mana-primary-container); display: grid; place-items: center; }
.row .pin.candidate-number { background: var(--mana-accent); color: #fff; font-weight: 700; font-size: 16px; box-shadow: 0 0 0 2px var(--mana-surface), 0 0 0 4px var(--mana-accent); }
.row .what { flex: 1; min-width: 0; }
.row .name { font-weight: 600; }
.row .detail, .row .far { color: var(--mana-text-secondary); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Distances in ink; colour is kept for what needs attention. */
.row .far { color: var(--mana-text); font-weight: 700; }
/* Home and Work side by side, so more fits above the keyboard. */
.pair { display: flex; }
.row.half { flex: 1; min-width: 0; }
/* The Menu: groups, each row's value (On, RM120 of RM300) on the right. */
.menuGroup { grid-column: 1 / -1; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--mana-text-secondary); padding: 10px 6px 2px; }
.menuRow { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; min-height: 52px; padding: 8px 6px; border: 0; border-radius: 12px; background: none; color: var(--mana-text); text-align: left; font-size: 16px; }
.menuRow .ico { color: var(--mana-text-secondary); }
.menuRow .label { flex: 1; }
.menuRow .vehicle { width: 44px; height: 44px; }
.menuRow .value { color: var(--mana-primary); font-size: 14px; font-weight: 700; }
.pill.wide { grid-column: span 3; justify-content: flex-start; font-size: 16px; }

#banner { display: flex; gap: 14px; align-items: center; padding: 14px 18px; background: var(--mana-turn-banner); color: #fff; position: relative; }
#arrow { font-size: 40px; width: 44px; text-align: center; }
#bannerDistance { font-size: 30px; font-weight: 700; }
#bannerText { font-size: 18px; opacity: .95; }
#then { position: absolute; left: 14px; bottom: -34px; background: var(--mana-turn-banner-pill); color: #fff; padding: 5px 12px; border-radius: 14px; font-size: 15px; }

/* --stack: the height of the card along the bottom (app.js), so the buttons ride just above it. */
#side { position: fixed; right: 12px; bottom: calc(env(safe-area-inset-bottom) + max(210px, var(--stack, 0px) + 24px)); display: flex; flex-direction: column; gap: 12px; z-index: 1; }
.fab { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--mana-surface); box-shadow: 0 2px 8px rgba(0, 0, 0, .25); font-size: 24px; color: var(--mana-primary); }
#trafficButton.off { opacity: .45; }
/* Bigger and a rounded square: used while moving, and set apart from the round map buttons. */
#reportButton { width: 64px; height: 64px; border-radius: 22px; align-self: center; }
/* The speed sign, alone on the map's left edge while driving. */
#speedView { position: fixed; left: 12px; bottom: calc(env(safe-area-inset-bottom) + var(--stack, 118px) + 24px); z-index: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }

/* Bottom cards rise and fade in on a decelerating curve, and leave quicker and smaller. */
.bottomCard { opacity: 0; transform: translateY(16px); transition: opacity 160ms cubic-bezier(.3, 0, 1, 1), transform 160ms cubic-bezier(.3, 0, 1, 1); }
.bottomCard.in { opacity: 1; transform: none; transition-duration: 240ms; transition-timing-function: cubic-bezier(.2, 0, 0, 1); }
@media (prefers-reduced-motion: reduce) { .bottomCard { transition: none; } }
#placeCard { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); padding: 16px 20px; z-index: 2; }
#placeName { font-size: 20px; font-weight: 700; }
#placeDetail { color: var(--mana-text-secondary); font-size: 15px; margin-top: 4px; }
.placeActions { display: flex; gap: 8px; margin-top: 14px; }
.placeExtras:has(:not([hidden])) { margin-top: 6px; }
.plain .ico { width: 20px; height: 20px; }
/* Narrow cards: Save and Close keep only their icons, so Directions never shrinks. */
@media (max-width: 379px) { .placeActions .pill span { display: none; } }
/* The route card's actions: icon above its word. */
#routeActions { flex-basis: 100%; display: flex; gap: 8px; }
.action { flex: 1; min-height: 64px; border: 0; border-radius: 32px; background: var(--mana-surface-variant); color: var(--mana-text); font-size: 12px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.icon.big { width: 56px; height: 52px; border-radius: 26px; }
#panel { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); padding: 14px 16px; z-index: 2; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#trip { flex-basis: 100%; display: flex; flex-direction: column; }
.tripRow { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.tripRow .n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--mana-primary-container); color: var(--mana-primary); font-size: 13px; font-weight: 700; display: grid; place-items: center; }
.tripRow .what { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 0; background: none; color: var(--mana-text); text-align: left; font-size: 15px; padding: 12px 0; }
.tripRow .btn { flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--mana-text-secondary); display: grid; place-items: center; }
.tripLink { border: 0; background: none; color: var(--mana-primary); font-weight: 600; text-align: left; padding: 12px 0 12px 36px; min-height: 48px; }
#routes { flex-basis: 100%; display: flex; flex-direction: column; gap: 6px; }
.route { display: flex; justify-content: space-between; gap: 8px; border: 2px solid var(--mana-divider); border-radius: 14px; padding: 8px 12px; background: none; text-align: left; color: var(--mana-text); }
.route.on { border-color: var(--mana-primary); background: var(--mana-selected); }
.route .time { font-size: 20px; font-weight: 700; color: var(--mana-text); }
.route .sub { color: var(--mana-text-secondary); font-size: 14px; }
.route > .sub { white-space: nowrap; }
#navInfo { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.navStats { flex: 1; min-width: 0; }
#speedView { width: 72px; height: 72px; display: grid; place-items: center; border: 2px solid var(--mana-field-line); border-radius: 50%; background: #fff; color: #1B1B1F; }
#speedReading { display: flex; flex-direction: column; align-items: center; line-height: 1; }
#speedReading strong { font-size: 25px; font-variant-numeric: tabular-nums; }
#speedReading small { margin-top: 3px; font-size: 11px; color: #5F6368; }
/* Above the speed, overlapping only its edge (as the app's SpeedView), so the number stays clear. */
#speedLimit { position: absolute; z-index: 1; top: -32px; left: 50%; transform: translateX(-50%); width: 48px; height: 48px; padding: 0; cursor: pointer; display: grid; place-items: center; border: 5px solid #CE1126; border-radius: 50%; background: #fff; color: #1B1B1F; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
/* Going over: the bubble flashes red six times, 300 ms each (as the app's SpeedView), then stays red. */
#speedView.speeding { border-color: var(--mana-danger); background: var(--mana-danger); color: #fff; animation: speedFlash 600ms step-end 3; }
#speedView.speeding #speedReading small { color: inherit; opacity: .85; }
@keyframes speedFlash { 50% { border-color: var(--mana-field-line); background: #fff; color: #1B1B1F; } }
@media (prefers-reduced-motion: reduce) { #speedView.speeding { animation: none; } }
#navEta { font-size: 28px; font-weight: 700; color: var(--mana-text); }
#navLeft { color: var(--mana-text-secondary); }
.primary { flex: 1; border: 0; border-radius: 28px; padding: 14px; background: var(--mana-accent); color: #fff; font-size: 18px; font-weight: 600; }
/* Calm grey pills (Add stop, Exit); Exit's red is only in its label. */
.pill { display: flex; align-items: center; gap: 6px; flex: none; min-height: 52px; border: 0; border-radius: 26px; padding: 0 16px; background: var(--mana-surface-variant); color: var(--mana-text); font-size: 14px; font-weight: 700; }
.pill .ico { width: 20px; height: 20px; }
.pill.exit { color: var(--mana-danger-text); }
.plain { border: 0; background: none; color: var(--mana-primary); font-weight: 600; padding: 10px; }

#sheet { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); padding: 16px; z-index: 3; text-align: center; }
#sheetTitle { font-weight: 600; margin-bottom: 10px; }
.sheetText { grid-column: 1 / -1; margin: 0; text-align: left; font-size: 15px; }
/* Your level: the sign beside your title and points, a bar to the next level; rows as in the Menu. */
#searchBox #levelButton { width: 48px; height: 48px; padding: 4px; border: 0; background: none; opacity: 1; cursor: pointer; }
#levelButton .levelSign { width: 40px; height: 40px; }
.levelBadge { color: var(--badge-day); }
:root.night .levelBadge { color: var(--badge-night); }
.levelHead { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; text-align: left; }
.levelHead .levelSign { width: 88px; height: 88px; flex: none; }
.levelTitle { font-size: 24px; font-weight: 700; }
.levelPoints { font-size: 16px; color: var(--mana-text-secondary); }
.menuRow .levelSign { width: 32px; height: 32px; flex: none; }
.menuRow.still { cursor: default; }
.sheetText.muted { color: var(--mana-text-secondary); font-size: 14px; }
/* The road to the next level (--p from 0 to 1): asphalt with a dashed centre line, the covered part in blue,
   your car on it facing along the road, the next level's sign standing at the end. */
.levelRoad { grid-column: 1 / -1; position: relative; height: 56px; --sign: 44px; }
.levelRoad .road { position: absolute; left: 0; right: calc(var(--sign) * .55); bottom: 6px; height: 20px; border-radius: 10px; background: #DADCE0; overflow: hidden; }
.levelRoad .road::after { content: ""; position: absolute; left: 10px; right: 10px; top: 9px; border-top: 2px dashed #fff; }
.levelRoad .covered { height: 100%; width: max(20px, calc(var(--p) * 100%)); border-radius: 10px; background: var(--mana-primary); }
.levelRoad .roadCar { position: absolute; width: 30px; height: 30px; bottom: 1px; transform: rotate(90deg);
  left: clamp(0px, calc(var(--p) * (100% - var(--sign) * .55) - 15px), calc(100% - var(--sign) * .55 - 30px)); }
.levelRoad .levelSign { position: absolute; right: 0; bottom: 6px; width: var(--sign); height: var(--sign); }
:root.night .levelRoad .road { background: #3A4048; }
.qr { grid-column: 1 / -1; width: min(260px, 70vw); justify-self: center; }
#tiles textarea { grid-column: 1 / -1; font: inherit; padding: 10px; border: 1px solid var(--mana-field-line); border-radius: 12px; resize: vertical; background: var(--mana-surface); color: var(--mana-text); }
#tiles .primary { grid-column: 1 / -1; }
#tiles input[type="text"] { grid-column: 1 / -1; font: inherit; padding: 10px; border: 1px solid var(--mana-field-line); border-radius: 12px; background: var(--mana-surface); color: var(--mana-text); }
.fieldLabel { grid-column: 1 / -1; text-align: left; font-size: 14px; font-weight: 600; }
#tiles .check { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; text-align: left; font-size: 15px; }
#tiles .check input { width: 20px; height: 20px; flex: none; }
.tile.kind { --tile: var(--mana-field-line); min-height: 56px; }
.payLink { text-decoration: none; text-align: center; }
/* Three to a row, all in view at once: no scrolling while driving. */
#tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#sheetTitle { text-align: left; font-size: 18px; font-weight: 700; }
/* A small icon button at the end of a sheet title (the car colours in Your vehicle): 48px to tap, no bigger to see. */
.titleAction { float: right; width: 48px; height: 48px; margin: -12px -10px -12px 0; border: 0; border-radius: 50%; background: none; color: var(--mana-text-secondary); cursor: pointer; }
.titleAction:active { background: color-mix(in srgb, currentColor 12%, transparent); }
/* A tile: the colour as a tint and a border, its icon in the colour, its word in ink. */
.tile { min-height: 84px; border: 2px solid var(--tile); border-radius: 20px; padding: 10px 4px; background: color-mix(in srgb, var(--tile) 14%, transparent);
  color: var(--mana-text); font-size: 14px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.tile .limitSign { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; border: 5px solid #CE1126; background: #fff; color: #000; font-size: 22px; font-weight: 700; box-sizing: border-box; }
.tile svg { width: 34px; height: 34px; fill: color-mix(in srgb, var(--tile) 75%, black); }
/* Icons a little darker by day and lighter at night, so each stands out from its tint (3:1 or more). */
:root.night .tile svg { fill: color-mix(in srgb, var(--tile) 55%, white); }
/* Add stop and Exit are used while moving: 64px. */
#navInfo .pill { min-height: 64px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 230px); max-width: calc(100% - 32px); background: #323232; color: #fff; padding: 10px 16px; border-radius: 18px; z-index: 4; font-size: 15px; text-align: center; }
#install { position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); padding: 6px 16px 4px; z-index: 5; font-size: 15px; }
#install a { color: var(--mana-primary); }
[hidden] { display: none !important; }
#update { display: block; width: 100%; margin-top: 8px; padding: 12px 16px; border: 0; color: #fff; background: var(--mana-accent); font-size: 15px; text-align: center; }
#update[hidden] { display: none; }

.tile.currentLimit { outline: 3px solid currentColor; outline-offset: -3px; }

.menuRow.lockedColour .vehicle { opacity: .4; }
.menuRow.lockedColour .label, .menuRow.lockedColour .value { color: var(--mana-text-secondary); }
.menuRow.lockedColour .value { max-width: 160px; }
.colourLock { width: 16px; height: 16px; vertical-align: middle; margin-right: 4px; }
