/* Road Rules. The town fills the screen from above; the readouts sit along the top edge, the
   pedals in the bottom corners where thumbs rest, and the blinkers just above them. */
:root {
  /* R-C40: colours that were written out in rules, as tokens (theme-derive.py) */
  --kBg1: #1a251e;
  --kBg10: rgba(16, 22, 18, .62);
  --kBg11: rgba(255, 255, 255, .32);
  --kBg12: rgba(255, 210, 122, .5);
  --kBg13: rgba(255, 210, 122, .45);
  --kBg14: rgba(255, 176, 0, .55);
  --kBg15: rgba(6, 10, 8, .5);
  --kBg16: rgba(16, 22, 18, .55);
  --kBg17: #f4f1e6;
  --kBg18: #dfe8f2;
  --kBg2: #26332a;
  --kBg3: #314136;
  --kBg4: #223028;
  --kBg5: #2b3a31;
  --kBg6: #1b261f;
  --kBg7: #172019;
  --kBg8: #000000;
  --kBg9: rgba(250, 250, 246, .94);
  --kInk1: #000000;
  --kInk2: #182019;
  --kInk3: #ffd27a;
  --kInk4: #ffffff;
  --kInk5: #14202a;
  --kLine1: #2c3a31;
  --kLine2: #ffd27a;
  --kLine3: #4a7a5a;
  --kLine4: #ffffff;
  --kLine5: #ffe9a8;
  --kLine6: #ffb000;
  --kLine7: #8aa0b8;

  --bg: #16201a;
  --ink: #eef3ee;
  --dim: #a9b6ac;
  --card: #1d2922;
  --line: #36483c;
  --accent: #ffb338;
  --accentInk: #3a2204;
  --good: #57d68d;
  --bad: #ff6b5b;
  --glass: rgba(12, 18, 14, .74);
}

/* R-C40: the light look. This product's own is dark; the other is chosen with the switch beside Home. */
:root[data-theme="light"] {
  --kBg1: #b5bdb7;
  --kBg10: rgba(197, 202, 198, .62);
  --kBg11: rgba(31, 31, 31, .32);
  --kBg12: rgba(69, 48, 0, .5);
  --kBg13: rgba(69, 48, 0, .45);
  --kBg14: rgba(141, 95, 0, .55);
  --kBg15: rgba(210, 214, 212, .5);
  --kBg16: rgba(197, 202, 198, .55);
  --kBg17: #282722;
  --kBg18: #292d31;
  --kBg2: #a7b1aa;
  --kBg3: #9aa59e;
  --kBg4: #aab4ae;
  --kBg5: #a0aba4;
  --kBg6: #b4bcb6;
  --kBg7: #bac1bb;
  --kBg8: #f7f7f7;
  --kBg9: rgba(34, 34, 32, .94);
  --kInk1: #717171;
  --kInk2: #acb7ad;
  --kInk3: #170000;
  --kInk4: #000000;
  --kInk5: #a5b4c2;
  --kLine1: #a1aba4;
  --kLine2: #453000;
  --kLine3: #67836f;
  --kLine4: #1f1f1f;
  --kLine5: #342907;
  --kLine6: #8d5f00;
  --kLine7: #4e5a67;

  --bg: #f1f9f4;
  --ink: #1e201e;
  --dim: #4d544f;
  --card: #e4eee8;
  --line: #bcc9c0;
  --accent: #a26a00;
  --accentInk: #ffffff;
  --good: #02a25d;
  --bad: #ef6051;
  --glass: rgba(241, 247, 243, .74);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
}
#app { display: flex; flex-direction: column; height: 100%; }

#hdr {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px;
  background: var(--kBg1); border-bottom: 1px solid var(--kLine1);
}
#hdrTitle { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
            font-weight: 700; font-size: 15px; }
@media (max-width: 380px) { #hdrTitle { visibility: hidden; } }
/* R-C26: [hidden] loses to any display of our own */
[hidden] { display: none !important; }
.pill {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 12px;
  background: var(--kBg2); color: var(--ink); font-size: 18px; cursor: pointer;
}
.pill:active { background: var(--kBg3); }

.scr { display: none; flex: 1; overflow-y: auto; padding: 12px; }
.scr.on { display: block; }
#scr-play.on { display: flex; padding: 0; overflow: hidden; }
#scr-menu, #scr-how, #scr-book { max-width: 720px; margin: 0 auto; width: 100%; }

h1 { font-size: 30px; margin: 8px 0 4px; }
.sub { color: var(--dim); font-size: 14px; line-height: 1.45; margin-bottom: 12px; }
.stat { color: var(--dim); font-size: 13px; }
.goal { color: var(--ink); font-size: 14px; line-height: 1.45; margin: 4px 2px 8px; min-height: 20px; }

.big {
  display: block; width: 100%; min-height: 52px; margin: 8px 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--kBg2);
  color: var(--ink); font-size: 17px; font-weight: 600; cursor: pointer;
}
.big:disabled { opacity: .5; cursor: default; }
.big.primary { background: var(--accent); border-color: var(--kLine2); color: var(--accentInk); }
.twoRow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.twoRow .big { margin: 0; }

/* R16.6 a tab for each way to go */
#modeTabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 2px; }
.modeTab {
  min-height: 48px; border-radius: 12px; border: 2px solid transparent; background: var(--kBg4); color: var(--dim);
  font-size: 14px; font-weight: 700; cursor: pointer; padding: 0 2px; white-space: nowrap;
}
.modeTab.on { border-color: var(--accent); color: var(--ink); background: var(--kBg5); }
/* R13.1 the jobs: a grid of cards that wraps, each a place, its rule's picture and its stars */
#jobRow { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 5px; margin: 6px 0 4px; }
.job {
  min-height: 76px; min-width: 0; border-radius: 12px; border: 2px solid transparent;
  background: var(--kBg4); color: var(--ink); cursor: pointer; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.job .em { font-size: 22px; line-height: 1.1; }
.job .pic.small { width: 30px; height: 30px; }
.job .st { font-size: 9px; min-height: 12px; letter-spacing: -1px; }
.job.newest { border-color: var(--kLine3); }
.job.sel { border-color: var(--accent); background: var(--kBg5); }
.job.locked { opacity: .45; }
.pic { display: block; width: 64px; height: 64px; }
.pic.small { width: 44px; height: 44px; }

#paintRow { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.paint {
  width: 48px; height: 48px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, .2);
  font-size: 20px; cursor: pointer; color: var(--kInk1);
}
.paint.sel { border-color: var(--kLine4); box-shadow: 0 0 0 2px var(--accent); }
.paint.locked { opacity: .4; }

#custom { margin: 10px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--kBg6); }
#custom > summary { list-style: none; }
#custom > summary::-webkit-details-marker { display: none; }
#custom > summary::after { content: "▾"; margin-left: auto; color: var(--dim); }
#custom[open] > summary::after { content: "▴"; }
summary { min-height: 48px; display: flex; align-items: center; padding: 0 12px; cursor: pointer; font-weight: 600; }
.setBody { padding: 10px 12px 14px; }
.setRow { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.setLbl { flex: 1 1 120px; font-size: 14px; }
.setNote { color: var(--dim); font-size: 12px; line-height: 1.4; }
.knob { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.knobBtn {
  min-height: 44px; min-width: 56px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--kBg7); color: var(--dim);
  font-size: 13px; cursor: pointer;
}
.knobBtn.on { border: 2px solid var(--accent); color: var(--ink); background: var(--kBg2); font-weight: 700; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 8px 0; font-size: 14px; line-height: 1.5; }
.card h2 { font-size: 17px; margin: 0 0 4px; }

/* R13.5 the Sign Book */
#bookGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin: 8px 0; }
.sign {
  min-height: 132px; border-radius: 14px; border: 1px solid var(--line); background: var(--kBg4); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer;
  font-size: 13px; padding: 6px;
}
.sign .pic { width: 80px; height: 80px; }
.sign.locked .pic { filter: grayscale(1) brightness(.35); }
.sign.locked { color: var(--dim); }

/* ---- the town ------------------------------------------------------------------------------- */
#stage { position: relative; flex: 1; width: 100%; overflow: hidden; touch-action: none; background: var(--kBg8); }
#cvs { display: block; width: 100%; height: 100%; touch-action: none; }
#glFail {
  position: absolute; inset: 20% 12% auto; padding: 14px; border-radius: 12px; z-index: 30;
  background: var(--kBg6); color: var(--ink); font-size: 14px; line-height: 1.5;
}
#hud {
  position: absolute; top: 6px; left: 6px; right: 6px; pointer-events: none; z-index: 5;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 6px;
}
#hudL { display: flex; gap: 6px; align-items: flex-start; }
#speedBox {
  display: flex; align-items: center; gap: 4px; background: var(--glass); border-radius: 14px; padding: 4px 6px 4px 10px;
  font-variant-numeric: tabular-nums;
}
#speedBox b { font-size: 26px; min-width: 32px; text-align: right; }
#speedBox small { color: var(--dim); font-size: 11px; margin-right: 2px; }
#speedBox.over b { color: var(--bad); }
#limitPic { width: 44px; height: 44px; }
#aheadPic { width: 56px; height: 56px; background: var(--glass); border-radius: 14px; padding: 4px; }
#cup { background: var(--glass); border-radius: 14px; font-size: 26px; padding: 6px 8px; line-height: 1; }
#cup.spilt { animation: wobble .4s 2; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 33% { transform: rotate(-14deg); } 66% { transform: rotate(14deg); } }
#goalChip { background: var(--glass); border-radius: 14px; padding: 6px 12px; font-size: 26px; line-height: 1.1; white-space: nowrap; }
#goalChip b { font-size: 24px; }

#msg {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%); z-index: 6; pointer-events: none;
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 16px);
  background: var(--kBg9); color: var(--kInk2); border-radius: 18px; padding: 6px 14px 6px 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35); border: 3px solid transparent;
}
#msg .pic { width: 72px; height: 72px; flex-shrink: 0; }
#msgWords { font-size: 16px; font-weight: 700; line-height: 1.3; }
#msg.hint { border-color: var(--kLine2); }
#msg.fault { border-color: var(--bad); }
#msg.kept, #msg.new { border-color: var(--good); }

/* R13.2 the pedals in the bottom corners, the blinkers above them */
#ctl { position: absolute; inset: auto 0 0 0; height: 0; z-index: 4; }
.pedal {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); width: 92px; height: 92px; border-radius: 50%;
  font-size: 40px; cursor: pointer; touch-action: none; background: var(--kBg10);
  border: 3px solid rgba(255, 255, 255, .35); color: var(--ink);
}
.brakeP { left: calc(env(safe-area-inset-left, 0px) + 14px); }
.goP { right: calc(env(safe-area-inset-right, 0px) + 14px); }
.pedal.down { background: var(--kBg11); transform: scale(.96); }
#btnLook.on { background: var(--kBg12); border-color: var(--kLine2); }
.blk {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 122px); width: 66px; height: 66px; border-radius: 50%;
  font-size: 30px; cursor: pointer; touch-action: manipulation; background: var(--kBg10);
  border: 3px solid rgba(255, 255, 255, .3); color: var(--ink);
}
#btnLeft { left: calc(env(safe-area-inset-left, 0px) + 26px); }
/* R19.1 the gear, between the pedals */
#btnGear, #btnLights { left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 26px); font-size: 28px; font-weight: 800; }
#btnLights.on { border-color: var(--kLine5); box-shadow: 0 0 14px rgba(255, 233, 168, .7); }
#btnHead { left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 26px); font-size: 30px; }
#btnHead.on { border-color: var(--kLine2); background: var(--kBg13); }
#btnHead:not([hidden]) ~ #btnLights { bottom: calc(env(safe-area-inset-bottom, 0px) + 104px); }
#btnGear.rev { border-color: var(--kLine2); color: var(--kInk3); }
#btnRight { right: calc(env(safe-area-inset-right, 0px) + 26px); }
.blk.on { border-color: var(--kLine6); box-shadow: 0 0 14px rgba(255, 176, 0, .8); animation: blinker .8s steps(1) infinite; }
@keyframes blinker { 0% { background: var(--kBg14); } 56% { background: var(--kBg10); } }
#btnBelt { position: absolute; left: 50%; bottom: 40%; transform: translateX(-50%); width: auto; padding: 0 28px; min-height: 64px; font-size: 22px; z-index: 7; }
#watchTag {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); transform: translateX(-50%); z-index: 6;
  background: var(--glass); border-radius: 14px; padding: 10px 18px; font-size: 18px; font-weight: 700; cursor: pointer; min-height: 44px;
}

/* ---- overlays ---- */
.ovl {
  position: absolute; inset: 0; z-index: 20; display: none;
  align-items: flex-start; justify-content: center; padding: 16px; overflow-y: auto;
  background: var(--kBg15);
}
.ovl.on { display: flex; }
.ovlCard {
  margin: auto; width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 16px; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.ovlCard h2 { margin: 0 0 6px; font-size: 22px; }
.ovlCard p { color: var(--dim); font-size: 14px; line-height: 1.5; margin: 6px 0 10px; }
.ovlCard .pic { width: 96px; height: 96px; margin: 0 auto 6px; }
#briefEmoji { font-size: 44px; line-height: 1.1; }
/* the replay plays behind this card, so it sits low and lets the town show */
#oops { background: none; align-items: flex-end; }
#oops .ovlCard { margin: auto auto 0; }
#doneStars { font-size: 40px; letter-spacing: 4px; }
#doneList { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; text-align: left; }
.doneRow { display: flex; align-items: center; gap: 10px; font-size: 14px; }
#quiz { background: none; padding: 0; }
#quizBar {
  position: absolute; top: 8px; left: 8px; right: 8px; background: var(--glass); border-radius: 14px; padding: 8px 12px; text-align: center;
}
#quizBar h2 { margin: 0; font-size: 22px; }
#quizBar p { margin: 2px 0 0; color: var(--dim); font-size: 14px; }
.qTap {
  position: absolute; width: 68px; height: 68px; margin: -34px 0 0 -34px; border-radius: 50%;
  border: 4px solid var(--kLine4); background: var(--kBg16); color: var(--kInk4); font-size: 28px; font-weight: 800; cursor: pointer;
}
.qTap.right { border-color: var(--good); box-shadow: 0 0 16px var(--good); }
.qTap.wrong { border-color: var(--bad); }
#quizAfter {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); transform: translateX(-50%);
  width: calc(100% - 16px); max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; text-align: center;
}
#quizAfter .pic { width: 80px; height: 80px; margin: 0 auto; }
#quizAfter p { margin: 4px 0; font-size: 15px; }
/* the shared runtime's notices (a newer version is ready) */
.toast-host { position: fixed; left: 0; right: 0; bottom: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 40; }
@media (prefers-reduced-motion: reduce) { #cup.spilt, .blk.on { animation: none; } }
/* a phone on its side: the cards put their buttons in a row */
@media (max-height: 480px) {
  .ovlCard { padding: 10px 12px; }
  .ovlCard h2 { font-size: 19px; margin-bottom: 2px; }
  .ovlCard p { margin: 4px 0 6px; font-size: 13px; }
  .ovlCard .pic { width: 64px; height: 64px; }
  #done .big, #paused .big, #oops .big, #brief .big { display: inline-block; width: calc(33% - 8px); min-width: 120px; min-height: 46px; margin: 4px 2px; padding: 0 8px; font-size: 15px; }
  .blk { bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); }
  #btnLeft { left: calc(env(safe-area-inset-left, 0px) + 116px); }
  #btnRight { right: calc(env(safe-area-inset-right, 0px) + 116px); }
}

/* R20.3 the licence card */
.licence {
  margin: 10px auto; max-width: 320px; border-radius: 14px; padding: 12px 14px; text-align: left;
  background: linear-gradient(135deg, var(--kBg17), var(--kBg18)); color: var(--kInk5); border: 2px solid var(--kLine7);
  display: grid; grid-template-columns: 96px 1fr; gap: 4px 12px; align-items: center;
}
.licence[hidden] { display: none; }
.licence .lcHead { grid-column: 1 / -1; font-weight: 800; font-size: 17px; letter-spacing: .04em; }
.licence canvas { width: 96px; height: 96px; }
.licence .lcText { font-size: 15px; line-height: 1.4; }
