:root {
    --topbar-h: 64px;
    --container-max: 760px;      /* matches .container width: min(760px, 100%) */
    --back-btn-w: 92px;          /* approx width of the back pill */
    --back-gap: 16px;            /* spacing between button and container */
  }

  html, body {
    overflow-x: hidden;
  }

  /* Improved base typography and body styling */
  body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #111;
    color: #eee;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-y: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.5;
  }

  main {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-top: calc(var(--topbar-h) + 18px);
    overflow: visible; /* Allow sticky children to work */
  }
  
  .content,
  .page {
    padding-top: calc(var(--topbar-h) + 18px);
  }
  
  .view {
    width: 100%;
    overflow: visible; /* Allow sticky positioning to work */
  }
  
  .container {
    width: min(760px, 100%);
    margin: 0 auto;
  }

  .container.instrument {
    width: min(720px, 100%);
    margin: 0 auto;
    text-align: center;
  }
  
  /* Improved controls spacing */
  .controls {
    margin: 20px auto 0;
    width: min(760px, 100%);
  }

  /* Improved spacing for config and action rows */
  .config-row,
  .action-row,
  .secondary-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 12px 0;
  }
  
  .config-row label {
    font-weight: 500;
    font-size: 14px;
    color: #ddd;
    opacity: 0.9;
  }

  /* Make action buttons feel primary and consistent */
  .action-row button {
    min-width: 220px;
  }

  /* Reset should never float weirdly */
  .secondary-row button {
    min-width: 140px;
    opacity: 0.9;
  }

  /* On smaller widths: stack primary actions */
  @media (max-width: 720px) {
    .action-row {
      flex-direction: column;
    }
    .action-row button {
      width: 100%;
      max-width: 360px;
    }
    .config-row {
      justify-content: center;
    }
  }
  
  /* Enhanced form input styling */
  input[type="number"],
  input.text,
  select {
    padding: 9px 12px;
    font-size: 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: #eee;
    transition: all 0.2s ease;
    outline: none;
  }
  
  input[type="number"]:focus,
  input.text:focus,
  select:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
  }
  
  input[type="number"] {
    width: 80px;
  }
  
  input.text {
    flex: 1;
    min-width: 200px;
  }
  
  /* Modern button styles with hover/active/disabled states */
  button {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
    color: #eee;
    border-radius: 10px;
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
    outline: none;
  }
  
  button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  
  button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    background: rgba(255, 255, 255, 0.08);
  }
  
  button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }
  
  button:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.3);
    outline-offset: 2px;
  }
  
  /* Action row buttons (primary actions) */
  .action-row button {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    font-weight: 600;
  }
  
  .action-row button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
  }
  
  button.secondary {
    opacity: 0.85;
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  button.secondary:hover:not(:disabled) {
    opacity: 1;
    background: rgba(255, 255, 255, 0.06);
  }
  
  /* Test area with smooth visibility transitions */
  .test-area {
    width: 100%;
    max-width: 520px;
    height: 200px;
    margin: 16px auto;
    background: #151515;
    border: 2px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    border-radius: 14px;
    position: relative;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: border-color 0.3s ease, background-color 0.3s ease;
  }
  
  .test-area:not(.hidden) {
    border-color: rgba(255, 255, 255, 0.15);
    background: #121212;
    animation: testAreaFadeIn 0.3s ease-out;
  }
  
  @keyframes testAreaFadeIn {
    0% {
      opacity: 0;
      transform: scale(0.98);
    }
    100% {
      opacity: 1;
      transform: scale(1);
    }
  }
  
  /* Stimulus text styling with smooth appearance */
  .test-area:not(.hidden) {
    font-size: clamp(24px, 5vw, 32px);
    font-weight: 600;
    letter-spacing: 0.5px;
    color: #eee;
    text-align: center;
    line-height: 1.2;
  }
  
  /* Subtle pulse animation for active test area */
  @keyframes subtlePulse {
    0%, 100% {
      box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    50% {
      box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05);
    }
  }
  
  .test-area:not(.hidden):focus-within {
    animation: subtlePulse 2s ease-in-out infinite;
  }
  
  /* Flash overlay with smooth fade transitions */
  .flash-overlay {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #4af;
    border-radius: 50%;
    pointer-events: none;
    top: 20px;
    right: 20px;
    z-index: 10;
    box-shadow: 0 0 16px rgba(68, 170, 255, 0.9), 0 0 32px rgba(68, 170, 255, 0.5);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  
  .flash-overlay:not(.hidden) {
    opacity: 1;
    transform: scale(1);
    animation: flashPulse 0.3s ease-out;
  }
  
  @keyframes flashPulse {
    0% {
      transform: scale(0.6);
      opacity: 0;
    }
    50% {
      transform: scale(1.1);
    }
    100% {
      transform: scale(1);
      opacity: 1;
    }
  }
  
  .hidden {
    display: none;
  }

  /* Session panel sticky header */
  .sticky-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(18, 18, 20, 0.92);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 10px 12px;
    margin: -10px -12px 10px;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
  }

  .sticky-header p {
    margin: 0;
  }
  
  .sticky-header h2 {
    margin: 0 0 8px 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #eee;
    opacity: 0.95;
  }
  
  
  /* Session trials scrollable container */
  .session-trials {
    /* Keep it scrollable and fixed-height */
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;

    /* Ensure at least 5 trials visible before scrolling starts */
    /* Each trial: ~1.45em line-height + 4px margin-bottom + 4px padding = ~2em total */
    /* 5 trials * 2em + padding (6px top + 6px bottom = 12px) = ~10em + 12px */
    line-height: 1.45;
    max-height: calc(5 * 2em + 16px); /* 5 full trials visible before scroll */
    padding-top: 6px;
    padding-bottom: 6px;
    padding-left: 20px;
    padding-right: 4px;
    margin: 0;

    /* Prevent scroll chaining to the page */
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    overflow-x: hidden;
    
    font-size: 14px;
    color: #ddd;
    /* Ensure scrolling is always enabled */
    -webkit-overflow-scrolling: touch;
    position: relative;
  }
  
  /* Subtle top fade overlay - graceful fade for older items as they scroll upward */
  .session-trials::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(to bottom, 
      rgba(26, 26, 26, 0.95) 0%,
      rgba(26, 26, 26, 0.75) 40%,
      rgba(26, 26, 26, 0.35) 75%,
      rgba(26, 26, 26, 0) 100%
    );
    pointer-events: none;
    z-index: 2;
  }
  
  /* Ensure trial list items don't cause overflow */
  .session-trials li {
    flex-shrink: 0;
    margin-bottom: 4px;
    padding: 2px 0;
    transition: opacity 120ms ease, transform 120ms ease;
  }
  
  /* Trial emphasis: opacity-based, never hide (no display:none) */
  .session-trials li.is-latest {
    opacity: 1;
    font-weight: 650;
  }

  .session-trials li.is-2nd {
    opacity: 0.95;
  }

  .session-trials li.is-3rd {
    opacity: 0.78;
  }

  .session-trials li.is-4th {
    opacity: 0.60;
  }

  .session-trials li.is-5th {
    opacity: 0.42;
  }

  .session-trials li.is-older {
    opacity: 0.25; /* still visible when you scroll up */
    font-weight: 400;
  }
  
  /* Scrollbar styling for trial list */
  .session-trials::-webkit-scrollbar {
    width: 6px;
  }
  
  .session-trials::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 3px;
  }
  
  .session-trials::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
  }
  
  .session-trials::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
  }
  
  /* Trial list base spacing (do NOT control scrolling here; .session-trials does) */
  #trialList {
    margin: 0;
    padding-left: 20px;
    padding-right: 4px;
  }
  
  #trialList li {
    margin-bottom: 4px;
    padding: 2px 0;
  }
  
  /* Hide empty elements when no session is active */
  .sticky-header:empty,
  .sticky-header p:empty {
    display: none;
  }
  
  #summary:empty {
    display: none;
  }
  
  /* Card/Panel styling with improved spacing and visual hierarchy */
  .panel {
    overflow: hidden;
    width: 100%;
    margin: 16px auto;
    text-align: left;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 20px 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--topbar-h) - 120px);
  }
  
  .panel:hover {
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  
  /* Session panel: fixed-height card that doesn't push page down */
  .panel.session-panel {
    display: flex !important;
    flex-direction: column !important;
    /* Keep the card within the viewport so it won't grow and push the page */
    max-height: calc(100vh - var(--topbar-h) - 140px) !important;
    height: auto;
    overflow: hidden !important;
    overflow-anchor: none; /* reduce browser scroll-jumps on append */
    /* Prevent any content from expanding the panel */
    box-sizing: border-box;
  }
  
  /* Session trials must remain scrollable even after session ends */
  .panel.session-panel .session-trials {
    flex: 1 1 auto;
    min-height: 0;
    /* max-height is set in base .session-trials rule (fixed 5-line window) */
    overflow-y: auto !important;
    overflow-x: hidden;
    overscroll-behavior: contain; /* Prevent scroll chaining to the page */
    box-sizing: border-box;
  }
  
  /* Ensure summary doesn't interfere with flex layout */
  .panel.session-panel #summary {
    flex-shrink: 0;
    margin-top: 12px;
    overflow: visible;
  }

  .op-advice {
    margin-top: 12px;
    padding: 16px 16px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
  }
  .op-advice h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 650;
  }
  .op-advice-body {
    margin-top: 10px;
    line-height: 1.55;
    color: rgba(255,255,255,0.92);
  }
  .op-advice-body ul {
    margin: 10px 0 0;
    padding-left: 22px;
  }
  .op-advice-body li {
    margin: 6px 0;
  }
  .op-advice .note {
    margin-top: 10px;
  }
  
  .panel h2 {
    margin: 0 0 12px 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #eee;
    opacity: 0.95;
  }

  /* Divided attention legend styling */
  .divided-legend {
    line-height: 1.35;
  }

  .divided-legend .legend-go,
  .divided-legend .legend-nogo {
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    display: inline-block;
    margin: 0 2px;
    border: 1px solid rgba(255,255,255,0.14);
  }

  .divided-legend .legend-go {
    background: rgba(80, 200, 120, 0.14);
  }

  .divided-legend .legend-nogo {
    background: rgba(240, 90, 90, 0.12);
  }

  .divided-legend .legend-blue {
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
  }

  /* Utility header for cards (title left, actions right) */
  .card-utility {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .card-utility h3 {
    margin: 0;
  }

  /* Copy-ready blocks */
  .copy-block {
    position: relative;
  }

  .copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;

    padding: 6px 10px;
    font-size: 12px;
    line-height: 1;

    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.06);
    color: #eee;

    cursor: pointer;
    opacity: 0.85;

    transition:
      background 0.2s ease,
      border-color 0.2s ease,
      box-shadow 0.2s ease,
      opacity 0.2s ease,
      transform 0.15s ease;
  }

  .copy-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.30);
    box-shadow: 0 0 0 2px rgba(255,255,255,0.06);
    transform: translateY(-0.5px);
  }

  .copy-btn:active {
    transform: translateY(0);
    box-shadow: none;
  }

  .copy-btn:focus-visible {
    outline: 2px solid rgba(255,255,255,0.35);
    outline-offset: 2px;
  }

  .copy-icon {
    font-size: 14px;
    line-height: 1;
  }

  /* Tooltip (shown on hover/focus) */
  .copy-btn[data-tooltip] {
    position: relative;
  }

  .copy-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    right: 0;
    top: calc(100% + 8px);

    padding: 6px 8px;
    font-size: 12px;
    line-height: 1.1;
    white-space: nowrap;

    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.14);
    background: rgba(0,0,0,0.85);
    color: rgba(255,255,255,0.92);

    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;

    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 10;
  }

  .copy-btn:hover::after,
  .copy-btn:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
  }

  /* Copied state (micro-polish) */
  .copy-btn.is-copied {
    opacity: 1;
    background: rgba(255,255,255,0.14);
    border-color: rgba(255,255,255,0.34);
    box-shadow: 0 0 0 2px rgba(255,255,255,0.08);
  }

.copy-status {
  display: block;
  margin-top: 6px;
  font-size: 12px;
}

/* View back button container */
.view-back {
  margin-bottom: 12px;
}

/* History view: floating Back button (no overlap across breakpoints) */
#view-history .view-back {
  position: fixed;
  z-index: 200;
  top: calc(var(--topbar-h) + 18px);
  display: flex;
  align-items: center;
  pointer-events: none;
}

#view-history .view-back > * {
  pointer-events: auto;
}

/* Desktop: place it in the left gutter beside the centered container */
@media (min-width: 980px) {
  #view-history .view-back {
    left: calc((100vw - var(--container-max)) / 2 - var(--back-btn-w) - var(--back-gap));
  }
  #view-history .container {
    padding-left: var(--container-pad);
  }
}

/* Tablet/mid widths: pin to left edge and reserve space so it never overlaps content */
@media (min-width: 641px) and (max-width: 979px) {
  #view-history .view-back {
    left: 16px;
  }
  /* Reserve horizontal space for the fixed button so headings/content don't sit beneath it */
  #view-history .container {
    padding-left: calc(var(--container-pad) + var(--back-btn-w) + 12px);
  }
}

/* Mobile: keep it inline/in-flow (your existing behavior) */
@media (max-width: 640px) {
  #view-history .view-back {
    position: static;
    left: auto;
    top: auto;
    margin: 0 0 12px 0;
    pointer-events: auto;
  }
  #view-history .container {
    padding-left: var(--container-pad);
  }
}

/* Ghost button style (secondary, minimal) */
.btn.btn-ghost {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.12);
  color: #eee;
  padding: 8px 10px;
  border-radius: 10px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.btn.btn-ghost:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.18);
  opacity: 1;
}

.btn.btn-ghost:active {
  background: rgba(255,255,255,0.06);
}

.btn.btn-ghost:focus-visible {
  outline: 2px solid rgba(255,255,255,0.3);
  outline-offset: 2px;
}

/* Baseline-relative diagram */
.baseline-diagram {
  position: relative;
  height: 120px;
  margin: 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.baseline-diagram .band {
  position: absolute;
  left: 18%;
  right: 18%;
  height: 28px;
  border-radius: 999px;
  background: rgba(255,255,255,0.10);
}

.points {
  position: relative;
  display: flex;
  gap: 10px;
  z-index: 1;
}

.points.baseline {
  margin-left: 4%;
}

.points.check {
  margin-right: 4%;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
}

.dot.single {
  background: rgba(255,255,255,0.90);
}

.diagram-micro {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 14px;
  font-size: 12px;
}

.diagram-micro > div {
  flex: 1;
}

.micro-mid {
  text-align: center;
}

.micro-right {
  text-align: right;
}

.micro-time {
  display: inline-block;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin-right: 8px;
}

.micro-desc {
  opacity: 0.75;
}

@media (max-width: 640px) {
  .diagram-micro {
    flex-direction: column;
    gap: 8px;
  }
  .micro-mid,
  .micro-right {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .baseline-dot:nth-child(4) {
    display: none;
  }
}

.diagram-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
  
  .panel.context-panel {
    background: #181818;
    border-color: rgba(255, 255, 255, 0.05);
  }
  
  
  /* Typography improvements for summary and content */
  #summary {
    margin-top: 14px;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.6;
    color: #eee;
    opacity: 0.95;
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid rgba(255, 255, 255, 0.1);
  }
 
  /* Improved baseline actions spacing */
  .baseline-actions {
    margin: 12px 0 8px;
  }
  
  button.danger {
    border: 1px solid rgba(255, 107, 107, 0.4);
    background: rgba(255, 107, 107, 0.08);
    color: #ff6b6b;
  }
  
  button.danger:hover:not(:disabled) {
    background: rgba(255, 107, 107, 0.15);
    border-color: rgba(255, 107, 107, 0.6);
  }
  
  button.danger:active:not(:disabled) {
    background: rgba(255, 107, 107, 0.12);
  }
  
  /* Improved baseline list styling */
  #baselineList {
    margin: 12px 0 0;
    padding-left: 20px;
    line-height: 1.5;
    font-size: 14px;
    opacity: 0.95;
    color: #ddd;
  }
  
  #baselineList li {
    margin-bottom: 6px;
    padding: 2px 0;
  }


  /* Enhanced baseline progress and guidance */
  #baselineProgress, #baselineGuidance {
    margin: 8px 0;
    opacity: 0.9;
    font-size: 14px;
    line-height: 1.5;
    color: #ccc;
  }
  
  #baselineInfo {
    line-height: 1.6;
    color: #ddd;
  }

  /* Improved note/helper text styling */
  .note {
    font-size: 13px;
    opacity: 0.7;
    margin-top: 8px;
    line-height: 1.5;
    color: #aaa;
    font-style: italic;
  }

  /* Topbar stays pinned */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 1000;

    display: flex;
    align-items: center;
    gap: 12px;

    padding: 0 16px;
    box-sizing: border-box;

    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }

  /* Prevent purple visited styling on topbar links */
  .topbar a,
  .topbar a:visited {
    color: inherit;
  }

  .topbar a {
    text-decoration: none;
  }

  #menuBtn {
    width: 48px;
    height: 48px;
    font-size: 20px;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
  }

  #menuBtn:hover {
    background: rgba(255, 255, 255, 0.06);
  }

  #menuBtn:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.09);
  }

  #menuBtn:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.35);
    outline-offset: 2px;
  }

  .topbar .title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.6px;
    opacity: 0.95;
  }

  /* Brand link with text swap on hover (overlay-based, no reflow) */
  .brand-link {
    position: relative;
    display: inline-block;
    white-space: nowrap;
    cursor: pointer;
  }

  .brand-link .brand-short {
    display: inline-block;
  }

  .brand-link .brand-long {
    display: none;
  }

  /* Text swap ONLY on true hover devices (desktop, mouse/trackpad) */
  @media (hover: hover) and (pointer: fine) {
    .brand-link .brand-long {
      display: inline-block;
      position: absolute;
      left: 0;
      top: 0;
      opacity: 0;
      transform: translateY(1px);
      transition: opacity 0.15s ease, transform 0.15s ease;
      pointer-events: none;
    }

    .brand-link .brand-short {
      opacity: 1;
      transition: opacity 0.15s ease;
    }

    .brand-link:hover .brand-short,
    .brand-link:focus-visible .brand-short {
      opacity: 0;
    }

    .brand-link:hover .brand-long,
    .brand-link:focus-visible .brand-long {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .brand-link:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.3);
    outline-offset: 2px;
    border-radius: 4px;
  }

  .topbar-page {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-left: 0;
    max-width: 45vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
    font-size: 15px;
    opacity: 0.75;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }

  .topbar-page::before {
    content: "";
    margin: 0;
  }

  .topbar-page.is-hidden {
    opacity: 0;
    transform: translateY(-2px);
    pointer-events: none;
  }

  /* Topbar right section */
  .topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .topbar-link {
    font-size: 14px;
    color: inherit;
    text-decoration: none;
    opacity: 0.85;
    transition: opacity 0.2s ease;
  }

  .topbar-link:hover {
    opacity: 1;
  }

  /* Topbar CTA (used for "Learn more") */
  .topbar-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    padding: 8px 12px;
    border-radius: 999px;

    border: 1px solid rgba(255,255,255,0.16);
    background: rgba(255,255,255,0.06);

    opacity: 0.95; /* override base link fade slightly */
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  }

  .topbar-cta:hover {
    background: rgba(255,255,255,0.10);
    border-color: rgba(255,255,255,0.26);
    transform: translateY(-0.5px);
    opacity: 1;
  }

  .topbar-cta:focus-visible {
    outline: 2px solid rgba(255,255,255,0.35);
    outline-offset: 2px;
  }

  /* Small arrow affordance without extra markup */
  .topbar-cta::after {
    content: "→";
    opacity: 0.8;
    transform: translateY(-0.5px);
  }

  /* --- Topbar CTA: prevent 2-line wrap on narrow screens --- */
  .topbar-cta {
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
  }

  .topbar-cta .lang {
    white-space: nowrap;
  }

  /* If space gets tight, keep it on one line and allow graceful truncation */
  .topbar-right .topbar-cta {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Mobile tightening */
  @media (max-width: 420px) {
    .topbar {
      gap: 8px;
      padding: 0 12px;
    }

    .topbar-right {
      gap: 8px;
    }

    .topbar-cta {
      padding: 6px 10px;
      font-size: 13px;
      border-color: rgba(255,255,255,0.14);
      background: rgba(255,255,255,0.05);
    }

    /* Arrow is nice on desktop, but costs space on mobile */
    .topbar-cta::after {
      display: none;
    }

    .topbar-right .topbar-cta {
      max-width: 120px;
    }
  }

  /* Super narrow phones - hide Learn More button */
  @media (max-width: 480px) {
    .topbar-cta {
      display: none;
    }
  }

  /* Super narrow phones */
  @media (max-width: 360px) {
    .topbar {
      gap: 6px;
      padding: 0 10px;
    }

    .topbar .title {
      font-size: 16px;
    }

    .topbar-right {
      gap: 6px;
    }
  }

  /* Language selector */
  .lang-select-wrapper {
    position: relative;
  }

  .lang-select {
    padding: 6px 28px 6px 10px;
    border: 1px solid #333;
    background: transparent;
    color: inherit;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    appearance: none;
    background-image:
      linear-gradient(45deg, transparent 50%, rgba(255,255,255,0.6) 50%),
      linear-gradient(135deg, rgba(255,255,255,0.6) 50%, transparent 50%);
    background-position:
      calc(100% - 12px) calc(50% - 1px),
      calc(100% - 8px) calc(50% - 1px);
    background-size: 4px 4px, 4px 4px;
    background-repeat: no-repeat;
    transition: border-color 0.2s ease, background-color 0.2s ease;
  }

  .lang-select:hover {
    border-color: #555;
    background-color: rgba(255, 255, 255, 0.03);
  }

  .lang-select:focus {
    outline: none;
    border-color: #666;
    background-color: rgba(255, 255, 255, 0.05);
  }

  .lang-select option {
    background: #1a1a1a;
    color: #eee;
  }

  body.menu-open .topbar {
    opacity: 0.65;
  }

  /* Overlay should NOT cover the topbar */
  .menu-overlay {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: 100vw;
    height: calc(100vh - var(--topbar-h));
    z-index: 1050;
    background: rgba(0,0,0,0.35);
  }
  .menu-overlay.hidden {
    display: none;
  }

  /* Menu should start UNDER the topbar */
  .menu {
    position: fixed;
    top: var(--topbar-h);
    left: 0;

    width: 260px;
    height: calc(100vh - var(--topbar-h));

    z-index: 1100;
    overflow-y: auto;

    background: rgba(0,0,0,0.70);
    backdrop-filter: blur(8px);
    border-right: 1px solid rgba(255,255,255,0.06);
    padding: 18px 10px 10px;

    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .menu-header {
    height: auto;
    padding: 0 0 10px 0;
    position: relative;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 0;
  }

  .menu-close-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: #eee;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    opacity: 0.7;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .menu-close-btn:hover {
    opacity: 1;
  }

  .menu.open {
    transform: translateX(0);
  }

  .menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s ease;
    font-size: inherit;
    font-family: inherit;
  }
  
  /* Support both buttons and links in menu */
  a.menu-item {
    border: none;
  }
  
  button.menu-item {
    /* Ensure buttons look like links when styled as menu-item */
    border: none;
  }
  
  .menu-item:hover {
    background: #1a1a1a;
  }

  #menu .menu-item[aria-current="page"] {
    font-weight: 600;
    background: #1a1a1a;
  }

  #menu .menu-item[aria-current="page"]:hover {
    background: #222;
  }

  #menu .menu-item.is-disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: default;
  }

  .view.hidden {
    display: none;
  }

  .view.active {
    display: block;
  }

  /* Documentation-style content (About, How to Use, FAQ, Docs) */
  /* Enhanced typography for documentation views */
  .view h2,
  .page h2 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: clamp(24px, 5vw, 28px);
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #eee;
    line-height: 1.2;
  }
  
  .view h3,
  .page h3 {
    margin-top: 32px;
    margin-bottom: 12px;
    font-size: clamp(18px, 4vw, 20px);
    font-weight: 600;
    opacity: 0.95;
    color: #eee;
    letter-spacing: -0.2px;
    line-height: 1.3;
  }
  
  .view h3:first-child,
  .page h3:first-child {
    margin-top: 0;
  }

  .view p,
  .page p {
    margin-left: auto;
    margin-right: auto;
  }

  .view ul,
  .page ul {
    max-width: 720px;
    margin: 10px auto 14px;
    padding-left: 22px;
    text-align: left;
  }

  .view li,
  .page li {
    text-align: left;
  }

  .view blockquote,
  .page blockquote {
    margin-left: auto;
    margin-right: auto;
  }

  .view hr,
  .page hr {
    border: none;
    border-top: 1px solid #222;
    margin: 24px 0;
  }

  .view strong,
  .page strong {
    font-weight: 600;
  }

  .view em,
  .page em {
    opacity: 0.85;
  }

  /* Documentation page styles (applies to all view sections) */
  .view .hero,
  .page .hero {
    margin-bottom: 32px;
  }

  .view .lead,
  .page .lead {
    font-size: 18px;
    line-height: 1.6;
    margin: 16px 0;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }

  /* Enhanced card styling for documentation */
  .view .card,
  .page .card {
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 24px 28px;
    margin: 28px auto;
    max-width: 720px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
  }
  
  .view .card:hover,
  .page .card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  
  .view .card h3,
  .page .card h3 {
    margin-top: 0;
    margin-bottom: 14px;
  }

  .view blockquote.quote,
  .view .quote,
  .page blockquote.quote,
  .page .quote {
    margin: 20px auto;
    padding: 16px 20px;
    border-left: 3px solid #444;
    background: #161616;
    font-style: italic;
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
  }

  .view .muted,
  .page .muted {
    opacity: 0.7;
    font-size: 14px;
  }

  .view .footer,
  .page .footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid #222;
    text-align: center;
    opacity: 0.6;
    font-size: 14px;
  }

  .footer a {
    color: inherit;               /* inherit muted text color */
    text-decoration: none;        /* no underline by default */
    border-bottom: 1px solid rgba(255,255,255,0.18);
    padding-bottom: 1px;
    opacity: 0.85;
    transition: 
      color 0.15s ease,
      border-color 0.15s ease,
      opacity 0.15s ease;
  }

  .footer a:hover,
  .footer a:focus {
    color: #fff;                  /* gently brighter on intent */
    border-bottom-color: rgba(255,255,255,0.45);
    opacity: 1;
  }

  .footer a:focus-visible {
    outline: none;
    box-shadow: 0 2px 0 rgba(255,255,255,0.35);
  }

  /* ================================
     Docs & content links (dark theme)
     Avoid bright blue / purple links
     ================================ */

  .page a:not(.docs-nav-btn):not(.topbar-link):not(.menu-item) {
    color: rgba(220, 225, 230, 0.9);       /* readable light gray */
    text-decoration: none;
    border-bottom: 1px solid rgba(220, 225, 230, 0.25);
    padding-bottom: 1px;
    transition:
      color 0.15s ease,
      border-color 0.15s ease,
      opacity 0.15s ease;
  }

  /* Visited links should NOT turn purple */
  .page a:visited:not(.docs-nav-btn):not(.topbar-link):not(.menu-item) {
    color: rgba(220, 225, 230, 0.85);
  }

  /* Hover / focus */
  .page a:hover,
  .page a:focus {
    color: #ffffff;
    border-bottom-color: rgba(255,255,255,0.5);
    opacity: 1;
  }

  /* Keyboard focus (accessible but subtle) */
  .page a:focus-visible {
    outline: none;
    box-shadow: 0 2px 0 rgba(255,255,255,0.35);
  }

  .page p a {
    font-weight: 500;
  }

  /* Ensure note class works within cards */
  .view .card .note,
  .page .card .note {
    margin-top: 12px;
    font-size: 13px;
    opacity: 0.7;
  }

  /* Make sure footer appears in all views by default */
  .view .container > .footer {
    margin-top: 48px;
  }

/* --- Responsive foundation --- */
* { box-sizing: border-box; }

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Make text scale nicely across devices */
:root{
  --container-pad: 20px;
  --radius: 18px;
}

@media (max-width: 600px){
  :root{ --container-pad: 14px; }
}

/* Add responsive padding to existing containers */
.container, .container.instrument {
  padding-left: var(--container-pad);
  padding-right: var(--container-pad);
}

/* Headline and body text: clamp = responsive scaling */
h1 {
  font-size: clamp(28px, 6vw, 48px);
  line-height: 1.15;
}

body, p, li, label {
  font-size: clamp(14px, 3.6vw, 16px);
}

/* Controls: stack on small screens - enhance existing rules */
@media (max-width: 600px){
  .config-row, .action-row, .secondary-row {
    flex-direction: column;
    align-items: stretch;
  }

  /* Buttons full width on mobile */
  .action-row button {
    width: 100%;
    max-width: 100%;
    min-width: unset;
  }

  .secondary-row button {
    width: 100%;
    max-width: 100%;
    min-width: unset;
  }

  /* Inputs/selects full width on mobile */
  input, select {
    width: 100%;
    max-width: 100%;
  }
}

/* Session/Baseline cards: ensure full width on mobile */
@media (max-width: 600px) {
  .card, .panel {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
  }
}

/* Topbar: prevent elements pushing outside screen */
.topbar {
  width: 100%;
  max-width: 100%;
}

.lang-toggle {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

/* Make sure nothing causes sideways scroll */
img, video, iframe, canvas {
  max-width: 100%;
  height: auto;
}

/* ----------------------------
   History cards (Phase 1.5)
---------------------------- */
  /* Enhanced history list spacing */
  .history-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 16px;
  }

  /* Enhanced history card styling */
  .history-card {
    background: #161616;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 16px 16px 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  }
  
  .history-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
  }

  /* Improved history header typography */
  .history-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
  }
  
  .history-ts {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.2px;
    color: #eee;
  }
  
  .history-meta {
    opacity: 0.75;
    font-size: 13px;
    margin-top: 3px;
    color: #aaa;
    font-weight: 500;
  }

  /* Enhanced badge/chip styles for metrics and quality labels */
  .badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.3px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
    opacity: 0.95;
    transition: all 0.2s ease;
  }
  
  .badge.ok {
    border-color: rgba(58, 221, 58, 0.5);
    background: rgba(58, 221, 58, 0.12);
    color: #6f6;
  }
  
  .badge.warn {
    border-color: rgba(204, 204, 51, 0.5);
    background: rgba(204, 204, 51, 0.12);
    color: #ffc;
  }
  
  .badge.bad {
    border-color: rgba(255, 107, 107, 0.6);
    background: rgba(255, 107, 107, 0.15);
    color: #ff6b6b;
  }
  
  .badge.na {
    border-color: #666;
    background: rgba(255, 255, 255, 0.03);
    opacity: 0.8;
  }
  
  /* Quality label badges */
  .history-line .badge,
  #summary .badge {
    margin-left: 4px;
    vertical-align: middle;
  }
  
  /* Chip rows (useful on doc pages too) */
  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    max-width: 720px;
    margin: 12px auto 0;
  }

  /* Chip style for small inline metrics (errors, flash info) */
  .chip {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #ccc;
    margin: 0 2px;
    letter-spacing: 0.2px;
  }

  /* Slightly roomier chips when used as semantic tags */
  .chips .chip {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 999px;
  }

  /* Semantic chip variants matching badge palette */
  .chip.ok {
    border-color: rgba(58, 221, 58, 0.45);
    background: rgba(58, 221, 58, 0.10);
    color: #7f7;
  }

  .chip.warn {
    border-color: rgba(204, 204, 51, 0.45);
    background: rgba(204, 204, 51, 0.10);
    color: #ffd;
  }

  .chip.bad {
    border-color: rgba(255, 107, 107, 0.55);
    background: rgba(255, 107, 107, 0.12);
    color: #ff8b8b;
  }

  .chip.na {
    opacity: 0.75;
  }

  /* Improved history body spacing */
  .history-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 4px;
  }

  /* History summary section with chips */
  .history-summary {
    margin-top: 2px;
  }

  .history-summary .chips {
    justify-content: flex-start;
    margin: 0;
    max-width: none;
  }

  .history-affordance {
    margin-top: 8px;
    font-size: 13px;
    opacity: 0.7;
  }

  /* History details section (collapsed by default) */
  .history-details {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: none;
  }

  .history-card.is-open .history-details {
    display: block;
  }

  .history-card:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.3);
    outline-offset: 2px;
  }

  .history-card {
    cursor: pointer;
  }

  /* Typography improvements for history lines */
  .history-line {
    font-size: 14px;
    line-height: 1.5;
    color: #ddd;
  }
  
  .history-line.muted {
    opacity: 0.75;
    font-size: 13px;
  }
  
  .history-compare {
    margin-top: 8px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 600;
    font-size: 14px;
    color: #eee;
  }
  
  .history-compare.muted {
    opacity: 0.7;
    font-weight: 500;
  }
  
  .history-tags {
    opacity: 0.85;
    font-size: 13px;
    font-style: italic;
    color: #ccc;
    margin-top: 4px;
  }
  
  .history-reason {
    opacity: 0.8;
    font-size: 13px;
    color: #ff6b6b;
  }

  /* Trial list styling */
  .trial-toggle {
    margin-top: 10px;
  }

  .trial-list {
    margin-top: 10px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.10);
    background: rgba(255,255,255,0.04);
  }

  .trial-list.hidden {
    display: none;
  }

  .trial-row {
    display: grid;
    grid-template-columns: 70px 1fr 90px;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 13px;
    color: #ddd;
  }

  .trial-row:last-child {
    border-bottom: none;
  }

  .trial-i {
    opacity: 0.75;
  }

  .trial-outcome {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    opacity: 0.95;
  }

  .trial-rt {
    text-align: right;
    opacity: 0.85;
  }

  /* Home — History preview */
  .home-history-note {
    margin: 6px 0 10px;
  }

  .home-history-list {
    list-style: none;
    padding: 0;
    margin: 0 0 12px;
    display: grid;
    gap: 10px;
  }

  .home-history-item {
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 12px;
    padding: 10px 12px;
    background: rgba(255,255,255,0.03);
    cursor: pointer;
  }

  .home-history-item:hover {
    border-color: rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.05);
  }

  .home-history-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .home-history-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .home-history-title strong {
    font-weight: 650;
  }

  .home-history-when {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .home-history-sub {
    margin-top: 6px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
  }

  .home-history-metrics {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
  }

  .home-history-metrics span {
    white-space: nowrap;
  }

  /* Mobile fixes for home history panel */
  @media (max-width: 640px) {
    .home-history-top {
      flex-wrap: wrap;
      gap: 6px;
      align-items: flex-start;
    }

    .home-history-title {
      flex: 1 1 auto;
      min-width: 0;
      flex-wrap: wrap;
      gap: 6px;
    }

    .home-history-when {
      white-space: normal;
      font-size: 12px;
      flex: 0 0 100%;
      order: -1;
      margin-bottom: 2px;
      opacity: 0.85;
    }

    .home-history-sub {
      flex-wrap: wrap;
      gap: 6px;
      align-items: flex-start;
    }

    .home-history-metrics {
      gap: 8px;
      flex: 1 1 auto;
      min-width: 0;
    }

    .home-history-metrics span {
      font-size: 13px;
    }
  }

  /* Tiny accent strip to make it feel "earned" */
  .home-history-item.is-valid {
    box-shadow: inset 3px 0 0 rgba(255,255,255,0.20);
  }
  .home-history-item.is-invalid {
    box-shadow: inset 3px 0 0 rgba(255,255,255,0.08);
    opacity: 0.92;
  }

input.text {
  padding: 8px;
  font-size: 16px;
}

  /* Enhanced history actions styling */
  .history-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin: 12px 0 16px;
  }
  
  #exportStatus {
    font-size: 14px;
    opacity: 0.85;
    color: #aaa;
    font-style: italic;
  }

  /* Enhanced trend card styling */
  .trend-card {
    margin-top: 16px;
  }
  
  .trend-list {
    list-style: none;
    padding-left: 0;
    margin: 12px 0 0;
    text-align: left;
  }
  
  .trend-item {
    display: flex;
    gap: 12px;
    align-items: baseline;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    transition: background-color 0.2s ease;
  }
  
  .trend-item:hover {
    background-color: rgba(255, 255, 255, 0.02);
    padding-left: 8px;
    padding-right: 8px;
    margin-left: -8px;
    margin-right: -8px;
    border-radius: 6px;
  }
  
  .trend-item:last-child {
    border-bottom: none;
  }
  
  .trend-left {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  
  .trend-right {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    color: #ddd;
  }

/* --- v0.2.2 polish add-on (safe) --- */

/* 1) Make selects feel more deliberate */
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(255,255,255,0.55) 50%),
    linear-gradient(135deg, rgba(255,255,255,0.55) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

/* Try to keep option text readable in dark themes (works in some browsers) */
select option {
  background: #151515;
  color: #eee;
}

/* If options are disabled, make it obvious but not "faded into nothing" */
select option:disabled {
  color: rgba(238, 238, 238, 0.55);
}

/* 2) Calm the "invalid" message tone visually (still red, less alarm) */
.history-reason {
  color: rgba(255, 170, 170, 0.95);
  background: rgba(255, 107, 107, 0.06);
  border-left: 2px solid rgba(255, 107, 107, 0.28);
}

/* 3) Chips: make them look a bit more "instrument readout" */
.chip {
  border-radius: 999px;
  padding: 3px 10px;
  font-variant-numeric: tabular-nums;
}

/* Docs navigation */
.docs-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 32px auto;
  max-width: 720px;
  padding: 0 16px;
  flex-wrap: wrap;
}

.docs-nav-left,
.docs-nav-center,
.docs-nav-right {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.docs-nav-left {
  justify-content: flex-start;
}

.docs-nav-right {
  justify-content: flex-end;
}

.docs-nav-btn {
  padding: 10px 20px;
  font-size: 14px;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #eee;
  transition: all 0.2s ease;
  display: inline-block;
  white-space: nowrap;
}

.docs-nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
}

@media (max-width: 600px) {
  .docs-nav {
    flex-direction: column;
    gap: 12px;
  }
  
  .docs-nav-left,
  .docs-nav-center,
  .docs-nav-right {
    width: 100%;
    justify-content: center;
  }
}

/* 4) Badge alignment polish */
.badge {
  font-variant-numeric: tabular-nums;
}

/* 5) Reduce hover lift on cards slightly (more "calm instrument") */
.panel:hover,
.history-card:hover {
  transform: translateY(-0.5px);
}

/* Inline toggle styling for "Resume last page" */
.inline-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.inline-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: rgba(255, 255, 255, 0.6);
  margin: 0;
  flex-shrink: 0;
}

.inline-toggle:hover {
  opacity: 1;
}

/* Context panel visibility */
.context-panel.is-hidden {
  display: none !important;
}

/* Onboarding overlay */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.onboarding-overlay.hidden {
  display: none !important;
}

.onboarding-card {
  width: min(520px, 100%);
  background: #1a1a1a;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 16px;
  padding: 22px 20px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  text-align: left;
}

body.onboarding-open {
  overflow: hidden;
}

/* Precision stage (fullscreen overlay) */
.precision-stage {
  position: fixed;
  inset: 0;
  z-index: 4000;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  overflow: hidden;
}

.precision-stage.hidden {
  display: none !important;
}

body.precision-open {
  overflow: hidden;
}

body.precision-prep-open,
html.precision-prep-open {
  overflow: hidden;
}

.precision-target {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.3), 0 0 40px rgba(255, 255, 255, 0.15);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.12s ease-out, transform 0.12s ease-out;
  z-index: 5; /* Above stage background, below HUD */
  /* Width and height are set via inline styles in JS */
}

.precision-target.show {
  opacity: 1;
  transform: scale(1);
}

.precision-hud {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.precision-hud-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.precision-hud-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.precision-trial-counter {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 500;
  background: rgba(0, 0, 0, 0.3);
  padding: 6px 10px;
  border-radius: 6px;
}

.precision-feedback {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 500;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
}

.precision-feedback.show {
  opacity: 1;
  transform: translateY(0);
}

.precision-fullscreen-notice {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 8px;
  border-radius: 6px;
  pointer-events: none; /* Don't block interactions */
  white-space: nowrap;
}

.precision-fullscreen-notice.hidden {
  display: none;
}

.exit-button {
  pointer-events: auto;
  padding: 8px 16px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  cursor: pointer;
}

.exit-button:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}