/* ======================================================================
   GetCalcMaster — patches.v27.css (bundled)
   - Bundles patches.v17.css → patches.v26.css into a single request
   - Reduces initial page-load round trips (especially on mobile / high latency)
   ====================================================================== */

/* ---- Begin: patches.v17.css ---- */
/* ======================================================================
   GetCalcMaster — v13 UX upgrades ("best in world" ROI backlog)
   This file is intentionally plain CSS (no Tailwind build required).
   Load after tailwind.css.
   ====================================================================== */

/* =====================================================================
   Global control sizing (pixel-aligned)
   - Ensures cm-chip / cm-btn / cm-btn-lite align across Notebook + site
   ===================================================================== */
:root {
    /* Default button/chip height (matches h-9 icon buttons = 36px). */
    --cm-chip-h: 36px;
}

@media (pointer: coarse) {
    :root { --cm-chip-h: 44px; }
}

.cm-btn,
.cm-btn-lite,
.cm-chip {
    min-height: var(--cm-chip-h);
}

/* ------------------------------------------------------------
   Tooltip (delayed hover + long-press)
   ------------------------------------------------------------ */
.cm-tooltip {
    position: fixed;
    z-index: 70;
    display: none;
    pointer-events: none;

    max-width: min(340px, 92vw);
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid rgb(226 232 240);
    background: rgba(255, 255, 255, 0.95);
    color: rgb(15 23 42);

    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.2;

    box-shadow:
        0 10px 15px -3px rgba(15, 23, 42, 0.12),
        0 4px 6px -4px rgba(15, 23, 42, 0.10);

    backdrop-filter: blur(12px);
    transform: translateY(-2px);
    opacity: 0;
    transition: opacity 120ms ease, transform 120ms ease;
}

/* =====================================================================
   v18 — Notebook rails + print/PDF reliability (pixel-perfect)
   ===================================================================== */

/* Sticky rails (Notebook):
   - Stay visible under the sticky topbar
   - Scroll internally so the *page* doesn't need to scroll just to see Problems
   - Uses --cm-topbar-h set by app-shell (scroll-shrink aware) */
@media (min-width: 1024px) {
    .cm-sticky-rail {
        position: sticky;
        top: calc(var(--cm-topbar-h, 56px) + 0.75rem);
        align-self: start;

        /* Make the rail a predictable "viewport" so nested scrollers
           (Problems/Errors, History, Minimap) can be sized reliably. */
        height: calc(100dvh - var(--cm-topbar-h, 56px) - 1.5rem);
        max-height: calc(100dvh - var(--cm-topbar-h, 56px) - 1.5rem);

        display: flex;
        flex-direction: column;
        gap: 0.75rem;

        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;

        /* Allow children to use flex + min-height:0 correctly. */
        min-height: 0;

        padding-bottom: 0.75rem;

        /* Scrollbar polish (desktop) */
        scrollbar-width: thin;
    }

    /* Remove Tailwind mt-3 spacing inside rails (gap handles spacing).
       This prevents uneven/bouncy vertical rhythm when panels toggle. */
    .cm-sticky-rail > .mt-3 { margin-top: 0 !important; }
    .cm-sticky-rail > .cm-card { margin-top: 0 !important; }

    /* WebKit scrollbar styling */
    .cm-sticky-rail::-webkit-scrollbar { width: 10px; }
    .cm-sticky-rail::-webkit-scrollbar-thumb {
        border-radius: 9999px;
        border: 3px solid transparent;
        background-clip: content-box;
        background: rgba(15, 23, 42, 0.22);
    }
    .cm-sticky-rail::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.30); }
    .dark .cm-sticky-rail::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.22); }
    .dark .cm-sticky-rail::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.30); }
}

/* Notebook Print/PDF fallback (same-tab print overlay) */
#cm-print-overlay {
    display: none;
}

body.cm-print-active #cm-print-overlay {
    display: block;
    background: white;
    color: #0f172a;

    /* Make the fallback print view immediately visible + scrollable */
    position: fixed;
    inset: 0;
    z-index: 9999;
    overflow: auto;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)) 16px;
}

@media (min-width: 768px) {
    body.cm-print-active #cm-print-overlay {
        padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom)) 24px;
    }
}

body.cm-print-active {
    background: white !important;
    overflow: hidden;
}

/* Only show the print overlay in print mode */
@media print {
    body.cm-print-active {
        overflow: visible !important;
    }

    body.cm-print-active > *:not(#cm-print-overlay) {
        display: none !important;
    }

    body.cm-print-active #cm-print-overlay {
        display: block !important;
        position: static !important;
        inset: auto !important;
        overflow: visible !important;
        padding: 0 !important;
    }

    body.cm-print-active #cm-print-overlay .cm-no-print {
        display: none !important;
    }
}

/* =====================================================================
   v19 — Notebook workspace tabs + toolbars (stable, no-bounce)
   ===================================================================== */

/* Workspace tabs bar (Notebook): keep layout stable; allow horizontal scroll for many tabs. */
.cm-workspace-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.75rem;
}

@media (max-width: 639.98px) {
    .cm-workspace-bar {
        grid-template-columns: 1fr;
    }
}

.cm-workspace-tabs-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
    /* Hide the scrollbar (still scrollable). Visible scrollbars looked
       broken/unprofessional in pixel validation on mobile + desktop. */
    scrollbar-width: none;
}

.cm-workspace-tabs-row > * {
    flex: 0 0 auto;
}

.cm-workspace-tabs-row::-webkit-scrollbar { display: none; }

/* Notebook toolbar: responsive 2-col layout with grouped, scrollable action rows. */
.cm-notebook-toolbar {
    display: grid;
    gap: 0.75rem;
}

@media (min-width: 1024px) {
    .cm-notebook-toolbar {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: start;
    }
}

.cm-notebook-toolbar-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.cm-toolbar-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
    /* Hide the scrollbar (still scrollable). */
    scrollbar-width: none;
}

.cm-toolbar-row > * {
    flex: 0 0 auto;
}

.cm-toolbar-row::-webkit-scrollbar { display: none; }

.cm-toolbar-group {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    padding-right: 0.75rem;
    margin-right: 0.75rem;
    border-right: 1px solid rgb(226 232 240);
}

.dark .cm-toolbar-group {
    border-right-color: rgb(30 41 59);
}

.cm-toolbar-group:last-child {
    border-right: 0;
    padding-right: 0;
    margin-right: 0;
}

/* Mobile: keep the notebook toolbar compact.
   Wrapping every group to 100% creates a very tall "wall" of buttons.
   Instead, keep each row swipe-scrollable (like a mobile command bar).
*/
@media (max-width: 639.98px) {
    .cm-toolbar-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.5rem;
        padding-bottom: 0.25rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .cm-toolbar-row::-webkit-scrollbar {
        display: none;
    }

    .cm-toolbar-group {
        width: auto;
        flex: 0 0 auto;
        flex-wrap: nowrap;
        border-right: 1px solid rgb(226 232 240);
        padding-right: 0.75rem;
        margin-right: 0.75rem;
        padding-bottom: 0;
        border-bottom: 0;
    }

    .dark .cm-toolbar-group {
        border-right-color: rgb(30 41 59);
    }
}

/* Problems panel: keep header/filter visible; scroll long lists inside the panel. */
@media (min-width: 1024px) {
    .cm-sticky-rail .cm-problems-panel {
        flex: 1 1 auto;
        min-height: 0;
    }

    .cm-problems-panel {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .cm-problems-scroller {
        flex: 1 1 auto;
        min-height: 0;
        overflow: auto;
        padding-right: 2px;
        scrollbar-gutter: stable;
        scrollbar-width: thin;
    }

    .cm-problems-scroller::-webkit-scrollbar { width: 10px; }
    .cm-problems-scroller::-webkit-scrollbar-thumb {
        border-radius: 9999px;
        border: 3px solid transparent;
        background-clip: content-box;
        background: rgba(15, 23, 42, 0.20);
    }
    .cm-problems-scroller::-webkit-scrollbar-thumb:hover { background: rgba(15, 23, 42, 0.28); }
    .dark .cm-problems-scroller::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.20); }
    .dark .cm-problems-scroller::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.28); }
}

.dark .cm-tooltip {
    border-color: rgb(30 41 59);
    background: rgba(2, 6, 23, 0.95);
    color: rgb(248 250 252);
    box-shadow:
        0 14px 24px -8px rgba(0, 0, 0, 0.55),
        0 6px 10px -6px rgba(0, 0, 0, 0.45);
}

.cm-tooltip-show {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.cm-tooltip[data-side="top"]::after,
.cm-tooltip[data-side="bottom"]::after {
    content: "";
    position: absolute;
    left: var(--cm-tip-arrow-x, 50%);
    transform: translateX(-50%);
    border: 6px solid transparent;
}

.cm-tooltip[data-side="top"]::after {
    bottom: -12px;
    border-top-color: rgba(255, 255, 255, 0.95);
    filter: drop-shadow(0 1px 0 rgba(15, 23, 42, 0.12));
}

.dark .cm-tooltip[data-side="top"]::after {
    border-top-color: rgba(2, 6, 23, 0.95);
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.35));
}

.cm-tooltip[data-side="bottom"]::after {
    top: -12px;
    border-bottom-color: rgba(255, 255, 255, 0.95);
    filter: drop-shadow(0 1px 0 rgba(15, 23, 42, 0.12));
}

.dark .cm-tooltip[data-side="bottom"]::after {
    border-bottom-color: rgba(2, 6, 23, 0.95);
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.35));
}

.cm-tooltip-kbd {
    display: inline-flex;
    align-items: center;
    margin-left: 0.5rem;
    padding: 0.2rem 0.45rem;
    border-radius: 0.6rem;
    background: rgb(241 245 249);
    color: rgb(71 85 105);
    font-size: 10px;
    font-weight: 800;
}

.dark .cm-tooltip-kbd {
    background: rgb(15 23 42);
    color: rgb(226 232 240);
}

/* ------------------------------------------------------------
   Function search (in-calc autocomplete)
   ------------------------------------------------------------ */
.cm-fs-pop {
    position: fixed;
    z-index: 65;
    display: none;

    max-width: min(560px, 92vw);
    border-radius: 1rem;
    border: 1px solid rgb(226 232 240);
    background: rgba(255, 255, 255, 0.98);
    box-shadow:
        0 16px 28px -12px rgba(15, 23, 42, 0.22),
        0 10px 15px -12px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(12px);
}

.dark .cm-fs-pop {
    border-color: rgb(30 41 59);
    background: rgba(2, 6, 23, 0.98);
}

.cm-fs-open { display: block; }

.cm-fs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;

    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid rgb(226 232 240);

    font-size: 0.75rem;
    font-weight: 800;
    color: rgb(100 116 139);
}

.dark .cm-fs-head {
    border-bottom-color: rgb(30 41 59);
    color: rgb(148 163 184);
}

.cm-fs-list {
    max-height: 320px;
    overflow: auto;
    padding: 0.25rem;
}

.cm-fs-item {
    width: 100%;
    text-align: left;

    padding: 0.5rem 0.75rem;
    border-radius: 0.85rem;

    background: transparent;
    border: 0;
    cursor: pointer;
}

.cm-fs-item:hover { background: rgb(248 250 252); }
.dark .cm-fs-item:hover { background: rgba(15, 23, 42, 0.55); }

.cm-fs-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.95);
}

.dark .cm-fs-item:focus-visible {
    box-shadow: 0 0 0 2px rgba(71, 85, 105, 0.95);
}

.cm-fs-item-active {
    background: rgb(15 23 42);
    color: white;
}

.dark .cm-fs-item-active {
    background: rgb(248 250 252);
    color: rgb(15 23 42);
}

.cm-fs-name {
    font-size: 0.875rem;
    font-weight: 800;
}

.cm-fs-meta {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgb(100 116 139);
}

.dark .cm-fs-meta { color: rgb(148 163 184); }

.cm-fs-item-active .cm-fs-meta {
    color: rgba(255, 255, 255, 0.82);
}

.dark .cm-fs-item-active .cm-fs-meta {
    color: rgb(51 65 85);
}

/* ------------------------------------------------------------
   Mobile-first calculator dock + swipeable bottom sheet rail
   ------------------------------------------------------------ */
.cm-keypad-dock { margin-top: 1rem; }

@media (max-width: 767px) {
    .cm-keypad-dock {
        position: sticky;
        bottom: 0px;
        z-index: 30;

        margin-left: -1rem;
        margin-right: -1rem;
        padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom));

        border-top: 1px solid rgba(148, 163, 184, 0.35);
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(10px);
    }

    .dark .cm-keypad-dock {
        border-top-color: rgba(51, 65, 85, 0.6);
        background: rgba(2, 6, 23, 0.88);
    }

    /* Hide desktop rail when mobile sheet is enabled */
    .cm-rail-docked { display: none !important; }
}

.cm-mobile-rail {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
}

@media (min-width: 768px) {
    .cm-mobile-rail { display: none !important; }
}

.cm-mobile-rail.cm-mobile-rail-open { display: block; }

.cm-mobile-rail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.30);
    backdrop-filter: blur(6px);
}

.cm-mobile-rail-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;

    max-height: 84vh;
    border-radius: 1.5rem 1.5rem 0 0;

    border: 1px solid rgb(226 232 240);
    background: rgb(255 255 255);

    box-shadow:
        0 -22px 60px -28px rgba(15, 23, 42, 0.55),
        0 -8px 18px -12px rgba(15, 23, 42, 0.35);

    transform: translateY(100%);
    transition: transform 220ms ease;
    will-change: transform;
}

.dark .cm-mobile-rail-sheet {
    border-color: rgb(30 41 59);
    background: rgb(2 6 23);
}

.cm-mobile-rail-open .cm-mobile-rail-sheet {
    transform: translateY(0);
}

.cm-mobile-rail-handle {
    display: flex;
    justify-content: center;
    padding: 0.75rem 0;
    touch-action: none;
}

.cm-mobile-rail-pill {
    height: 0.375rem;
    width: 3.5rem;
    border-radius: 9999px;
    background: rgb(203 213 225);
}

.dark .cm-mobile-rail-pill { background: rgb(51 65 85); }

.cm-mobile-rail-tabs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem 0.5rem;
}

.cm-mobile-rail-body {
    padding: 0 1rem 1rem;
    overflow: auto;
    max-height: calc(84vh - 56px);
}

/* Flatten panels inside the sheet for a cleaner mobile feel */
.cm-mobile-rail .cm-rail-panel {
    border: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
}

/* ------------------------------------------------------------
   History readability upgrades
   ------------------------------------------------------------ */
.cm-history-expr,
.cm-history-res {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

/* ------------------------------------------------------------
   Tiny screens (iPhone SE / narrow Android)
   ------------------------------------------------------------ */
@media (max-width: 420px) {
    .cm-card { padding: 12px !important; }
    .cm-rail-panel { padding: 12px !important; }
    .cm-toolbar { padding: 12px !important; }

    .cm-calc-grid { gap: 12px !important; }
    .cm-toolbar-grid { grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)) !important; }
}

/* ------------------------------------------------------------
   Generic focus ring helper (use on dynamic buttons created in JS)
   ------------------------------------------------------------ */
.cm-focus-ring:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.95);
}

.dark .cm-focus-ring:focus-visible {
    box-shadow: 0 0 0 2px rgba(71, 85, 105, 0.95);
}

/* Mobile dock launch row (Explain/History buttons above keypad) */
.cm-mobile-rail-launch { display: none; }
@media (max-width: 767px) {
  .cm-mobile-rail-launch { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
}

/* Mobile rail header spacer */
.cm-mobile-rail-spacer { flex: 1 1 auto; }

/* =====================================================================
   v15 — Navigation + drawer menu (no bottom tab bar)
   ===================================================================== */

/* Ensure icons render at a predictable size even when Tailwind
   build output is cached by the browser/PWA. */
.cm-icon { width: 20px; height: 20px; }

/* Sticky topbar polish (scroll-aware) */
.cm-topbar {
    transition: background-color 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
    /* Reduce sub-pixel jitter in some browsers when scrolling under a
       blurred sticky header (compositing hint). */
    will-change: background-color, box-shadow;
    transform: translateZ(0);
}

.cm-topbar.cm-topbar-scrolled {
    background: rgba(255, 255, 255, 0.92) !important;
    box-shadow:
        0 1px 0 rgba(15, 23, 42, 0.06),
        0 10px 20px -18px rgba(15, 23, 42, 0.35);
}

.dark .cm-topbar.cm-topbar-scrolled {
    background: rgba(2, 6, 23, 0.92) !important;
    box-shadow:
        0 1px 0 rgba(51, 65, 85, 0.40),
        0 10px 20px -18px rgba(0, 0, 0, 0.6);
}

/* NOTE: avoid changing header height on scroll.
   Height changes create subtle layout "bounce" for sticky rails + toolbars. */

/* Desktop nav: active underline (subtle + confident) */
.cm-desktop-nav .cm-is-active {
    position: relative;
}

.cm-desktop-nav .cm-is-active::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 6px;
    height: 2px;
    border-radius: 9999px;
    background: currentColor;
    opacity: 0.28;
}

/* Deterministic responsive nav (hardened with !important to survive
   stale PWA caches / partial CSS reloads):
   - <768px: burger (drawer menu)
   - 768–1023px: tablet dock + burger
   - 1024–1279px: desktop nav (dropdowns) + burger
   - >=1280px: desktop nav (dropdowns), burger hidden
*/
.cm-desktop-nav { display: none !important; }
.cm-tablet-dock { display: none !important; }
.cm-menu-btn { display: inline-flex !important; }

@media (min-width: 768px) and (max-width: 1023.98px) {
  .cm-tablet-dock { display: flex !important; }
  .cm-desktop-nav { display: none !important; }
  .cm-menu-btn { display: inline-flex !important; }
}

@media (min-width: 1024px) {
  .cm-desktop-nav { display: flex !important; }
  .cm-tablet-dock { display: none !important; }
  .cm-menu-btn { display: inline-flex !important; }
}

@media (min-width: 1280px) {
  .cm-desktop-nav { display: flex !important; }
  .cm-tablet-dock { display: none !important; }
  .cm-menu-btn { display: none !important; }
}

/* ------------------------------------------------------------
   Drawer menu overlay (iOS/PWA feel)
   ------------------------------------------------------------ */
.cm-menu {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
}

.cm-menu.hidden { display: none; }

.cm-menu-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, .38);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  opacity: 0;
  transition: opacity .18s ease;
}

.cm-menu-panel {
  position: relative;
  height: 100%;
  width: min(92vw, 420px);
  margin: 0;
  background: rgba(255, 255, 255, .86);
  border-right: 1px solid rgba(148, 163, 184, .45);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  backdrop-filter: blur(24px) saturate(140%);
  transform: translate3d(-14px, 0, 0);
  opacity: 0;
  transition: transform .22s cubic-bezier(.2, .85, .2, 1), opacity .22s ease;
  box-shadow: 0 24px 64px rgba(2, 6, 23, .22);
  display: flex;
  flex-direction: column;
  outline: none;
}

.dark .cm-menu-panel {
  background: rgba(2, 6, 23, .78);
  border-right: 1px solid rgba(51, 65, 85, .55);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}

.cm-menu-show .cm-menu-backdrop { opacity: 1; }
.cm-menu-show .cm-menu-panel { transform: translate3d(0, 0, 0); opacity: 1; }

/* Centered “glass card” mode on iPad */
@media (min-width: 48rem) {
  .cm-menu {
    justify-content: center;
    align-items: center;
    padding: 18px;
  }

  .cm-menu-panel {
    height: min(86vh, 720px);
    border-radius: 24px;
    border: 1px solid rgba(148, 163, 184, .45);
  }

  .dark .cm-menu-panel { border: 1px solid rgba(51, 65, 85, .55); }
}

/* Menu content */
.cm-menu-top {
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(148, 163, 184, .35);
  padding-top: calc(14px + env(safe-area-inset-top));
}
.dark .cm-menu-top { border-bottom: 1px solid rgba(51, 65, 85, .55); }

.cm-menu-top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.cm-menu-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.cm-menu-mark {
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #fff;
  background: linear-gradient(135deg, #0f172a 0%, #334155 55%, #0f172a 100%);
  box-shadow: 0 10px 26px rgba(2, 6, 23, .18);
}

.dark .cm-menu-mark {
  background: linear-gradient(135deg, #e2e8f0 0%, #94a3b8 60%, #e2e8f0 100%);
  color: #0f172a;
}

.cm-menu-title { font-weight: 900; letter-spacing: -0.02em; line-height: 1.1; }
.cm-menu-subtitle { font-size: 12px; font-weight: 700; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cm-menu-close {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(148, 163, 184, .45);
  background: rgba(255, 255, 255, .55);
}
.dark .cm-menu-close { border: 1px solid rgba(51, 65, 85, .55); background: rgba(2, 6, 23, .45); }

.cm-menu-actions { display: flex; gap: 10px; margin-top: 12px; }

.cm-menu-action {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, .45);
  background: rgba(255, 255, 255, .58);
  font-weight: 800;
  font-size: 13px;
}
.dark .cm-menu-action { border: 1px solid rgba(51, 65, 85, .55); background: rgba(2, 6, 23, .45); }

.cm-menu-scroll {
  padding: 14px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

.cm-menu-section { margin-top: 14px; }
.cm-menu-section:first-child { margin-top: 0; }

.cm-menu-section-title {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: .6;
  margin-bottom: 10px;
}

.cm-menu-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }

.cm-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 12px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, .45);
  background: rgba(255, 255, 255, .62);
  font-weight: 900;
  transition: transform .12s ease, background-color .12s ease, border-color .12s ease;
}

.cm-menu-item:active { transform: scale(.99); }

@media (hover:hover) {
  .cm-menu-item:hover { background: rgba(255, 255, 255, .78); }
}

.dark .cm-menu-item { border: 1px solid rgba(51, 65, 85, .55); background: rgba(2, 6, 23, .42); }

@media (hover:hover) {
  .dark .cm-menu-item:hover { background: rgba(2, 6, 23, .56); }
}

.cm-menu-item-primary {
  background: linear-gradient(135deg, rgba(15, 23, 42, .96) 0%, rgba(51, 65, 85, .92) 55%, rgba(15, 23, 42, .96) 100%);
  color: #fff;
  border-color: rgba(15, 23, 42, .08);
}
@media (hover:hover) { .cm-menu-item-primary:hover { filter: brightness(1.03); } }

.dark .cm-menu-item-primary {
  background: linear-gradient(135deg, rgba(226, 232, 240, .92) 0%, rgba(148, 163, 184, .88) 55%, rgba(226, 232, 240, .92) 100%);
  color: #0f172a;
  border-color: rgba(148, 163, 184, .22);
}

.cm-menu-kbd {
  font-size: 12px;
  font-weight: 900;
  opacity: .72;
  padding: 4px 8px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, .45);
  background: rgba(255, 255, 255, .55);
}
.dark .cm-menu-kbd { border: 1px solid rgba(51, 65, 85, .55); background: rgba(2, 6, 23, .45); }

/* Menu accordion for nested links (Calc / Graph) */
.cm-menu-acc { }
.cm-menu-acc summary { list-style: none; cursor: pointer; }
.cm-menu-acc summary::-webkit-details-marker { display: none; }
.cm-menu-chevron { font-size: 12px; font-weight: 900; opacity: .75; transition: transform .15s ease; }
.cm-menu-acc[open] > summary .cm-menu-chevron { transform: rotate(180deg); }

.cm-menu-subgrid { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 8px; padding-left: 6px; }

.cm-menu-subitem {
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, .35);
  background: rgba(255, 255, 255, .55);
  transition: transform .12s ease, background-color .12s ease, border-color .12s ease;
}
.cm-menu-subitem:active { transform: scale(.99); }

@media (hover:hover) { .cm-menu-subitem:hover { background: rgba(255, 255, 255, .72); } }

.dark .cm-menu-subitem { border: 1px solid rgba(51, 65, 85, .55); background: rgba(2, 6, 23, .35); }
@media (hover:hover) { .dark .cm-menu-subitem:hover { background: rgba(2, 6, 23, .5); } }

.cm-menu-subtitle { font-weight: 900; font-size: 13px; line-height: 1.2; }
.cm-menu-subdesc { margin-top: 2px; font-size: 12px; font-weight: 700; opacity: .72; line-height: 1.2; }

/* Reduce accidental horizontal scroll on iOS when menu is open */
.cm-menu-open body { overscroll-behavior: contain; }

/* ------------------------------------------------------------
   Key label clarity: make '=' unmistakable (fixes “looks like -”)
   ------------------------------------------------------------ */
.cm-key[data-cm-key="="] {
    font-size: 1.25rem !important;
    line-height: 1 !important;
    font-weight: 900 !important;
}

@media (prefers-reduced-motion: reduce) {
    .cm-topbar { transition: none !important; }
    .cm-menu-backdrop,
    .cm-menu-panel,
    .cm-menu-item,
    .cm-menu-subitem {
        transition: none !important;
    }
}

/* =====================================================================
   v16 — Converter: selected units inside inputs, aligned IO fields,
   and professional, actionable errors.
   ===================================================================== */

.cv-combo {
    padding-right: 2.5rem; /* leaves room for a future inline icon */
}

/* Field-level invalid state (scoped to conversion panel to avoid global churn) */
.cv-panel .cm-field.cm-invalid {
    border-color: rgb(251 113 133);
    box-shadow: 0 0 0 2px rgba(244, 63, 94, 0.18);
}

.dark .cv-panel .cm-field.cm-invalid {
    border-color: rgba(251, 113, 133, 0.65);
    box-shadow: 0 0 0 2px rgba(244, 63, 94, 0.22);
}

/* Output box aligned with cm-field */
.cv-output {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;

    border-radius: 0.75rem;
    border: 1px solid rgb(226 232 240);
    background: rgb(248 250 252);
    padding: 0.5rem 0.75rem;

    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: rgb(15 23 42);
}

.dark .cv-output {
    border-color: rgb(30 41 59);
    background: rgba(15, 23, 42, 0.38);
    color: rgb(248 250 252);
}

.cv-output-empty {
    color: rgb(100 116 139);
    font-weight: 800;
}

.dark .cv-output-empty {
    color: rgb(148 163 184);
}

.cv-output-error {
    border-color: rgb(254 205 211);
    background: rgb(255 241 242);
    color: rgb(159 18 57);
}

.dark .cv-output-error {
    border-color: rgba(251, 113, 133, 0.35);
    background: rgba(190, 18, 60, 0.16);
    color: rgb(253 164 175);
}

/* Professional message surfaces */

/* Converter banner (layout-stable): shows helpful Tip by default,
   switches to Error styling without changing layout. */
.cv-banner {
    border-radius: 1rem;
    padding: 0.75rem 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;

    /* Stable height prevents the page from "bouncing" when message changes */
    min-height: 72px;
}

@media (max-width: 640px) {
    .cv-banner { min-height: 84px; }
}

.cv-banner-icon {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.875rem;
    flex: 0 0 auto;
}

.cv-banner-main { min-width: 0; }

.cv-banner-title {
    font-weight: 900;
    font-size: 0.875rem;
    line-height: 1.1;
}

.cv-banner-body {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.25;
    opacity: 0.9;

    /* Clamp so the banner height stays stable */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}

.cv-banner-info {
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(241, 245, 249, 0.85);
    color: rgb(15 23 42);
}

.cv-banner-info .cv-banner-icon {
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(255, 255, 255, 0.85);
    color: rgb(71 85 105);
}

.dark .cv-banner-info {
    border-color: rgba(51, 65, 85, 0.55);
    background: rgba(15, 23, 42, 0.42);
    color: rgb(248 250 252);
}

.dark .cv-banner-info .cv-banner-icon {
    border-color: rgba(51, 65, 85, 0.7);
    background: rgba(2, 6, 23, 0.55);
    color: rgb(226 232 240);
}

.cv-banner-error {
    border: 1px solid rgb(254 205 211);
    background: rgb(255 241 242);
    color: rgb(159 18 57);
}

.cv-banner-error .cv-banner-icon {
    border: 1px solid rgb(254 205 211);
    background: rgba(254, 205, 211, 0.35);
    color: rgb(159 18 57);
}

.dark .cv-banner-error {
    border-color: rgba(251, 113, 133, 0.35);
    background: rgba(190, 18, 60, 0.14);
    color: rgb(253 164 175);
}

.dark .cv-banner-error .cv-banner-icon {
    border-color: rgba(251, 113, 133, 0.35);
    background: rgba(190, 18, 60, 0.20);
    color: rgb(253 164 175);
}

/* Field-level error stays compact */
.cv-field-err {
    border-radius: 1rem;
    border: 1px solid rgb(254 205 211);
    background: rgb(255 241 242);
    padding: 0.75rem 0.875rem;
    color: rgb(159 18 57);
}

.dark .cv-field-err {
    border-color: rgba(251, 113, 133, 0.35);
    background: rgba(190, 18, 60, 0.14);
    color: rgb(253 164 175);
}

.cv-msg-title {
    font-weight: 900;
    font-size: 0.875rem;
    line-height: 1.1;
}

.cv-msg-list {
    margin-top: 0.4rem;
    padding-left: 1.1rem;
    list-style: disc;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.25;
}

/* Converter dropdown (combobox listbox) */
.cv-dd {
    position: fixed;
    z-index: 65;
    max-height: 320px;
    overflow: auto;
    padding: 0.25rem;

    border-radius: 1rem;
    border: 1px solid rgb(226 232 240);
    background: rgba(255, 255, 255, 0.98);
    box-shadow:
        0 18px 30px -14px rgba(15, 23, 42, 0.22),
        0 10px 16px -14px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(12px);
}

.dark .cv-dd {
    border-color: rgb(30 41 59);
    background: rgba(2, 6, 23, 0.98);
}

.cv-dd-item {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0.55rem 0.75rem;
    border-radius: 0.85rem;
}

/* NOTE: the active item is set via JS (cv-dd-active). If :hover wins,
   the selection "turns white" on hover. So we only apply hover styling
   when NOT active, and explicitly preserve active colors when hovered. */
.cv-dd-item:hover:not(.cv-dd-active) {
    background: rgb(241 245 249);
}

.dark .cv-dd-item:hover:not(.cv-dd-active) {
    background: rgba(15, 23, 42, 0.55);
}

.cv-dd-item.cv-dd-active:hover {
    background: rgb(15 23 42);
    color: white;
}

.dark .cv-dd-item.cv-dd-active:hover {
    background: rgb(248 250 252);
    color: rgb(15 23 42);
}

.cv-dd-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.9);
}

.dark .cv-dd-item:focus-visible {
    box-shadow: 0 0 0 2px rgba(71, 85, 105, 0.95);
}

.cv-dd-active {
    background: rgb(15 23 42);
    color: white;
}

.dark .cv-dd-active {
    background: rgb(248 250 252);
    color: rgb(15 23 42);
}

.cv-dd-main {
    font-size: 0.875rem;
    font-weight: 900;
}

.cv-dd-sub {
    margin-top: 0.2rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: rgb(100 116 139);
}

.dark .cv-dd-sub {
    color: rgb(148 163 184);
}

.cv-dd-active .cv-dd-sub {
    color: rgba(255, 255, 255, 0.82);
}

.dark .cv-dd-active .cv-dd-sub {
    color: rgb(51 65 85);
}

.cv-dd-empty {
    padding: 0.75rem;
    border-radius: 0.85rem;
    color: rgb(100 116 139);
    font-size: 0.75rem;
    font-weight: 700;
}

.dark .cv-dd-empty {
    color: rgb(148 163 184);
}

/* ------------------------------------------------------------
   Tailwind purge patches (Finance + Graph arbitrary grids)
   ------------------------------------------------------------ */

/* Our shipped tailwind.css is pre-purged for performance.
   When we introduce new Tailwind-style utilities in views,
   we define them here so no Tailwind rebuild is required. */

@media (min-width: 48rem) {
    /* Finance: tax results + input row need 5 columns on md+ */
    .md\:grid-cols-5 {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}

/* Mortgage/Graph: arbitrary grid templates used in markup */
.grid-cols-\[1fr_110px\] {
    grid-template-columns: 1fr 110px;
}

.grid-cols-\[1fr_6rem\] {
    grid-template-columns: 1fr 6rem;
}

@media (min-width: 64rem) {
    /* Right-rail layouts for Finance + Tax + Mortgage */
    .lg\:grid-cols-\[1fr_360px\] {
        grid-template-columns: 1fr 360px;
    }
}

/* ------------------------------------------------------------
   Finance polish (mobile overflow + numeric alignment)
   ------------------------------------------------------------ */

/* Keep chips single-line (prevents uneven chip heights on mobile). */
.cm-chip { white-space: nowrap; }

/* Tabular numerals for currency columns (tables + finance outputs). */
.cm-num { font-variant-numeric: tabular-nums; }

/* iOS momentum scrolling for horizontal overflow containers. */
.cm-scroll-x { -webkit-overflow-scrolling: touch; }

/* ------------------------------------------------------------
   Tailwind purge patches (new responsive utilities used in views)
   ------------------------------------------------------------ */

@media (min-width: 40rem) {
    .sm\:hidden { display: none; }

    .sm\:text-sm {
        font-size: var(--text-sm);
        line-height: var(--tw-leading, var(--text-sm--line-height));
    }

    .sm\:px-3 {
        padding-left: calc(var(--spacing) * 3);
        padding-right: calc(var(--spacing) * 3);
    }

    .sm\:items-start { align-items: flex-start; }
    .sm\:justify-end { justify-content: flex-end; }
}

/* ------------------------------------------------------------
   Notebook Presentation Mode (v20.7)
   - Full-screen reader overlay
   - Section-by-section navigation + TOC
   - Print/PDF-ready typography
   ------------------------------------------------------------ */

html.cm-present-open,
html.cm-present-open body {
    overflow: hidden;
}

.cm-present-overlay {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.72);
    padding: 14px;
}

.cm-present-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.dark .cm-present-panel {
    background: #020617;
    border-color: rgba(148, 163, 184, 0.25);
}

.cm-present-topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(248, 250, 252, 0.9);
}

.dark .cm-present-topbar {
    background: rgba(2, 6, 23, 0.85);
    border-bottom-color: rgba(148, 163, 184, 0.18);
}

.cm-present-title {
    font-weight: 900;
    letter-spacing: -0.01em;
    color: rgb(15 23 42);
    max-width: 58vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dark .cm-present-title {
    color: rgb(226 232 240);
}

.cm-present-sub {
    font-size: 12px;
    font-weight: 700;
    color: rgb(71 85 105);
}

.dark .cm-present-sub {
    color: rgb(148 163 184);
}

.cm-present-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

.cm-present-toc {
    width: 320px;
    max-width: 85vw;
    border-right: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(248, 250, 252, 0.8);
    overflow: auto;
    padding: 12px;
}

.dark .cm-present-toc {
    border-right-color: rgba(148, 163, 184, 0.18);
    background: rgba(2, 6, 23, 0.65);
}

.cm-present-toc.hidden {
    display: none;
}

.cm-present-main {
    flex: 1;
    min-width: 0;
    overflow: auto;
    padding: 18px 18px 26px;
}

.cm-present-content {
    max-width: 980px;
    margin: 0 auto;
}

.cm-present-section {
    margin: 0 0 28px 0;
}

.cm-present-sec-h {
    font-weight: 950;
    letter-spacing: -0.02em;
    margin: 0 0 10px 0;
    color: rgb(15 23 42);
}

.dark .cm-present-sec-h {
    color: rgb(226 232 240);
}

.cm-present-cell {
    border: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 16px;
    padding: 14px;
    margin: 12px 0;
    background: rgba(255, 255, 255, 0.9);
}

.dark .cm-present-cell {
    background: rgba(2, 6, 23, 0.75);
    border-color: rgba(148, 163, 184, 0.18);
}

.cm-present-label {
    font-size: 11px;
    font-weight: 900;
    color: rgb(100 116 139);
    margin-top: 8px;
}

.dark .cm-present-label {
    color: rgb(148 163 184);
}

.cm-present-code {
    margin-top: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 13px;
    font-weight: 800;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 10px;
    border-radius: 14px;
    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(248, 250, 252, 0.95);
    color: rgb(15 23 42);
}

.dark .cm-present-code {
    background: rgba(15, 23, 42, 0.35);
    border-color: rgba(148, 163, 184, 0.18);
    color: rgb(226 232 240);
}



/* ------------------------------------------------------------
   Notebook Presenter View (v20.8)
   - Second-screen friendly controller UI
   - Speaker notes from :::notes text cells
   - Timer + audience blanking
   ------------------------------------------------------------ */

.cm-present-panel-presenter .cm-present-body {
    align-items: stretch;
}

.cm-present-notes {
    width: 360px;
    max-width: 92vw;
    border-left: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(248, 250, 252, 0.8);
    overflow: auto;
    padding: 12px;
}

.dark .cm-present-notes {
    border-left-color: rgba(148, 163, 184, 0.18);
    background: rgba(2, 6, 23, 0.65);
}

.cm-present-notes-h {
    font-size: 11px;
    font-weight: 950;
    letter-spacing: 0.02em;
    color: rgb(71 85 105);
}

.dark .cm-present-notes-h {
    color: rgb(148 163 184);
}

.cm-present-notes-empty {
    margin-top: 10px;
    border: 1px dashed rgba(15, 23, 42, 0.18);
    border-radius: 14px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.7);
    color: rgb(51 65 85);
    font-weight: 700;
    line-height: 1.4;
}

.dark .cm-present-notes-empty {
    background: rgba(2, 6, 23, 0.55);
    border-color: rgba(148, 163, 184, 0.22);
    color: rgb(226 232 240);
}

.cm-present-notes-md {
    margin-top: 10px;
}

.cm-present-next {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed rgba(15, 23, 42, 0.18);
}

.dark .cm-present-next {
    border-top-color: rgba(148, 163, 184, 0.22);
}

.cm-present-timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 999px;
    padding: 6px 10px;
    background: rgba(248, 250, 252, 0.9);
    font-size: 12px;
    font-weight: 900;
    color: rgb(15 23 42);
}

.dark .cm-present-timer {
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.35);
    color: rgb(226 232 240);
}

.cm-present-blank-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70vh;
    border-radius: 16px;
    background: #000000;
}

.cm-present-blank-text {
    font-size: 18px;
    font-weight: 950;
    letter-spacing: -0.02em;
    color: #ffffff;
    opacity: 0.92;
}


@media (max-width: 60rem) {
    .cm-present-panel-presenter .cm-present-body {
        flex-direction: column;
    }

    .cm-present-notes {
        width: auto;
        border-left: none;
        border-top: 1px solid rgba(15, 23, 42, 0.10);
    }

    .dark .cm-present-notes {
        border-top-color: rgba(148, 163, 184, 0.18);
    }
}
/* MarkdownLite typography */
.cm-md-root {
    font-size: 16px;
    line-height: 1.65;
    color: rgb(15 23 42);
}

.dark .cm-md-root {
    color: rgb(226 232 240);
}

.cm-md-h {
    font-weight: 950;
    letter-spacing: -0.01em;
    margin: 16px 0 10px;
}

.cm-md-h1 { font-size: 24px; }
.cm-md-h2 { font-size: 20px; }
.cm-md-h3 { font-size: 18px; }
.cm-md-h4 { font-size: 16px; }
.cm-md-h5 { font-size: 14px; }
.cm-md-h6 { font-size: 13px; }

.cm-md-p { margin: 10px 0; }

.cm-md-icode {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-weight: 800;
    font-size: 0.95em;
    padding: 2px 6px;
    border-radius: 10px;
    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(248, 250, 252, 0.95);
}

.dark .cm-md-icode {
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.35);
}

.cm-md-code {
    margin: 12px 0;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(15, 23, 42, 0.10);
    background: rgba(248, 250, 252, 0.95);
    overflow: auto;
}

.dark .cm-md-code {
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.35);
}

.cm-md-code-inner {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 13px;
    font-weight: 800;
    white-space: pre;
}

.cm-md-ul,
.cm-md-ol {
    margin: 10px 0 10px 22px;
}

.cm-md-li { margin: 6px 0; }

.cm-md-quote {
    margin: 12px 0;
    padding: 10px 12px;
    border-left: 4px solid rgba(2, 132, 199, 0.7);
    border-radius: 12px;
    background: rgba(14, 165, 233, 0.08);
}

.dark .cm-md-quote {
    border-left-color: rgba(56, 189, 248, 0.55);
    background: rgba(56, 189, 248, 0.12);
}

.cm-md-q { margin: 8px 0; }

.cm-md-link {
    text-decoration: underline;
    text-underline-offset: 2px;
}

@media print {
    html.cm-present-open,
    html.cm-present-open body {
        overflow: visible !important;
    }

    html.cm-present-open .cm-topbar,
    html.cm-present-open #cm-bottom-tabs,
    html.cm-present-open .cm-present-overlay {
        position: static !important;
    }

    html.cm-present-open .cm-present-overlay {
        background: transparent !important;
        padding: 0 !important;
    }

    html.cm-present-open .cm-present-topbar,
    html.cm-present-open .cm-present-toc {
        display: none !important;
    }

    html.cm-present-open .cm-present-panel {
        border: none !important;
        border-radius: 0 !important;
    }

    html.cm-present-open .cm-present-main {
        overflow: visible !important;
        padding: 0 !important;
    }

    html.cm-present-open .cm-present-section {
        break-before: page;
        page-break-before: always;
    }

    html.cm-present-open .cm-present-section:first-child {
        break-before: auto;
        page-break-before: auto;
    }

    html.cm-present-open .cm-present-cell {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
/* ---- End: patches.v17.css ---- */

/* ---- Begin: patches.v18.css ---- */
/* =====================================================================
   GetCalcMaster — UI Polish Patch v18
   Focus:
   - Notebook: toolbar clipping, sticky rail scroll reliability, minimap sizing
   - Calculators: inline page subhead + desktop layout that keeps keypad visible
   - Global: remove <summary> markers ("." bullets) for consistent menus
   ===================================================================== */

/* ------------------------------------------------------------
   Global: normalize details/summary
   - Fixes the "tab turns into ." issue (default marker/bullet showing on hover)
   ------------------------------------------------------------ */
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::marker { content: ""; }

/* ------------------------------------------------------------
   Shared panel headers (Notebook rail)
   ------------------------------------------------------------ */
.cm-panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
}
.cm-panel-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ------------------------------------------------------------
   Notebook: toolbar layout
   - Give actions area more room on desktop
   - Primary row wraps (Run buttons never clipped)
   - Secondary row keeps horizontal scroll, but shows a slim scrollbar
   ------------------------------------------------------------ */
@media (min-width: 1024px) {
  .cm-notebook-toolbar {
    grid-template-columns: minmax(0, 560px) minmax(0, 1fr);
  }

  /* Wrap primary actions on desktop so nothing is half-hidden */
  .cm-toolbar-row-primary {
    flex-wrap: wrap;
    overflow: visible;
    scrollbar-width: auto;
  }

  /* Make horizontal scroll discoverable for the dense secondary row */
  .cm-toolbar-row-secondary {
    scrollbar-width: thin;
  }
  .cm-toolbar-row-secondary::-webkit-scrollbar {
    display: block;
    height: 8px;
  }
  .cm-toolbar-row-secondary::-webkit-scrollbar-thumb {
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.18);
  }
  .dark .cm-toolbar-row-secondary::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.22);
  }
}

/* ------------------------------------------------------------
   Notebook: sticky rail scroll reliability
   - Add 100vh fallback for browsers without dvh support.
   ------------------------------------------------------------ */
@media (min-width: 1024px) {
  .cm-sticky-rail {
    height: calc(100vh - var(--cm-topbar-h, 56px) - 1.5rem);
    max-height: calc(100vh - var(--cm-topbar-h, 56px) - 1.5rem);

    height: calc(100dvh - var(--cm-topbar-h, 56px) - 1.5rem);
    max-height: calc(100dvh - var(--cm-topbar-h, 56px) - 1.5rem);
  }
}

/* Prevent the Problems header actions (Count + Fix menu) from wrapping awkwardly */
.cm-problems-panel summary.cm-btn-lite { white-space: nowrap; }

/* Minimap: responsive height (prevents it being "tucked" / oversized) */
.cm-minimap-bar {
  height: clamp(140px, 22vh, 220px);
}

/* ------------------------------------------------------------
   Calculators: keep keypad visible on desktop
   - Main card becomes a 2-column workspace: (Display+Tools) | (Keypad)
   - Right column is sticky so the keypad stays on screen while scrolling tools
   ------------------------------------------------------------ */
.cm-calc-main-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 1024px) {
  .cm-calc-main-grid {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }

  /* Align keypad with the top of the workspace (no extra mt-4) */
  .cm-calc-main-grid .cm-keypad-dock { margin-top: 0 !important; }

  /* Keep keypad visible while scrolling long tool panels (Engineering, etc.) */
  .cm-calc-keypad-col {
    position: sticky;
    top: calc(var(--cm-topbar-h, 56px) + 1rem);
    align-self: start;
  }
}

/* Tight-height displays: shave a bit of vertical space so the keypad fits without page scroll */
@media (min-width: 1024px) and (max-height: 760px) {
  .cm-calc-grid {
    --cm-key-h: 40px;
    --cm-chip-h: 32px;
  }
}
/* ---- End: patches.v18.css ---- */

/* ---- Begin: patches.v19.css ---- */
/* v19 — Notebook Inspector (single right rail panel w/ tabs)
   NOTE: Color tokens are defined in patches.v20.css (loaded after this file).
*/

.cm-inspector {
  /* The inspector lives inside the sticky rail (which is the scroll container). */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cm-inspector-top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--cm-bg);
  border-bottom: 1px solid var(--cm-border);
}

.dark .cm-inspector-top {
  background: var(--cm-bg);
}

.cm-inspector-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.85rem;
}

.cm-inspector-title {
  font-size: 0.9rem;
  font-weight: 800;
}

.cm-inspector-close {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 10px;
  padding: 0.35rem 0.5rem;
  color: var(--cm-fg2);
}

.cm-inspector-close:hover {
  background: var(--cm-bg2);
}

.cm-inspector-tabs {
  display: flex;
  gap: 6px;
  padding: 0.25rem 0.55rem 0.55rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.cm-inspector-tabs::-webkit-scrollbar {
  display: none;
}

.cm-inspector-tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--cm-fg2);
  white-space: nowrap;
}

.cm-inspector-tab:hover {
  background: var(--cm-bg2);
}

.cm-inspector-tab.is-active {
  background: var(--cm-bg2);
  border-color: var(--cm-border);
  color: var(--cm-fg);
}

.cm-inspector-body {
  padding: 0.75rem;
}
/* ---- End: patches.v19.css ---- */

/* ---- Begin: patches.v20.css ---- */
/* v20 — Workstation polish
   - Design tokens used by inspector + prose
   - cm-prose typography for SEO / Learn pages
   - Layout density toggle (Comfortable / Compact)
*/

:root {
  /* Surface + borders */
  --cm-bg: #ffffff;
  --cm-bg2: rgba(15, 23, 42, 0.04); /* slate-900 @ 4% */
  --cm-border: rgba(148, 163, 184, 0.35); /* slate-400 @ 35% */

  /* Text */
  --cm-fg: rgb(15 23 42); /* slate-900 */
  --cm-fg2: rgb(71 85 105); /* slate-600 */

  /* Accent */
  --cm-accent: rgb(99 102 241); /* indigo-500 */

  /* Code */
  --cm-code-bg: rgba(15, 23, 42, 0.045);
}

html.dark {
  --cm-bg: rgb(2 6 23); /* slate-950 */
  --cm-bg2: rgba(148, 163, 184, 0.10); /* slate-400 @ 10% */
  --cm-border: rgba(51, 65, 85, 0.75); /* slate-700 @ 75% */

  --cm-fg: rgb(248 250 252); /* slate-50 */
  --cm-fg2: rgb(148 163 184); /* slate-400 */

  --cm-accent: rgb(129 140 248); /* indigo-400 */

  --cm-code-bg: rgba(248, 250, 252, 0.065);
}

/* ---------------------------------------------
   Typography (no Tailwind Typography plugin)
----------------------------------------------*/

.cm-prose {
  color: var(--cm-fg);
  font-size: 0.98rem;
  line-height: 1.7;
}

.cm-prose :where(p, ul, ol, blockquote, pre, table, hr) {
  margin-top: 1em;
}

.cm-prose :where(h2, h3, h4) {
  scroll-margin-top: 88px;
}

.cm-prose h2 {
  margin-top: 1.8em;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.cm-prose h3 {
  margin-top: 1.5em;
  font-size: 1.08rem;
  font-weight: 850;
  letter-spacing: -0.01em;
}

.cm-prose h4 {
  margin-top: 1.25em;
  font-size: 1rem;
  font-weight: 850;
}

.cm-prose a {
  color: var(--cm-accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.cm-prose a:hover {
  opacity: 0.92;
}

.cm-prose ul {
  padding-left: 1.25em;
  list-style: disc;
}

.cm-prose ol {
  padding-left: 1.25em;
  list-style: decimal;
}

.cm-prose li {
  margin-top: 0.35em;
}

.cm-prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.92em;
  background: var(--cm-code-bg);
  border: 1px solid var(--cm-border);
  border-radius: 0.55em;
  padding: 0.12em 0.35em;
}

.cm-prose pre {
  background: var(--cm-code-bg);
  border: 1px solid var(--cm-border);
  border-radius: 1rem;
  padding: 0.95em 1.05em;
  overflow: auto;
}

.cm-prose pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: 0.9em;
}

.cm-prose blockquote {
  border-left: 3px solid var(--cm-border);
  padding: 0.35em 0 0.35em 1em;
  color: var(--cm-fg2);
}

.cm-prose table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.95em;
}

.cm-prose th,
.cm-prose td {
  border: 1px solid var(--cm-border);
  padding: 0.55em 0.6em;
  vertical-align: top;
}

.cm-prose th {
  background: var(--cm-bg2);
  font-weight: 800;
}

.cm-prose hr {
  border: 0;
  border-top: 1px solid var(--cm-border);
  margin: 1.8em 0;
}

/* ---------------------------------------------
   Density toggle
----------------------------------------------*/

html.cm-density-comfy {
  /* Default / reference. */
  --spacing: 0.25rem;
}

html.cm-density-compact {
  /* Global spacing scale (Tailwind v4 uses --spacing in calc()). */
  --spacing: 0.225rem;

  /* Tighten keypad height for small laptops. */
  --cm-key-h: 40px;
}

@media (min-width: 768px) {
  html.cm-density-compact {
    --cm-key-h: 46px;
  }
}

@media (min-width: 1024px) {
  html.cm-density-compact {
    --cm-key-h: 44px;
  }
}

/* Slightly smaller inspector padding in compact mode */
html.cm-density-compact .cm-inspector-body {
  padding: 0.6rem;
}
/* ---- End: patches.v20.css ---- */

/* ---- Begin: patches.v21.css ---- */
/* v21 — Notebook Inspector Graph polish + tooltip fixes
   - Stacked graph header + scope controls (prevents word-per-line wrapping)
   - Segmented control styling
   - Graph canvas scrollbars + legend
   - Responsive stacking for generic panel headers in narrow rails
*/

@media (max-width: 420px) {
  .cm-panel-head {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .cm-panel-head-actions {
    justify-content: flex-start;
  }
}

/* -----------------------------
   Dependency graph panel (Inspector)
------------------------------*/

.cm-graph-head {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cm-graph-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.cm-graph-title {
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgb(100 116 139); /* slate-500 */
}

.dark .cm-graph-title {
  color: rgb(148 163 184); /* slate-400 */
}

.cm-graph-stat {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border: 1px solid var(--cm-border);
  background: var(--cm-bg2);
  color: var(--cm-fg2);
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

.cm-graph-stat.is-warn {
  border-color: rgba(220, 38, 38, 0.30);
  background: rgba(220, 38, 38, 0.08);
  color: rgb(185 28 28); /* red-700 */
}

.dark .cm-graph-stat.is-warn {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.12);
  color: rgb(254 202 202); /* red-200 */
}

.cm-graph-desc {
  font-size: 0.85rem;
  line-height: 1.25rem;
  color: var(--cm-fg2);
}

.cm-graph-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.cm-graph-controls-label {
  font-size: 0.75rem;
  font-weight: 900;
  color: rgb(100 116 139);
}

.dark .cm-graph-controls-label {
  color: rgb(148 163 184);
}

/* Segmented control */
.cm-seg {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.15rem;
  border-radius: 999px;
  border: 1px solid var(--cm-border);
  background: var(--cm-bg2);
}

.cm-seg-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 900;
  color: var(--cm-fg2);
  background: transparent;
  white-space: nowrap;
}

.cm-seg-btn:hover {
  background: rgba(15, 23, 42, 0.06);
}

.dark .cm-seg-btn:hover {
  background: rgba(148, 163, 184, 0.14);
}

.cm-seg-btn.is-active {
  background: var(--cm-bg);
  color: var(--cm-fg);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
}

.dark .cm-seg-btn.is-active {
  background: rgba(2, 6, 23, 0.92);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
}

/* Graph canvas scrollbars */
.cm-graph-canvas {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.cm-graph-canvas::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.cm-graph-canvas::-webkit-scrollbar-thumb {
  border-radius: 9999px;
  border: 3px solid transparent;
  background-clip: content-box;
  background: rgba(15, 23, 42, 0.20);
}

.cm-graph-canvas::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 23, 42, 0.28);
}

.dark .cm-graph-canvas::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.20);
}

.dark .cm-graph-canvas::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.28);
}

/* Legend */
.cm-graph-legend {
  color: var(--cm-fg2);
  font-size: 0.75rem;
  font-weight: 700;
}

.cm-graph-legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.9rem;
}

.cm-graph-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.cm-graph-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid currentColor;
}

.cm-dot-active { color: #1e40af; }   /* blue */
.cm-dot-stale { color: #d97706; }    /* amber */
.cm-dot-error { color: #dc2626; }    /* red */
.cm-dot-missing { color: #7c3aed; }  /* purple */

.cm-graph-legend-note {
  margin-top: 0.25rem;
  color: var(--cm-fg2);
  font-weight: 650;
}
/* ---- End: patches.v21.css ---- */

/* ---- Begin: patches.v22.css ---- */
/* =====================================================================
   GetCalcMaster — patches.v22
   Tier: Lab UX parity
   - Global inline validation styles for .cm-field
   - Presets + Results Inspector rail polish
   ===================================================================== */

/* Field-level invalid state (global for labs) */
.cm-field.cm-invalid,
.cm-base-input.cm-invalid,
textarea.cm-invalid,
select.cm-invalid,
input.cm-invalid {
    border-color: rgb(251 113 133) !important; /* rose-400 */
    box-shadow: 0 0 0 2px rgba(244, 63, 94, 0.18) !important; /* rose-500 */
}

.dark .cm-field.cm-invalid,
.dark .cm-base-input.cm-invalid,
.dark textarea.cm-invalid,
.dark select.cm-invalid,
.dark input.cm-invalid {
    border-color: rgba(251, 113, 133, 0.70) !important;
    box-shadow: 0 0 0 2px rgba(244, 63, 94, 0.22) !important;
}

.cm-field-error {
    margin-top: 0.35rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: rgb(225 29 72); /* rose-600 */
}

.dark .cm-field-error {
    color: rgb(251 113 133); /* rose-400 */
}

/* Small keycap styling used in lab rail */
.cm-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 0.5rem;
    border: 1px solid rgb(226 232 240);
    background: rgb(248 250 252);
    font-size: 0.75rem;
    font-weight: 900;
    color: rgb(51 65 85);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
}

.dark .cm-kbd {
    border-color: rgb(30 41 59);
    background: rgba(15, 23, 42, 0.35);
    color: rgb(226 232 240);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

/* Inspector canvas */
.cm-inspector-canvas {
    width: 100%;
    border-radius: 0.75rem;
    border: 1px solid rgb(226 232 240);
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.9), rgba(255, 255, 255, 0.9));
}

.dark .cm-inspector-canvas {
    border-color: rgb(30 41 59);
    background: rgba(15, 23, 42, 0.25);
}

/* =====================================================================
   Admin — Monetization surfaces sidebar
   ===================================================================== */

.cm-admin-monet-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

@media (min-width: 1024px) {
    .cm-admin-monet-grid {
        grid-template-columns: 260px 1fr;
        align-items: start;
    }
}

.cm-admin-monet-nav {
    position: relative;
}

@media (min-width: 1024px) {
    .cm-admin-monet-nav {
        position: sticky;
        top: 16px;
        max-height: calc(100vh - 32px);
        overflow: auto;
        padding-right: 6px;
    }
}

.cm-admin-nav-group-title {
    cursor: pointer;
    user-select: none;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgb(100 116 139);
    padding: 4px 4px;
    list-style: none;
}

.cm-admin-nav-group-title::-webkit-details-marker {
    display: none;
}

.cm-admin-nav-group-title:before {
    content: "▸";
    display: inline-block;
    margin-right: 6px;
    transform: rotate(0deg);
    transition: transform 0.15s ease;
    color: rgb(148 163 184);
}

.cm-admin-nav-group[open] > .cm-admin-nav-group-title:before {
    transform: rotate(90deg);
}

.cm-admin-nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-size: 0.9rem;
    font-weight: 800;
    color: rgb(51 65 85);
    background: transparent;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    text-decoration: none;
}

.cm-admin-nav-item .truncate {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cm-admin-nav-item:hover {
    background: rgb(248 250 252);
    border-color: rgb(226 232 240);
    color: rgb(15 23 42);
}

.cm-admin-nav-item-active {
    background: rgb(15 23 42);
    border-color: rgb(15 23 42);
    color: #fff;
}

.cm-admin-nav-item-active:hover {
    background: rgb(15 23 42);
    border-color: rgb(15 23 42);
    color: #fff;
}

.cm-admin-nav-badge {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.1rem;
    height: 1.35rem;
    padding: 0 9px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 900;
    border: 1px solid rgb(226 232 240);
    background: rgb(248 250 252);
    color: rgb(71 85 105);
}

.cm-admin-nav-badge.on {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.10);
    color: rgb(6 95 70);
}

.cm-admin-nav-badge.off {
    border-color: rgba(148, 163, 184, 0.6);
    background: rgba(148, 163, 184, 0.12);
    color: rgb(51 65 85);
}

.dark .cm-admin-nav-group-title {
    color: rgb(148 163 184);
}

.dark .cm-admin-nav-group-title:before {
    color: rgb(100 116 139);
}

.dark .cm-admin-nav-item {
    color: rgb(226 232 240);
}

.dark .cm-admin-nav-item:hover {
    background: rgba(15, 23, 42, 0.5);
    border-color: rgba(30, 41, 59, 0.9);
    color: #fff;
}

.dark .cm-admin-nav-item-active {
    background: rgba(226, 232, 240, 0.10);
    border-color: rgba(226, 232, 240, 0.18);
    color: #fff;
}

.dark .cm-admin-nav-item-active:hover {
    background: rgba(226, 232, 240, 0.10);
    border-color: rgba(226, 232, 240, 0.18);
    color: #fff;
}

.dark .cm-admin-nav-badge {
    border-color: rgba(30, 41, 59, 0.9);
    background: rgba(2, 6, 23, 0.35);
    color: rgb(203 213 225);
}

.dark .cm-admin-nav-badge.on {
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.14);
    color: rgb(110 231 183);
}

.dark .cm-admin-nav-badge.off {
    border-color: rgba(100, 116, 139, 0.9);
    background: rgba(100, 116, 139, 0.20);
    color: rgb(226 232 240);
}
/* ---- End: patches.v22.css ---- */

/* ---- Begin: patches.v23.css ---- */
/* =====================================================================
   GetCalcMaster — patches.v23
   Tier: UI polish + accessibility

   Goals
   - Make the UI feel more “premium” without changing the layout grammar.
   - Improve perceived depth (subtle aurora background + richer shadows).
   - Add motion/contrast accessibility guards.

   Notes
   - Loaded after tailwind.css and patches.v17–v22.
   - Safe overrides only (no structural/layout breaking changes).
   ===================================================================== */

:root {
    /* Aurora palette (subtle, not neon) */
    --cm-aurora-a: 99 102 241;  /* indigo-500 */
    --cm-aurora-b: 236 72 153;  /* pink-500 */
    --cm-aurora-c: 14 165 233;  /* sky-500 */
}

/* ---------------------------------------------------------------------
   Premium background (very subtle)
   --------------------------------------------------------------------- */

body {
    background:
        radial-gradient(1200px circle at 12% -10%, rgba(var(--cm-aurora-a) / 0.12), transparent 55%),
        radial-gradient(1000px circle at 88% 0%, rgba(var(--cm-aurora-b) / 0.10), transparent 55%),
        radial-gradient(900px circle at 50% 110%, rgba(var(--cm-aurora-c) / 0.08), transparent 60%),
        #ffffff;
}

.dark body {
    background:
        radial-gradient(1200px circle at 12% -10%, rgba(var(--cm-aurora-a) / 0.18), transparent 58%),
        radial-gradient(1000px circle at 88% 0%, rgba(var(--cm-aurora-b) / 0.14), transparent 60%),
        radial-gradient(900px circle at 50% 110%, rgba(var(--cm-aurora-c) / 0.12), transparent 62%),
        #020617; /* slate-950-ish */
}

/* ---------------------------------------------------------------------
   Depth polish (cards + primary buttons)
   --------------------------------------------------------------------- */

.cm-card {
    box-shadow:
        0 1px 0 rgba(15, 23, 42, 0.04),
        0 18px 30px rgba(15, 23, 42, 0.06);
}

.dark .cm-card {
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.04),
        0 18px 30px rgba(0, 0, 0, 0.40);
}

/* Primary button: keep the same “ink” language, add subtle gradient. */
.cm-btn {
    background-image: linear-gradient(135deg, rgb(15 23 42), rgb(30 41 59));
}

.cm-btn:hover {
    background-image: linear-gradient(135deg, rgb(15 23 42), rgb(51 65 85));
}

.dark .cm-btn {
    background-image: linear-gradient(135deg, rgb(241 245 249), rgb(226 232 240));
}

.dark .cm-btn:hover {
    background-image: linear-gradient(135deg, rgb(248 250 252), rgb(226 232 240));
}

/* Make focus states a touch clearer on high DPI screens */
.cm-btn:focus-visible,
.cm-btn-lite:focus-visible,
.cm-chip:focus-visible,
.cm-nav-link:focus-visible,
.cm-key:focus-visible,
.cm-field:focus-visible,
.cm-base-input:focus-visible {
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.35);
}

.dark .cm-btn:focus-visible,
.dark .cm-btn-lite:focus-visible,
.dark .cm-chip:focus-visible,
.dark .cm-nav-link:focus-visible,
.dark .cm-key:focus-visible,
.dark .cm-field:focus-visible,
.dark .cm-base-input:focus-visible {
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.28);
}

/* ---------------------------------------------------------------------
   Details/accordion summary helper (used by CAS builder + other labs)
   --------------------------------------------------------------------- */

.cm-details {
    border-radius: 1rem;
    border: 1px solid rgb(226 232 240);
    background: rgba(255, 255, 255, 0.65);
}

.dark .cm-details {
    border-color: rgb(30 41 59);
    background: rgba(2, 6, 23, 0.35);
}

.cm-details > summary {
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.cm-details > summary::-webkit-details-marker {
    display: none;
}

.cm-details > summary .cm-details-caret {
    transition: transform 0.15s ease;
}

.cm-details[open] > summary .cm-details-caret {
    transform: rotate(90deg);
}

/* ---------------------------------------------------------------------
   Accessibility
   --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

@media (prefers-contrast: more) {
    .cm-card,
    .cm-details {
        border-color: rgb(100 116 139) !important; /* slate-500 */
    }

    .dark .cm-card,
    .dark .cm-details {
        border-color: rgb(148 163 184) !important; /* slate-400 */
    }

    .cm-chip,
    .cm-btn-lite,
    .cm-key {
        border-color: rgb(100 116 139) !important;
    }

    .dark .cm-chip,
    .dark .cm-btn-lite,
    .dark .cm-key {
        border-color: rgb(148 163 184) !important;
    }
}
/* ---- End: patches.v23.css ---- */

/* ---- Begin: patches.v24.css ---- */
/* =====================================================================
   GetCalcMaster — patches.v24
   Tier: Media-rich notebooks + report polish

   Adds
   - MarkdownLite images + figure captions
   - Better image sizing in Notebook + Presenter + exports
   ===================================================================== */

/* MarkdownLite images / figures */
.cm-md-fig {
    margin: 14px 0;
}

.cm-md-img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 14px;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: rgba(248, 250, 252, 0.95);
    box-shadow: 0 10px 18px rgba(15, 23, 42, 0.08);
}

.dark .cm-md-img {
    border-color: rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.35);
    box-shadow: 0 12px 22px rgba(0, 0, 0, 0.45);
}

.cm-md-cap {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 800;
    color: rgb(71 85 105);
}

.dark .cm-md-cap {
    color: rgb(148 163 184);
}

/* Inline images (rare, but safe) */
.cm-md-img-inline {
    display: inline-block;
    max-width: 100%;
    height: auto;
    vertical-align: middle;
    border-radius: 10px;
    border: 1px solid rgba(15, 23, 42, 0.10);
}

.dark .cm-md-img-inline {
    border-color: rgba(148, 163, 184, 0.18);
}
/* ---- End: patches.v24.css ---- */

/* ---- Begin: patches.v25.css ---- */
/* =====================================================================
   GetCalcMaster — patches.v25
   Tier: Lab layout polish (sponsor placement)

   Fixes
   - Prevent lab sponsor blocks from rendering underneath the sticky right rail
   - Remove the large empty "gap" created by CSS grid row coupling when the
     rail is taller than the main lab content
   ===================================================================== */

/*
   Implementation notes
   - Lab pages add:  .cm-calc-grid.cm-lab-grid
   - They wrap main + sponsor in: .cm-lab-col
   - On mobile, we flatten the wrapper (display: contents) so we can keep the
     reading order: main → rail → sponsor.
   - On md+, the wrapper becomes a vertical flex column so sponsor stays
     directly under the main lab (independent of rail height).
*/

.cm-lab-grid .cm-lab-col {
    display: contents;
}

.cm-lab-grid .cm-lab-main {
    order: 1;
}

.cm-lab-grid .cm-lab-rail {
    order: 2;
}

.cm-lab-grid .cm-lab-sponsor {
    order: 3;
    min-width: 0;
}

@media (min-width: 768px) {
    .cm-lab-grid .cm-lab-col {
        display: flex;
        flex-direction: column;
        gap: 16px;
        min-width: 0;
    }
}


/* =====================================================================
   Notebook — Danger-lite button (Reset)
   - Makes destructive actions visually distinct while preserving layout
   ===================================================================== */

.cm-btn-danger-lite {
    border-color: var(--color-rose-200);
    color: var(--color-rose-700);
}

.cm-btn-danger-lite:hover {
    background-color: var(--color-rose-50);
}

.cm-btn-danger-lite:focus-visible {
    --tw-ring-color: var(--color-rose-700);
}

@media (prefers-color-scheme: dark) {
    .cm-btn-danger-lite {
        border-color: var(--color-rose-900);
        color: var(--color-rose-300);
    }

    .cm-btn-danger-lite:hover {
        background-color: rgba(136, 19, 55, 0.25);
    }
}
/* ---- End: patches.v25.css ---- */

/* ---- Begin: patches.v26.css ---- */
/* =====================================================================
   GetCalcMaster — patches.v26
   Tier: Programmer Calculator UI polish

   Fixes
   - Show full binary (BIN) representation without truncation by
     rendering BIN as a wrapping textarea with monospace styling.
   ===================================================================== */

/* Programmer Calculator — BIN row */
.cm-base-bin {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 12px;
    line-height: 1.2;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
    resize: none;
}

.cm-base-row[data-cm-base="BIN"] {
    align-items: flex-start;
}

.cm-base-row[data-cm-base="BIN"] .cm-base-label {
    padding-top: 2px;
}

/* =====================================================================
   Converter — Quick pick chips + unit pills
   Tier: UX polish + clarity

   Goals
   - Category chips look clickable + show active state
   - Unit pills highlight FROM vs TO clearly
   - Stage toggle is a compact pill that can be clicked to switch
   ===================================================================== */

/* Category chips */
.cv-cat {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.36rem 0.68rem;
    border-radius: 999px;
    border: 1px solid rgb(226 232 240);
    background: rgb(248 250 252);
    color: rgb(15 23 42);
    font-size: 0.86rem;
    font-weight: 900;
    line-height: 1;
    user-select: none;
    white-space: nowrap;
    transition: transform .12s ease, background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.cv-cat:hover {
    background: rgb(241 245 249);
}

.cv-cat:active {
    transform: scale(.99);
}

.cv-cat:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, .9);
}

.cv-cat.active {
    background: rgb(15 23 42);
    border-color: rgba(15, 23, 42, .22);
    color: rgb(248 250 252);
}

.dark .cv-cat {
    border-color: rgb(30 41 59);
    background: rgba(15, 23, 42, .40);
    color: rgb(226 232 240);
}

.dark .cv-cat:hover {
    background: rgba(15, 23, 42, .60);
}

.dark .cv-cat.active {
    background: rgb(248 250 252);
    border-color: rgba(148, 163, 184, .35);
    color: rgb(15 23 42);
}

/* Unit pills */
.cv-unit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.42rem;
    padding: 0.44rem 0.68rem;
    border-radius: 999px;
    border: 1px solid rgb(226 232 240);
    background: rgb(255 255 255);
    color: rgb(15 23 42);
    font-size: 0.92rem;
    font-weight: 950;
    font-variant-numeric: tabular-nums;
    user-select: none;
    transition: transform .12s ease, background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.cv-unit:hover {
    background: rgb(248 250 252);
}

.cv-unit:active {
    transform: scale(.99);
}

.cv-unit:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, .9);
}

/* Selected states */
.cv-unit.is-from {
    background: rgb(15 23 42);
    border-color: rgba(15, 23, 42, .22);
    color: rgb(248 250 252);
}

.cv-unit.is-to {
    background: rgba(224, 231, 255, .9);
    border-color: rgba(79, 70, 229, .25);
    color: rgb(15 23 42);
}

/* Same unit for both FROM + TO */
.cv-unit.is-from.is-to {
    background: linear-gradient(90deg, rgb(15 23 42), rgb(79 70 229));
    border-color: rgba(15, 23, 42, .18);
    color: rgb(248 250 252);
}

.dark .cv-unit {
    border-color: rgb(30 41 59);
    background: rgba(15, 23, 42, .40);
    color: rgb(226 232 240);
}

.dark .cv-unit:hover {
    background: rgba(15, 23, 42, .62);
}

.dark .cv-unit.is-from {
    background: rgb(248 250 252);
    border-color: rgba(148, 163, 184, .35);
    color: rgb(15 23 42);
}

.dark .cv-unit.is-to {
    background: rgba(129, 140, 248, .20);
    border-color: rgba(129, 140, 248, .32);
    color: rgb(248 250 252);
}

.dark .cv-unit.is-from.is-to {
    background: linear-gradient(90deg, rgb(248 250 252), rgba(129, 140, 248, .45));
    border-color: rgba(148, 163, 184, .30);
    color: rgb(15 23 42);
}

/* Small FROM/TO badges inside the pill */
.cv-unit-badge {
    font-size: 0.64rem;
    font-weight: 950;
    padding: 0.12rem 0.40rem;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, .18);
    background: rgba(15, 23, 42, .06);
    letter-spacing: .06em;
    text-transform: uppercase;
    line-height: 1;
}

.cv-unit.is-from .cv-unit-badge-from {
    border-color: rgba(255, 255, 255, .28);
    background: rgba(255, 255, 255, .16);
    color: rgb(255 255 255);
}

.cv-unit-badge-to {
    border-color: rgba(79, 70, 229, .25);
    background: rgba(79, 70, 229, .12);
    color: rgb(67 56 202);
}

.cv-unit.is-to .cv-unit-badge-to {
    border-color: rgba(79, 70, 229, .25);
    background: rgba(79, 70, 229, .12);
    color: rgb(67 56 202);
}

.cv-unit.is-from.is-to .cv-unit-badge-to {
    border-color: rgba(255, 255, 255, .28);
    background: rgba(255, 255, 255, .16);
    color: rgb(255 255 255);
}

.dark .cv-unit-badge-to {
    border-color: rgba(129, 140, 248, .35);
    background: rgba(129, 140, 248, .22);
    color: rgb(226 232 240);
}

/* Stage toggle pill */
.cv-stage {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.22rem 0.56rem;
    border-radius: 999px;
    border: 1px solid rgb(226 232 240);
    background: rgb(248 250 252);
    color: rgb(51 65 85);
    font-size: 0.72rem;
    font-weight: 950;
    letter-spacing: .06em;
    text-transform: uppercase;
    transition: transform .12s ease, background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.cv-stage:hover {
    background: rgb(241 245 249);
}

.cv-stage:active {
    transform: scale(.99);
}

.cv-stage:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, .9);
}

.cv-stage[data-stage="from"] {
    border-color: rgba(15, 23, 42, .22);
}

.cv-stage[data-stage="to"] {
    border-color: rgba(79, 70, 229, .25);
}

.dark .cv-stage {
    border-color: rgb(30 41 59);
    background: rgba(15, 23, 42, .40);
    color: rgb(226 232 240);
}

.dark .cv-stage:hover {
    background: rgba(15, 23, 42, .60);
}

.dark .cv-stage[data-stage="from"] {
    border-color: rgba(148, 163, 184, .35);
}

.dark .cv-stage[data-stage="to"] {
    border-color: rgba(129, 140, 248, .32);
}
/* ---- End: patches.v26.css ---- */
