/* Special Delivery. Fonts live in the two variables below and nowhere else (view/fonts.mjs mirrors them for canvas text).
   Layout uses logical properties so a right-to-left language mirrors menus; gameplay and numbers stay left to right (.keep-ltr). */
:root {
  --font-ui: system-ui, "Segoe UI", "Noto Sans", "Noto Sans Arabic", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", "Noto Sans TC", "Noto Sans Devanagari", "Noto Sans Bengali", "Noto Sans Thai", var(--sbg-font-fallback, sans-serif);
  --font-display: "Arial Black", "Segoe UI Black", system-ui, var(--sbg-font-fallback, sans-serif);
  --navy: #0b1830; --ink: #07111f; --cream: #fff8e8; --mustard: #ffd447; --coral: #ff6b62; --teal: #45d8e8; --green: #54d98c; --lilac: #b979ff;
  --panel: #fff8e8; --edge: #07111f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--navy); color: var(--ink); font-family: var(--font-ui); overflow: hidden; -webkit-user-select: none; user-select: none; }
.shell { position: fixed; inset: 0; }
.game-canvas, .game-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.keep-ltr { direction: ltr; unicode-bidi: isolate; }
.live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }
button, a.button { font: inherit; cursor: pointer; }
:focus-visible { outline: 4px solid var(--teal); outline-offset: 2px; }

/* ---------- screens ---------- */
.ui { position: absolute; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; pointer-events: auto; background: rgba(7, 17, 31, .72); overflow: auto; }
.screen.title { background: linear-gradient(0deg, rgba(7, 17, 31, .65), rgba(7, 17, 31, 0) 45%), url("../../../assets/games/special-delivery.webp") center / cover; place-items: end center; padding: clamp(12px, 4vh, 40px) 16px; }
@media (max-aspect-ratio: 1/1) {
  .screen.title { background: linear-gradient(180deg, rgba(11, 24, 48, 0) 34%, var(--navy) 52%), url("../../../assets/games/special-delivery.webp") 6% 0 / auto 56% no-repeat, var(--navy); }
}
.screen.title .menu { display: flex; flex-wrap: wrap; justify-content: center; max-inline-size: min(980px, 100%); }
.screen.title .menu .btn { min-inline-size: 150px; justify-content: center; }
.screen.title .menu .notice { flex-basis: 100%; text-align: center; margin: 4px 0 0; }
.card { inline-size: min(980px, 100%); max-block-size: 100%; overflow: auto; background: var(--panel); border: 4px solid var(--edge); border-radius: 22px; box-shadow: 8px 10px 0 var(--edge); padding: clamp(14px, 2.4vw, 26px); }
.card.narrow { inline-size: min(560px, 100%); }
.eyebrow { margin: 0 0 4px; font-size: .75rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
:lang(ar) .eyebrow, :lang(ur) .eyebrow, :lang(hi) .eyebrow, :lang(bn) .eyebrow, :lang(th) .eyebrow { letter-spacing: 0; text-transform: none; }
h1, h2, h3 { margin: 0 0 8px; font-family: var(--font-display); line-height: 1.05; }
h1 { font-size: clamp(1.8rem, 5vw, 3rem); }
h2 { font-size: clamp(1.3rem, 3vw, 2rem); }
p { margin: 0 0 10px; line-height: 1.45; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-block-size: 44px; padding: 10px 18px; border: 3px solid var(--edge); border-radius: 14px; background: var(--mustard); color: var(--ink); font-weight: 800; box-shadow: 3px 4px 0 var(--edge); text-align: center; text-decoration: none; }
.btn:hover { background: #ffe27a; }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 var(--edge); }
.btn.alt { background: var(--teal); }
.btn.quiet { background: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.menu { display: grid; gap: 10px; }
.menu .btn { justify-content: flex-start; font-size: 1.05rem; }
.menu .tagline { color: #fff; font-family: var(--font-display); font-size: clamp(1rem, 2.4vw, 1.5rem); text-shadow: 0 2px 0 #000a; margin-block: 0 6px; }
.menu .notice { color: #fff; font-size: .8rem; text-shadow: 0 1px 0 #000a; }

.pill { display: inline-block; padding: 2px 10px; border: 2px solid var(--edge); border-radius: 999px; background: #fff; font-size: .78rem; font-weight: 800; }
.pill.gold { background: #ffd447; } .pill.silver { background: #dfe6ee; } .pill.bronze { background: #e9a56b; }
.medal { inline-size: 26px; block-size: 26px; border: 3px solid var(--edge); border-radius: 50%; display: inline-block; vertical-align: middle; background: #fff; }
.medal.gold { background: #ffd447; } .medal.silver { background: #dfe6ee; } .medal.bronze { background: #e9a56b; } .medal.none { background: transparent; border-style: dashed; opacity: .5; }

/* ---------- dispatch board ---------- */
.chapter { margin-block: 14px 6px; }
.chapter h3 { display: flex; align-items: center; gap: 10px; }
.chapter.locked { opacity: .55; }
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.job { text-align: start; display: grid; gap: 4px; padding: 10px 12px; border: 3px solid var(--edge); border-radius: 14px; background: #fff; box-shadow: 3px 4px 0 var(--edge); }
.job:hover:not([disabled]) { background: #fffbe6; }
.job b { font-size: 1rem; }
.job small { color: #394a5e; }

/* ---------- briefing ---------- */
.brief-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
@media (max-width: 760px) { .brief-grid { grid-template-columns: 1fr; } }
.client { display: flex; gap: 10px; align-items: baseline; margin-block-end: 8px; }
.client q { font-style: italic; }
.legs { margin: 0; padding-inline-start: 18px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.choice { text-align: start; padding: 8px 10px; border: 3px solid var(--edge); border-radius: 12px; background: #fff; }
.choice[aria-pressed="true"] { background: var(--teal); }
.choice[disabled] { opacity: .5; }
.choice small { display: block; color: #394a5e; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-block: 6px; }

/* ---------- result ---------- */
.result-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-block: 10px; }
.stat { background: #fff; border: 3px solid var(--edge); border-radius: 12px; padding: 8px; text-align: center; }
.stat small { display: block; font-weight: 800; }
.stat strong { font-size: 1.3rem; }
.big-medal { inline-size: 84px; block-size: 84px; border-width: 5px; }

/* ---------- garage / options ---------- */
.shop { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.item { display: grid; gap: 4px; padding: 10px 12px; border: 3px solid var(--edge); border-radius: 14px; background: #fff; }
.pips { display: flex; gap: 4px; }
.pip { inline-size: 18px; block-size: 8px; border: 2px solid var(--edge); border-radius: 4px; background: #fff; }
.pip.on { background: var(--green); }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-block-end: 1px dashed #b9a97a; }
.opt input[type="checkbox"] { inline-size: 24px; block-size: 24px; flex: none; }
.opt small { display: block; color: #394a5e; }
.opt input[type="range"] { inline-size: 100%; }

/* ---------- hud ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; font-weight: 800; }
.hud > * { position: absolute; pointer-events: none; }
.hud .objective { inset-block-start: 10px; inset-inline-start: 10px; max-inline-size: min(420px, 56vw); padding: 8px 12px; background: var(--panel); border: 3px solid var(--edge); border-radius: 14px; box-shadow: 3px 4px 0 var(--edge); }
.hud .objective small { display: block; font-size: .72rem; opacity: .7; }
.hud .objective strong { display: block; font-size: 1rem; }
.hud .metrics { inset-block-start: 10px; inset-inline-end: 10px; display: flex; gap: 8px; align-items: stretch; }
.hud .metric { padding: 6px 10px; background: var(--panel); border: 3px solid var(--edge); border-radius: 14px; min-inline-size: 74px; text-align: center; box-shadow: 3px 4px 0 var(--edge); }
.hud .metric small { display: block; font-size: .66rem; opacity: .7; }
.hud .metric strong { font-size: 1.3rem; }
.hud .bar { display: block; block-size: 7px; margin-block-start: 3px; background: #d9d1b8; border-radius: 4px; overflow: hidden; direction: ltr; }
.hud .bar b { display: block; block-size: 100%; inline-size: 100%; background: var(--green); transform-origin: left; }
.hud .metric[data-level="warning"] .bar b { background: var(--mustard); }
.hud .metric[data-level="critical"] .bar b { background: var(--coral); }
.hud .rulehint { inset-block-end: 12px; inset-inline-start: 50%; transform: translateX(-50%); padding: 4px 12px; background: #fff; border: 3px solid var(--edge); border-radius: 999px; font-size: .8rem; }
.hud .arrow { inset-block-start: 96px; inset-inline-start: 50%; transform: translateX(-50%); text-align: center; color: #fff; text-shadow: 0 2px 0 #000c; }
.hud .arrow i { display: block; font-style: normal; font-size: 2.2rem; line-height: 1; }
.hud .toast { inset-block-start: 62%; inset-inline-start: 50%; transform: translateX(-50%); padding: 8px 16px; background: var(--cream); border: 3px solid var(--edge); border-radius: 14px; box-shadow: 3px 4px 0 var(--edge); max-inline-size: 80vw; text-align: center; }
.hud .toast[data-tone="warning"] { background: #ffd6d2; }
.hud .toast[data-tone="route"] { background: #d6f4f8; }
.hud .buttons { inset-block-end: 10px; inset-inline-end: 10px; display: flex; gap: 8px; pointer-events: auto; }
.hud .buttons .btn { min-block-size: 40px; padding: 6px 12px; }
.high-contrast .hud .objective, .high-contrast .hud .metric { border-width: 4px; background: #fff; }

/* ---------- touch pad ---------- */
.touch { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; align-items: flex-end; padding: 12px 14px 14px; pointer-events: none; direction: ltr; }
.touch .group { display: flex; gap: 10px; pointer-events: auto; }
.touch button { min-inline-size: 74px; block-size: 74px; max-inline-size: 140px; padding-inline: 10px; border-radius: 999px; border: 4px solid var(--edge); background: #fff8e8e0; font-weight: 900; font-size: 1rem; line-height: 1.05; overflow-wrap: break-word; touch-action: none; }
.touch button.go { background: #54d98ce0; min-inline-size: 92px; block-size: 92px; }
.touch button:active, .touch button.down { background: var(--mustard); }
.big-touch .touch button { min-inline-size: 96px; block-size: 96px; }
.big-touch .touch button.go { min-inline-size: 116px; block-size: 116px; }
@media (pointer: fine) { .touch { display: none !important; } }
@media (max-height: 460px) { .touch button { min-inline-size: 58px; block-size: 58px; } .touch button.go { min-inline-size: 72px; block-size: 72px; } .hud .objective { max-inline-size: 38vw; } }

.map-card svg, .map-card canvas { inline-size: 100%; block-size: auto; border: 3px solid var(--edge); border-radius: 12px; background: #1b2a3a; }
.map-wrap { position: relative; aspect-ratio: var(--ar, 1.6); inline-size: min(100%, max(360px, calc((100vh - 230px) * var(--ar, 1.6)))); inline-size: min(100%, max(360px, calc((100dvh - 230px) * var(--ar, 1.6)))); margin-inline: auto; }
.map-wrap img { inline-size: 100%; block-size: 100%; border: 3px solid var(--edge); border-radius: 12px; display: block; }
.map-wrap .dot { position: absolute; inline-size: 14px; block-size: 14px; margin: -7px 0 0 -7px; border: 3px solid var(--edge); border-radius: 50%; background: var(--green); }
.map-wrap .dot.you { background: var(--coral); }
.map-wrap .dot.pickup { background: var(--mustard); }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
.reduced-motion .btn:active { transform: none; }

/* ---------- small screens: the clock, cargo and speed cards sit under the objective, the pause and map buttons move up, clear of the pad ---------- */
@media (max-width: 640px) {
  .hud .objective { inset-block-start: 74px; max-inline-size: calc(100vw - 20px); }
  .hud .metrics { inset-inline-start: 10px; justify-content: space-between; }
  .hud .metric { min-inline-size: 0; flex: 1 1 0; padding: 4px 6px; }
  .hud .metric strong { font-size: 1.05rem; }
  .hud .arrow { inset-block-start: 150px; }
  .hud .toast { inset-block-start: 55%; }
}
@media (pointer: coarse) {
  .hud .buttons { inset-block-start: 88px; inset-block-end: auto; }
}
@media (pointer: coarse) and (max-width: 640px) {
  .hud .buttons { inset-block-start: 150px; inset-inline-end: 10px; }
  .hud .arrow { inset-block-start: 190px; }
}

@media (max-width: 480px) {
  .touch { padding: 10px 8px 12px; }
  .touch .group { gap: 6px; }
  .touch button { min-inline-size: 60px; block-size: 60px; font-size: .85rem; padding-inline: 8px; }
  .touch button.go { min-inline-size: 76px; block-size: 76px; }
  .big-touch .touch button { min-inline-size: 66px; block-size: 66px; }
  .big-touch .touch button.go { min-inline-size: 84px; block-size: 84px; }
}
@media (pointer: coarse) { .hud .rulehint { inset-block-end: 100px; } }
@media (pointer: coarse) and (max-height: 460px) { .hud .rulehint { inset-block-end: 10px; inset-inline-start: 38%; } }

/* The in-run overlay keeps its left and right (they are gameplay, like the board): only the words inside it follow the language's direction. */
.hud { direction: ltr; }
.hud .objective, .hud .metric, .hud .toast, .hud .rulehint, .hud .arrow { unicode-bidi: plaintext; }
.card h3 { margin-block: 12px 4px; }
.card b + .pill { margin-inline-start: 8px; }
.legs { margin-block: 0 8px; }

/* ---------- painted UI icons (art/ui-icons.webp: 4 x 4 cells) ---------- */
.ico { display: inline-block; inline-size: var(--ico, 22px); block-size: var(--ico, 22px); flex: none; vertical-align: middle; background: url("./art/ui-icons.webp") no-repeat; background-size: 400% 400%; background-position: calc(var(--col) * 33.3333%) calc(var(--row) * 33.3333%); margin-inline-end: 4px; }
.ico-cake { --col: 0; --row: 0; }
.ico-tray { --col: 1; --row: 0; }
.ico-tank { --col: 2; --row: 0; }
.ico-stopwatch { --col: 3; --row: 0; }
.ico-coins { --col: 0; --row: 1; }
.ico-wrench { --col: 1; --row: 1; }
.ico-pin { --col: 2; --row: 1; }
.ico-horn { --col: 3; --row: 1; }
.ico-handbrake { --col: 0; --row: 2; }
.ico-bronze { --col: 1; --row: 2; }
.ico-silver { --col: 2; --row: 2; }
.ico-gold { --col: 3; --row: 2; }
.ico-star { --col: 0; --row: 3; }
.ico-arrow { --col: 1; --row: 3; }
.ico-lock { --col: 2; --row: 3; }
.ico-wheel { --col: 3; --row: 3; }
.ico.medal-ico { --ico: 30px; margin: 0; }
.ico.big-medal { --ico: 88px; margin: 0; }
.ico.menu-ico { --ico: 28px; margin-inline-end: 10px; }
.hud .metric small .ico { --ico: 16px; }
.hud .arrow .ico { --ico: 44px; margin: 0; filter: drop-shadow(0 2px 0 #000a); }
.touch button .ico { --ico: 34px; margin: 0; }
.pill .ico { --ico: 16px; }
