:root {
  --ink: #332c24; --muted: #86796a; --paper: #f5efe4; --glass: rgba(248, 243, 234, .8);
  --line: rgba(120, 95, 70, .22); --hover: rgba(120, 95, 70, .1); --accent: #2f6b3f; --accent2: #3e8a52; --tile: #2f6b3f;
  --shadow: 0 10px 30px rgba(60, 40, 20, .18), 0 2px 6px rgba(60, 40, 20, .1);
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --gutter: 24px; --bottom: max(18px, env(safe-area-inset-bottom));
}
body.night {
  --ink: #efe6d6; --muted: #a8998a; --paper: #1a1916; --glass: rgba(22, 21, 19, .78);
  --line: rgba(235, 220, 195, .14); --hover: rgba(235, 220, 195, .08); --shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1c1a17; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

#app { position: fixed; inset: 0; }
#app canvas { display: block; touch-action: none; }

/* ---------- title: the element tile ---------- */
.title { position: fixed; left: var(--gutter); top: 18px; z-index: 5; pointer-events: none; user-select: none; transition: opacity .4s; color: #fbf6ec; text-shadow: 0 1px 12px rgba(0, 0, 0, .45); }
.title h1 { margin: 0; font: 600 clamp(19px, 2.8vw, 28px)/1.1 var(--serif); letter-spacing: .18em; display: flex; align-items: center; }
.title h1 a { color: inherit; text-decoration: none; pointer-events: auto; display: inline-flex; align-items: center; }
.title h1 a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; }
.el { position: relative; display: inline-grid; place-items: center; width: 1.75em; height: 1.75em; margin: 0 .08em 0 .3em; border-radius: 3px;
  background: linear-gradient(160deg, #3d8150, #24583a); border: 1px solid rgba(255, 255, 255, .35); box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(0, 0, 0, .15);
  font: 700 .82em/1 var(--sans); letter-spacing: 0; color: #f6f1e4; text-shadow: none; }
.el sup { position: absolute; right: .28em; top: .22em; font: 600 .3em/1 var(--sans); }
.el sub { position: absolute; left: 0; right: 0; bottom: .2em; text-align: center; font: 500 .24em/1 var(--sans); opacity: .85; }
.title p { margin: 9px 0 0; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; opacity: .85; }

/* ---------- the stops: a timeline ---------- */
#stops { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 10; display: flex; align-items: center; gap: 0; padding: 5px;
  border-radius: 14px; background: var(--glass); -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line); box-shadow: var(--shadow); transition: opacity .35s; }
#stops button { appearance: none; border: 0; background: transparent; cursor: pointer; display: grid; gap: 3px; padding: 7px 12px; border-radius: 10px; text-align: left; transition: background .15s, color .15s; }
#stops button b { font: 600 9.5px/1 var(--sans); letter-spacing: .16em; color: var(--muted); }
#stops button span { font: 600 13px/1 var(--serif); letter-spacing: .04em; white-space: nowrap; }
#stops button:hover { background: var(--hover); }
#stops button[aria-pressed="true"] { background: var(--accent); color: #f6f1e4; }
#stops button[aria-pressed="true"] b { color: rgba(246, 241, 228, .75); }
#stops i { width: 14px; height: 1px; background: var(--line); }

/* ---------- control bars ---------- */
#dock, #views {
  position: fixed; z-index: 10; display: flex; align-items: center; gap: 4px; padding: 6px; border-radius: 16px;
  background: var(--glass); -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line); box-shadow: var(--shadow); transition: opacity .35s;
}
#dock { left: 50%; bottom: var(--bottom); transform: translateX(-50%); }
#views { right: var(--gutter); top: 18px; }
.grp { display: flex; align-items: center; gap: 2px; }
.grp + .grp { border-left: 1px solid var(--line); padding-left: 6px; margin-left: 2px; }
#dock button, #views button {
  appearance: none; border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 11px; border-radius: 11px;
  font: 500 12.5px/1 var(--sans); color: var(--ink); transition: background .15s, color .15s;
}
#dock button:hover, #views button:hover { background: var(--hover); }
#dock button[aria-pressed="true"], #views button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
#dock svg, #views svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#b-sound .mute { display: none; }
#b-sound[aria-pressed="false"] .wave { display: none; }
#b-sound[aria-pressed="false"] .mute { display: inline; }
.time input[type=range] { width: 118px; accent-color: var(--accent2); cursor: pointer; }
.time output { min-width: 64px; font: 500 12px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }

/* the scene button: an element tile */
#dock #act {
  margin-left: 6px; background: linear-gradient(160deg, #3d8150, #24583a); color: #f6f1e4; padding: 8px 15px 8px 8px; border-radius: 11px; gap: 9px;
  font: 600 13px/1 var(--serif); letter-spacing: .16em; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28), 0 6px 16px rgba(30, 80, 45, .35);
  transition: transform .12s ease, box-shadow .2s, filter .15s;
}
#dock #act .sym { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, .45);
  font: 700 12px/1 var(--sans); letter-spacing: 0; background: rgba(0, 0, 0, .12); }
#dock #act:hover { filter: brightness(1.08); transform: translateY(-1px); }
#dock #act:active { transform: scale(.96); }
#dock #act[disabled] { filter: grayscale(.5) brightness(.85); cursor: default; transform: none; }
#dock #act.busy .sym { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#hint {
  position: fixed; left: var(--gutter); top: 86px; z-index: 5; margin: 0; max-width: 40vw; color: #fbf6ec; text-shadow: 0 1px 10px rgba(0, 0, 0, .5);
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase; opacity: .8; pointer-events: none; transition: opacity .8s;
}
#hint.gone { opacity: 0; }
#goal { position: fixed; left: 50%; top: 78px; transform: translateX(-50%); z-index: 9; margin: 0; padding: 9px 16px; border-radius: 999px; max-width: calc(100vw - 32px);
  background: rgba(20, 19, 17, .72); color: #f3ead9; font: 500 13px/1.35 var(--sans); letter-spacing: .02em; text-align: center;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, .12); box-shadow: 0 8px 24px rgba(0, 0, 0, .3); }
#goal b { color: #9fd9a9; font-weight: 600; letter-spacing: .12em; margin-right: 8px; font-size: 11px; }

/* ---------- info card, tooltip, bubbles ---------- */
#card {
  position: fixed; left: var(--gutter); bottom: calc(var(--bottom) + 70px); z-index: 12; width: min(340px, calc(100vw - 2 * var(--gutter)));
  padding: 16px 44px 17px 18px; border-radius: 14px; background: var(--glass);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: rise .22s ease-out;
}
#card h2 { margin: 0 0 6px; font: 600 17px/1.2 var(--serif); }
#card p { margin: 0; font-size: 13.5px; line-height: 1.45; opacity: .86; }
.x { position: absolute; right: 8px; top: 8px; width: 30px; height: 30px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); }
.x:hover { background: var(--hover); color: var(--ink); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

#tip { position: fixed; left: 0; top: 0; z-index: 13; pointer-events: none; padding: 6px 9px; border-radius: 8px; background: var(--ink); color: var(--paper); font: 500 12px var(--sans); white-space: nowrap; }
#bubbles { position: fixed; inset: 0; z-index: 9; pointer-events: none; overflow: hidden; }
.bubble {
  position: absolute; left: 0; top: 0; padding: 9px 13px; border-radius: 14px; background: #fffdf8; color: #2b251e;
  font: italic 500 15px/1.25 var(--serif); white-space: nowrap; box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  opacity: 0; transition: opacity .25s; margin-top: -10px;
}
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -7px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: #fffdf8; }
.bubble.in { opacity: 1; }

/* the episode card when a stop opens */
#titlecard { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 16; pointer-events: none; text-align: center; color: #f7f0e2;
  text-shadow: 0 2px 24px rgba(0, 0, 0, .6); animation: card 3.2s ease forwards; }
#titlecard b { display: block; font: 600 12px/1 var(--sans); letter-spacing: .4em; opacity: .8; }
#titlecard span { display: block; margin-top: 12px; font: 600 clamp(30px, 6vw, 58px)/1 var(--serif); letter-spacing: .12em; }
@keyframes card { 0% { opacity: 0; transform: translate(-50%, -46%); } 18% { opacity: 1; transform: translate(-50%, -50%); } 72% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- walk ---------- */
#walk-ui { position: fixed; inset: 0; z-index: 14; pointer-events: none; }
#walk-ui .cross { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85); box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); transition: transform .15s; }
#walk-ui .cross.on { transform: scale(1.8); border-color: #ffd08a; }
.walk-help, .drive-help { position: absolute; left: 50%; top: 22px; transform: translateX(-50%); margin: 0; padding: 9px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; box-shadow: var(--shadow); }
#walk-exit, #drive-exit, #cinema-exit {
  position: absolute; right: var(--gutter); top: 18px; pointer-events: auto; cursor: pointer; border: 1px solid var(--line);
  background: var(--glass); padding: 10px 15px; border-radius: 11px; font: 500 12.5px var(--sans); box-shadow: var(--shadow);
}
#joy { position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); background: rgba(0, 0, 0, .12); display: none; }
#joy span { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255, 255, 255, .8); }
#joy.on { display: block; }

/* ---------- drive ---------- */
#drive-ui { position: fixed; inset: 0; z-index: 14; pointer-events: none; }
#drive-ui .gauges { position: absolute; left: var(--gutter); bottom: calc(var(--bottom) + 8px); color: #fbf6ec; text-shadow: 0 2px 12px rgba(0, 0, 0, .5); }
#drive-ui .gauges span { font: 600 44px/1 var(--serif); font-variant-numeric: tabular-nums; }
#drive-ui .gauges small { margin-left: 6px; font: 600 11px var(--sans); letter-spacing: .2em; opacity: .8; }
#key { position: absolute; left: 50%; bottom: calc(var(--bottom) + 12px); transform: translateX(-50%); pointer-events: auto; cursor: pointer; width: 76px; height: 76px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .6); background: radial-gradient(circle at 40% 35%, #4a8a5a, #1f4a2c); color: #f6f1e4; font: 700 13px var(--sans); letter-spacing: .16em; box-shadow: 0 8px 22px rgba(0, 0, 0, .4); }
#key.cranking { animation: shake .09s linear infinite; }
#key.running { background: radial-gradient(circle at 40% 35%, #8a8a8a, #3a3a3a); }
@keyframes shake { 50% { transform: translate(-50%, 1px) rotate(3deg); } }
.pedals, #wheel { display: none; }
body.touch .pedals { display: flex; gap: 12px; position: absolute; right: var(--gutter); bottom: calc(var(--bottom) + 10px); pointer-events: auto; }
body.touch .pedals button { width: 76px; height: 96px; border-radius: 14px; border: 1px solid rgba(255, 255, 255, .3); background: rgba(20, 20, 20, .5); color: #f3ead9; font: 700 11px var(--sans); letter-spacing: .14em; }
body.touch .pedals button.on { background: rgba(70, 140, 90, .7); }
body.touch #wheel { display: block; position: absolute; left: var(--gutter); bottom: calc(var(--bottom) + 70px); width: 150px; height: 44px; pointer-events: auto; border-radius: 22px; border: 1px solid rgba(255, 255, 255, .3); background: rgba(20, 20, 20, .45); }
body.touch #wheel span { position: absolute; left: 50%; top: 4px; width: 36px; height: 36px; margin-left: -18px; border-radius: 50%; background: rgba(255, 255, 255, .85); }
body.touch #drive-ui .gauges { bottom: calc(var(--bottom) + 130px); }

/* ---------- cinema ---------- */
#cinema-ui { position: fixed; inset: 0; z-index: 14; pointer-events: none; color: #e9e2d2; font: 600 11.5px var(--sans); letter-spacing: .22em; }
#shotlabel { position: absolute; left: var(--gutter); bottom: 22px; opacity: .78; }
#cinema-exit { color: #e9e2d2; background: rgba(20, 20, 22, .55); border-color: rgba(255, 255, 255, .15); }
body.cinema .title, body.cinema #views, body.cinema #hint, body.cinema #card, body.cinema #stops, body.cinema #dock .grp, body.cinema #goal { display: none; }
body.cinema #dock { background: rgba(20, 20, 22, .5); border-color: rgba(255, 255, 255, .12); }
body.walking .title, body.walking #hint, body.walking #views, body.walking #dock, body.walking #stops { opacity: 0; pointer-events: none; }
body.driving .title, body.driving #hint, body.driving #views, body.driving #dock, body.driving #stops, body.driving #card { opacity: 0; pointer-events: none; }
body.scripted #views, body.scripted #hint { opacity: .35; }

/* ---------- help ---------- */
#help {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 20; width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  padding: 22px 24px 18px; border-radius: 16px; background: var(--glass); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line); box-shadow: var(--shadow); animation: rise .2s ease-out;
}
#help h2 { margin: 0 0 12px; font: 600 20px var(--serif); }
#help dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 13.5px; line-height: 1.4; }
#help dt { font-weight: 600; white-space: nowrap; }
#help dd { margin: 0; opacity: .86; }
#help .fine { margin: 16px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
#help .fine a { color: inherit; }

/* ---------- loader, errors ---------- */
#loader { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: #1c1a17; transition: opacity 1.1s ease; text-align: center; }
#loader h1 { margin: 0; font: 600 clamp(22px, 4vw, 34px) var(--serif); letter-spacing: .24em; color: #efe6d6; }
#loader p { margin: 12px 0 0; font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: #a8998a; animation: breathe 1.8s ease-in-out infinite; }
.failed #loader p { animation: none; color: #e59b88; letter-spacing: .06em; text-transform: none; font-size: 14px; }
body.ready #loader { opacity: 0; pointer-events: none; }
@keyframes breathe { 50% { opacity: .45; } }
#err { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 50; max-width: 80vw; padding: 8px 14px; border-radius: 8px; background: #7e2c22; color: #fff; font: 12px ui-monospace, Menlo, monospace; }
#flash { position: fixed; inset: 0; z-index: 25; background: #fff; pointer-events: none; animation: flash .45s ease-out forwards; }
@keyframes flash { from { opacity: .7; } to { opacity: 0; } }

body.clean .title, body.clean #dock, body.clean #views, body.clean #hint, body.clean #card, body.clean #tip, body.clean #stops, body.clean #goal { display: none !important; }

/* ---------- narrow screens ---------- */
@media (max-width: 1320px) { #views span { display: none; } #views button { padding: 9px; } }
@media (max-width: 1060px) { #dock .modes span { display: none; } #dock .modes button { padding: 9px; } }
@media (max-width: 760px) {
  #stops { top: 86px; }
  #hint { top: 140px; max-width: 60vw; }
  #goal { top: 140px; }
}
@media (max-width: 640px) {
  :root { --gutter: 12px; --bottom: max(10px, env(safe-area-inset-bottom)); }
  .title { top: 14px; left: 16px; }
  .title p { letter-spacing: .14em; font-size: 10px; }
  /* the views stand in a column on the right, under the stops, so the title keeps the top */
  #views { left: auto; right: 12px; top: 124px; flex-direction: column; padding: 4px; }
  #views .grp { gap: 0; flex-direction: column; }
  #views button { padding: 8px; }
  #stops { left: 12px; right: 12px; transform: none; top: 70px; justify-content: space-between; }
  #stops button { padding: 6px 8px; }
  #stops button span { font-size: 12px; }
  #stops i { flex: 1; min-width: 4px; }
  #hint { top: 132px; left: 16px; max-width: calc(100vw - 88px); font-size: 10px; }
  #goal { top: 128px; left: 12px; right: 70px; transform: none; max-width: none; font-size: 12px; }
  #dock { left: 12px; right: 12px; transform: none; flex-wrap: wrap; justify-content: space-between; row-gap: 4px; }
  .grp + .grp { border-left: 0; padding-left: 0; margin-left: 0; }
  #dock .grp.modes { flex: 1; justify-content: space-between; }
  .grp.time { width: 100%; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
  .time input[type=range] { flex: 1; width: auto; }
  #dock #act { flex: 1 1 100%; justify-content: center; padding: 7px 12px 7px 7px; font-size: 12px; }
  #card { bottom: calc(var(--bottom) + 150px); }
  .walk-help, .drive-help { white-space: normal; text-align: center; width: calc(100vw - 150px); left: 16px; transform: none; font-size: 11.5px; }
}
/* a phone on its side: little height, so the stops go under the views on the right and the hint goes */
@media (max-height: 500px) and (orientation: landscape) {
  #stops { left: auto; right: var(--gutter); transform: none; top: 66px; }
  #hint { display: none; }
  #goal { top: auto; bottom: calc(var(--bottom) + 66px); }
  #card { bottom: calc(var(--bottom) + 66px); max-height: calc(100vh - 150px); overflow: auto; }
}
@media (max-width: 400px) { .title h1 { font-size: 17px; } #dock .modes button { padding: 8px 7px; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
