:root {
  --ink: #1d1d1f;
  --muted: #8a8a8e;
  --line: #e5e5ea;
  --accent: #2f6fed;
  --bail: #c0392b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* (the visible height on phones, as the browser bars come and go) */
  overflow: hidden;
  background: #fff;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  user-select: none;
}

/* The tools, down the left side (icons only), then the grid toggle and the line types — floating
   over the map with no panel behind them, so the track shows through. Each button is frosted
   glass (a backdrop blur over a translucent white fill), with a hairline edge and a soft shadow,
   so it holds its own against a busy track; the picked one is tinted with the accent. */
.workspace { flex: 1; min-height: 0; display: flex; position: relative; }
.workspace > main { flex: 1; min-width: 0; }
.toolbox {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 52px;
  padding: 10px 0;
  user-select: none;
  overflow-y: auto;
  pointer-events: none; /* (the gaps between buttons are the map's) */
}
.tb-inner > *, .tb-section > * { pointer-events: auto; }
.tb-inner, .tb-inner > .tb-section { pointer-events: none; } /* (the gaps are the map's) */
/* Buttons keep their size: when the bar's too tall for the screen it re-lays itself out
   (toolbarLayout.js) — a second column by section, then item by item — and past that scrolls. */
.tb-inner { display: flex; flex-direction: column; align-items: center; gap: 5px; margin-block: auto; } /* (centred down the screen; auto margins, so a bar too tall to fit still scrolls from its top) */
.tb-inner > *, .tb-section > * { flex-shrink: 0; }
.tb-section { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.toolbox.two-sections, .toolbox.two-items { width: 94px; }
/* (Scrolling — the wheel, a trackpad or a finger — without a scrollbar crowding the two columns.) */
.toolbox { scrollbar-width: none; }
.toolbox::-webkit-scrollbar { display: none; }
/* By section: the tools down one column, the grid and the line types down the other. */
.toolbox.two-sections .tb-inner { display: grid; grid-template-columns: 36px 36px; grid-template-rows: auto auto 1fr; column-gap: 6px; row-gap: 5px; justify-content: center; align-content: start; align-items: start; }
/* (The tools column spans all three rows: any height it has over the other column goes to the last row, so both stay packed to the top.) */
.toolbox.two-sections [data-section="tools"] { grid-column: 1; grid-row: 1 / span 3; }
.toolbox.two-sections .tb-sep-a { display: none; }
.toolbox.two-sections [data-section="grid"] { grid-column: 2; grid-row: 1; }
.toolbox.two-sections .tb-sep-b { grid-column: 2; grid-row: 2; justify-self: center; }
.toolbox.two-sections [data-section="types"] { grid-column: 2; grid-row: 3; align-self: start; }
/* Item by item: everything flows down the first column and on into the second (its height set by the script). */
.toolbox.two-items .tb-inner { flex-wrap: wrap; align-content: flex-start; justify-content: flex-start; column-gap: 6px; width: 78px; margin: auto; }
.toolbox.two-items .tb-section { display: contents; }
.toolbox { transition: transform 0.22s ease, opacity 0.22s ease; }
/* Mid-ride the tool bar slides off to the left; it's back on pause. */
body.riding .toolbox { transform: translateX(-100%); opacity: 0; pointer-events: none; }
body.riding .toolbox > * { pointer-events: none; }
.toolbox button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  -webkit-backdrop-filter: blur(6px) saturate(1.2);
  backdrop-filter: blur(6px) saturate(1.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
}
.toolbox button:hover { background: rgba(255, 255, 255, 0.85); }
.toolbox button.active {
  background: rgba(225, 234, 253, 0.82);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 8px rgba(47, 111, 237, 0.18);
}
.toolbox button img { width: 18px; height: 18px; object-fit: contain; }
.toolbox [data-tool="edit"] img { transform: translateX(3px); } /* (the arrow's weight sits left of its box: nudged to look centred) */
.toolbox hr { width: 20px; border: 0; border-top: 2px solid rgba(0, 0, 0, 0.12); border-radius: 1px; margin: 5px 0; }
.toolbox button.swatch::before { width: 18px; height: 4px; margin: 0; transform: rotate(-35deg); }

/* The panels that open at the top left sit clear of the tool bar. */
#help, #tuning, #map-export, #pose { left: calc(var(--tb-w, 52px) + 12px) !important; top: 56px !important; }

/* The long-hover name beside a tool. */
#tip {
  position: fixed;
  z-index: 50;
  padding: 4px 8px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

.group { display: flex; gap: 4px; }
.tool-size { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 0 4px; }
.tool-size[hidden] { display: none; }
.tool-size input { width: 90px; }
.tool-size span { min-width: 34px; font-variant-numeric: tabular-nums; }
.group.right { margin-left: auto; }

button {
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
select {
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover { background: #f5f5f7; }
button.active { border-color: var(--ink); background: #f0f0f2; }
button.primary { background: var(--ink); color: #fff; border-color: var(--ink); min-width: 64px; }

button.swatch::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--swatch);
  border-radius: 2px;
}

main {
  position: relative;
  flex: 1;
  min-height: 0;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* Score: top center. The banked total rolls like an odometer; the live combo sits under it, and
   each trick pops in below as a chip. */
.hud {
  position: absolute;
  top: 58px; /* (under the run controls) */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  pointer-events: none;
  max-width: calc(100% - 32px);
}

button:disabled { opacity: 0.4; cursor: default; background: #fff; }

#combo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}
#combo:empty { display: none; }
.combo-names { max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-pot { font-variant-numeric: tabular-nums; font-size: 18px; white-space: nowrap; animation: pop 0.2s ease-out; }
/* The combo multiplier: bigger the higher it gets (--mult-scale), and a pulse each time it goes up. */
.combo-mult { display: inline-block; font-weight: 800; color: var(--accent); transform: scale(var(--mult-scale, 1)); transform-origin: left center; }
.combo-mult.pulse { animation: mult-pulse 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes mult-pulse { 0% { transform: scale(calc(var(--mult-scale, 1) * 1.7)); } 100% { transform: scale(var(--mult-scale, 1)); } }
/* Landing grades. */
.feed-item.clean { color: #15803d; font-weight: 700; border-color: rgba(21, 128, 61, 0.35); animation: grade-in 0.3s cubic-bezier(0.3, 1.6, 0.5, 1); }
.feed-item.sketchy { color: #b45309; font-weight: 600; font-style: italic; border-color: rgba(180, 83, 9, 0.35); animation: grade-in 0.3s ease-out; }
@keyframes grade-in { 0% { transform: scale(1.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
#combo.lost { color: var(--bail); animation: lose-chip 0.9s ease-in forwards; }
#combo.lost .combo-names, #combo.lost .combo-pot { text-decoration: line-through; }
#combo.lost .pending { opacity: 1; }
.combo-lost { white-space: nowrap; }
#ghost-score { font-size: 12px; color: var(--muted); }
/* The stance tag under the score: what the next trick is done from. */
#stance { margin-top: 3px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); background: rgba(0, 0, 0, 0.04); }
#stance:empty { display: none; }
#stance[data-stance="nollie"] { color: #2f6fed; background: rgba(47, 111, 237, 0.1); }
#stance[data-stance="fakie"] { color: #b26b00; background: rgba(178, 107, 0, 0.1); }
#stance[data-stance="switch"] { color: #b4235a; background: rgba(180, 35, 90, 0.1); }
#ghost-score:empty { display: none; }

/* A banked combo flies up into the total. */
.combo-out {
  position: absolute;
  top: 44px;
  left: 50%;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.combo-out.banked { color: var(--accent); animation: bank 0.45s ease-in forwards; }
@keyframes bank {
  from { transform: translate(-50%, 0) scale(1); opacity: 1; }
  to { transform: translate(-50%, -36px) scale(0.6); opacity: 0; }
}

.feed-item.combo { color: var(--accent); font-weight: 600; }

#rewind { /* (in the bottom stack, between the status line and the options pill) */
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#rewind[hidden] { display: none; }
#rewind-range { width: min(360px, 60vw); }
#rewind-label { min-width: 52px; text-align: right; }

#score {
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* Odometer digits: a 0–9(–0) column per digit, scrolled by transform, clipped to one digit. */
.odometer { display: inline-flex; }
.odo-digit {
  display: inline-block;
  height: 1em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
}
.odo-col { display: block; will-change: transform; }
.odo-col > span { display: block; height: 1em; }
.odo-sep { display: inline-block; height: 1em; }

#feed, #pending { display: flex; flex-direction: column; align-items: center; }
#combo .pending { opacity: 0.5; }
.feed-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--line);
  font-size: 13px;
  white-space: nowrap;
  animation: pop 0.25s ease-out;
}
.feed-item b { font-variant-numeric: tabular-nums; color: var(--accent); }
/* Pending (in the air, not landed yet): dashed and faded. Lost on a bail: struck out, dropped. */
.feed-item.pending { border-style: dashed; color: var(--muted); }
.feed-item.pending b { color: var(--muted); }
.feed-item.lost { color: var(--bail); text-decoration: line-through; border-color: rgba(192, 57, 43, 0.35); animation: lose-chip 0.9s ease-in forwards; }
.feed-item.lost b { color: var(--bail); }
@keyframes lose-chip {
  0% { transform: translateX(0); opacity: 1; }
  10% { transform: translateX(-5px); }
  20% { transform: translateX(5px); }
  30% { transform: translateX(-3px); }
  40% { transform: translateX(0); opacity: 1; }
  100% { transform: translateY(14px); opacity: 0; }
}
.feed-item.bail { color: var(--bail); font-weight: 600; border-color: rgba(192, 57, 43, 0.35); }
.feed-item.miss { color: var(--muted); }

@keyframes pop {
  from { transform: translateY(-4px); opacity: 0; }
}

#status {
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  width: max-content;
  max-width: min(640px, calc(100vw - 160px)); /* (the viewport's: its box is only as wide as the pill under it) */
  text-align: center;
}

#help {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 300px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  font-size: 13px;
}
#help h2 { font-size: 14px; margin: 0 0 8px; }

#tuning {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: 48px;
  width: 420px;
  max-width: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  font-size: 12px;
}
#tuning[hidden] { display: none; }

/* Pose editor (L): a small panel, top left. */
#pose {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 280px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 60px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  font-size: 12px;
}
#pose[hidden] { display: none; }
#pose h2 { margin: 0; font-size: 14px; }
#pose input[type=text], #pose textarea { width: 100%; font: inherit; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.pose-hint, .pose-status { margin: 0; color: var(--muted); }
.pose-status { min-height: 1.2em; color: var(--accent); }
.pose-check { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.pose-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.pose-lengths summary { cursor: pointer; color: var(--ink); font-weight: 600; margin-bottom: 4px; }
.pose-len { display: grid; grid-template-columns: 1fr 64px 62px; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); }
.pose-len input { width: 100%; font: inherit; padding: 2px 4px; border: 1px solid var(--line); border-radius: 4px; }
.pose-game-len { font-variant-numeric: tabular-nums; font-size: 11px; }

#assets[hidden] { display: none; }
#assets h2 { font-size: 14px; margin: 0 0 8px; }
.asset-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.asset-tabs button { font-size: 12px; padding: 3px 8px; }
.asset { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; font-size: 11px; }
.asset span { color: var(--muted); text-align: center; line-height: 1.2; }
.asset.active span { color: var(--ink); }
.asset-delete { position: absolute; top: 1px; right: 4px; font-size: 13px; color: var(--muted); cursor: pointer; }
.asset-delete:hover { color: var(--bail); }
.asset-empty { grid-column: 1 / -1; color: var(--muted); margin: 4px 0; }
.asset-params { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.asset-param { display: flex; align-items: center; gap: 4px; }
.asset-param > span { min-width: 56px; color: var(--muted); }
.asset-param button, .asset-actions button { font-size: 12px; padding: 3px 8px; }
.asset-actions { margin-top: 8px; }
.asset-hint { color: var(--muted); margin: 8px 0 0; }
#tuning h2 { font-size: 14px; margin: 0; }
#tuning h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 12px 0 4px;
}
.tune-hint { color: var(--muted); margin: 4px 0 4px; }
.tune-list { overflow-y: auto; flex: 1; min-height: 0; padding-right: 4px; }
.tune-row {
  display: grid;
  grid-template-columns: 1fr 90px 64px 22px;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  border-radius: 4px;
}
.tune-row.changed { background: #eef3fe; }
.tune-row.changed .tune-name { font-weight: 600; color: var(--accent); }
.tune-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tune-row input[type="range"] { width: 100%; }
.tune-row input[type="number"] {
  font: inherit;
  width: 100%;
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.tune-reset { padding: 0 4px; font-size: 12px; visibility: hidden; }
.tune-row.changed .tune-reset { visibility: visible; }
.tune-footer { display: flex; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 6px; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
#help dt { font-weight: 600; }
#help dd { margin: 0; color: #555; }
#help p { color: var(--muted); margin: 10px 0 0; }

/* Controls panel (? / F1): every key, grouped; riding keys rebindable. */
#help { overflow: auto; max-height: calc(100% - 24px); box-sizing: border-box; width: 340px; }
#help h3 { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.ctl-hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.ctl-row { display: grid; grid-template-columns: 92px 1fr; gap: 2px 10px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.ctl-row small { grid-column: 2; color: var(--muted); font-size: 11px; }
.ctl-row kbd, .ctl-key { font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 1px 6px; border: 1px solid var(--line); border-radius: 5px; background: #f7f7f9; text-align: center; }
.ctl-key { cursor: pointer; }
.ctl-key.waiting { background: #fff4d6; border-color: #e0b84b; }
.ctl-actions { margin-top: 6px; }
.ctl-tip { color: var(--muted); font-size: 11px; }

/* Map export panel: name + describe the track, copy / save it as a map file (maps/README.md). */
#map-export { position: absolute; top: 12px; left: 12px; width: 320px; max-width: calc(100% - 24px); box-sizing: border-box; padding: 12px 16px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06); font-size: 13px; }
#map-export h2 { font-size: 14px; margin: 0 0 8px; }
#map-export label { display: block; margin: 8px 0; }
#map-export label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
#map-export input, #map-export textarea { width: 100%; box-sizing: border-box; font: inherit; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.export-actions { display: flex; gap: 6px; }
.export-tip, .export-status { color: var(--muted); font-size: 12px; margin: 0 0 4px; }
.export-status { margin-top: 8px; min-height: 1em; }

/* Tool icons on their buttons (Select, Pen, Pencil — icons/). */
.tool-icon { height: 13px; width: auto; vertical-align: -2px; margin-right: 5px; }
.shape-icon { height: 15px; width: 15px; vertical-align: -3px; display: inline-block; }
[data-line] .shape-icon { margin-right: 5px; height: 13px; width: 13px; vertical-align: -2px; }

/* Bottom middle: the status line, and the tool's options in a frosted pill under it. */
#bottom {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100% - 120px);
}
.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
  backdrop-filter: blur(8px) saturate(1.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 14px rgba(0, 0, 0, 0.06);
  pointer-events: auto;
  user-select: none;
  white-space: nowrap;
}
.pill[hidden] { display: none; }
.pill button { padding: 3px 9px; background: rgba(255, 255, 255, 0.6); }
.pill button.active { border-color: var(--accent); background: rgba(225, 234, 253, 0.9); }

/* Floating over the selection (placed by ui.js): flip ↔ / ↕, rotate 90°. */
#sel-tools { position: absolute; z-index: 6; gap: 4px; padding: 4px; transition: opacity 0.12s; }
#sel-tools button { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; }
#sel-tools img { width: 16px; height: 16px; }

/* The bottom pill's buttons: the tool bar's size (36 px tall), keeping their labels. */
#options { padding: 6px; gap: 6px; border-radius: 12px; }
#options .tool-size { gap: 6px; padding: 0; }
#options button {
  height: 36px;
  min-width: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  font-size: 13px;
}
#options button { padding: 0; width: 36px; } /* (icon-only squares, like the tool bar's: names on hover) */
#options button img, #options .shape-icon { width: 16px; height: 16px; margin: 0; vertical-align: 0; }
#options input[type=range] { width: 110px; }

/* Top bar icons, beside their labels. (On the dark Play button: white.) */
.topbar button { display: inline-flex; align-items: center; gap: 6px; }
.top-icon { width: 13px; height: 13px; }
button.primary .top-icon { filter: invert(1); }
button:disabled .top-icon { opacity: 0.4; }

/* The run's controls (top left, beside the tool bar) and the menu button (top right): frosted
   icon buttons floating over the map, like the tool bar's. */
#run-controls { position: absolute; z-index: 6; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 5px; } /* (top middle; the score sits under it) */
#menu-wrap { position: absolute; z-index: 7; top: 10px; right: 10px; }
#run-controls button, #menu-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  -webkit-backdrop-filter: blur(6px) saturate(1.2);
  backdrop-filter: blur(6px) saturate(1.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
}
#run-controls button:hover, #menu-toggle:hover { background: rgba(255, 255, 255, 0.85); }
#run-controls button:disabled { cursor: default; }
#run-controls button[hidden] { display: none; } /* (undo / redo: only while editing, with something to undo / redo) */
#run-controls button:disabled img { opacity: 0.3; }
#run-controls img, #menu-toggle img { width: 16px; height: 16px; }
#menu-toggle[aria-expanded="true"] { border-color: var(--accent); background: rgba(225, 234, 253, 0.85); }

/* The menu: the map picker, the track's actions, the toggles (a tick when on) and their keys. */
#menu {
  position: absolute;
  top: 44px;
  right: 0;
  min-width: 230px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}
#menu[hidden] { display: none; }
#menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }
.menu-map { display: flex; align-items: center; gap: 8px; padding: 4px 6px; font-size: 12px; color: var(--muted); }
.menu-map select { flex: 1; min-width: 0; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 7px 10px 7px 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  position: relative;
}
.menu-item:hover { background: rgba(0, 0, 0, 0.05); }
.menu-item.toggle.active::before { content: "✓"; position: absolute; left: 10px; color: var(--accent); font-weight: 600; }
.menu-item.active { border: 0; background: transparent; }
.menu-item kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }

/* The speed readout, bottom left (clear of the tool bar), while a run's going. */
#speedo { position: absolute; z-index: 5; left: calc(var(--tb-w, 52px) + 8px); bottom: 14px; flex-direction: column; align-items: flex-start; gap: 0; padding: 6px 12px 7px; pointer-events: none; }
.speedo-now { display: flex; align-items: baseline; gap: 4px; }
#speed-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; min-width: 2ch; text-align: right; }
#speed-unit { font-size: 12px; font-weight: 600; color: var(--muted); }
.speedo-top { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* The Assets tool's tray, along the bottom: category tabs over one row of thumbnails (scroll it
   with the wheel, the ‹ › buttons, or by dragging). */
#assets {
  position: absolute;
  z-index: 6;
  left: calc(var(--tb-w, 52px) + 8px);
  right: calc(var(--tb-w, 52px) + 8px); /* (the same gap both sides — the tool bar's on the left — so it's centred) */
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px 8px 8px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.08);
  user-select: none;
}
#assets .asset-tabs { display: flex; align-items: center; gap: 4px; margin: 0; flex-wrap: nowrap; overflow-x: auto; }
#assets .asset-tabs button { font-size: 12px; padding: 3px 9px; border-radius: 14px; background: rgba(255, 255, 255, 0.7); }
#assets .asset-tabs button.active { border-color: var(--accent); background: rgba(225, 234, 253, 0.9); }
#assets .asset-hint { margin: 0 0 0 auto; padding-left: 12px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.asset-strip { display: flex; align-items: stretch; gap: 4px; }
.asset-row { flex: 1; min-width: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; cursor: grab; padding: 2px; }
.asset-row::-webkit-scrollbar { display: none; }
.asset-row:active { cursor: grabbing; }
.asset-row .asset { flex: none; position: relative; padding: 2px; width: 62px; height: 46px; display: grid; place-items: center; border-radius: 8px; background: rgba(255, 255, 255, 0.75); }
.asset-row .asset.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: rgba(225, 234, 253, 0.9); }
.asset-row .asset canvas { pointer-events: none; }
.asset-scroll { flex: none; width: 26px; padding: 0; font-size: 18px; line-height: 1; border-radius: 8px; background: rgba(255, 255, 255, 0.6); }
#asset-opts { gap: 10px; }
.asset-param { display: inline-flex; align-items: center; gap: 4px; }
.asset-param-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
#options .asset-value { width: auto; padding: 0 9px; }
/* (A count — steps: − [number] + — the box sized like the buttons beside it.) */
#options .asset-step { width: 34px; padding: 0; font-size: 18px; }
#options .asset-number { width: 50px; height: 44px; box-sizing: border-box; border: 1px solid var(--line); border-radius: 8px; text-align: center; font: 600 13px/1 system-ui, sans-serif; color: var(--ink); background: #fff; -moz-appearance: textfield; }
#options .asset-number::-webkit-inner-spin-button, #options .asset-number::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#options .asset-param > .asset-unit { min-width: 0; }
#options .asset-select { height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; font: 600 13px/1 system-ui, sans-serif; color: var(--ink); background: #fff; max-width: 180px; }
#options .asset-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#options .asset-number:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* The options pill: bigger buttons, a label per group, numbered (the number keys pick them), and
   it slides up / fades in when it has something to show (ui.js optionsPill). */
#options {
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.24s cubic-bezier(0.2, 1.35, 0.4, 1), opacity 0.18s ease-out;
}
#options.open { transform: none; opacity: 1; pointer-events: auto; }
#options.open.leaving { transform: translateY(18px); opacity: 0; transition-duration: 0.14s; transition-timing-function: ease-in; }
#options button { height: 44px; width: 44px; border-radius: 10px; position: relative; }
#options button img, #options .shape-icon { width: 20px; height: 20px; }
#options .asset-value { height: 44px; padding: 0 12px; font-size: 14px; }
#options .tool-size:not([hidden]) ~ .tool-size:not([hidden]) { border-left: 1px solid var(--line); padding-left: 10px; } /* (a divider between groups) */
#options .tool-size::before { content: attr(data-label); font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 0 2px 0 4px; }
#options button[data-key]:not([data-key=""])::after {
  content: attr(data-key);
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}

/* The asset tray slides up / fades in like the options pill (ui.js slider), and the status line +
   pill glide up above it and back down. */
#assets {
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.26s cubic-bezier(0.2, 1.25, 0.4, 1), opacity 0.2s ease-out;
}
#assets.open { transform: none; opacity: 1; pointer-events: auto; }
#bottom { transition: bottom 0.26s cubic-bezier(0.2, 1, 0.4, 1); }

/* The height meter row (in the speed card): fades in for a real air, holds the peak, fades out. */
.speedo-air { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; max-height: 0; opacity: 0; overflow: hidden; transition: opacity 0.2s, max-height 0.2s; }
.speedo-air.on { max-height: 20px; opacity: 1; margin-top: 2px; }
.speedo-air b { color: var(--ink); font-size: 15px; }

/* Keys named in the status line, drawn as key caps ("press [Enter] to ride"). */
#status kbd { display: inline-block; padding: 0 5px; margin: 0 1px; border: 1px solid #c7c7cc; border-bottom-width: 2px; border-radius: 4px; background: #fff; font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); vertical-align: 1px; }

/* The scoreboard: only during a run (hidden — not zeroed — while you edit a paused run). */
.hud { transition: opacity 0.2s; }
.hud.off { opacity: 0; pointer-events: none; }

/* The speed card lifts above the asset tray when both show (ui.js), like the bottom stack. */
#speedo { transition: bottom 0.26s cubic-bezier(0.2, 1, 0.4, 1); }

/* --- Replays -------------------------------------------------------------------------- */
#last-run, #replay-bar { pointer-events: auto; gap: 6px; }
#last-run .last-run-label, #replay-bar .rb-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 0 4px; }
#last-run button, #replay-bar button { height: 36px; padding: 0 12px; border-radius: 8px; }
#replay-bar .rb-play { width: 36px; padding: 0; display: grid; place-items: center; }
#replay-bar .rb-play img { width: 16px; height: 16px; }
#replay-bar .rb-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 78px; text-align: center; }
#replay-bar input[type=range] { width: min(320px, 30vw); }
#replay-bar .rb-speeds { display: inline-flex; gap: 3px; }
#replay-bar .rb-speed { padding: 0 8px; }
#replay-bar .rb-speed.active { border-color: var(--accent); background: rgba(225, 234, 253, 0.9); }
#replay-bar .rb-sep { width: 1px; align-self: stretch; background: var(--line); margin: 4px 2px; }
#replay-bar.recording { box-shadow: 0 0 0 2px #e5383b, 0 4px 14px rgba(0, 0, 0, 0.06); }
#replay-bar.recording button:not(.rb-close) { opacity: 0.4; pointer-events: none; }
/* Replaying: the editing controls step aside. */
body.replaying .toolbox, body.replaying #run-controls, body.replaying #options, body.replaying #sel-tools, body.replaying #assets, body.replaying #menu-wrap { display: none !important; }

#replay-summary, #finish-card {
  position: absolute; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, calc(100% - 40px)); padding: 18px 20px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.92); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 0, 0, 0.08); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}
#replay-summary[hidden], #finish-card[hidden] { display: none; }
#replay-summary h2, #finish-card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.fc-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 8px; border-radius: 999px; background: var(--accent); color: #fff; }
.fc-time { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.fc-time b { font-size: 34px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.fc-time span { font-size: 12px; color: var(--muted); }
.rs-warn { margin: -4px 0 10px; font-size: 12px; color: var(--bail); }
.rs-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 10px; margin-bottom: 16px; }
.rs-stat { display: flex; flex-direction: column; gap: 2px; }
.rs-stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.rs-stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.rs-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

#replays { position: absolute; z-index: 8; top: 56px; right: 12px; width: 340px; max-height: calc(100% - 120px); overflow: auto; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08); font-size: 13px; }
#replays[hidden] { display: none; }
#replays h2 { margin: 0 0 8px; font-size: 14px; }
.rp-item { display: flex; align-items: center; gap: 6px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.rp-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rp-main span { font-size: 11px; color: var(--muted); }
.rp-item button { padding: 3px 8px; font-size: 12px; }
.rp-empty { color: var(--muted); font-size: 12px; }

#toast { position: absolute; z-index: 30; left: 50%; top: 64px; transform: translate(-50%, -8px); padding: 7px 14px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 13px; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
body.replaying #speedo { bottom: 74px !important; } /* (lifted above the replay bar) */

/* A landed trick's chip fades out after its moment (ui.js FEED_SHOW_MS / FEED_FADE_MS). */
.feed-item { transition: opacity 0.5s ease, transform 0.5s ease; }
.feed-item.fading { opacity: 0; transform: translateY(-4px); }
.feed-item.gone { display: none; } /* (faded out: folded away, so the column doesn't keep its gap) */

/* Show keys (menu): the riding keys pressed, bottom right — pop in, held while down, fade out (keyCaps.js). */
#key-caps { position: absolute; z-index: 5; right: 14px; bottom: 14px; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: none; transition: bottom 0.26s cubic-bezier(0.2, 1, 0.4, 1); }
#key-caps[hidden] { display: none; }
/* One row per press (or keys pressed together: "Z + S"): rises in from below, fades out upward. */
.key-combo { display: flex; align-items: center; gap: 6px; animation: key-rise 0.22s ease-out; transition: opacity 0.4s ease, transform 0.4s ease; }
.key-combo.fading { opacity: 0; transform: translateY(-10px); }
@keyframes key-rise { from { opacity: 0; transform: translateY(10px); } }
.key-plus { font: 700 14px/1 system-ui, sans-serif; color: var(--muted); }
.key-cap { min-width: 34px; height: 34px; padding: 0 10px; display: inline-grid; place-items: center; border: 1px solid #c7c7cc; border-bottom-width: 3px; border-radius: 8px; background: rgba(255, 255, 255, 0.9); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06); font: 600 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); transition: border-color 0.12s, background 0.12s, transform 0.12s; }
.key-cap.held { border-color: var(--accent); background: rgba(225, 234, 253, 0.95); transform: translateY(1px); }
body.replaying #key-caps { bottom: 74px; } /* (lifted above the replay bar) */

/* --- Tricks panel (Y): a card per trick — preview (looping while hovered), keys, tip, points ---- */
#tricks { position: absolute; z-index: 9; top: 56px; left: calc(var(--tb-w, 52px) + 12px); right: 12px; bottom: 12px; max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; background: rgba(255, 255, 255, 0.97); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); font-size: 13px; overflow: hidden; }
#tricks[hidden] { display: none; }
.tk-head { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tk-head h2 { margin: 0; font-size: 16px; }
.tk-tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tk-tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 12px; cursor: pointer; color: var(--ink); }
.tk-tab.active { border-color: var(--accent); background: rgba(225, 234, 253, 0.9); color: var(--accent); font-weight: 600; }
.tk-close { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--muted); padding: 4px 6px; }
.tk-close:hover { color: var(--ink); }
.tk-body { overflow: auto; padding: 4px 16px 16px; }
.tk-section h3 { margin: 14px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.tk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tk-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none; transition: border-color 0.15s, box-shadow 0.15s; }
.tk-card:hover, .tk-card:focus-visible, .tk-card.playing { border-color: var(--accent); box-shadow: 0 2px 10px rgba(47, 111, 237, 0.12); }
.tk-preview { width: 100%; height: 140px; border-radius: 6px; background: #f6f7fa; display: block; }
.tk-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tk-title b { font-size: 14px; }
.tk-diff { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; }
.tk-diff.d1 { color: #2d7a46; background: #e3f3e8; }
.tk-diff.d2 { color: #9a6200; background: #fbefd9; }
.tk-diff.d3 { color: #b03a2e; background: #f9e3e0; }
.tk-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.tk-keys kbd { display: inline-block; min-width: 22px; padding: 1px 6px; text-align: center; border: 1px solid #c7c7cc; border-bottom-width: 2px; border-radius: 5px; background: #fff; font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); }
.tk-plus, .tk-then { color: var(--muted); font-weight: 700; font-size: 12px; }
.tk-note { color: var(--muted); font-size: 11px; }
.tk-tip { margin: 0; color: #555; font-size: 12px; line-height: 1.4; }
.tk-foot { display: flex; flex-direction: column; gap: 1px; margin-top: auto; font-size: 11px; }
.tk-pts { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tk-stances { color: var(--muted); }

/* --- Keyframe editor (menu › Keyframes): stage + timeline, inspector beside --------------------- */
#keyframes { position: absolute; z-index: 12; inset: 12px; display: flex; flex-direction: column; background: rgba(255, 255, 255, 0.98); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14); font-size: 13px; overflow: hidden; }
#keyframes[hidden] { display: none; }
#keyframes select, #keyframes input[type="number"] { font: inherit; font-size: 12px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
#keyframes button { font: inherit; font-size: 12px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); cursor: pointer; }
#keyframes button:hover { border-color: var(--accent); color: var(--accent); }
#keyframes button:focus-visible, #keyframes select:focus-visible, #keyframes input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#keyframes button.tk-close { border: 0; padding: 4px 6px; }
#keyframes button.kf-save { border-color: var(--accent); background: var(--accent); color: #fff; }
#keyframes button.kf-save:hover { color: #fff; filter: brightness(1.08); }
.kf-from { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.kf-status { color: var(--muted); font-size: 12px; }
.kf-status.dirty { color: #9a6200; }
.kf-spacer { flex: 1; }
.kf-body { flex: 1; min-height: 0; display: flex; }
.kf-main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 10px 12px 12px; gap: 8px; }
.kf-stage { flex: 1; min-height: 0; width: 100%; border-radius: 8px; background: #f6f7fa; touch-action: none; }
.kf-bar { display: flex; align-items: center; gap: 10px; }
#keyframes button.kf-play { width: 40px; font-size: 13px; }
.kf-where { color: var(--muted); font-variant-numeric: tabular-nums; }
.kf-timeline { width: 100%; height: 64px; display: block; cursor: pointer; touch-action: none; }
.kf-inspector { width: 250px; flex: none; overflow-y: auto; border-left: 1px solid var(--line); padding: 10px 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.kf-inspector h3 { margin: 6px 0 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kf-keyinfo { margin: 0; color: var(--ink); }
.kf-fields { display: grid; gap: 6px; }
.kf-field { display: grid; grid-template-columns: 1fr 76px; align-items: center; gap: 6px; color: #555; }
.kf-field > span { display: flex; align-items: center; gap: 4px; }
.kf-field input[type="checkbox"] { margin: 0 4px 0 0; }
.kf-field select { width: 100%; }
.kf-field.kf-ease { grid-template-columns: auto 1fr; }
.kf-row { display: flex; gap: 6px; flex-wrap: wrap; }
.kf-check { display: flex; align-items: center; gap: 6px; color: #555; }
.kf-hint { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }

/* --- Touch ------------------------------------------------------------------------------------ */
/* (No page scroll / zoom from fingers on the map: they draw, pan and pinch — touchEditor.js.) */
#game { touch-action: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.touch #tip { display: none !important; } /* (no hover on a touch screen) */

/* Riding by touch: two thumb zones over the map (touchRide.js) — the whole height in landscape,
   the bottom half in portrait. Under the run controls / menu, over the map. */
#touch-ride { position: absolute; z-index: 4; left: 0; right: 0; bottom: 0; top: 56px; display: none; touch-action: none; }
body.touch.riding #touch-ride { display: flex; }
@media (orientation: portrait) { #touch-ride { top: 50%; } }
.tr-zone { position: relative; flex: 1; overflow: hidden; }
.tr-left { border-right: 1px dashed rgba(0, 0, 0, 0.06); }
.tr-hint { position: absolute; top: 8px; left: 0; right: 0; text-align: center; font-size: 11px; letter-spacing: 0.04em; color: rgba(0, 0, 0, 0.28); pointer-events: none; }
.tr-ring { position: absolute; width: 92px; height: 92px; margin: -46px 0 0 -46px; border-radius: 50%; border: 2px solid rgba(47, 111, 237, 0.35); background: rgba(47, 111, 237, 0.06); opacity: 0; transition: opacity 0.12s; pointer-events: none; }
.tr-ring.on { opacity: 1; }
.tr-ring.hard { border-color: rgba(47, 111, 237, 0.8); background: rgba(47, 111, 237, 0.14); } /* (pushed far: the quick spin) */
.tr-knob { position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; background: rgba(47, 111, 237, 0.55); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); }
.tr-flash { position: absolute; left: 0; right: 0; top: 40%; text-align: center; font: 700 18px/1 system-ui, sans-serif; color: var(--accent); opacity: 0; pointer-events: none; }
.tr-flash.on { animation: tr-flash 0.7s ease-out forwards; }
@keyframes tr-flash { 0% { opacity: 0; transform: translateY(6px); } 15% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-10px); } }
/* The run's buttons in right-thumb reach (touch, a run on — paused too): a column at the right
   edge above the trick zone. Grab only while riding. */
#touch-run { display: none; position: absolute; z-index: 6; right: calc(12px + env(safe-area-inset-right, 0px)); top: 24%; flex-direction: column; gap: 10px; }
body.touch.run-on #touch-run { display: flex; }
body.touch #touch-run button { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; padding: 0; border: 1px solid rgba(0, 0, 0, 0.08); background: rgba(255, 255, 255, 0.72); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12); touch-action: none; }
#touch-run img { width: 20px; height: 20px; }
#tr-grab { font: 800 11px/1 system-ui, sans-serif; letter-spacing: 0.04em; color: var(--ink); }
#tr-grab.down { background: var(--accent) !important; color: #fff; }
body:not(.riding) #tr-grab { display: none !important; }
@media (orientation: portrait) { #touch-run { top: auto; bottom: calc(50% + 12px); flex-direction: row-reverse; } }
/* After a wreck (touch): one big button to get going again, under the right thumb. */
#touch-retry { position: absolute; z-index: 6; right: calc(84px + env(safe-area-inset-right, 0px)); bottom: calc(28% + env(safe-area-inset-bottom, 0px)); padding: 16px 26px; border-radius: 999px; border: 0; background: var(--accent); color: #fff; font: 800 17px/1 system-ui, sans-serif; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); touch-action: none; animation: retry-in 0.25s ease-out; }
#touch-retry[hidden], body:not(.touch) #touch-retry { display: none; }
@keyframes retry-in { from { transform: translateY(12px) scale(0.92); opacity: 0; } }
@media (orientation: portrait) { #touch-retry { right: 50%; transform: translateX(50%); bottom: calc(25% + env(safe-area-inset-bottom, 0px)); animation: none; } }
/* (Riding by touch the bottom's the thumbs': the status line goes — a bail shows in the score's
   chips — and the key caps, which would show keyboard keys.) */
body.touch.riding #status { visibility: hidden; }
body.touch #key-caps { display: none !important; }
/* (The zone hints say their piece as a run starts, then get out of the way.) */
body.touch.riding .tr-hint { animation: tr-hint 3s ease forwards; }
@keyframes tr-hint { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
/* (Full screen / a home-screen web app: the floating controls stay clear of the notch and the rounded corners.) */
#run-controls, #menu-wrap { top: calc(10px + env(safe-area-inset-top, 0px)); }
#menu-wrap { right: calc(10px + env(safe-area-inset-right, 0px)); }
.toolbox { padding-top: calc(10px + env(safe-area-inset-top, 0px)); padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); left: env(safe-area-inset-left, 0px); }
#speedo { left: calc(var(--tb-w, 52px) + 8px + env(safe-area-inset-left, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }

/* --- Locker (I): cosmetics — a live preview, a tab per slot, item tiles ------------------------ */
#locker { position: absolute; z-index: 9; top: 56px; right: 12px; width: min(560px, calc(100% - 76px)); max-height: calc(100% - 68px); display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; background: rgba(255, 255, 255, 0.97); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); font-size: 13px; overflow: auto; }
#locker[hidden] { display: none; }
.lk-head { display: flex; align-items: baseline; gap: 10px; }
.lk-head h2 { margin: 0; font-size: 16px; }
.lk-count { flex: 1; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.lk-preview { width: 100%; height: 160px; border-radius: 8px; display: block; flex: none; }
.lk-tabs { flex: none; }
.tk-tab.fresh::after, .lk-item.fresh::after { content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 5px; border-radius: 50%; background: #e3121b; vertical-align: 2px; }
.lk-item.fresh { position: relative; }
.lk-item.fresh::after { position: absolute; top: 6px; right: 6px; margin: 0; }
.lk-hint { margin: 0; color: var(--muted); font-size: 12px; }
.lk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.lk-item { display: flex; flex-direction: column; align-items: stretch; gap: 3px; padding: 6px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font: inherit; text-align: left; cursor: pointer; color: var(--ink); }
.lk-item:hover, .lk-item:focus-visible { border-color: var(--accent); outline: none; }
.lk-item.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47, 111, 237, 0.25); }
.lk-item.locked { cursor: default; }
.lk-item.locked .lk-swatch { filter: grayscale(1) opacity(0.45); }
.lk-swatch { width: 100%; height: 64px; border-radius: 6px; display: block; }
.lk-item b { font-size: 12px; }
.lk-how { font-size: 10.5px; color: var(--muted); line-height: 1.3; }
.lk-item.on .lk-how { color: var(--accent); font-weight: 600; }

/* A dark track skin (Locker): the text drawn straight over the map goes light. (Pills and panels keep their own white backgrounds.) */
body.dark-track #score, body.dark-track #ghost-score { color: #f5f5f7; }
body.dark-track #status { color: rgba(255, 255, 255, 0.65); }
body.dark-track .tr-hint { color: rgba(255, 255, 255, 0.35); }

/* Locked Locker items: unlock by watching an ad (where one can be shown — ads/ads.js). */
.lk-cell { display: flex; flex-direction: column; gap: 4px; }
.lk-cell .lk-item { flex: 1; }
.lk-ad { border: 1px solid var(--accent); background: rgba(225, 234, 253, 0.7); color: var(--accent); border-radius: 7px; padding: 4px 6px; font: 600 11px/1.3 system-ui, sans-serif; cursor: pointer; }
.lk-ad:hover:not(:disabled) { background: rgba(225, 234, 253, 1); }
.lk-ad:disabled { opacity: 0.6; cursor: default; }
.lk-ad-note { font-size: 10.5px; line-height: 1.3; color: var(--bail); }
.lk-ad-note:empty { display: none; }

/* The test ad (ads.js 'test' provider): stands in for a real video ad. */
.ad-test { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(10, 10, 14, 0.82); }
.ad-test-card { width: min(420px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 10px; padding: 22px; border-radius: 14px; background: #fff; color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); font-size: 14px; }
.ad-test-card b { font-size: 18px; }
.ad-test-card p { margin: 0; color: #555; line-height: 1.45; }
.ad-test-tag { align-self: flex-start; padding: 2px 8px; border-radius: 999px; background: #ffe9a8; color: #7a5600; font: 700 10px/1.6 system-ui, sans-serif; letter-spacing: 0.06em; text-transform: uppercase; }
.ad-test-bar { height: 6px; border-radius: 3px; background: #ececf1; overflow: hidden; }
.ad-test-bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.ad-test-close { align-self: flex-end; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }

/* --- Tools guide (U): a card per editing tool (shares the Tricks panel's card styles) ---------- */
#tools-guide { position: absolute; z-index: 9; top: 56px; left: calc(var(--tb-w, 52px) + 12px); right: 12px; bottom: 12px; max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; background: rgba(255, 255, 255, 0.97); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); font-size: 13px; overflow: hidden; }
#tools-guide[hidden] { display: none; }
.tg-sub { flex: 1; color: var(--muted); font-size: 12px; }
.tg-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); margin-top: 12px; }
.tg-preview { height: auto; aspect-ratio: 260 / 150; }
.tg-key { display: inline-block; min-width: 22px; padding: 1px 6px; text-align: center; border: 1px solid #c7c7cc; border-bottom-width: 2px; border-radius: 5px; background: #fff; font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); }
.tg-how { display: flex; gap: 8px; font-size: 12px; line-height: 1.4; }
.tg-label { flex: none; width: 40px; padding-top: 1px; font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.tg-how ul { margin: 0; padding-left: 14px; color: #444; }
body:not(.touch) .tg-how:nth-of-type(2) { opacity: 0.7; } /* (on a desktop, the touch line is the lesser one) */

/* Riding: no mouse pointer over the game (main.js: back on a bail, on pause, or when the mouse moves). */
body.hide-cursor, body.hide-cursor * { cursor: none !important; }

/* --- A STICK challenge ---------------------------------------------------------------------------- */
#challenge-hud {
  position: absolute; z-index: 5; top: 58px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 6px 12px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.82); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.08); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08); white-space: nowrap;
}
#challenge-hud[hidden] { display: none; }
body.challenge-on .hud { top: 108px; } /* (the score under the strip) */
.ch-hud-word { display: flex; gap: 3px; }
.ch-hud-letter { display: inline-grid; place-items: center; width: 24px; height: 28px; border-radius: 6px; font: 900 18px/1 system-ui, sans-serif; color: rgba(29, 29, 31, 0.28); background: rgba(0, 0, 0, 0.05); }
.ch-hud-letter.got { color: #1d1d1f; background: #f5b800; animation: letter-got 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes letter-got { 0% { transform: scale(1.6); } 100% { transform: scale(1); } }
.ch-hud-clock { font: 800 18px/1 system-ui, sans-serif; font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.ch-hud-clock.low { color: var(--bail); animation: pulse-low 0.6s ease-in-out infinite alternate; }
@keyframes pulse-low { to { opacity: 0.55; } }
.ch-hud-mode { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.ch-hud-mode button { border: 0; border-radius: 0; padding: 4px 10px; font-size: 12px; background: transparent; cursor: pointer; }
.ch-hud-mode button.active { background: var(--ink); color: #fff; }
.ch-hud-warn { font-size: 12px; color: var(--bail); }
.ch-hud-hard { font-size: 11px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: #fff; background: var(--bail); padding: 2px 7px; border-radius: 999px; }

#challenge-panel { position: absolute; z-index: 8; top: 56px; right: 12px; width: 320px; padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08); font-size: 13px; }
#challenge-panel[hidden] { display: none; }
#challenge-panel h2 { margin: 0 0 10px; font-size: 14px; }
.ch-modes { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.ch-modes button { border: 0; border-radius: 0; padding: 5px 12px; background: transparent; cursor: pointer; font-weight: 600; }
.ch-modes button.active { background: var(--ink); color: #fff; }
.ch-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.ch-row > span:first-child { width: 64px; color: var(--muted); }
.ch-word { font: 800 15px/1 system-ui, sans-serif; letter-spacing: 0.12em; text-transform: uppercase; width: 150px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; }
.ch-time { width: 80px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; font-variant-numeric: tabular-nums; }
.ch-letters { display: flex; gap: 3px; flex-wrap: wrap; }
.ch-letter { display: inline-grid; place-items: center; width: 22px; height: 26px; border-radius: 5px; font: 900 15px/1 system-ui, sans-serif; color: rgba(29, 29, 31, 0.35); border: 1px dashed rgba(0, 0, 0, 0.2); }
.ch-letter.placed { color: #1d1d1f; background: #f5b800; border: 1px solid transparent; }
.ch-hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.ch-hint.warn { color: #b45309; }

#challenge-card {
  position: absolute; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, calc(100% - 40px)); padding: 18px 20px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.92); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid rgba(0, 0, 0, 0.08); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
}
#challenge-card[hidden] { display: none; }
#challenge-card h2 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
#challenge-card.lost h2 { color: var(--bail); }
.fc-badge.hard { background: var(--bail); }
.cc-word { display: flex; gap: 4px; margin-bottom: 12px; }
.cc-letter { display: inline-grid; place-items: center; width: 32px; height: 38px; border-radius: 7px; font: 900 22px/1 system-ui, sans-serif; color: rgba(29, 29, 31, 0.3); background: rgba(0, 0, 0, 0.05); }
.cc-letter.got { color: #1d1d1f; background: #f5b800; }

.asset.placed { opacity: 0.35; }

/* --- Home (home.js): over the live scene, softly blurred ---------------------------------------- */
#home { position: absolute; inset: 0; z-index: 25; overflow: auto; background: linear-gradient(180deg, rgba(250, 250, 252, 0.3), rgba(250, 250, 252, 0.7)); -webkit-overflow-scrolling: touch; }
#home[hidden] { display: none; }
body.home #game { filter: blur(3px) saturate(0.9); }
/* (The game's own controls step aside while home is up.) */
body.home .toolbox, body.home #run-controls, body.home #menu-wrap, body.home .hud, body.home #bottom, body.home #speedo,
body.home #challenge-hud, body.home #touch-run, body.home #touch-retry, body.home #touch-ride, body.home #sel-tools,
body.home #assets, body.home #last-run, body.home #key-caps, body.home #finish-card, body.home #challenge-card { display: none !important; }
/* (Its panels open over it.) */
body.home #locker, body.home #replays, body.home #help, body.home #tricks, body.home #tools-guide { z-index: 40; }
body.home #tricks, body.home #tools-guide { left: 12px; }

.home-inner { box-sizing: border-box; max-width: 1180px; margin: 0 auto; padding: calc(28px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(40px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px)); display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 28px; align-items: start; }
@media (max-width: 820px) { .home-inner { grid-template-columns: minmax(0, 1fr); } }
.home-head h1 { margin: 0; font: 900 clamp(34px, 6vw, 56px)/1 system-ui, sans-serif; letter-spacing: -0.03em; color: var(--ink); text-wrap: balance; }
.home-head p { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.home-play { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 22px 0 8px; }
.home-section { margin-top: 26px; }
.home-section h2 { margin: 0 0 10px; font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.home-empty { margin: 0; color: var(--muted); font-size: 13px; }

.home-card { position: relative; display: flex; flex-direction: column; border-radius: 14px; background: rgba(255, 255, 255, 0.78); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border: 1px solid rgba(0, 0, 0, 0.07); box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06); overflow: hidden; transition: transform 0.15s, box-shadow 0.15s; }
.home-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1); }
.home-card-open { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 3px; padding: 0 0 12px; min-width: 0; }
.home-card-open:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 14px; }
.home-thumb { display: block; width: 100%; height: auto; aspect-ratio: 220 / 120; background: rgba(240, 241, 245, 0.8); border-bottom: 1px solid rgba(0, 0, 0, 0.05); margin-bottom: 8px; }
.home-card-title { padding: 0 12px; font-weight: 800; font-size: 15px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-card-sub { padding: 0 12px; font-size: 12px; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.home-card-badge { position: absolute; top: 10px; left: 10px; padding: 3px 9px; border-radius: 999px; background: var(--accent); color: #fff; font: 800 11px/1.2 system-ui, sans-serif; letter-spacing: 0.04em; text-transform: uppercase; }
.home-play .home-card:first-child { border-color: rgba(47, 111, 237, 0.35); }
.home-new .home-card-open { justify-content: center; align-items: flex-start; padding: 18px 0 16px; height: 100%; box-sizing: border-box; }
.home-new-plus { margin: 0 12px 6px; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--ink); color: #fff; font: 700 28px/1 system-ui, sans-serif; }
.home-card-actions { display: flex; gap: 6px; padding: 0 12px 10px; }
.home-mini { padding: 3px 9px; font-size: 12px; border-radius: 7px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.home-mini.danger { color: var(--bail); }

.home-side { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 10px; }
.home-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.home-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; border-radius: 12px; border: 1px solid rgba(0, 0, 0, 0.07); background: rgba(255, 255, 255, 0.78); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink); text-align: left; }
.home-tile:hover { background: #fff; }
.home-tile kbd { display: none; }
.home-tile-icon { font-size: 18px; line-height: 1; }
.home-side h3 { margin: 10px 0 0; font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.home-settings { display: flex; flex-direction: column; border-radius: 12px; overflow: hidden; border: 1px solid rgba(0, 0, 0, 0.07); background: rgba(255, 255, 255, 0.78); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.home-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; font-size: 13px; color: var(--ink); cursor: pointer; text-align: left; }
.home-toggle:last-child { border-bottom: 0; }
.home-toggle.active, .home-toggle:hover { background: transparent; border-color: var(--line); color: var(--ink); } /* (not the old menu's lit row: the switch shows it) */
.home-toggle[hidden] { display: none; }
.home-toggle kbd { margin-left: auto; font-size: 11px; color: var(--muted); }
.home-toggle::after { content: ''; flex: none; width: 34px; height: 20px; border-radius: 999px; background: #d9d9de; box-shadow: inset 0 0 0 2px #d9d9de; transition: background 0.15s; background-image: radial-gradient(circle at 10px 10px, #fff 7px, transparent 7.5px); }
.home-toggle.active::after { background-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); background-image: radial-gradient(circle at 24px 10px, #fff 7px, transparent 7.5px); }
@media (max-width: 560px) {
  .home-play, .home-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .home-card-title { font-size: 13px; }
  .home-card-sub { font-size: 11px; }
  .home-new-plus { width: 34px; height: 34px; font-size: 22px; }
}

/* The home page's Pause / Play background button (bottom right, over the scene). */
.home-scene { position: fixed; z-index: 26; right: calc(16px + env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px 8px 10px; border-radius: 999px; border: 1px solid rgba(0, 0, 0, 0.08); background: rgba(255, 255, 255, 0.82); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1); font: 600 13px/1 system-ui, sans-serif; color: var(--ink); cursor: pointer; }
.home-scene:hover { background: #fff; }
.home-scene img { width: 14px; height: 14px; }
