  :root {
    --bg: #1c1a17; --bar: #2a2724; --fg: #f3f1ea; --muted: #a8a397; --line: rgba(243,241,234,0.1);
    --accent: #d08c3e; --brown: #3a2210; --bar-h: 46px;
    --display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
    --sans: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { height: 100%; background: var(--bg); color: var(--fg); }
  body { font: 500 16px/1.5 var(--sans); display: flex; flex-direction: column; height: 100svh; overflow: hidden; -webkit-font-smoothing: antialiased; }
  button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
  button:focus-visible, a:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; border-radius: 6px; }

  .stage-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
  .stage { position: relative; flex: none;
    height: min(calc(100vh - var(--bar-h)), 150vw); height: min(calc(100svh - var(--bar-h)), 150vw);
    width: calc(min(calc(100vh - var(--bar-h)), 150vw) * 2 / 3); width: calc(min(calc(100svh - var(--bar-h)), 150vw) * 2 / 3); }
  canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: manipulation; cursor: pointer; outline: none; }

  .panel { position: absolute; inset: 0; overflow-y: auto; padding: 28px 24px 32px;
    background: rgba(24,20,16,0.96); opacity: 0; visibility: hidden; transform: translateY(16px);
    transition: opacity 220ms, transform 300ms cubic-bezier(.16,1,.3,1), visibility 0s 300ms; }
  .panel.open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
  .panel h2 { font: 400 44px/1 var(--display); text-shadow: 0 4px 0 var(--brown); margin-bottom: 18px; transform: rotate(-1.5deg); transform-origin: left; }
  .panel h2 span { color: var(--accent); }
  .panel h3 { font: 400 22px/1.1 var(--display); color: var(--accent); margin: 22px 0 8px; }
  .panel p, .panel li { color: #ddd7cb; font-size: 15px; }
  .panel p + p { margin-top: 10px; }
  .panel ul { list-style: none; display: grid; gap: 8px; }
  .panel kbd { font: 600 13px var(--sans); background: #3b352f; border-bottom: 3px solid #12100d; border-radius: 6px; padding: 1px 8px; color: var(--fg); }
  .panel a { color: var(--accent); }
  .medals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .medals li { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.05); border-radius: 12px; padding: 8px 12px; }
  .medals svg { width: 28px; height: 28px; flex: none; }
  .medals b { font: 400 18px var(--display); display: block; line-height: 1.1; }
  .levels { width: 100%; border-collapse: collapse; font-size: 14px; }
  .levels th, .levels td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
  .levels th { color: var(--muted); font-weight: 600; }
  .lab-btn { margin-top: 10px; font: 600 14px var(--sans); color: var(--fg); background: #3b352f; border-radius: 999px; padding: 6px 16px; }
  .lab-btn[aria-pressed="true"] { background: #2b4a5e; color: #9fd3ff; }
  .back { margin-top: 26px; font: 400 22px var(--display); background: var(--accent); color: #fff; padding: 8px 26px; border-radius: 12px; box-shadow: 0 4px 0 #8a5520; text-shadow: 0 2px 0 var(--brown); }
  .back:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5520; }

  .bar { height: var(--bar-h); flex: none; display: flex; align-items: center; gap: 4px; background: var(--bar); border-top: 1px solid var(--line); padding: 0 8px; font-size: 14px; }
  .logo { font: 400 19px/1 var(--display); padding: 0 10px 0 4px; white-space: nowrap; text-shadow: 0 2px 0 #000; }
  .logo span { color: var(--accent); }
  .logo { display: inline-block; transform: rotate(-3deg); }   /* same tilt as the big title */
  .tab { height: var(--bar-h); padding: 0 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
  .tab[aria-current="page"] { background: rgba(255,255,255,0.08); color: var(--fg); }
  .tab:hover { color: var(--fg); }
  .spacer { flex: 1; }
  .levels-pick { display: inline-flex; background: rgba(0,0,0,0.25); border-radius: 999px; padding: 3px; }
  .levels-pick button { font-weight: 600; font-size: 13px; color: var(--muted); border-radius: 999px; padding: 4px 11px; }
  .levels-pick button[aria-pressed="true"] { background: var(--accent); color: #fff; }
  .home { color: var(--muted); font-weight: 600; padding: 0 10px; white-space: nowrap; text-decoration: none; }
  .home:hover { color: var(--fg); }
  .sound { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: rgba(255,255,255,0.07); margin-left: 4px; }
  .sound svg { width: 18px; height: 18px; }
  @media (max-width: 700px) {
    .home, .logo span.long { display: none; }
    .tab { padding: 0 8px; font-size: 13px; }
    .levels-pick button { padding: 4px 7px; font-size: 12px; }
  }
  @media (max-width: 420px) {
    .logo { display: none; }
    .bar { padding: 0 4px; gap: 2px; }
    .tab { padding: 0 6px; font-size: 12px; }
    .levels-pick button { padding: 4px 6px; font-size: 11px; }
    .sound { width: 30px; height: 30px; }
  }
  
  .over { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 0 1.5em; pointer-events: none; font-family: var(--sans); color: #f5eee2;
    transform: translateZ(0); -webkit-backface-visibility: hidden; }
  .over[hidden] { display: none; }
  .over .title { font: 400 3.4em/1 var(--display); margin-bottom: 0.35em; color: #f5eee2;
    -webkit-text-stroke: 0.09em #493020; paint-order: stroke fill; text-shadow: 0 0.07em 0 #493020, 0 0.12em 0.2em rgba(0,0,0,0.3);
    opacity: 0; transform: translateY(-0.3em); transition: opacity 300ms 250ms, transform 300ms 250ms; }
  .over .modal { width: 100%; padding: 1.5em; pointer-events: auto;
    background: rgba(40,37,40,0.96); border: 1px solid rgba(255,255,255,0.16); border-radius: 1.55em;
    box-shadow: 0 0.5em 0 rgba(0,0,0,0.12), 0 1.1em 2.4em rgba(0,0,0,0.35);
    opacity: 0; transform: translateY(3.5em); transition: opacity 400ms 500ms, transform 450ms 500ms cubic-bezier(.16,1,.3,1); }
  .over.show .title, .over.show .modal { opacity: 1; transform: none; }
  
  @media (max-height: 550px) {
    .over {
      justify-content: flex-start;
      padding-top: 20px;
      padding-bottom: 20px;
    }
  }

  /* mode switch on the start screen (1em = 16 game pixels, like the card) */
  .modes { position: absolute; left: 50%; top: 90.5%; transform: translateX(-50%); display: flex; gap: 0.3em;
    background: rgba(20,16,12,0.55); border-radius: 2em; padding: 0.25em; white-space: nowrap; }
  /* the rows fade and slide instead of popping in and out */
  .modes { transition: opacity 220ms ease, transform 280ms cubic-bezier(.16,1,.3,1), visibility 0s; }
  .modes.gone { opacity: 0; visibility: hidden; pointer-events: none; transform: translateX(-50%) translateY(0.5em);
    transition: opacity 180ms ease, transform 280ms ease, visibility 0s 180ms; }
  .modes.opps { top: 59.5%; background: rgba(20,16,12,0.45); }
  .modes.opps button { font-size: 0.72em; padding: 0.55em 0.75em; }
  .modes.opps button[aria-pressed="true"] { background: #f3f1ea; color: #3a2210; }
  .modes button { font: 600 0.8em/1 var(--sans); color: #e8e2d6; padding: 0.55em 0.9em; border-radius: 2em; }
  .modes button[aria-pressed="true"] { background: #d08c3e; color: #fff; }
  .race { display: flex; align-items: center; justify-content: space-between; gap: 0.6em; margin: -0.4em 0 1.1em;
    padding: 0.55em 0.9em; border-radius: 0.8em; background: #34303a; font-size: 0.85em; font-weight: 700; }
  .race[hidden] { display: none; }
  .race b { font: 400 1.25em/1 var(--display); }
  .race .verdict { color: #ffaa36; }
  .race > span { white-space: nowrap; }
  .race.unlock { background: #3a3326; color: #f5eee2; }
  .race.unlock b { color: #ffcf3f; }
  .race .try { white-space: nowrap; flex: none; font: 700 0.95em/1 var(--sans); background: #ffaa36; color: #492b14; border-radius: 1em; padding: 0.4em 0.9em; }
  .race .try[disabled] { background: #514c53; color: #cfc4ad; }
  /* skin button on the start screen and the skin page */
  .skin-btn { position: absolute; top: 2.2%; right: 3%; width: 3.1em; height: 3.1em; padding: 0; border-radius: 50%;
    display: grid; place-items: center; background: rgba(20,16,12,0.55); border: 1px solid rgba(243,241,234,0.18);
    transition: opacity 220ms ease, transform 160ms ease, background 160ms, visibility 0s; }
  .skin-btn:hover { background: rgba(20,16,12,0.75); transform: scale(1.06); }
  .skin-btn:active { transform: scale(0.95); }
  /* small paintbrush badge: the tip is painted in the four medal colours */
  .skin-btn .brush { position: absolute; right: -0.3em; bottom: -0.25em; width: 1.55em; height: 1.55em; padding: 0.12em;
    background: #2a2421; border: 1px solid rgba(243,241,234,0.22); border-radius: 50%; transition: transform 200ms ease; }
  .skin-btn:hover .brush { transform: rotate(-14deg); }
  .skin-btn canvas { position: static; inset: auto; width: 2.4em; height: 2.4em; cursor: inherit; }   /* not the full-size game canvas rule */
  .skin-btn.gone { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 180ms ease, visibility 0s 180ms; }
  .skin-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 14px; }
  .skin-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 8px; border-radius: 14px;
    background: rgba(255,255,255,0.05); border: 2px solid transparent; color: var(--fg); }
  .skin-card canvas { position: static; inset: auto; width: 120px; height: 64px; cursor: inherit; }   /* not the full-size game canvas rule */
  .skin-card b { font: 400 18px var(--display); }
  .skin-card b.rare { font-size: 20px; -webkit-text-stroke: 4px #140e08; paint-order: stroke fill; }   /* medal storks: outlined, like the game's lettering */
  /* locked: the colour is there, but sunk into the card */
  .skin-card b.locked { color: color-mix(in srgb, var(--c) 38%, #2b2723); -webkit-text-stroke-color: #1a1612; }
  /* unlocked: an "enchanted" band of light sweeps through the letters */
  /* unlocked: an "enchanted" band of light sweeps through the letters (a layer on top, clipped to the letter shapes) */
  .skin-card b.shine { color: var(--c); position: relative; }
  .skin-card b.shine::after { content: attr(data-text); position: absolute; inset: 0; -webkit-text-stroke: 0;
    background: linear-gradient(105deg, transparent 42%, var(--l) 50%, transparent 58%) 0 0 / 300% 100%;
    -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: enchant 2.6s linear infinite; animation-delay: inherit; pointer-events: none; }
  @keyframes enchant { 0% { background-position: 100% 0; } 55%, 100% { background-position: 0% 0; } }
  @media (prefers-reduced-motion: reduce) { .skin-card b.shine::after { display: none; } }
  .skin-card small { color: var(--muted); font-size: 12px; }
  .skin-card[aria-pressed="true"] { border-color: #ffaa36; background: rgba(255,170,54,0.1); }
  .skin-card[disabled] { cursor: default; }
  .skin-card[disabled] canvas { filter: grayscale(1) brightness(0.45); }
  .race.lost .verdict { color: #9fd3ff; }
  .tag { display: inline-block; padding: 0.35em 1em; background: #514c53; border-radius: 1.25em; font-size: 0.875em; font-weight: 700; margin-bottom: 1.1em; }
  .grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.8fr); align-items: center; gap: 1.1em; margin-bottom: 1.4em; }
  .left { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
  .medal { position: relative; width: 4.75em; height: 4.75em; margin-bottom: 0.8em; display: grid; place-items: center;
    background: #3b373e; border: 0.125em dashed #77707a; border-radius: 50%; transition: background 300ms, border-color 300ms, box-shadow 300ms; }
  .medal svg { width: 2.8em; height: 2.8em; fill: #8b818c; transition: fill 300ms; }
  .medal .lock { position: absolute; right: -0.25em; bottom: -0.2em; width: 1.7em; height: 1.7em; display: grid; place-items: center;
    background: #514b54; border: 0.125em solid #282629; border-radius: 50%; }
  .medal .lock svg { width: 0.85em; height: 0.85em; fill: #f5eee2; }
  .medal.won { border-style: solid; border-color: var(--m); background: color-mix(in srgb, var(--m) 22%, #2b282c); box-shadow: 0 0 1.6em color-mix(in srgb, var(--m) 45%, transparent); }
  .medal.won > svg { fill: var(--m); }
  .medal.won .lock { display: none; }
  .medal.pop { animation: pop 520ms cubic-bezier(.3,1.6,.5,1); }
  @keyframes pop { 0% { transform: scale(0.4); } 100% { transform: scale(1); } }
  .status { font-size: 0.875em; font-weight: 700; color: #b8b0a7; margin-bottom: 0.65em; }
  .medal.won + .status { color: var(--m); }
  .bar-track { position: relative; width: 100%; height: 0.75em; margin: 0.2em 0 0.6em; background: #1d1b20; border-radius: 1em; }
  .bar-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--n) 75%, #000), var(--n)); transition: width 250ms ease; }
  .goal { position: absolute; top: 50%; right: -0.3em; width: 1.25em; height: 1.25em; display: grid; place-items: center; transform: translateY(-50%);
    background: #514b54; border: 0.125em solid #282629; border-radius: 50%; }
  .goal svg { width: 0.75em; height: 0.75em; fill: var(--n); }
  .sub { font-size: 0.75em; font-weight: 700; color: #b8b0a7; margin-bottom: 0.9em; }
  .minarets { display: flex; align-items: center; gap: 0.4em; padding: 0.45em 0.75em; background: #464149; border-radius: 1.2em;
    font-size: 0.75em; font-weight: 700; white-space: nowrap; max-width: 100%; }
  .minarets svg { width: 1.2em; height: 1.45em; fill: #ffaa36; flex: none; }
  .right { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; }
  .lbl { font-size: 0.875em; font-weight: 700; color: #b8b0a7; }
  .score { font: 400 4.5em/1 var(--display); margin: 0.03em 0 0.2em; -webkit-text-stroke: 0.05em #493020; paint-order: stroke fill; text-shadow: 0 0.06em 0 rgba(0,0,0,0.3); }
  .best-row { display: flex; align-items: center; gap: 0.4em; }
  .best { font: 400 3em/1 var(--display); color: #ffaa36; -webkit-text-stroke: 0.05em #5a351c; paint-order: stroke fill; text-shadow: 0 0.06em 0 rgba(0,0,0,0.3); }
  .new { font-size: 0.8em; font-weight: 700; background: #ffaa36; color: #492b14; padding: 0.15em 0.6em; border-radius: 1em; animation: pop 520ms cubic-bezier(.3,1.6,.5,1); }
  .divider { height: 1px; background: rgba(255,255,255,0.09); margin-bottom: 1.25em; }
  .actions { display: flex; gap: 0.75em; }
  .btn { min-height: 3.75em; display: flex; align-items: center; justify-content: center; gap: 0.5em; border: 0; border-radius: 1em;
    font-weight: 700; cursor: pointer; touch-action: manipulation; transition: transform 100ms, filter 100ms; }
  .btn:active { transform: translateY(0.2em); filter: brightness(0.96); }
  .btn:hover { filter: brightness(1.06); }
  .btn svg { width: 1.55em; height: 1.55em; fill: currentColor; flex: none; }
  .retry { flex: 1; min-width: 0; color: #492b14; background: linear-gradient(180deg, #ffbd55, #f3a039); box-shadow: 0 0.3em 0 #ce781a;
    font: 400 1.4em/1 var(--display); white-space: nowrap; min-height: 2.7em; border-radius: 0.72em; }
  .retry svg { width: 1.1em; height: 1.1em; }
  .home-btn { width: 4em; flex: none; color: #f5eee2; background: #49444d; border: 1px solid rgba(255,255,255,0.12); box-shadow: 0 0.3em 0 #302c33; }
  @media (prefers-reduced-motion: reduce) {
    .panel, .over .title, .over .modal, .medal, .bar-fill { transition: none; }
    .medal.pop, .new { animation: none; }
  }
