:root {
  --green: #1d4d34; --cream: #fbf6e9; --ink: #1b1b1b; --red: #c8161d; --gold: #f2c14e; --pink: #ff7ac8;
  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --sign: 'Transport', 'Helvetica Neue', Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9d3ea; font-family: var(--font); color: var(--ink); overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }

/* ---------- the front: a road sign ---------- */
#front { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px;
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,.35), transparent 60%), linear-gradient(#a9d3ea, #cfe7c3 70%, #86b96a);
  transition: opacity .6s, transform .6s; overflow-y: auto; touch-action: auto; user-select: auto; -webkit-user-select: auto; }
#front.gone { opacity: 0; transform: scale(1.08); pointer-events: none; }
.sign { background: var(--green); color: #fff; border: 6px solid #fff; outline: 3px solid var(--green); border-radius: 14px; padding: 14px 30px 12px; text-align: center; box-shadow: 0 10px 0 rgba(0,0,0,.18); transform: rotate(-2deg); animation: swing 4s ease-in-out infinite; }
@keyframes swing { 50% { transform: rotate(1.5deg); } }
.sign-top { font: 900 clamp(42px, 11vw, 78px)/0.9 var(--sign); letter-spacing: 2px; }
.sign-bot { font: 900 clamp(30px, 8vw, 54px)/1 var(--sign); letter-spacing: 14px; color: var(--gold); margin-top: 2px; }
.sign-sub { font: italic 600 clamp(11px, 3vw, 15px) var(--sign); margin-top: 8px; opacity: .9; }
.frontbot { width: 96px; height: 96px; filter: drop-shadow(0 6px 0 rgba(0,0,0,.15)); animation: bob 2.4s ease-in-out infinite; }
body.xmas .frontbot { position: relative; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }
.panel { width: min(360px, 100%); background: var(--cream); border: 3px solid var(--ink); border-radius: 18px; padding: 18px; box-shadow: 0 6px 0 var(--ink); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.panel input { font: 600 18px var(--font); padding: 12px 14px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; width: 100%; }
.panel button { font: 800 18px var(--font); padding: 13px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s; }
.panel button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.panel button.primary, #menu button.primary { background: var(--gold); }
.lede { margin: 0; font-size: 17px; line-height: 1.35; }
.small { margin: 0; font-size: 13px; opacity: .75; line-height: 1.4; }
.keys { display: block; }
body.touch .keys { display: none; }
.err { color: var(--red); font-weight: 700; margin: 0; min-height: 1em; }
.panel details summary { cursor: pointer; font-size: 14px; opacity: .8; }
.panel details input { margin-top: 8px; }
.panel a { color: var(--green); font-weight: 700; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; display: none; }
body.playing #hud { display: block; }
#tl { position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); display: flex; flex-direction: column; gap: 6px; }
#bpbox, #tut { background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; padding: 5px 11px; box-shadow: 0 3px 0 var(--ink); display: flex; align-items: center; gap: 6px; width: max-content; }
#bp { font: 900 22px var(--font); }
#bpbox small { font-size: 11px; opacity: .6; font-weight: 700; }
#tut { flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 10px; }
#cups { display: flex; gap: 3px; }
#cups.jiggle { animation: jiggle .5s; }
@keyframes jiggle { 25% { transform: rotate(-6deg) scale(1.15); } 50% { transform: rotate(5deg) scale(1.1); } 75% { transform: rotate(-3deg); } }
.cup { width: 26px; height: 22px; fill: #fff; stroke: var(--ink); stroke-width: 1.6; --fill: 0; }
.cup path:first-child { fill: color-mix(in srgb, #b9763a calc(var(--fill) * 100%), #fff); }
.cup.full path:first-child { fill: #b9763a; }
.cup.steam { animation: steam .8s infinite alternate; }
@keyframes steam { to { transform: translateY(-2px); filter: drop-shadow(0 -3px 2px rgba(255,255,255,.9)); } }
#tutname { font: 800 12px var(--font); opacity: .6; }
#tut.hot #tutname { opacity: 1; color: var(--red); }
#minimap { position: absolute; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); width: 150px; height: 150px; border-radius: 50%; box-shadow: 0 4px 0 rgba(0,0,0,.35); }
#btnMenu { pointer-events: auto; position: absolute; top: calc(166px + var(--safe-t)); right: calc(14px + var(--safe-r)); width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--ink); background: var(--cream); font-size: 22px; box-shadow: 0 3px 0 var(--ink); }
#objective { position: absolute; top: calc(10px + var(--safe-t)); left: 50%; transform: translateX(-50%) translateY(-140%); max-width: min(460px, calc(100vw - 400px)); background: var(--gold); border: 3px solid var(--ink); border-radius: 14px; padding: 7px 14px; box-shadow: 0 3px 0 var(--ink); text-align: center; font-weight: 800; transition: transform .35s cubic-bezier(.3,1.6,.6,1), opacity .25s; opacity: 0; visibility: hidden; }
#objective.on { transform: translateX(-50%); opacity: 1; visibility: visible; }
#objtext { font-size: 15px; line-height: 1.25; }
#objtimer { font: 900 20px var(--font); font-variant-numeric: tabular-nums; }
#objtimer:empty { display: none; }
#objtimer.urgent { color: var(--red); animation: pulse .6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.15); } }
#cargo { display: none; align-items: center; gap: 6px; font-size: 12px; margin-top: 3px; }
#cargo .bar { flex: 1; height: 8px; background: rgba(0,0,0,.2); border-radius: 4px; overflow: hidden; min-width: 80px; }
#cargobar { height: 100%; background: #2e9e5b; width: 100%; transition: width .3s; }
#speedo { position: absolute; left: calc(14px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); background: rgba(27,27,27,.75); color: #fff; border-radius: 12px; padding: 6px 12px; opacity: 0; transform: translateY(10px); transition: .3s; }
#speedo.on { opacity: 1; transform: none; }
#vname { font: 700 12px var(--font); opacity: .8; }
#mph { font: 900 22px var(--font); font-variant-numeric: tabular-nums; }
#radio { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); background: #2a2a2a; color: #f6e7a6; font: 700 13px var(--font); padding: 6px 14px; border-radius: 20px; opacity: 0; transition: .3s; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; }
#radio.on { opacity: .92; }
#subtitle { position: absolute; left: 50%; bottom: calc(56px + var(--safe-b)); transform: translateX(-50%); width: min(620px, 90vw); text-align: center; color: #fff; font: 700 16px/1.35 var(--font); text-shadow: 0 2px 0 #000, 0 0 6px #000; opacity: 0; transition: opacity .4s; }
#subtitle.on { opacity: 1; }
#hint { position: absolute; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); background: rgba(255,255,255,.92); border: 2px solid var(--ink); border-radius: 10px; padding: 4px 10px; font: 800 14px var(--font); opacity: 0; transition: .2s; white-space: nowrap; }
#hint.on { opacity: 1; }
body.touch #hint { display: none; }
#toasts { position: absolute; top: calc(90px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(440px, 80vw); }
.toast { background: var(--cream); border: 2.5px solid var(--ink); border-radius: 12px; padding: 6px 12px; font: 700 14px/1.3 var(--font); box-shadow: 0 3px 0 var(--ink); text-align: center; animation: pop .35s cubic-bezier(.3,1.7,.6,1); transition: opacity .5s, transform .5s; }
.toast.big { font-size: 17px; }
.toast.tut { background: #ffe1d6; }
.toast.good { background: #ffe0f2; }
.toast.bad { background: #ffd9d9; }
.toast.say { background: #fff; font-style: italic; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
#bubbles { position: absolute; inset: 0; overflow: hidden; }
.bubble { position: absolute; left: 0; top: 0; background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; padding: 5px 10px; font: 700 14px/1.25 var(--font); max-width: 220px; text-align: center; box-shadow: 0 3px 0 rgba(0,0,0,.25); white-space: normal; will-change: transform; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -10px; margin-left: -7px; border: 7px solid transparent; border-top-color: var(--ink); }

/* touch controls */
#stickzone, #buttons { display: none; }
body.touch #stickzone { display: block; position: absolute; left: 0; bottom: 0; width: 50%; height: 60%; pointer-events: auto; }
#stick { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 3px solid rgba(255,255,255,.75); background: rgba(0,0,0,.18); opacity: 0; transition: opacity .15s; }
#stick.on { opacity: 1; }
#knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%; background: rgba(255,255,255,.9); border: 3px solid var(--ink); transform: translate(-50%,-50%); }
body.touch #buttons { display: grid; position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); grid-template-columns: 64px 64px 92px; grid-template-rows: 64px 64px; gap: 10px; pointer-events: auto; }
#buttons button { border: 3px solid var(--ink); border-radius: 50%; background: rgba(251,246,233,.92); box-shadow: 0 4px 0 var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; font-weight: 800; transition: transform .07s, box-shadow .07s; touch-action: none; }
#buttons button.down { transform: translateY(3px) scale(.95); box-shadow: 0 1px 0 var(--ink); }
#buttons .ico { font-size: 24px; line-height: 1; }
#buttons .lbl { font-size: 10px; line-height: 1.1; max-width: 86px; text-align: center; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
#btnAction { grid-column: 3; grid-row: 1 / 3; width: 92px; height: 92px; align-self: center; background: var(--gold) !important; }
#btnAction .ico { font-size: 34px; }
#btnAction.idle { opacity: .55; filter: saturate(.3); }
#btnHorn { grid-column: 2; grid-row: 1; }
#btnBrake { grid-column: 1; grid-row: 2; }
#btnRadio { grid-column: 1; grid-row: 1; }
#btnPhone { grid-column: 2; grid-row: 2; }
body.touch #speedo { bottom: auto; top: calc(130px + var(--safe-t)); }
body.touch #subtitle { bottom: calc(170px + var(--safe-b)); font-size: 14px; }
body.touch #radio { bottom: calc(180px + var(--safe-b)); }

/* ---------- GuffBot on the phone ---------- */
#dialog { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 160%); width: min(620px, calc(100vw - 20px)); z-index: 30; display: flex; gap: 12px; align-items: flex-start; background: var(--cream); border: 3px solid var(--ink); border-radius: 18px; padding: 12px; box-shadow: 0 6px 0 var(--ink); transition: transform .4s cubic-bezier(.3,1.4,.6,1); cursor: pointer; }
#dialog.on { transform: translate(-50%, 0); }
.face { flex: 0 0 78px; height: 96px; border-radius: 10px; background: var(--red) url(/guffbot.webp) center 70% / 70px no-repeat; border: 3px solid var(--ink); position: relative; animation: talk .25s infinite alternate; }
.face::before { content: 'TELEPHONE'; position: absolute; top: 3px; left: 0; right: 0; text-align: center; color: #fff; font: 800 8px var(--sign); letter-spacing: 1px; }
body.xmas .face::after { content: '🎅'; position: absolute; top: 8px; left: 50%; transform: translateX(-50%) rotate(-12deg); font-size: 24px; }
@keyframes talk { to { background-position: center 68%; } }
.dlgbody { flex: 1; min-height: 96px; display: flex; flex-direction: column; }
#dlgname { font: 900 13px var(--font); color: var(--red); text-transform: uppercase; letter-spacing: .5px; }
#dlgtext { font: 700 17px/1.4 var(--font); margin-top: 4px; flex: 1; }
.dlgtap { font-size: 12px; opacity: .5; text-align: right; animation: blink 1s infinite alternate; }
@keyframes blink { to { opacity: .15; } }

/* ---------- overlays and the menu ---------- */
#overlay, #menu { position: fixed; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; background: rgba(20,30,25,.55); padding: 16px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); touch-action: auto; }
#overlay.on, #menu.on { display: flex; }
.card { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--cream); border: 3px solid var(--ink); border-radius: 20px; padding: 20px; box-shadow: 0 8px 0 var(--ink); animation: pop .35s cubic-bezier(.3,1.5,.6,1); }
#overlay h2 { margin: 0 0 8px; font: 900 22px var(--sign); text-align: center; color: var(--green); }
#ovtext p { font-size: 16px; line-height: 1.45; margin: 8px 0; text-align: center; }
#ovbtn, #menu button { width: 100%; font: 800 16px var(--font); padding: 12px; margin-top: 8px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s; }
#ovbtn { background: var(--gold); margin-top: 14px; }
#ovbtn:active, #menu button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.menutitle { font: 900 22px var(--sign); color: var(--green); text-align: center; }
#mStats { text-align: center; font-size: 13px; line-height: 1.5; margin: 6px 0 4px; opacity: .85; }
.toggles { display: flex; gap: 6px; }
.toggles button { font-size: 13px !important; padding: 9px 4px !important; }
.toggles button.off { opacity: .45; text-decoration: line-through; }
#menu button.quiet { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; font-weight: 600; opacity: .7; }
#gazette, #inviteBox { display: none; margin-top: 8px; }
#gazette.on, #inviteBox.on { display: block; }
#gazette { background: #f4efe1; border: 2px solid var(--ink); padding: 12px; font-family: Georgia, 'Times New Roman', serif; }
.masthead { font: 900 26px/1 'Old English Text MT', 'UnifrakturMaguntia', Georgia, serif; text-align: center; border-bottom: 3px double var(--ink); padding-bottom: 6px; }
.dateline { font-size: 11px; text-align: center; margin: 4px 0 8px; font-style: italic; }
#gazette p { margin: 6px 0; font-size: 13px; line-height: 1.3; font-weight: 700; }
#gazette p.lead { font-size: 17px; text-transform: uppercase; }
#gazette p.sig { font-weight: 400; font-style: italic; font-size: 12px; }
#inviteBox p { font-size: 14px; margin: 4px 0; text-align: center; }
#inviteBox input { width: 100%; font: 600 14px var(--font); padding: 10px; border: 2px solid var(--ink); border-radius: 10px; user-select: all; -webkit-user-select: all; }
#inviteBox .row { display: flex; gap: 8px; }
.howto { margin-top: 10px; font-size: 14px; line-height: 1.4; }
.howto summary { cursor: pointer; font-weight: 800; text-align: center; padding: 6px; }
.hub { display: block; text-align: center; margin-top: 12px; font-weight: 800; color: var(--green); }

@media (max-width: 700px) {
  #minimap { width: 112px; height: 112px; }
  #btnMenu { top: calc(128px + var(--safe-t)); width: 40px; height: 40px; }
  #objective { top: calc(132px + var(--safe-t)); max-width: calc(100vw - 80px); left: calc(50% - 20px); }
  #toasts { top: calc(200px + var(--safe-t)); }
  #bp { font-size: 18px; }
  #bpbox small { display: none; }
  .cup { width: 20px; height: 17px; }
  #dlgtext { font-size: 15px; }
  .face { flex-basis: 64px; height: 80px; background-size: 56px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #minimap { width: 100px; height: 100px; }
  #btnMenu { top: calc(116px + var(--safe-t)); }
  body.touch #speedo { top: auto; bottom: calc(14px + var(--safe-b)); left: 50%; transform: translateX(-50%); }
  #objective { top: calc(8px + var(--safe-t)); max-width: calc(100vw - 340px); }
  #toasts { top: calc(70px + var(--safe-t)); }
  body.touch #subtitle { bottom: calc(10px + var(--safe-b)); width: 40vw; }
}
#spree { position: absolute; left: 50%; top: 38%; transform: translateX(-50%); font: 900 26px var(--font); color: #fff; -webkit-text-stroke: 1.5px var(--ink); text-shadow: 0 4px 0 var(--ink); opacity: 0; transition: opacity .3s; white-space: nowrap; }
#spree.on { opacity: 1; }
#spree.bump { animation: spreebump .35s cubic-bezier(.3,1.8,.6,1); }
@keyframes spreebump { from { transform: translateX(-50%) scale(1.5) rotate(-4deg); } }
