:root {
    --glass: rgba(12, 14, 20, 0.62);
    --glass-border: rgba(212, 176, 23, 0.35);
    --accent: #ffc030;
    --accent-soft: rgba(255, 192, 48, 0.85);
    --text: #f5efe0;
    --text-dim: rgba(245, 239, 224, 0.55);
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  html, body { width: 100%; height: 100%; overflow: hidden; background: #0d1a18; }
  body {
    font-family: "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  #stage { position: fixed; inset: 0; touch-action: none; }
  #stage canvas { display: block; }

  /* ---------- HUD: literal HB1 arcade hierarchy ----------
     Text and pips sit directly over play with strong shadows. No brown cards,
     glass windows, or boxed stat islands compete with the road. */
  .hud {
    position: fixed; top: 0; left: 0; right: 0;
    padding: max(8px, env(safe-area-inset-top)) 12px 0;
    pointer-events: none; z-index: 10;
    font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  }
  .hud-top {
    position: relative; min-height: 70px; isolation: isolate;
    padding: 7px 9px 0;
  }
  .hud-top::before {
    content: ''; position: absolute; z-index: -1;
    left: -12px; right: -12px; top: -8px; height: 72px;
    background:
      linear-gradient(180deg, rgba(2,7,12,.91) 0%, rgba(3,9,14,.76) 70%, rgba(3,9,14,0) 100%),
      linear-gradient(90deg, rgba(255,185,35,.12), transparent 34%, transparent 66%, rgba(88,211,166,.10));
    border-top: 1px solid rgba(255,222,109,.34);
    box-shadow: 0 8px 18px rgba(0,0,0,.28), inset 0 -1px rgba(255,192,48,.16);
    pointer-events: none;
  }
  .hud-wave {
    position: absolute; left: 50%; top: -1px; transform: translateX(-50%);
    min-width: 82px; text-align: center; background: none; border: 0;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,.95));
  }
  .wave-kicker {
    color: #ffd46a; font-size: 9px; font-weight: 950; letter-spacing: .20em;
    line-height: 1; text-transform: uppercase;
  }
  .wave-value {
    margin-top: 2px; color: #fff36d; font-size: 28px; font-weight: 950;
    line-height: 1; letter-spacing: .02em; font-variant-numeric: tabular-nums;
    text-shadow: 0 0 8px #ff9d00, 1px 2px #140700;
  }
  .wave-value small { color: #fff4c4; font-size: 11px; letter-spacing: .05em; }
  .hud-panel {
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,.95));
  }
  .hud-left { position: absolute; left: 0; top: 0; display: flex; gap: 11px; align-items: center; min-width: 180px; }
  .life-pips { display: flex; gap: 3px; align-items: center; }
  .life-pips i {
    width: 15px; height: 15px; display: block; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff4a3, #f2ae19 68%);
    border: 1px solid rgba(255,232,125,.9);
    box-shadow: 0 0 7px rgba(255,192,48,.72);
  }
  .life-pips i.lost { background: rgba(255,255,255,.08); box-shadow: none; border-color: rgba(255,255,255,.16); }
  .hud-row { display: flex; gap: 13px; align-items: baseline; }
  .hud-stat .label,
  .hud-dist .label {
    font-size: 9px; font-weight: 950; letter-spacing: .14em;
    color: #f2cb6b; text-transform: uppercase; margin-bottom: 2px;
  }
  .hud-stat .value {
    font-size: 18px; font-weight: 950; line-height: 1.05;
    font-variant-numeric: tabular-nums; color: #fff4c4;
    text-shadow: 0 2px 0 #281400, 0 0 5px #000;
  }
  .hud-stat .value.score { font-size: 23px; color: #fff36d; text-shadow: 0 0 9px #ff9d00, 1px 2px #140700; }
  .honey-ic { display: inline-block; width: 14px; height: 14px;
    background: url('assets/collectibles/x1x-jar.png') center / contain no-repeat;
    filter: drop-shadow(0 0 4px rgba(255,192,48,.72));
    vertical-align: -3px; margin-left: 3px; }
  .hud-right {
    position: absolute; right: 0; top: 0;
    display: grid; grid-template-columns: 154px 154px 88px;
    grid-template-areas: "mile goal controls";
    gap: 13px; align-items: start; pointer-events: none;
  }
  .hud-controls { grid-area: controls; display: flex; gap: 6px; justify-content: flex-end; pointer-events: auto; }
  .icon-btn {
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(3,8,13,.78); border: 1px solid rgba(255,226,91,.68);
    color: #fff4c4; font-size: 14px;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,.65), 0 0 7px rgba(255,192,48,.14);
  }
  .icon-btn:active { transform: scale(0.92); }
  .hud-dist { width: 154px; }
  .hud-mile { grid-area: mile; }
  .hud-goal { grid-area: goal; margin: 0; }
  .hud-dist .bar-wrap {
    margin-top: 4px; height: 6px; border-radius: 4px;
    background: rgba(0,0,0,.58); overflow: hidden;
    border: 1px solid rgba(255,255,255,.12);
  }
  .hud-dist .bar { height: 100%; width: 0%; background: linear-gradient(90deg, #d4a017, #ffe25b); box-shadow: 0 0 8px rgba(255,192,48,.55); }
  .hud-dist .val { font-size: 13px; font-weight: 950; margin-top: 2px; color: #fff8d5; font-variant-numeric: tabular-nums; text-shadow: 0 2px 2px #000, 0 0 5px rgba(0,0,0,.85); }
  .hud-goal .bar { background: linear-gradient(90deg, #3fa96f, #7be0a8); box-shadow: 0 0 8px rgba(90,220,150,.5); }
  .hud-goal .label { color: #9de0ba; }

  /* persistent boost meter (HB1 energy): bottom center */
  .boost-meter {
    position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%;
    transform: translateX(-50%);
    z-index: 10; pointer-events: none;
    width: min(260px, 62vw);
  }
  .boost-meter .label {
    font-size: 9px; font-weight: 950; letter-spacing: .18em; color: rgba(255,235,166,.82);
    text-transform: uppercase; text-align: center; margin-bottom: 3px;
  }
  .boost-meter .bar-wrap {
    height: 10px; border-radius: 6px; overflow: hidden;
    background: rgba(3,10,16,.85);
    border: 1px solid rgba(255,196,48,.40);
    box-shadow: 0 2px 10px rgba(0,0,0,.5);
  }
  .boost-meter .bar {
    height: 100%; width: 100%;
    background: linear-gradient(90deg, #ffb72f, #ffc030 55%, #ffe080);
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(255,192,48,.55);
    transition: width .08s linear;
  }
  .boost-meter .bar.boosting {
    background: linear-gradient(90deg, #ffd96a, #fff3c0 55%, #ffe080);
    box-shadow: 0 0 14px rgba(255,224,128,.85);
  }

  /* Felix improvements: HUD juice — score pops, critical lives, new best */
  .score-pop {
    position: absolute; left: 100%; top: 0; margin-left: 6px;
    font-size: 13px; font-weight: 800; color: var(--accent);
    text-shadow: 0 0 10px rgba(255,192,48,.6);
    pointer-events: none; white-space: nowrap;
    animation: scorePop .9s ease-out forwards;
    font-variant-numeric: tabular-nums;
  }
  @keyframes scorePop {
    0% { opacity: 0; transform: translateY(6px) scale(.7); }
    20% { opacity: 1; transform: translateY(0) scale(1); }
    70% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-18px) scale(1); }
  }
  .hud-left { position: absolute; }
  .life-pips.critical i:not(.lost) {
    animation: criticalPulse .7s ease-in-out infinite;
  }
  @keyframes criticalPulse {
    50% { box-shadow: 0 0 14px rgba(255,90,40,.95), 0 0 4px rgba(255,90,40,.9);
      transform: scale(1.18);
      background: radial-gradient(circle at 35% 30%, #ffd0a0, #e04a0a 70%); }
  }
  .newbest-chip {
    margin-top: 10px; display: inline-block;
    padding: 5px 16px; border-radius: 999px;
    background: linear-gradient(135deg, #ffd06a, #d4900a);
    color: #1a1408; font-size: 12px; font-weight: 900; letter-spacing: .12em;
    text-transform: uppercase;
    box-shadow: 0 0 18px rgba(255,192,48,.6);
    animation: bestPulse 1s ease-in-out infinite;
  }
  @keyframes bestPulse { 50% { transform: scale(1.06); } }

  /* Shared HB1-style arcade callout: compact, high, and never a window. */
  .arcade-callout {
    position: fixed; left: 50%; top: max(64px, calc(env(safe-area-inset-top) + 54px));
    transform: translate(-50%, -8px) scale(.92);
    width: max-content; max-width: min(56vw, 480px);
    padding: 3px 18px 4px;
    color: #ffe86b; background: linear-gradient(90deg, transparent, rgba(3,8,14,.62) 18%, rgba(3,8,14,.62) 82%, transparent);
    border-left: 2px solid #ffe25b; border-right: 2px solid #ffe25b;
    opacity: 0; pointer-events: none; z-index: 40;
    font: 950 clamp(11px, 1.3vw, 16px) "Arial Rounded MT Bold", "Avenir Next Condensed", ui-monospace, "SFMono-Regular", Menlo, monospace;
    letter-spacing: .10em; text-align: center; white-space: nowrap;
    text-shadow: 0 2px 2px #000, 0 0 8px rgba(255,173,39,.78);
    transition: opacity .12s, transform .12s;
  }
  .arcade-callout.on { opacity: 1; transform: translate(-50%, 0) scale(1); }
  .arcade-callout.green { color: #a8f4c8; border-color: #6ee6a1; text-shadow: 0 2px 2px #000, 0 0 8px rgba(90,220,150,.72); }
  .arcade-callout.warning { color: #fff0b5; border-color: #ffac47; }
  .mult-chip {
    position: fixed; top: max(42px, calc(env(safe-area-inset-top) + 36px)); left: 50%;
    transform: translateX(-50%); z-index: 11; opacity: 0; pointer-events: none;
    color: #fff36d; font: 950 10px ui-monospace, monospace; letter-spacing: .12em;
    text-shadow: 0 0 8px #ff9d00, 0 2px 2px #000; transition: opacity .15s;
  }
  .mult-chip.on { opacity: 1; }

  @media (max-width: 620px) {
    .hud { padding-left: 7px; padding-right: 7px; }
    .hud-top { min-height: 104px; padding-top: 6px; }
    .hud-top::before { height: 104px; left: -7px; right: -7px; }
    .hud-left { min-width: 0; gap: 7px; }
    .life-pips i { width: 12px; height: 12px; }
    .hud-row { gap: 9px; }
    .hud-stat .label { font-size: 8px; letter-spacing: .12em; }
    .hud-stat .value { font-size: 16px; }
    .hud-stat .value.score { font-size: 20px; }
    .wave-kicker { font-size: 8px; }
    .wave-value { font-size: 26px; }
    .hud-right {
      left: 0; right: 0; top: 0; padding-top: 55px;
      grid-template-columns: 1fr 1fr;
      grid-template-areas: "mile goal";
      gap: 22px;
    }
    .hud-controls { position: absolute; right: 0; top: 0; }
    .icon-btn { width: 34px; height: 34px; font-size: 13px; }
    .hud-dist { width: auto; }
    .hud-dist .val { font-size: 12px; }
    .hud-mile { text-align: left; }
    .hud-goal { text-align: right; }
    .arcade-callout {
      top: max(98px, calc(env(safe-area-inset-top) + 90px));
      max-width: calc(100vw - 30px); padding: 3px 12px 4px;
      font-size: 10px; letter-spacing: .07em;
    }
    .mult-chip { top: max(82px, calc(env(safe-area-inset-top) + 74px)); }
    #ov-start { overflow-x: hidden; padding-left: 24px; padding-right: 24px; }
    #ov-start .ov-title { width: min(300px, calc(100vw - 48px)); font-size: 25px; letter-spacing: .02em; white-space: normal; }
    #ov-start .ov-sub { width: min(290px, calc(100vw - 56px)); font-size: 10px; letter-spacing: .07em; }
    #ov-start .ov-body { width: min(280px, calc(100vw - 64px)); font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
    #ov-start .wallet-panel { width: min(280px, calc(100vw - 64px)); }
    #ov-start .settlement-status { width: 100%; font-size: 9px; overflow-wrap: anywhere; }
    #ov-start .ov-foot { left: 32px; right: 32px; bottom: max(10px, env(safe-area-inset-bottom)); font-size: 8px; line-height: 1.35; white-space: normal; }
  }

  /* control hints */
  #hint {
    position: fixed; bottom: max(70px, calc(env(safe-area-inset-bottom) + 60px)); left: 50%;
    transform: translateX(-50%);
    z-index: 9; pointer-events: none;
    background: none; border: 0;
    border-radius: 0; padding: 4px 10px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    font: 900 10px ui-monospace, "SFMono-Regular", Menlo, monospace;
    letter-spacing: .08em; color: rgba(255,244,196,.72);
    text-shadow: 0 2px 3px #000, 0 0 6px rgba(255,192,48,.38);
    opacity: 0; transition: opacity .4s;
    white-space: nowrap;
  }
  #hint.on { opacity: 1; }

  /* ---------- overlays ---------- */
  .overlay {
    position: fixed; inset: 0; z-index: 20;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: radial-gradient(ellipse at center, rgba(10,14,16,.55) 0%, rgba(6,10,10,.92) 100%);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: opacity .35s;
    text-align: center;
    padding: 24px;
  }
  .overlay.off { opacity: 0; pointer-events: none; }
  .logo-badge {
    width: 84px; height: 84px; border-radius: 22px;
    background: radial-gradient(circle at 35% 30%, #ffe080, #d4900a 65%);
    display: flex; align-items: center; justify-content: center;
    font-size: 40px; font-weight: 900; color: #1a1408;
    box-shadow: 0 0 34px rgba(255,192,48,.45), inset 0 2px 6px rgba(255,255,255,.4);
    margin-bottom: 14px;
  }
  .hive-badge {
    position: relative; width: 92px; height: 78px; margin-bottom: 18px;
    border-radius: 48% 48% 28% 28% / 58% 58% 24% 24%;
    background: repeating-linear-gradient(to bottom,#ffd96a 0 9px,#c98708 10px 13px,#efb72d 14px 23px);
    border: 3px solid #f4c44d;
    box-shadow: 0 0 36px rgba(255,192,48,.48),inset 0 4px 7px rgba(255,245,180,.38);
  }
  .hive-badge::after {
    content: ''; position: absolute; left: 35px; bottom: 7px;
    width: 22px; height: 29px; border-radius: 50% 50% 18% 18%;
    background: #1a1009; box-shadow: 0 0 0 4px #f0bd3c;
  }
  .ov-title {
    font-size: 34px; font-weight: 900; letter-spacing: .06em;
    color: var(--accent); text-transform: uppercase;
    text-shadow: 0 0 24px rgba(255,192,48,.35);
  }
  .ov-sub {
    margin-top: 6px; font-size: 13px; color: var(--text-dim); letter-spacing: .1em; text-transform: uppercase;
  }
  .ov-body {
    margin-top: 18px; font-size: 14px; color: var(--text-dim); line-height: 1.7;
    max-width: 320px;
  }
  .ov-stats {
    margin-top: 16px; display: flex; gap: 22px; justify-content: center;
  }
  .ov-stat .label { font-size: 10px; letter-spacing: .14em; color: var(--text-dim); text-transform: uppercase; }
  .ov-stat .value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
  .ov-stat .value.score { color: var(--accent); }
  #death-cause { margin-top: 14px; font-size: 13px; color: var(--text-dim); font-style: italic; }
  .settlement-card {
    width: min(330px, calc(100vw - 40px)); margin-top: 16px; padding: 13px 15px;
    border-radius: 14px; border: 1px solid rgba(255,196,72,.38);
    background: linear-gradient(145deg,rgba(4,13,20,.88),rgba(6,9,14,.92));
    box-shadow: 0 10px 30px rgba(0,0,0,.28); text-align: left;
  }
  .settlement-card[hidden], [hidden] { display: none !important; }
  .settlement-kicker { font-size: 9px; letter-spacing: .14em; color: #f5c85c; text-transform: uppercase; }
  .settlement-title { margin-top: 3px; font-size: 18px; font-weight: 900; color: #fff0b0; }
  .settlement-detail { margin: 5px 0 8px; font-size: 12px; line-height: 1.45; color: #f5efe0; }
  .settlement-status { min-height: 31px; margin-top: 7px; font-size: 10px; line-height: 1.45; color: var(--text-dim); }
  .settlement-status[data-kind="success"] { color: #7be0a8; }
  .settlement-status[data-kind="error"] { color: #ff9075; }
  .wallet-panel { width: min(330px, calc(100vw - 40px)); margin-top: 16px; }
  .reward-note { margin-bottom: 9px; color: #f5c85c; font-size: 10px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
  .wallet-row, .claim-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
  .wallet-state { margin-top: 7px; color: var(--text-dim); font-size: 10px; letter-spacing: .04em; }
  .btn-secondary, .btn-compact, .receipt-link {
    border: 1px solid rgba(255,196,72,.45); background: rgba(5,14,18,.76); color: #fff0b0;
    border-radius: 999px; padding: 10px 15px; font: 800 11px system-ui, sans-serif;
    letter-spacing: .06em; text-transform: uppercase; cursor: pointer; text-decoration: none;
  }
  .btn-compact { margin-top: 7px; }
  .receipt-link { display: inline-block; margin-top: 8px; color: #7be0ff; border-color: rgba(123,224,255,.45); }
  button:disabled { opacity: .55; cursor: wait; }
  button[aria-busy="true"] {
    opacity: 1; cursor: wait; transform: translateY(3px) scale(.975) !important;
    box-shadow: inset 0 3px 9px rgba(45,24,0,.46), 0 2px 10px rgba(255,192,48,.22) !important;
  }
  button[aria-busy="true"]::before {
    content: "⌛"; display: inline-block; margin-right: .48em;
    animation: hourglass-spin .9s linear infinite;
  }
  @keyframes hourglass-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }
  .btn, .btn-secondary, .btn-compact { touch-action: manipulation; }
  .btn {
    margin-top: 22px;
    background: linear-gradient(135deg, #ffc030, #d4900a);
    color: #1a1408; border: none;
    font-size: 16px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
    padding: 13px 44px; border-radius: 999px; cursor: pointer;
    box-shadow: 0 6px 24px rgba(255,192,48,.35);
    transition: transform .12s, box-shadow .12s;
  }
  .btn:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(255,192,48,.45); }
  .btn:active { transform: translateY(3px) scale(.96); box-shadow: inset 0 3px 9px rgba(45,24,0,.46), 0 2px 8px rgba(255,192,48,.22); }
  .btn-secondary:active, .btn-compact:active { transform: translateY(2px) scale(.97); background: rgba(24,20,10,.92); }
  @media (max-height: 760px) {
    .overlay { justify-content: flex-start; overflow-y: auto; padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: max(20px, env(safe-area-inset-bottom)); }
    .logo-badge { width: 62px; height: 62px; font-size: 30px; margin-bottom: 8px; }
    .ov-body { margin-top: 10px; line-height: 1.45; }
    .btn { margin-top: 14px; }
  }
  .ov-foot {
    position: absolute; bottom: calc(14px + env(safe-area-inset-bottom));
    font-size: 9px; letter-spacing: .12em; color: rgba(245,239,224,.3); text-transform: uppercase;
  }
  .kbd { font-family: ui-monospace, monospace; background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12); border-radius: 4px; padding: 1px 5px; font-size: 11px; }

/* Strict-CSP replacements for former inline style attributes. */
.ov-title-compact { font-size: 26px; }
.ov-title-large { font-size: 28px; }
#lvl-time { margin-top: 12px; font-size: 13px; color: var(--text-dim); }
