  html, body { margin: 0; height: 100%; overflow: hidden; }
  canvas { display: block; }
  :root { --scope-r: 31vmin; } /* fallback before JS sets the per-scope calibrated value on boot (see js/core/optics.js) */
  :root { --vignette-r: 56vh; } /* fixed tube-aperture size — independent of --scope-r, which is a per-scope reticle-graphic calibration value (not an aperture size), and never touched by JS */

  #nav {
    position: absolute; top: 0; left: 0; right: 0; z-index: 20;
    display: flex; gap: 8px; padding: 10px 14px;
    pointer-events: none;
  }
  #location-wrap, #rifle-wrap, #optics-wrap { position: relative; }
  #location-btn, #rifle-btn, #optics-btn {
    font-family: monospace; font-size: 14px;
    color: #fff; background: rgba(20, 24, 32, 0.55);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    backdrop-filter: blur(4px);
    pointer-events: auto; cursor: pointer;
    padding: 8px 12px;
    transition: background 0.15s, border 0.15s;
  }
  #location-btn:hover, #location-btn:focus, #location-btn.open,
  #rifle-btn:hover, #rifle-btn:focus, #rifle-btn.open,
  #optics-btn:hover, #optics-btn:focus, #optics-btn.open {
    background: rgba(20, 24, 32, 0.8);
    border-color: #fff; outline: none;
  }
  #location-menu, #rifle-menu, #optics-menu {
    display: none;
    position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 148px; padding: 4px;
    color: #fff; background: rgba(20, 24, 32, 0.8);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    backdrop-filter: blur(4px);
    pointer-events: auto;
  }
  #location-menu.open, #rifle-menu.open, #optics-menu.open { display: block; }
  #location-menu .menu-item, #rifle-menu .menu-item, #optics-menu .menu-item,
  .loc-submenu .menu-item, .rifle-submenu .menu-item, .optics-submenu .menu-item {
    display: block; width: 100%;
    font-family: monospace; font-size: 14px; text-align: left;
    color: #fff; background: transparent;
    border: 1px solid transparent; border-radius: 6px;
    padding: 8px 12px; cursor: pointer;
    transition: background 0.15s;
  }
  #location-menu .menu-item:hover, #location-menu .menu-item:focus,
  #rifle-menu .menu-item:hover, #rifle-menu .menu-item:focus,
  #optics-menu .menu-item:hover, #optics-menu .menu-item:focus,
  .loc-submenu .menu-item:hover, .loc-submenu .menu-item:focus,
  .rifle-submenu .menu-item:hover, .rifle-submenu .menu-item:focus,
  .optics-submenu .menu-item:hover, .optics-submenu .menu-item:focus {
    background: rgba(255,255,255,0.15); outline: none;
  }
  #location-menu .menu-item.active {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.25);
  }
  #location-menu .loc-row, #rifle-menu .rifle-row, #optics-menu .optics-row {
    display: block; width: 100%;
    position: relative;
  }
  .loc-submenu, .rifle-submenu, .optics-submenu {
    display: none;
    position: absolute; top: 0; left: calc(100% + 6px);
    min-width: 220px; padding: 4px;
    color: #fff; background: rgba(20, 24, 32, 0.8);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    backdrop-filter: blur(4px);
    pointer-events: auto;
    z-index: 1;
  }
  .loc-submenu.open, .rifle-submenu.open, .optics-submenu.open { display: block; }

  #overlay {
    position: absolute; inset: 0; z-index: 10;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 12px;
    background: rgba(0,0,0,.55); color: #fff; font-family: monospace;
    cursor: pointer;
  }
  #overlay h1 { margin: 0; font-size: 28px; }
  #overlay p { margin: 0; font-size: 14px; opacity: .85; }
  .hidden { display: none !important; }

  #scope {
    position: absolute; inset: 0; z-index: 15;
    pointer-events: none;
    opacity: 0;
    transform: scale(1.35);
    transition: opacity 0.16s ease-out, transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1);
    background: none;
  }
  #scope.on { opacity: 1; transform: scale(1); }
  #scope::before {
    content: ''; position: absolute; left: 50%; top: 50%;
    width: calc(2 * var(--scope-r) * var(--reticle-scale, 1));
    height: calc(2 * var(--scope-r) * var(--reticle-scale, 1));
    margin: calc(-1 * var(--scope-r) * var(--reticle-scale, 1)) 0 0
            calc(-1 * var(--scope-r) * var(--reticle-scale, 1));
    background: var(--reticle-image, url('Resource_Images/Reticles/CR1542-C-2900034_B.png')) center / contain no-repeat;
  }
  /* Vignette lives on ::after (not #scope's own background) so it paints
     above the reticle (::before) in document order — a pseudo-element
     always paints above its own parent's background, so the reticle could
     never sit behind a vignette living there, and would keep bleeding
     through at high FFP magnification regardless of z-index tuning. */
  #scope::after {
    content: ''; position: absolute; inset: 0; /* full viewport — a radial-gradient's final stop fills its own box, so this must cover everything beyond --vignette-r, not just be sized to it */
    pointer-events: none;
    background: radial-gradient(circle at 50% 50%,
      rgba(0, 0, 0, 0) calc(var(--vignette-r) - 4vh),
      rgba(0, 0, 0, 0.5) calc(var(--vignette-r) - 2vh),
      #000 var(--vignette-r));
  }

  /* Overlay UI — turret HUD (nested at the top of #pane-right, see
     engine.js), both panes, and the Fire button — is 'pinned' (scope
     mode) only, not "whenever isScoped()": zoom mode keeps a clean,
     unobstructed sight picture for observing/ranging; scope mode pins
     everything and frees the cursor, which is also the only state with a
     free cursor, so visibility and interactivity coincide here with no
     separate gating needed. `#scope.pinned ~ selector` mirrors the same
     no-JS-wiring trick `#scope.on` already uses. No change to
     --vignette-r — these overlay the aperture rather than fitting inside
     the black margins, so the circle doesn't need to resize. */
  #pane-left, #pane-right, #fire-btn { display: none; }
  #scope.pinned ~ #pane-left, #scope.pinned ~ #pane-right, #scope.pinned ~ #fire-btn {
    display: block;
  }

  #pane-left, #pane-right {
    position: absolute; top: 56px; bottom: 0;
    width: 270px; box-sizing: border-box;
    z-index: 16;
    overflow-y: auto;
    padding: 12px;
    font-family: monospace; font-size: 13px; color: #fff;
    background: rgba(20, 24, 32, 0.7);
    backdrop-filter: blur(4px);
  }
  #pane-left { left: 0; border-right: 1px solid rgba(255,255,255,0.3); }
  #pane-right { right: 0; border-left: 1px solid rgba(255,255,255,0.3); }

  #fire-btn {
    position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
    z-index: 16;
    font-family: monospace; font-size: 18px; font-weight: bold; letter-spacing: 1px;
    color: #fff; background: #b0271e;
    border: 2px solid rgba(255,255,255,0.6); border-radius: 8px;
    padding: 10px 30px; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    transition: background 0.15s, border 0.15s;
  }
  #fire-btn:hover, #fire-btn:focus { background: #d5342a; border-color: #fff; outline: none; }

  /* Turret HUD: now nests inside #pane-right's normal document flow (no
     longer an absolutely-positioned floating overlay), so it shares the
     pane's scope-mode-only visibility for free. */
  #turret-hud {
    display: flex; flex-direction: column; gap: 10px; align-items: center;
    padding-bottom: 12px; margin-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.25);
  }
  .turret-widget {
    display: flex; align-items: center; gap: 6px;
  }
  .turret-elevation.turret-row { flex-direction: row; }
  .turret-windage.turret-column { flex-direction: column; }
  .turret-btn {
    font-family: monospace; font-size: 16px; font-weight: bold; line-height: 1;
    color: #fff; background: rgba(20, 24, 32, 0.55);
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 6px;
    width: 30px; height: 30px;
    cursor: pointer;
    transition: background 0.15s, border 0.15s;
  }
  .turret-btn:hover, .turret-btn:focus {
    background: rgba(20, 24, 32, 0.85); border-color: #fff; outline: none;
  }
  .turret-value {
    min-width: 52px; text-align: center;
    font-size: 15px;
    background: rgba(20, 24, 32, 0.55);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 6px;
    padding: 6px 8px;
    cursor: text;
    user-select: none;
  }
  .turret-value input {
    width: 100%; box-sizing: border-box;
    font-family: monospace; font-size: 15px;
    color: #fff; background: rgba(0,0,0,0.4);
    border: 1px solid #fff; border-radius: 4px;
    text-align: center;
    padding: 2px 4px;
  }

  #zoom-readout {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    z-index: 20; display: none; white-space: nowrap;
    font-family: monospace; font-size: 14px;
    color: #fff; background: rgba(20, 24, 32, 0.55);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px; backdrop-filter: blur(4px);
    padding: 6px 12px;
    pointer-events: none;
  }

  #range-readout {
    position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
    z-index: 20; display: none; white-space: nowrap;
    font-family: monospace; font-size: 14px;
    color: #fff; background: rgba(20, 24, 32, 0.55);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px; backdrop-filter: blur(4px);
    padding: 6px 12px;
    pointer-events: none;
  }

  #incline-readout {
    position: absolute; bottom: 100px; left: 50%; transform: translateX(-50%);
    z-index: 20; display: none; white-space: nowrap;
    font-family: monospace; font-size: 14px;
    color: #fff; background: rgba(20, 24, 32, 0.55);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px; backdrop-filter: blur(4px);
    padding: 6px 12px;
    pointer-events: none;
  }

  /* ===== Reference pane (js/ui/reference-pane.js): formulas button + modal, calculator, notepad ===== */
  #reference-pane .ref-section { margin-bottom: 14px; }
  #reference-pane .ref-heading {
    font-size: 11px; opacity: 0.7; margin: 0 0 6px;
    text-transform: uppercase; letter-spacing: 0.5px;
  }

  .ref-buttons { display: flex; flex-direction: column; gap: 8px; }
  .ref-btn {
    display: block; width: 100%;
    font-family: monospace; font-size: 13px;
    color: #fff; background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.3); border-radius: 6px;
    padding: 8px; cursor: pointer;
    transition: background 0.15s;
  }
  .ref-btn:hover, .ref-btn:focus { background: rgba(255,255,255,0.2); outline: none; }

  /* Shared modal styling for every buildRefModal() popup (Formulas,
     Glossary, D.O.P.E. data, Help) — the dope and help ids were missing
     from these lists (found during review), so both rendered completely
     unstyled: no centering overlay, no dark box, default browser fonts. */
  #formulas-backdrop, #glossary-backdrop, #dope-backdrop, #help-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 30;
    align-items: center; justify-content: center;
    background: rgba(0,0,0,0.6);
  }
  #formulas-backdrop.open, #glossary-backdrop.open, #dope-backdrop.open, #help-backdrop.open { display: flex; }
  #formulas-modal, #glossary-modal, #dope-modal, #help-modal {
    width: 360px; max-width: 90vw;
    font-family: monospace; color: #fff;
    background: rgba(20, 24, 32, 0.95);
    border: 1px solid rgba(255,255,255,0.3); border-radius: 10px;
    padding: 18px;
    max-height: 80vh; overflow-y: auto;
  }
  #dope-modal { width: 420px; } /* wider — a 4-column table needs more room than the 360px default */
  #formulas-modal h2, #glossary-modal h2, #dope-modal h2, #help-modal h2 { margin: 0 0 4px; font-size: 16px; }
  #formulas-modal .formulas-note, #glossary-modal .glossary-note,
  #dope-modal .dope-note, #help-modal .help-note { font-size: 11px; opacity: 0.6; margin: 0 0 12px; }
  #formulas-modal ul, #help-modal ul { margin: 0 0 16px; padding-left: 18px; font-size: 13px; line-height: 1.6; }
  #help-modal h3 { margin: 14px 0 4px; font-size: 13px; opacity: 0.85; }
  #glossary-modal dl { margin: 0 0 16px; font-size: 13px; line-height: 1.6; }
  #glossary-modal dt { font-weight: bold; margin: 0 0 2px; }
  #glossary-modal dd { margin: 0 0 16px; font-size: 13px; line-height: 1.6; }
  #dope-modal table { width: 100%; border-collapse: collapse; margin: 0 0 16px; font-size: 12px; }
  #dope-modal th, #dope-modal td { text-align: right; padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.15); }
  #dope-modal th:first-child, #dope-modal td:first-child { text-align: left; }
  #dope-modal thead th { opacity: 0.7; font-weight: normal; border-bottom: 1px solid rgba(255,255,255,0.35); }
  #formulas-modal .close-btn, #glossary-modal .close-btn, #dope-modal .close-btn, #help-modal .close-btn {
    display: block; margin-left: auto;
    font-family: monospace; color: #fff; background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.3); border-radius: 6px;
    padding: 6px 16px; cursor: pointer;
  }
  #formulas-modal .close-btn:hover, #formulas-modal .close-btn:focus,
  #glossary-modal .close-btn:hover, #glossary-modal .close-btn:focus,
  #dope-modal .close-btn:hover, #dope-modal .close-btn:focus,
  #help-modal .close-btn:hover, #help-modal .close-btn:focus { background: rgba(255,255,255,0.25); outline: none; }

  .calc-display {
    width: 100%; box-sizing: border-box;
    font-family: monospace; font-size: 18px; text-align: right;
    color: #fff; background: rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.3); border-radius: 6px;
    padding: 8px; margin-bottom: 6px;
  }
  .calc-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .calc-btn {
    font-family: monospace; font-size: 14px;
    color: #fff; background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.25); border-radius: 5px;
    padding: 8px 0; cursor: pointer;
    transition: background 0.15s;
  }
  .calc-btn:hover, .calc-btn:focus { background: rgba(255,255,255,0.25); outline: none; }
  .calc-btn.op { background: rgba(80,120,200,0.35); }
  .calc-btn.op:hover { background: rgba(80,120,200,0.55); }
  .calc-btn.clear { background: rgba(200,80,60,0.35); }
  .calc-btn.clear:hover { background: rgba(200,80,60,0.55); }

  #notepad {
    display: block; width: 100%; box-sizing: border-box;
    min-height: 120px; resize: vertical;
    font-family: monospace; font-size: 12px;
    color: #fff; background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.25); border-radius: 6px;
    padding: 8px;
  }

  /* ===== Data pane (js/ui/data-pane.js): distance + windage entry, empty truth slots ===== */
  .data-row { margin-bottom: 14px; }
  .data-row label {
    display: block; font-size: 11px; opacity: 0.7; margin-bottom: 4px;
    text-transform: uppercase; letter-spacing: 0.5px;
  }
  .data-row-fields { display: flex; align-items: center; gap: 6px; }
  .data-input {
    font-family: monospace; font-size: 14px;
    color: #fff; background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.3); border-radius: 6px;
    padding: 6px 8px;
  }
  #distance-input { width: 100%; box-sizing: border-box; }
  .windage-dir-input { width: 30px; text-align: center; text-transform: uppercase; padding-left: 0; padding-right: 0; }
  .windage-mag-input { flex: 1; min-width: 0; }
  .truth-slot {
    min-width: 48px; min-height: 30px; flex: none;
    box-sizing: border-box;
    border: 1px dashed rgba(255,255,255,0.35); border-radius: 6px;
    background: rgba(255,255,255,0.05);
  }

  /* Hit/miss popup: same family as #zoom-readout/#range-readout (a plain
     toggled div, not a full modal backdrop) — a screen-dimming overlay
     after every single shot would be a lot more disruptive than the
     reference popups, which are opened deliberately. */
  #hit-miss-popup {
    display: none;
    position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%);
    z-index: 25;
    font-family: monospace; font-size: 28px; font-weight: bold; text-align: center;
    color: #fff;
    padding: 16px 36px;
    border: 2px solid #fff; border-radius: 10px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.5);
  }
  #hit-miss-popup.hit { background: rgba(20, 140, 60, 0.9); }
  #hit-miss-popup.miss { background: rgba(170, 30, 30, 0.9); }
  #hit-miss-popup.no-target { background: rgba(90, 90, 40, 0.9); font-size: 22px; }
  #hit-miss-popup .miss-distance {
    display: block; font-size: 13px; font-weight: normal; margin-top: 6px; opacity: 0.9;
  }
