/* BrainWeave — the frame around every screen: side bar (desktop), rail (tablet), top bar + tab bar (phone). */

.app { min-height: 100dvh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.app[data-shell="out"] { display: block; }
.app[data-shell="out"] .side, .app[data-shell="out"] .topbar, .app[data-shell="out"] .tabbar { display: none; }

/* ───────── side bar ───────── */
.side { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: var(--s4); padding: var(--s5) var(--s3) var(--s3); background: var(--paper-sunk); border-right: 1px solid var(--line); overflow-y: auto; z-index: var(--z-nav); }
.brand { display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s2); min-height: 44px; text-decoration: none; color: var(--ink); border-radius: var(--r); }
.brand:hover { color: var(--ink); }
.brand .mark { width: 32px; height: 32px; flex: none; }
.brand .names { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand .word { font-family: var(--font-read); font-size: 1.3rem; font-weight: 600; letter-spacing: -0.015em; font-variation-settings: "opsz" 30; }
.brand .lib { font-size: var(--fs-xs); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .add { margin: 0 var(--s1); }
/* The side bar's Add a book steps back (shell.js sets .quiet) when the page shows a filled main button of its own, and
   always on a page for reading or writing (a note, a hub, a book, a page of writing). Written to win over any look's own
   side bar button. */
:root[data-theme] .side .btn.add.quiet { background: transparent; border: 1px solid color-mix(in srgb, currentColor 38%, transparent); color: inherit; box-shadow: none; text-shadow: none; }
:root[data-theme] .side .btn.add.quiet:hover { background: color-mix(in srgb, currentColor 12%, transparent); border-color: currentColor; color: inherit; box-shadow: none; }
.findbtn { display: flex; align-items: center; gap: var(--s2); min-height: var(--hit); margin: 0 var(--s1); padding: 0 var(--s3); border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-3); font-size: var(--fs-md); text-align: left; }
.findbtn:hover { border-color: var(--ink-2); color: var(--ink-2); }
.findbtn .grow { flex: 1; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: var(--s3) var(--s3) var(--s1); }
.nav-item { position: relative; display: flex; align-items: center; gap: var(--s3); min-height: var(--hit); padding: 0 var(--s3); border-radius: var(--r); color: var(--ink-2); font-weight: 600; text-decoration: none; width: 100%; text-align: left; }
.nav-item:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 3px 3px 0; background: var(--madder); }
.nav-item[aria-current="page"] .icon { color: var(--accent); }
.nav-item .count { margin-left: auto; }
.side .spacer { flex: 1 1 auto; }
.account { display: flex; align-items: center; gap: var(--s3); min-height: 52px; padding: 0 var(--s2); border-radius: var(--r); width: 100%; text-align: left; border-top: 1px solid var(--line); border-top-left-radius: 0; border-top-right-radius: 0; padding-top: var(--s2); }
.account:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.account .who { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.account .who b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .who span { font-size: var(--fs-xs); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ───────── main column ───────── */
.frame { min-width: 0; display: flex; flex-direction: column; min-height: 100dvh; }
#main { flex: 1 1 auto; min-width: 0; outline: none; }
#main:focus-visible { box-shadow: none; outline: none; }
.topbar{ display: none; }
.tabbar { display: none; }
.samplebar { display: flex; align-items: center; justify-content: center; gap: var(--s3); flex-wrap: wrap; padding: var(--s2) var(--s4); background: var(--warn-soft); color: var(--ink); font-size: var(--fs-sm); font-weight: 550; border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); text-align: center; }

/* ───────── tablet: the side bar folds to a rail ───────── */
@media (max-width: 1023px) and (min-width: 720px) {
  .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .side { padding: var(--s4) var(--s2) var(--s2); align-items: center; gap: var(--s3); }
  .brand .names, .findbtn .grow, .findbtn kbd, .nav-item .label, .account .who, .account .chev, .nav-label, .side .add .label { display: none; }
  .brand { padding: 0; justify-content: center; }
  .side .add, .findbtn { width: var(--hit); padding: 0; justify-content: center; margin: 0; }
  .nav { align-items: center; width: 100%; }
  .nav-item { width: 44px; min-height: 44px; padding: 0; justify-content: center; }
  .nav-item[aria-current="page"]::before { left: -10px; }
  .account { justify-content: center; padding: var(--s2) 0 0; }
  /* The Needs-you count stays in sight on the rail, as a small badge on the corner of its icon (hidden at none). */
  .nav-item .count:not([hidden]) { position: absolute; top: 0; right: -4px; margin: 0; min-height: 18px; padding: 0 5px; font-size: 0.6875rem; line-height: 18px; pointer-events: none; }
}
/* On the rail each button's name shows in a tag beside it, over the page, while the pointer is on it or the keyboard is on
   it (the name is always its accessible name too). The rail then lets the tags stand out past its edge; a window too short
   for the whole rail keeps the rail's own scrolling instead, and the names stay in each button's tooltip. */
@media (max-width: 1023px) and (min-width: 720px) and (min-height: 640px) {
  .side { overflow: visible; }
  .side .add, .side .findbtn, .side .account { position: relative; }
  .side :is(.nav-item:hover, .nav-item:focus-visible) > .label,
  .side :is(.add:hover, .add:focus-visible) > .label,
  .side :is(.findbtn:hover, .findbtn:focus-visible) > .grow,
  .side :is(.account:hover, .account:focus-visible) > .who {
    display: flex; flex-direction: column; position: absolute; left: calc(100% + 14px); top: 50%; transform: translateY(-50%); z-index: 3;
    width: max-content; max-width: 260px; padding: 7px 12px; border-radius: var(--r-sm); background: var(--ink); color: var(--paper);
    font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: 650; line-height: 1.3; letter-spacing: 0; white-space: nowrap; text-align: left;
    pointer-events: none; box-shadow: var(--shadow-2);
  }
  .side :is(.account:hover, .account:focus-visible) > .who b { font-weight: 650; }
  .side :is(.account:hover, .account:focus-visible) > .who span { color: color-mix(in srgb, var(--paper) 72%, var(--ink)); }
  /* While the account menu is open the menu itself names the account (its first line is the email), so the tag beside
     the button is left out and never sits over the menu. */
  .side .account[aria-expanded="true"] > .who { display: none; }
}

/* ───────── phone: top bar + bottom tabs ───────── */
@media (max-width: 719px) {
  .app { display: block; }
  .side { display: none; }
  .topbar{ display: flex; align-items: center; gap: var(--s1); position: sticky; top: 0; z-index: var(--z-nav); height: var(--topbar-h); padding: 0 var(--s2) 0 var(--s4); background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
  .topbar .brand { padding: 0; flex: 1; min-width: 0; }
  .topbar .brand .mark { width: 28px; height: 28px; }
  .topbar .brand .word { font-size: 1.15rem; }
  .topbar .needs { position: relative; }
  .topbar .needs[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
  .topbar .needs .count { position: absolute; top: 1px; right: -1px; min-height: 17px; padding: 0 5px; font-size: 0.6875rem; }
  .frame { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .app[data-shell="out"] .frame { padding-bottom: 0; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 0.6875rem; font-weight: 600; color: var(--ink-3); text-decoration: none; position: relative; min-width: 0; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--madder); }
  .tabbar a:focus-visible { outline-offset: -3px; box-shadow: none; }
}

/* ───────── signed-out and setup screens ───────── */
.gate { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.gate-art { position: relative; background: var(--accent); color: #F4F1FF; padding: var(--s12); display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
:root[data-theme="midnight"] .gate-art { background: #1B2150; }
.gate-art::before { content: ""; position: absolute; inset: 0; background:
  repeating-linear-gradient(90deg, rgba(255, 255, 255, .07) 0 2px, transparent 2px 26px),
  repeating-linear-gradient(0deg, rgba(0, 0, 0, .10) 0 2px, transparent 2px 26px); }
.gate-art > * { position: relative; }
.gate-art .brand, .gate-art .brand:hover { color: #fff; }
.gate-art blockquote { font-family: var(--font-read); font-size: clamp(1.5rem, 2.4vw, 2.25rem); line-height: 1.2; font-weight: 400; max-width: 18ch; font-variation-settings: "opsz" 48; }
.gate-art .points { display: flex; flex-direction: column; gap: var(--s3); font-size: var(--fs-md); color: #DCE0FF; }
.gate-art .points li { display: flex; gap: var(--s3); align-items: flex-start; }
.gate-form { display: flex; align-items: center; justify-content: center; padding: var(--s12) var(--s6); }
.gate-form > .inner { width: 100%; max-width: var(--form-max); display: flex; flex-direction: column; gap: var(--s6); }
@media (max-width: 899px) {
  .gate { grid-template-columns: 1fr; }
  .gate-art { padding: var(--s6) var(--s5); gap: var(--s5); }
  .gate-art .points { display: none; }
  .gate-art blockquote { font-size: 1.375rem; max-width: none; }
  .gate-form { padding: var(--s8) var(--s5) var(--s12); align-items: flex-start; }
}

/* ───────── find-anything palette ───────── */
dialog.palette { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface-raised); color: var(--ink); padding: 0; width: min(640px, calc(100vw - 24px)); margin-top: 12vh; box-shadow: var(--shadow-2); overflow: hidden; max-height: 70dvh; }
dialog.palette[open] { display: flex; flex-direction: column; animation: pop var(--fast) var(--ease); }
dialog.palette::backdrop { background: var(--scrim); }
.palette .search > .input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; min-height: 56px; font-size: var(--fs-lg); background: transparent; }
.palette .search > .input:focus-visible { outline: none; border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.palette .results { overflow: auto; padding: 6px; }
.palette .opt { display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: 0 var(--s3); border-radius: var(--r-sm); cursor: pointer; color: var(--ink); }
.palette .opt .sub { color: var(--ink-3); font-size: var(--fs-sm); margin-left: auto; white-space: nowrap; }
.palette .opt[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-strong); }
.palette .group { padding: var(--s2) var(--s3) 2px; }
.palette .foot { display: flex; gap: var(--s4); padding: var(--s2) var(--s4); border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--ink-3); background: var(--surface); }
@media (max-width: 719px) { dialog.palette { margin-top: 8px; max-height: 80dvh; } .palette .foot { display: none; } }
