/* Benefactory shell/interface overrides. */

/* HOME deployment marker stays after the dynamically inserted pre-module area. */
.benefactory-home-version {
  margin: 16px auto 0;
  padding: 4px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .05em;
  text-align: center;
  opacity: .65;
}

/* Restored non-sticky header, offset below the iOS status-area overlay. */
.topbar {
  --benefactory-topbar-row-height: 18px;
  min-height: 28px;
  margin-top: 36px;
  padding-top: 3px;
  padding-bottom: 7px;
  align-items: flex-end;
}

.brand {
  position: absolute;
  left: 50%;
  top: auto;
  bottom: 7px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 14px;
  line-height: var(--benefactory-topbar-row-height);
  font-weight: 400;
  letter-spacing: .01em;
  text-transform: uppercase;
}
.topbar-back-button,
.topbar-actions .version-button,
.topbar-actions .icon-button { height: var(--benefactory-topbar-row-height); min-height: var(--benefactory-topbar-row-height); }
.topbar-back-button { width: 42px; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--accent); font-family: var(--mono); font-size: 15px; font-weight: 500; line-height: 1; letter-spacing: 0; }
.topbar-actions .version-button { padding-top: 0; padding-bottom: 0; }
.topbar-actions .icon-button { font-size: 12px; }
.topbar-back-button:active { background: var(--panel); transform: scale(.98); }
.topbar-actions { margin-left: auto; }
.module-grid .module-card { height: var(--module-card-height, 60px); min-height: 0; max-height: var(--module-card-height, 60px); box-sizing: border-box; padding: 7px 8px; overflow: hidden; }
.module-card strong { font-weight: 400; }
.module-grid .module-card:not(.pre-module-card) { display: grid; grid-template-columns: 18px minmax(0, 1fr); grid-template-rows: auto; align-items: start; align-content: center; justify-content: initial; column-gap: 8px; row-gap: 0; }
.module-grid .module-card:not(.pre-module-card) .module-icon { grid-column: 1; grid-row: 1; margin-top: 1px; font-size: 18px; transform: translateX(3px); }
.module-grid .module-card:not(.pre-module-card) .graph-module-icon { font-family: "Segoe UI Symbol", "Segoe UI", sans-serif; font-variant-emoji: text; }
.module-grid .module-card:not(.pre-module-card) > span:last-child { grid-column: 2; grid-row: 1; min-width: 0; }
.module-grid .module-card:not(.pre-module-card) small { margin-top: 3px; }
.module-grid.module-slot-grid { grid-auto-rows: var(--module-card-height, 60px); }
.module-empty-slot { height: var(--module-card-height, 60px); min-height: 0; box-sizing: border-box; border: 1px dashed transparent; border-radius: 11px; pointer-events: none; transition: border-color .12s ease, background .12s ease; }
.module-grid.is-module-reordering .module-empty-slot { border-color: color-mix(in srgb, var(--accent) 28%, transparent); background: color-mix(in srgb, var(--accent) 4%, transparent); }
#view-root > .module-grid:not(.pre-module-grid) { touch-action: pan-y; }
.quick-note-screen { position: fixed; inset: 0; z-index: 100; box-sizing: border-box; padding: calc(env(safe-area-inset-top) + 14px) calc(env(safe-area-inset-right) + 14px) calc(env(safe-area-inset-bottom) + 14px) calc(env(safe-area-inset-left) + 14px); background: var(--bg); transform: translate3d(-100%, 0, 0); transition: transform .2s cubic-bezier(.2, .78, .22, 1); will-change: transform; pointer-events: none; overscroll-behavior: none; }
.quick-note-screen.is-open, .quick-note-screen.is-dragging { pointer-events: auto; }
.quick-note-screen.is-dragging { transition: none; }
.quick-note-input { display: block; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 0; outline: 0; resize: none; overflow: hidden; background: transparent; color: var(--body-text); caret-color: var(--accent); font-family: var(--mono); font-size: 16px; line-height: 1.38; letter-spacing: 0; white-space: pre-wrap; overflow-wrap: anywhere; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
.quick-note-input::placeholder { color: color-mix(in srgb, var(--standard) 42%, var(--bg) 58%); }
body.quick-note-open { overflow: hidden; }
.module-card-height-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.module-card-height-control input[type="range"] { width: 118px; accent-color: var(--accent); }
.module-card-height-control code { min-width: 38px; color: var(--accent); font-family: var(--mono); font-size: 9px; text-align: right; font-variant-numeric: tabular-nums; }
body.color-mode .color-intro, body.color-mode .color-hint, body.color-mode .color-rows, body.color-mode .color-result { width: min(100%, 650px); margin-left: auto; margin-right: auto; }
body.color-mode .color-row { position: relative; display: block; min-width: 0; }
body.color-mode .color-row-label { position: absolute; top: 50%; left: -16px; width: 12px; transform: translateY(-50%); text-align: right; }
body.color-mode .color-swatches { width: 100%; }
.notes-composer textarea { min-height: 112px; }
.notes-feed { margin-top: 12px; }
.notes-feed-list { display: grid; gap: 7px; }
.saved-note { margin-top: 0; }
.saved-note-text { margin: 0; color: var(--body-text); font-size: 12px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.saved-note-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.saved-note-time { color: var(--muted); font-family: var(--mono); font-size: 8px; font-variant-numeric: tabular-nums; }
.saved-note-delete { min-height: 24px; padding: 3px 7px; border: 1px solid var(--line); border-radius: 7px; background: transparent; color: var(--muted); font-family: var(--mono); font-size: 8px; }
.saved-note-delete:active { background: var(--panel-2); }
.notes-empty { margin: 0; padding: 12px 1px; color: var(--muted); font-family: var(--mono); font-size: 9px; }

/* Shell-owned Home exit. Keep module-local back controls only when they navigate within a module. */
.page-head > .back-button[data-open="home"],
.atoms-home,
[data-bench-home],
[data-branch-home],
.brows-home,
.buuks-back,
.color-home,
.crate-back,
[data-debug-home],
.etymo-back,
.fungi-back,
.globe-home,
.human-home,
.lex-head [data-home],
.notes-toolbar [data-notes-home],
.pivot-back,
.solar-home,
.solar-failure-home,
.template-home,
.trail-back,
.vibes-back,
.xlr8-back {
  display: none !important;
}

/* Reclaim the header column/space previously reserved for those duplicate Home exits. */
.atoms-heading-row { grid-template-columns: minmax(0, 1fr) !important; }
.bench-head { grid-template-columns: minmax(0, 1fr) auto !important; }
.buuks-head { grid-template-columns: 1fr auto !important; }
.crate-head { grid-template-columns: minmax(0, 1fr) auto !important; }
.etymo-head { grid-template-columns: minmax(0, 1fr) auto !important; }
.fungi-head { grid-template-columns: minmax(0, 1fr) 44px !important; }
.globe-commandbar { grid-template-columns: minmax(54px, 1fr) auto !important; }
.human-bar { grid-template-columns: minmax(0, 1fr) auto 31px !important; }
.solar-module-head { grid-template-columns: minmax(0, 1fr) auto !important; }
.template-commandbar { grid-template-columns: minmax(0, 1fr) auto !important; }
.vibes-head { grid-template-columns: minmax(0, 1fr) 42px !important; }

/* One shell roofline for normal, sticky, and full-screen module surfaces. */
:root {
  --benefactory-shell-topbar-height: 28px;
  --benefactory-shell-bottom: calc(env(safe-area-inset-top) + var(--benefactory-shell-topbar-height) + 36px);
}

.app:has(.brows-shell) > .topbar,
body.color-mode .app > .topbar,
.app:has(.debug-shell) > .topbar,
.app:has(.lexicon) > .topbar,
body.atoms-mode .app > .topbar,
body.xlr8-mode .app > .topbar {
  display: flex !important;
}

/* BROWS is fixed and otherwise sits above the shell. */
.app:has(.brows-shell) > .topbar {
  z-index: 100 !important;
}

.brows-shell {
  top: var(--benefactory-shell-bottom) !important;
  height: calc(100dvh - var(--benefactory-shell-bottom)) !important;
}

.brows-bar {
  grid-template-columns: minmax(0, 1fr) 34px !important;
  padding-top: 4px !important;
}

/* COLOR, ATOMS, and XLR8R own viewport-sized work areas, so reserve the shell explicitly. */
body.color-mode .view-root.color-active,
body.atoms-mode .view-root.atoms-active,
body.xlr8-mode .view-root.xlr8-active {
  height: calc(100dvh - var(--benefactory-shell-bottom)) !important;
}

body.color-mode .color-commandbar {
  grid-template-columns: minmax(0, 1fr) auto !important;
}

/* DEBUG previously removed the app safe-area padding; restore it and keep its sticky header below the shell. */
html body .app:has(.debug-shell) {
  padding-top: env(safe-area-inset-top) !important;
}

.debug-shell {
  min-height: calc(100dvh - var(--benefactory-shell-bottom)) !important;
}

.app .debug-head {
  top: var(--benefactory-shell-bottom) !important;
  grid-template-columns: minmax(0, 1fr) auto !important;
  padding-top: 4px !important;
}

/* Lexicon runtime CSS injects its own sticky offsets, so use stronger shell-owned offsets here. */
.lexicon {
  min-height: calc(100dvh - var(--benefactory-shell-bottom)) !important;
}

.app .lexicon .lex-head {
  top: var(--benefactory-shell-bottom) !important;
  padding-top: 8px !important;
}

.app .lexicon .lex-tabs {
  top: calc(var(--benefactory-shell-bottom) + var(--lex-head-h, 44px)) !important;
}

.app .lexicon .lex-ref-tools {
  top: calc(var(--benefactory-shell-bottom) + var(--lex-head-h, 44px) + var(--lex-tabs-h, 32px)) !important;
}

/* Module-owned sticky rails should dock under Benefactory instead of climbing over it. */
.app .crate-head,
.app .fungi-head,
.app .solar-controls,
.app .template-tabs {
  top: var(--benefactory-shell-bottom) !important;
}

/* XLR8R nested full-screen tools remain inside Benefactory rather than covering its shell. */
.xlr8-deck-shell,
.break-shell {
  top: var(--benefactory-shell-bottom) !important;
  bottom: 0 !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}

.xlr8-deck-header {
  padding-top: 7px !important;
}

.xlr8-deck-shell .xlr8-deck-excel-stage {
  height: 100% !important;
  min-height: 0 !important;
}

/* On iOS/WebKit, reserve the same safe-area height inside the non-sticky
   header, without any sticky offsets or scroll-triggered positioning. */
@supports (-webkit-touch-callout: none) {
    .app {
      padding-top: 0;
    }

    .topbar {
      min-height: calc(env(safe-area-inset-top) + 28px);
      padding-top: calc(env(safe-area-inset-top) + 3px);
      background: var(--bg);
    }

    /* DEBUG previously reinstates .app's safe-area padding. */
    html body .app:has(.debug-shell) {
      padding-top: 0 !important;
    }
}
