﻿      /* Mobile-first notebook calculator layout */
      :root {
        color-scheme: dark light;
        --bg: #0f1419;
        --surface: #161d26;
        --border: #2a3544;
        --text: #e6edf3;
        --muted: #8b9cb3;
        --accent: #3d8bfd;
        --error: #f85149;
        --success: #3fb950;
        --gutter-w: 2.5rem;
        --results-w: clamp(4.5rem, 26%, 7rem);
        --lh: 1.45;
        --editor-fs: 16px;
        --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
        --safe-b: env(safe-area-inset-bottom, 0px);
        --safe-t: env(safe-area-inset-top, 0px);
        --cell-pad-y: 0.45rem;
        --app-max-w: 430px;
        --sh-comment: var(--muted);
        --sh-section: var(--accent);
        --sh-var: #79c0ff;
        --sh-ref: #d2a8ff;
        --sh-fn: #ffa657;
        --sh-kw: #e3b341;
        --sh-num: var(--success);
        --sh-op: var(--muted);
        --sh-name: var(--text);
      }

      @media (prefers-color-scheme: light) {
        :root {
          --bg: #f6f8fa;
          --surface: #ffffff;
          --border: #d8dee4;
          --text: #1f2328;
          --muted: #57606a;
          --accent: #0969da;
          --error: #cf222e;
          --success: #1a7f37;
          --sh-var: #0550ae;
          --sh-ref: #8250df;
          --sh-fn: #bc4c00;
          --sh-kw: #cf222e;
        }
      }

      *,
      *::before,
      *::after {
        box-sizing: border-box;
      }

      html,
      body {
        margin: 0;
        min-height: 100%;
      }

      html {
        height: 100%;
        overflow: hidden;
        background: var(--bg);
      }

      body {
        height: 100%;
        overflow: hidden;
        display: flex;
        justify-content: center;
        background: transparent;
      }

      .app-frame {
        position: relative;
        width: 100%;
        max-width: var(--app-max-w);
        height: 100%;
        max-height: 100dvh;
        min-height: 100dvh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        overscroll-behavior: none;
        background: var(--bg);
        color: var(--text);
        font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
        font-size: 16px;
        line-height: var(--lh);
      }

      @media (min-width: 480px) {
        .app-frame {
          border-inline: 1px solid var(--border);
          box-shadow: 0 0 56px rgba(0, 0, 0, 0.38);
        }
      }

      /* One-screen shell: page does not scroll; only notebook columns scroll */

      .app-header {
        padding: calc(0.45rem + var(--safe-t)) 0.65rem 0.35rem;
        max-width: none;
        margin: 0;
        position: relative;
        z-index: 20;
      }

      .app-header-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.65rem;
      }

      .back-home {
        flex: 0 0 auto;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--muted);
        text-decoration: none;
        white-space: nowrap;
        padding-right: 0.55rem;
        margin-right: 0.15rem;
        border-right: 1px solid var(--border);
      }

      .back-home:hover {
        color: var(--accent);
        text-decoration: underline;
      }

      .app-header-actions {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        gap: 0.4rem;
      }

      .header-dock-btn {
        flex: 0 0 auto;
        font-size: 0.82rem !important;
        font-weight: 600 !important;
        padding: 0.34rem 0.62rem !important;
        min-height: 2.35rem !important;
        line-height: 1.15 !important;
      }

      .header-dock-btn.long {
        letter-spacing: 0.02em;
      }

      .tb-btn-block {
        display: block;
        width: 100%;
      }

      /* Full-screen menu stack + Insert tool sheet */
      .fullscreen-layer {
        position: absolute;
        inset: 0;
        z-index: 52;
        flex-direction: column;
        background: var(--bg);
        display: none;
        padding-top: calc(0.25rem + var(--safe-t));
      }

      .fullscreen-layer.is-open {
        display: flex;
      }

      .fullscreen-layer--tips {
        z-index: 53;
      }

      .fullscreen-layer--output {
        z-index: 54;
      }

      .fullscreen-layer--tree {
        z-index: 54;
      }

      .fullscreen-layer-head {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.35rem 0.75rem 0.55rem;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
      }

      .fullscreen-layer-back {
        flex: 0 0 auto;
        font-weight: 600;
        padding: 0.32rem 0.52rem !important;
        min-height: 2.4rem !important;
      }

      .fullscreen-layer-title {
        flex: 1;
        font-weight: 600;
        font-size: 1.02rem;
        margin: 0;
      }

      .fullscreen-layer-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding: 0.72rem 1rem calc(0.85rem + var(--safe-b));
      }

      .fullscreen-nav-list {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.5rem;
      }

      .fullscreen-nav-list .tb-btn {
        min-height: 2.85rem !important;
        justify-content: center;
      }

      /* Insert sheet: anchored to bottom everywhere (consistent with draggable keypad) */
      .insert-overlay {
        position: absolute;
        inset: 0;
        z-index: 58;
        display: none;
        align-items: flex-end;
        justify-content: center;
        padding: 0.4rem 0.35rem calc(3rem + var(--safe-b));
      }

      .insert-overlay.is-open {
        display: flex;
      }

      .section-gutter-menu {
        position: absolute;
        inset: 0;
        z-index: 59;
        display: none;
        align-items: flex-end;
        justify-content: center;
        padding: 0.4rem 0.35rem calc(3rem + var(--safe-b));
      }

      .section-gutter-menu.is-open {
        display: flex;
      }

      .section-gutter-menu-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.42);
        border: none;
        padding: 0;
        margin: 0;
        cursor: default;
      }

      .section-gutter-menu-panel {
        position: relative;
        z-index: 1;
        width: min(100%, calc(var(--app-max-w, 430px) - 0.5rem));
        margin: 0 auto;
        padding: 0.65rem 0.78rem calc(0.78rem + var(--safe-b));
        border-radius: 14px;
        border: 1px solid var(--border);
        background: var(--surface);
        box-shadow: 0 -8px 36px rgba(0, 0, 0, 0.28);
        max-height: min(78dvh, calc(100% - 3.25rem - var(--safe-b)));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
      }

      .section-gutter-menu-body {
        display: flex;
        flex-direction: column;
        gap: 0.55rem;
      }

      .insert-overlay-backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.42);
        border: none;
        padding: 0;
        margin: 0;
        cursor: default;
      }

      .insert-overlay-panel {
        position: relative;
        z-index: 1;
        width: min(100%, calc(var(--app-max-w, 430px) - 0.5rem));
        margin: 0 auto;
        padding: 0.65rem 0.78rem calc(0.78rem + var(--safe-b));
        border-radius: 14px;
        border: 1px solid var(--border);
        background: var(--surface);
        box-shadow: 0 -8px 36px rgba(0, 0, 0, 0.28);
        max-height: min(92dvh, calc(100% - 3.25rem - var(--safe-b)));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
      }

      .insert-overlay-panel-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.65rem;
        margin-bottom: 0.45rem;
        padding-bottom: 0.42rem;
        border-bottom: 1px solid var(--border);
      }

      .insert-overlay-panel-head span {
        font-weight: 600;
        font-size: 0.95rem;
        font-family: var(--font-mono);
      }

      .insert-overlay-panel-head .tb-btn {
        min-width: 2.35rem !important;
        flex-shrink: 0;
      }

      .insert-overlay-panel-body {
        display: flex;
        flex-direction: column;
        gap: 0.68rem;
      }

      .insert-overlay-section-title {
        margin: 0 0 0.32rem;
        font-size: 0.68rem;
        font-weight: 600;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: var(--muted);
      }

      .insert-overlay-grid {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.36rem;
      }

      .insert-overlay-grid.cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
      }

      .insert-overlay-grid.cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .insert-overlay-grid .tb-btn {
        min-height: 2.5rem !important;
        font-size: 0.8rem !important;
        padding: 0.26rem 0.3rem !important;
        line-height: 1.1 !important;
      }

      .insert-overlay-grid .tb-btn.insert-accent {
        border-color: color-mix(in srgb, var(--accent), transparent 35%);
        color: var(--accent);
        font-weight: 600;
      }

      .insert-overlay-empty-hint {
        margin: 0;
        font-size: 0.78rem;
        color: var(--muted);
        line-height: 1.35;
      }

      .panel-menu-hint {
        font-size: 0.74rem;
        color: var(--muted);
        line-height: 1.35;
        margin: -0.2rem 0 0.7rem;
      }

      .menu-field {
        margin-bottom: 0.92rem;
      }

      .menu-field-head {
        display: block;
        font-size: 0.74rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--muted);
        margin-bottom: 0.28rem;
      }

      #result-decimals-select.menu-decimals-select {
        width: 100%;
        min-height: 2.65rem;
        padding: 0.35rem 0.52rem;
        border-radius: 10px;
        border: 1px solid var(--border);
        background: var(--bg);
        color: var(--text);
        font-size: 1rem;
        font-family: inherit;
      }

      .panel-help-dock-inner {
        font-size: 0.82rem;
        line-height: 1.43;
        color: var(--muted);
      }

      .panel-help-dock-inner h3 {
        font-size: 0.87rem;
        font-weight: 600;
        color: var(--text);
        margin: 0.8rem 0 0.3rem;
      }

      .panel-help-dock-inner h3:first-of-type {
        margin-top: 0;
      }

      .panel-help-dock-inner ul {
        margin: 0.2rem 0 0;
        padding-left: 1.1rem;
      }

      .panel-help-dock-inner code {
        background: color-mix(in srgb, var(--bg), var(--surface) 40%);
        padding: 0.06rem 0.26rem;
        border-radius: 4px;
        font-size: 0.93em;
        color: var(--text);
      }

      .app-title {
        flex: 1;
        min-width: 0;
        font-size: 1.15rem;
        font-weight: 600;
        margin: 0;
      }

      /**
       * Sheet picker row — only pills + actions (decimals & file operations live under Menu).
       */
      .sheet-chrome {
        flex: none;
        max-width: none;
        margin: 0;
        padding: 0 0.45rem calc(0.25rem + var(--safe-t, 0));
        display: flex;
        align-items: stretch;
        gap: 0.42rem;
        min-height: 2.35rem;
        position: relative;
        z-index: 19;
      }

      #sheet-host {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 0.45rem;
      }

      .workbook-bar-scroll {
        flex: 1 1 auto;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
      }

      .workbook-bar-scroll-inner {
        display: flex;
        align-items: center;
        flex-wrap: nowrap;
        gap: 0.32rem;
        padding: 2px 0;
        /* Wider than the viewport when needed — do NOT cap at 100% or the row won't scroll on iOS */
        width: max-content;
      }

      button.book-chip {
        flex: 0 0 auto;
        min-width: 1.85rem;
        max-width: 3.25rem;
        overflow: hidden;
        text-overflow: clip;
        white-space: nowrap;
        padding: 0.26rem 0.36rem !important;
        font-size: 0.82rem !important;
        font-weight: 600 !important;
        justify-content: center;
      }

      button.book-chip.is-active {
        border-color: var(--accent);
        box-shadow: 0 0 0 1px var(--accent);
      }

      .workbook-bar-actions {
        flex: 0 0 auto;
        display: flex;
        gap: 0.32rem;
        align-items: center;
      }

      .book-new-btn {
        min-width: 2.65rem !important;
        padding-left: 0.42rem !important;
        padding-right: 0.42rem !important;
        font-size: 1.15rem !important;
        line-height: 1 !important;
        font-weight: 600 !important;
      }

      .book-manage-btn {
        font-size: 0.78rem !important;
        padding: 0.28rem 0.48rem !important;
      }

      .dlg-book-rows {
        list-style: none;
        padding: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
        gap: 0.45rem;
        max-height: min(50vh, 18rem);
        overflow-y: auto;
        margin-bottom: 0.85rem;
        -webkit-overflow-scrolling: touch;
      }

      .dlg-book-row {
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.45rem 0.55rem;
        display: flex;
        align-items: center;
        gap: 0.4rem;
        flex-wrap: wrap;
      }

      .dlg-book-row.is-active {
        border-color: color-mix(in srgb, var(--accent), transparent 50%);
        box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent), transparent 60%);
      }

      .dlg-book-row:not(.is-active) {
        cursor: pointer;
      }

      .dlg-book-row-title-wrap {
        flex: 1 1 140px;
        min-width: 120px;
        display: flex;
        flex-direction: column;
        gap: 2px;
      }

      .dlg-book-row-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
        justify-content: flex-end;
      }

      .dlg-book-row-actions button {
        flex: none;
      }

      .dlg-book-meta {
        font-size: 0.72rem;
        color: var(--muted);
        margin-top: -0.1rem;
      }

      .app-main {
        flex: 1;
        min-height: 0;
        max-width: none;
        width: 100%;
        margin: 0;
        padding: 0 0.5rem calc(0.35rem + var(--safe-b));
        display: flex;
        flex-direction: column;
      }

      /* Three synced scroll columns fill remaining height (never grow the outer page). */
      .sheet {
        flex: 1;
        min-height: 0;
        width: 100%;
        display: grid;
        grid-template-columns: var(--gutter-w) 1fr var(--results-w);
        grid-template-rows: minmax(0, 1fr);
        height: auto !important;
        max-height: none !important;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--surface);
        overflow: hidden;
      }

      .sheet > .scroll-sync {
        min-width: 0;
        min-height: 0;
      }

      .scroll-sync {
        overflow: auto;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-gutter: stable;
      }
      .scroll-sync::-webkit-scrollbar {
        width: 0;
        height: 0;
      }


      .gutter-inner,
      .results-inner {
        display: flex;
        flex-direction: column;
        min-height: 100%;
      }

      .gutter {
        background: var(--bg);
        border-right: 1px solid var(--border);
        user-select: none;
        text-align: right;
        padding: var(--cell-pad-y) 0.25rem;
      }

      /* Must match .editor font metrics exactly or line numbers drift vertically */
      .gutter-line {
        font-family: var(--font-mono);
        font-size: var(--editor-fs);
        line-height: var(--lh);
        color: var(--muted);
        padding: 0 0.15rem;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        flex-shrink: 0;
        box-sizing: border-box;
        cursor: pointer;
        -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 25%, transparent);
      }

      .gutter-line.is-section {
        color: var(--accent);
      }

      @media (hover: hover) and (pointer: fine) {
        .gutter-line:hover {
          color: var(--accent);
        }
      }
      .editor-wrap {
        display: grid;
        width: 100%;
        min-height: 100%;
      }

      .editor-highlight,
      .editor-input,
      .editor-empty-hint {
        grid-area: 1 / 1;
        font-weight: 400;
        font-variant-ligatures: none;
      }

      .editor-highlight {
        z-index: 0;
        margin: 0;
        padding: var(--cell-pad-y) 0.5rem;
        border: none;
        font-family: var(--font-mono);
        font-size: var(--editor-fs);
        line-height: var(--lh);
        background: var(--surface);
        white-space: pre;
        overflow: hidden;
        overflow-wrap: normal;
        tab-size: 2;
        pointer-events: none;
        color: var(--text);
      }

      .editor-highlight code {
        font: inherit;
        white-space: inherit;
        tab-size: inherit;
      }

      .sh-comment {
        color: var(--sh-comment);
        font-style: italic;
      }
      .sh-section {
        color: var(--sh-section);
      }
      .sh-var {
        color: var(--sh-var);
      }
      .sh-ref {
        color: var(--sh-ref);
      }
      .sh-section-ref {
        color: var(--sh-section);
      }
      .sh-fn {
        color: var(--sh-fn);
      }
      .sh-kw {
        color: var(--sh-kw);
      }
      .sh-num {
        color: var(--sh-num);
      }
      .sh-op {
        color: var(--sh-op);
      }
      .sh-name {
        color: var(--sh-name);
      }

      .editor-empty-hint {
        z-index: 1;
        margin: 0;
        padding: var(--cell-pad-y) 0.5rem;
        box-sizing: border-box;
        pointer-events: none;
        user-select: none;
        color: var(--muted);
        font-family: var(--font-mono);
        font-size: var(--editor-fs);
        line-height: var(--lh);
      }

      .editor-input {
        z-index: 2;
        margin: 0;
        padding: var(--cell-pad-y) 0.5rem;
        border: none;
        outline: none;
        resize: none;
        display: block;
        width: 100%;
        box-sizing: border-box;
        font-family: var(--font-mono);
        font-size: var(--editor-fs);
        line-height: var(--lh);
        background: transparent;
        color: transparent;
        caret-color: var(--text);
        white-space: pre;
        overflow: hidden;
        overflow-wrap: normal;
        overflow-x: auto;
        tab-size: 2;
        -webkit-text-fill-color: transparent;
      }

      .editor-input::selection {
        background: color-mix(in srgb, var(--accent) 38%, transparent);
      }

      .results-inner.results {
        border-left: none;
        padding: var(--cell-pad-y) 0.35rem;
      }

      .results {
        display: flex;
        flex-direction: column;
        border-left: 1px solid var(--border);
        background: var(--bg);
        padding: var(--cell-pad-y) 0.35rem;
        font-family: var(--font-mono);
        font-size: var(--editor-fs);
      }

      .result-line {
        font-size: var(--editor-fs);
        line-height: var(--lh);
        display: flex;
        align-items: center;
        justify-content: flex-end;
        text-align: right;
        flex-shrink: 0;
        box-sizing: border-box;
        min-width: 0;
        max-width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: normal;
      }

      .result-line.ok-result {
        color: var(--success);
      }

      .result-error {
        color: var(--error);
        font-size: var(--editor-fs);
        line-height: var(--lh);
        justify-content: flex-start;
        text-align: left;
      }

      .result-empty {
        color: var(--muted);
      }

      .result-line.result-text {
        color: var(--sh-var);
      }

      .result-line.result-section {
        color: var(--sh-section);
        font-weight: 600;
        justify-content: flex-start;
        text-align: left;
      }

      #results-scroll.results-column-hit {
        cursor: default;
      }

      #results-scroll.results-column-hit .result-line.ok-result {
        cursor: pointer;
      }

      @media (hover: hover) and (pointer: fine) {
        #results-scroll.results-column-hit .result-line.ok-result:hover {
          background: color-mix(in srgb, var(--success) 12%, transparent);
        }
      }

      .output-sheet-hint {
        font-size: 0.76rem;
        color: var(--muted);
        line-height: 1.38;
        margin: 0 0 0.45rem;
      }

      .output-sheet-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
        margin-bottom: 0.55rem;
      }

      .output-sheet-textarea {
        width: 100%;
        flex: 1 1 auto;
        min-height: min(52vh, 22rem);
        margin: 0;
        padding: 0.5rem 0.55rem;
        border-radius: 10px;
        border: 1px solid var(--border);
        background: var(--bg);
        color: var(--text);
        font-family: var(--font-mono);
        font-size: 0.85rem;
        line-height: 1.42;
        resize: vertical;
        white-space: pre;
        overflow: auto;
        tab-size: 2;
      }

      .value-tree-pre {
        width: 100%;
        flex: 1 1 auto;
        min-height: min(52vh, 22rem);
        margin: 0;
        padding: 0.55rem 0.65rem;
        border-radius: 10px;
        border: 1px solid var(--border);
        background: var(--bg);
        color: var(--text);
        font-family: var(--font-mono);
        font-size: 0.82rem;
        line-height: 1.45;
        white-space: pre;
        overflow: auto;
        tab-size: 2;
      }

      /* Floating draggable keypad (same UX on phones and desktops) */
      .calc-bar.calc-toolbox {
        position: absolute;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        top: var(--toolbox-top, min(72vh, calc(100dvh - 9.5rem)));
        left: var(--toolbox-left, 50%);
        right: auto;
        bottom: auto;
        transform: translate(var(--toolbox-tx, -50%), var(--toolbox-ty, -50%));
        width: auto;
        max-width: min(calc(100% - 16px), 8.85rem);
        padding: 0.35rem 0.38rem 0.42rem;
        border-radius: 12px;
        border: 1px solid var(--border);
        box-shadow: 0 6px 28px rgba(0, 0, 0, 0.28);
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0.32rem;
        background: color-mix(in srgb, var(--surface) 94%, transparent);
        /* Above header/sheet chrome; below overlays (≤52+) and toast (60) */
        z-index: 35;
      }

      .calc-toolbox-handle {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-width: 0;
        min-height: 1.72rem;
        margin: 0;
        padding: 0.18rem 0.35rem;
        border: 1px dashed color-mix(in srgb, var(--border) 80%, var(--accent));
        border-radius: 8px;
        background: color-mix(in srgb, var(--bg) 80%, transparent);
        color: var(--muted);
        font-size: 0.85rem;
        line-height: 1;
        letter-spacing: -0.12em;
        cursor: grab;
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
      }

      .calc-toolbox-handle.is-dragging {
        opacity: 0.92;
      }

      .calc-toolbox .toolbar-inner {
        max-width: min(calc(100% - 16px), 8.85rem);
        margin-inline: auto;
        flex: 1;
        min-width: 0;
        flex-direction: column;
        align-items: stretch;
        overflow-x: visible;
        overflow-y: visible;
        gap: 0.28rem;
        padding-bottom: 0;
      }

      .calc-toolbox .toolbar-primary {
        flex-flow: row wrap;
        justify-content: center;
        gap: 0.28rem;
      }

      .calc-toolbox .toolbar-actions {
        flex-flow: row wrap;
        justify-content: center;
        gap: 0.28rem;
        border-inline-start: none;
        padding-inline-start: 0;
        margin-inline-start: 0;
        border-block-start: 1px solid color-mix(in srgb, var(--border), transparent 20%);
        padding-top: 0.32rem;
        margin-top: 0.06rem;
      }

      .toolbar-inner {
        display: flex;
        flex-flow: row nowrap;
        gap: 0.35rem;
        align-items: center;
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        padding-bottom: 2px;
      }

      .toolbar-primary {
        display: flex;
        flex-flow: row nowrap;
        gap: 0.35rem;
        align-items: center;
        flex: 0 0 auto;
      }

      .toolbar-actions {
        display: flex;
        flex-flow: row nowrap;
        gap: 0.35rem;
        align-items: center;
        flex: 0 0 auto;
        padding-inline-start: 0.35rem;
        margin-inline-start: 0.1rem;
        border-inline-start: 1px solid color-mix(in srgb, var(--border), transparent 15%);
      }


      .tb-btn {
        touch-action: manipulation;
        min-height: 2.5rem;
        min-width: 2.25rem;
        padding: 0.25rem 0.45rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        color: var(--text);
        font-size: 0.9rem;
        font-weight: 500;
        cursor: pointer;
      }

      .tb-btn:active {
        transform: scale(0.97);
      }

      @media (hover: hover) and (pointer: fine) {
        .tb-btn:hover {
          border-color: var(--accent);
          color: var(--accent);
        }
      }

      /* Toast */
      .toast {
        position: absolute;
        left: 50%;
        right: auto;
        top: calc(3.25rem + var(--safe-t));
        bottom: auto;
        transform: translateX(-50%);
        background: rgba(15, 20, 25, 0.92);
        color: #fff;
        padding: 0.55rem 0.85rem;
        border-radius: 10px;
        font-size: 0.85rem;
        max-width: min(92%, 24rem);
        text-align: center;
        z-index: 60;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.18s ease;
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
      }
      @media (prefers-color-scheme: light) {
        .toast {
          background: rgba(40, 44, 52, 0.92);
        }
      }
      .toast.show {
        opacity: 1;
      }

      /* Dialog */
      .app-dialog {
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--surface);
        color: var(--text);
        padding: 1rem;
        width: min(100%, 22rem);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
        z-index: 40;
      }
      .app-dialog::backdrop {
        background: rgba(0, 0, 0, 0.5);
      }
      .dlg-title {
        font-weight: 600;
        font-size: 0.95rem;
        margin: 0 0 0.35rem;
      }
      .dlg-hint {
        color: var(--muted);
        font-size: 0.78rem;
        line-height: 1.35;
        margin: 0 0 0.75rem;
      }
      .dlg-field {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
      }
      .dlg-field label {
        color: var(--muted);
        font-size: 0.85rem;
        min-width: 3.5rem;
      }
      .dlg-field input {
        flex: 1;
        min-height: 2.5rem;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: var(--bg);
        color: var(--text);
        font-family: var(--font-mono);
        font-size: 1rem;
        padding: 0 0.5rem;
      }
      .dlg-actions {
        display: flex;
        gap: 0.5rem;
        justify-content: flex-end;
        flex-wrap: wrap;
      }
      .dlg-actions .tb-btn {
        min-width: 5rem;
      }

      @media (min-width: 480px) {
        :root {
          --app-max-w: 860px;
        }

        html {
          background: color-mix(in srgb, var(--bg) 52%, #000);
        }
      }

