/* Brain: one token set; dark is the reference, light and system accent are supported. */
:root {
  color-scheme: dark;
  --bg: #111214; --card: #1a1b1e; --text: #ececee; --muted: #9b9da5;
  --error: #ff7d7d; --on-error: #230c0c;
  --accent: AccentColor; --on-accent: AccentColorText;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --fs-1: 11px; --fs-2: 12px; --fs-3: 14px; --fs-4: 18px;
  --s1: 4px; --s2: 6px; --s3: 8px; --s4: 12px; --s5: 16px;
  --r-card: 14px; --r-pill: 999px;
  --motion: 1;
  --ease: cubic-bezier(0.33, 1, 0.68, 1);
  --ease-back: cubic-bezier(0.34, 1.4, 0.64, 1);
  --d-hover: calc(120ms * var(--motion)); --d-small: calc(180ms * var(--motion)); --d-open: calc(240ms * var(--motion));
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --hover: color-mix(in srgb, var(--text) 7%, transparent);
  --press: color-mix(in srgb, var(--text) 12%, transparent);
  --raise: color-mix(in srgb, var(--text) 6%, var(--card));
  --tint: color-mix(in srgb, var(--accent) 24%, transparent);
  --veil: color-mix(in srgb, var(--bg) 72%, transparent);
  --side-w: 288px; --panel-w: 288px;
}
@supports not (color: AccentColor) { :root { --accent: #6d8dff; --on-accent: #0a0d18; } }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { color-scheme: light; --bg: #f3f3f1; --card: #ffffff; --text: #1b1c1f; --muted: #62656d; --error: #c4302b; --on-error: #ffffff; }
}
:root[data-theme="light"] { color-scheme: light; --bg: #f3f3f1; --card: #ffffff; --text: #1b1c1f; --muted: #62656d; --error: #c4302b; --on-error: #ffffff; }
@media (prefers-reduced-motion: reduce) { :root { --motion: 0; } }
@media (pointer: coarse) { :root { --fs-3: 16px; } }

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 var(--fs-3)/1.55 var(--font); overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-2); }
.spacer { flex: 1; }
.only-narrow { display: none !important; }

/* transitions: color, opacity, transform only */
.icon-btn, .btn, .chip, .row, .menu-item, .item, .card, .nav-item, .tabbar a, .tabbar button, .search-field, .pal-item, .ac-item, .tag, .outline button, .seg button {
  transition: background-color var(--d-hover) var(--ease), color var(--d-hover) var(--ease), transform var(--d-hover) var(--ease), opacity var(--d-hover) var(--ease);
}

/* ---------- controls ---------- */
.icon-btn { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { background: var(--press); transform: scale(0.94); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 32px; padding: 0 var(--s5); border-radius: var(--r-pill); background: var(--raise); font-size: var(--fs-2); font-weight: 600; text-decoration: none; text-align: center; }
.btn:hover { background: color-mix(in srgb, var(--text) 12%, var(--card)); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { background: var(--error); color: var(--on-error); }
.btn.danger:hover { opacity: 0.9; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.chip { height: 30px; padding: 0 var(--s4); border-radius: var(--r-pill); background: var(--raise); font-size: var(--fs-2); font-weight: 500; color: var(--muted); white-space: nowrap; flex: none; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
input, select { height: 36px; padding: 0 var(--s4); border-radius: var(--r-pill); border: 0; background: var(--raise); width: 100%; }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input::placeholder { color: var(--muted); }
.field { display: grid; gap: var(--s2); margin-top: var(--s4); font-size: var(--fs-2); color: var(--muted); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.err { color: var(--error); font-size: var(--fs-2); margin: var(--s3) 0 0; }
.badge { min-width: 18px; height: 18px; padding: 0 var(--s2); border-radius: var(--r-pill); background: var(--raise); color: var(--muted); font-size: var(--fs-1); font-weight: 600; display: inline-grid; place-items: center; }
kbd { font: inherit; font-size: var(--fs-1); color: var(--muted); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); height: 100dvh; }
@media (min-width: 1180px) { .app[data-panel="open"]:not(.no-panel) { grid-template-columns: var(--side-w) minmax(0, 1fr) var(--panel-w); } }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100dvh; }
.scroll { flex: 1; overflow: auto; overscroll-behavior: contain; }
.scrim { position: fixed; inset: 0; background: var(--veil); opacity: 0; visibility: hidden; transition: opacity var(--d-open) var(--ease), visibility 0s linear var(--d-open); z-index: 20; }
[data-overlay="side"] .scrim, [data-overlay="panel"] .scrim { opacity: 1; visibility: visible; transition-delay: 0s; }

.side { background: var(--card); display: flex; flex-direction: column; min-height: 0; height: 100dvh; }
.side-head { display: flex; align-items: center; gap: var(--s1); padding: var(--s4) var(--s4) var(--s3); }
.brand { flex: 1; display: flex; align-items: center; gap: var(--s3); font-size: var(--fs-4); font-weight: 700; }
.search-field { display: flex; align-items: center; gap: var(--s3); height: 36px; margin: 0 var(--s4) var(--s3); padding: 0 var(--s4); border-radius: var(--r-pill); background: var(--raise); color: var(--muted); font-size: var(--fs-2); width: calc(100% - 2 * var(--s4)); }
.search-field span { flex: 1; }
.search-field:hover { color: var(--text); background: color-mix(in srgb, var(--text) 10%, var(--card)); }
.scopes { display: flex; flex-wrap: wrap; gap: var(--s2); padding: 0 var(--s4) var(--s3); }
.tree { flex: 1; overflow: auto; padding: var(--s2) var(--s3); min-height: 0; border-radius: var(--r-card); }
.tree.drop { background: var(--hover); }
.side-foot { padding: var(--s3); display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: var(--s3); min-height: 34px; padding: 0 var(--s4); border-radius: var(--r-pill); color: var(--muted); text-decoration: none; font-size: var(--fs-2); font-weight: 500; }
.nav-item .badge { margin-left: auto; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.on { background: var(--tint); color: var(--text); font-weight: 600; }

.row { display: flex; align-items: center; gap: var(--s3); min-height: 32px; padding: var(--s1) var(--s2) var(--s1) calc(var(--s3) + var(--d, 0) * var(--s4)); border-radius: var(--r-pill); font-size: var(--fs-2); color: var(--muted); cursor: pointer; user-select: none; }
.row .label { flex: 1; min-width: 0; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
.row .icon { width: 16px; height: 16px; }
.row.file { padding-left: calc(var(--s3) + var(--d, 0) * var(--s4) + 22px); color: var(--text); }
.row.dir { color: var(--text); font-weight: 500; }
.row:hover { background: var(--hover); }
.row.active { background: var(--tint); font-weight: 600; }
.row.dragging { opacity: 0.45; }
.row.drop { background: var(--tint); }
.chev { transition: transform var(--d-small) var(--ease); width: 14px !important; height: 14px !important; color: var(--muted); }
.chev.open { transform: rotate(90deg); }
.more { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); opacity: 0; flex: none; }
.row:hover .more, .row:focus-within .more, .row:focus .more { opacity: 1; }
.more:hover { background: var(--press); color: var(--text); }
@media (hover: none) { .more { opacity: 1; } }
.kids { animation: kids-in var(--d-small) var(--ease); }
@keyframes kids-in { from { opacity: 0; transform: translateY(-4px); } }
[data-d="1"] { --d: 1; } [data-d="2"] { --d: 2; } [data-d="3"] { --d: 3; } [data-d="4"] { --d: 4; } [data-d="5"] { --d: 5; } [data-d="6"] { --d: 6; }
[data-d="7"] { --d: 7; } [data-d="8"] { --d: 8; } [data-d="9"] { --d: 9; } [data-d="10"] { --d: 10; } [data-d="11"] { --d: 11; } [data-d="12"] { --d: 12; }
.empty { color: var(--muted); font-size: var(--fs-2); line-height: 1.5; padding: var(--s5); }
.empty .icon { width: 14px; height: 14px; vertical-align: -2px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: var(--s2); min-height: 52px; padding: var(--s2) var(--s4); flex: none; }
.crumbs { display: flex; align-items: center; gap: var(--s2); min-width: 0; flex: 1; font-size: var(--fs-2); color: var(--muted); line-height: 1.25; overflow-wrap: anywhere; }
.crumbs strong { color: var(--text); font-weight: 600; font-size: var(--fs-3); }
.crumbs .c { display: inline; }
.status { font-size: var(--fs-1); color: var(--muted); opacity: 0; transition: opacity var(--d-small) var(--ease); white-space: nowrap; }
.status.on { opacity: 1; }
.status.error { color: var(--error); }
.seg { position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; height: 34px; padding: 2px; border-radius: var(--r-pill); background: var(--raise); flex: none; }
.seg .thumb { position: absolute; top: 2px; bottom: 2px; left: 2px; width: calc(50% - 2px); border-radius: var(--r-pill); background: var(--accent); transition: transform var(--d-open) var(--ease-back); }
.seg[data-mode="edit"] .thumb { transform: translateX(100%); }
.seg button { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: var(--s2); padding: 0 var(--s4); border-radius: var(--r-pill); font-size: var(--fs-2); font-weight: 600; color: var(--muted); min-width: 68px; }
.seg button .icon { width: 15px; height: 15px; }
.seg button[aria-selected="true"] { color: var(--on-accent); }

/* ---------- pages & markdown ---------- */
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: var(--s5) calc(var(--s5) * 2) calc(var(--s5) * 5); }
.page.wide { max-width: 900px; }
.title { font-size: var(--fs-4); font-weight: 700; line-height: 1.3; margin: var(--s3) 0 var(--s3); overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0 0 var(--s4); }
.tag { display: inline-block; padding: 0 var(--s3); border-radius: var(--r-pill); background: var(--raise); font-size: var(--fs-2); font-weight: 500; color: var(--muted); text-decoration: none; line-height: 24px; }
.tag:hover { color: var(--text); background: color-mix(in srgb, var(--text) 12%, var(--card)); }
.md { line-height: 1.7; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md .table-wrap { margin: 0 0 var(--s4); }
.md h1 { font-size: var(--fs-4); font-weight: 700; margin: calc(var(--s5) * 1.5) 0 var(--s3); line-height: 1.3; }
.md h2 { font-size: var(--fs-3); font-weight: 700; margin: calc(var(--s5) * 1.5) 0 var(--s3); padding-bottom: var(--s2); border-bottom: 1px solid var(--line); }
.md h3 { font-size: var(--fs-3); font-weight: 600; margin: var(--s5) 0 var(--s2); }
.md h4, .md h5, .md h6 { font-size: var(--fs-2); font-weight: 700; margin: var(--s5) 0 var(--s2); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }
.md li:has(> input[type="checkbox"]) { list-style: none; margin-left: -22px; min-height: 28px; }
.md li li:has(> input[type="checkbox"]) { margin-left: 0; }
.md input[type="checkbox"] { appearance: none; width: 18px; height: 18px; margin: 0 var(--s3) 0 0; padding: 0; border-radius: 6px; border: 1.5px solid var(--muted); background: transparent; vertical-align: -4px; cursor: pointer; display: inline-grid; place-content: center; transition: background-color var(--d-hover) var(--ease), border-color var(--d-hover) var(--ease); }
.md input[type="checkbox"]:hover { border-color: var(--text); }
.md input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.md input[type="checkbox"]:checked::after { content: ""; width: 9px; height: 5px; border-left: 2px solid var(--on-accent); border-bottom: 2px solid var(--on-accent); transform: rotate(-45deg) translate(1px, -1px); }
.md blockquote { border-left: 3px solid var(--line); padding: 0 0 0 var(--s4); color: var(--muted); }
.md .callout { border: 0; background: var(--raise); border-radius: var(--r-card); padding: var(--s4) var(--s5); color: var(--text); }
.md .callout p:last-child { margin-bottom: 0; }
.callout-title { display: flex; align-items: center; gap: var(--s3); font-weight: 600; margin-bottom: var(--s2); }
.callout.danger .callout-title { color: var(--error); }
.md code { font-family: var(--mono); font-size: 0.9em; background: var(--raise); padding: 1px var(--s2); border-radius: 6px; }
.md pre { background: var(--raise); border-radius: var(--r-card); padding: var(--s4) var(--s5); overflow: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; height: 1px; background: var(--line); margin: var(--s5) 0; }
.md img { max-width: 100%; border-radius: var(--s4); }
.md a { text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 3px; }
.md a:hover { text-decoration-color: var(--text); }
.md a.wikilink { font-weight: 500; }
.md a.wikilink.missing { color: var(--muted); text-decoration-style: dashed; }
.md a.tag { text-decoration: none; }
.table-wrap { overflow-x: auto; }
.md table { border-collapse: collapse; min-width: 100%; }
.md th, .md td { padding: var(--s2) var(--s4); text-align: left; border-bottom: 1px solid var(--line); }
.md th { background: var(--raise); font-weight: 600; font-size: var(--fs-2); }
.md .empty { padding: 0; }

/* ---------- home, lists ---------- */
.hero { margin: var(--s3) 0 var(--s4); }
.hero h1 { font-size: var(--fs-4); font-weight: 700; margin: 0 0 var(--s1); }
.hero p { margin: 0; font-size: var(--fs-2); }
.page h2 { font-size: var(--fs-2); font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: calc(var(--s5) * 1.5) 0 var(--s3); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s4); margin: var(--s5) 0; }
.card { display: grid; gap: var(--s2); align-content: start; min-height: 96px; padding: var(--s5); border-radius: var(--r-card); background: var(--card); text-align: left; }
.card:hover { background: var(--raise); }
.card:active { transform: scale(0.98); }
.card-title { font-weight: 600; }
.card-sub { color: var(--muted); font-size: var(--fs-2); }
.card-sub b { color: var(--text); font-weight: 600; }
.card-foot { color: var(--muted); font-size: var(--fs-1); overflow-wrap: anywhere; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.item { display: flex; align-items: center; gap: var(--s4); min-height: 44px; padding: var(--s3) var(--s4); border-radius: var(--s4); text-decoration: none; }
.item:hover { background: var(--hover); }
.item > .icon { color: var(--muted); }
.item-main { display: grid; min-width: 0; flex: 1; }
.item-title { font-weight: 500; overflow-wrap: anywhere; }
.item-sub { color: var(--muted); font-size: var(--fs-2); overflow-wrap: anywhere; }
.item-meta { color: var(--muted); font-size: var(--fs-1); white-space: nowrap; }

/* ---------- editor ---------- */
.editor { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
#ta { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: var(--s5) calc(var(--s5) * 2); background: transparent; border: 0; border-radius: 0; resize: none; outline: 0; font-size: var(--fs-3); line-height: 1.7; display: block; height: auto; }
.banner { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); margin: 0 var(--s4); padding: var(--s3) var(--s4); background: var(--raise); border-radius: var(--r-card); font-size: var(--fs-2); }
.banner span { flex: 1; min-width: 140px; }
.etools { display: flex; justify-content: center; gap: var(--s2); padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); background: var(--card); overflow-x: auto; flex: none; }
.etools button { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.etools button:hover { background: var(--hover); color: var(--text); }
.etools button:active { background: var(--press); transform: scale(0.92); }
.ac { position: absolute; left: var(--s4); right: var(--s4); bottom: var(--s3); max-width: 520px; margin: 0 auto; padding: var(--s2); border-radius: var(--r-card); background: var(--raise); box-shadow: 0 0 0 1px var(--line), 0 8px 24px color-mix(in srgb, var(--bg) 70%, transparent); z-index: 5; }
.ac-item { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 36px; padding: 0 var(--s4); border-radius: 10px; font-size: var(--fs-3); }
.ac-item small { margin-left: auto; color: var(--muted); font-size: var(--fs-1); }
.ac-item.on, .ac-item:hover { background: var(--tint); }

/* ---------- side panel ---------- */
.panel { background: var(--card); overflow: auto; padding: var(--s4) var(--s4) var(--s5); min-height: 0; height: 100dvh; display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: var(--fs-3); font-weight: 700; color: var(--text); text-transform: none; letter-spacing: 0; }
.panel section { margin-top: var(--s5); }
.panel h3 { display: flex; align-items: center; gap: var(--s2); margin: 0 0 var(--s3); font-size: var(--fs-1); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.count { min-width: 18px; padding: 0 var(--s2); border-radius: var(--r-pill); background: var(--raise); text-align: center; letter-spacing: 0; }
.outline, .mentions { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.outline button { display: block; width: 100%; padding: 5px var(--s3); border-radius: 10px; font-size: var(--fs-2); color: var(--muted); overflow-wrap: anywhere; }
.outline button:hover { background: var(--hover); color: var(--text); }
.outline .lvl2 { padding-left: var(--s5); } .outline .lvl3 { padding-left: 24px; } .outline .lvl4 { padding-left: 32px; }
.mentions a { display: grid; gap: 2px; padding: var(--s2) var(--s3); border-radius: 10px; text-decoration: none; }
.mentions a:hover { background: var(--hover); }
.mentions .item-title { font-size: var(--fs-2); }
.props { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); margin: 0; font-size: var(--fs-2); }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }
.no-panel .panel { display: none !important; }
@media (min-width: 1180px) { .app[data-panel="open"]:not(.no-panel) .panel { display: block; } .panel-head .icon-btn { display: none; } }

/* ---------- graph ---------- */
.graph { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.graph-canvas { display: block; touch-action: none; cursor: grab; }
.graph-canvas.pointing { cursor: pointer; }
.graph-hint { position: absolute; left: var(--s5); right: var(--s5); bottom: var(--s4); margin: 0; font-size: var(--fs-1); color: var(--muted); pointer-events: none; }

/* ---------- mobile tab bar ---------- */
.tabbar { display: none; }

/* ---------- overlays ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; opacity: 0; transition: opacity var(--d-small) var(--ease); }
.modal.in { opacity: 1; }
.modal-scrim { position: absolute; inset: 0; background: var(--veil); }
.dialog { position: relative; width: min(440px, calc(100vw - 2 * var(--s5))); max-height: calc(100dvh - 2 * var(--s5)); overflow: auto; padding: var(--s5); border-radius: 18px; background: var(--card); box-shadow: 0 0 0 1px var(--line), 0 16px 48px color-mix(in srgb, var(--bg) 70%, transparent); transform: translateY(8px) scale(0.97); transition: transform var(--d-open) var(--ease-back); }
.modal.in .dialog { transform: none; }
.dialog h2 { margin: 0; font-size: var(--fs-4); font-weight: 700; text-transform: none; letter-spacing: 0; color: var(--text); }
.dialog p { margin: var(--s3) 0 0; }
.actions { display: flex; justify-content: flex-end; gap: var(--s3); margin-top: calc(var(--s5) + var(--s2)); }
.dialog.palette { align-self: start; margin-top: 12vh; width: min(620px, calc(100vw - 2 * var(--s5))); padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.pal-input { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); color: var(--muted); border-bottom: 1px solid var(--line); }
.pal-input input::-webkit-search-cancel-button { display: none; }
.pal-input input { height: 32px; padding: 0; background: none; border-radius: 0; font-size: var(--fs-4); color: var(--text); outline: none; -webkit-appearance: none; }
.pal-list { max-height: min(56dvh, 420px); overflow: auto; padding: var(--s3); }
.pal-h { padding: var(--s3) var(--s4) var(--s2); font-size: var(--fs-1); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pal-item { display: flex; align-items: center; gap: var(--s4); width: 100%; min-height: 40px; padding: var(--s2) var(--s4); border-radius: 10px; }
.pal-item > .icon { color: var(--muted); }
.pal-item.on { background: var(--tint); }
.pal-main { display: grid; min-width: 0; }
.pal-title { overflow-wrap: anywhere; font-weight: 500; }
.pal-sub { font-size: var(--fs-2); color: var(--muted); overflow-wrap: anywhere; }
mark { background: none; color: inherit; font-weight: 700; text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 3px; }

.menu-wrap { position: fixed; inset: 0; z-index: 60; }
.menu-scrim { position: absolute; inset: 0; }
.menu { position: fixed; left: var(--x); top: var(--y); min-width: 208px; padding: var(--s2); border-radius: var(--r-card); background: var(--raise); box-shadow: 0 0 0 1px var(--line), 0 12px 32px color-mix(in srgb, var(--bg) 70%, transparent); opacity: 0; transform: scale(0.94); transition: transform var(--d-small) var(--ease-back), opacity var(--d-hover) var(--ease); }
.menu-wrap.in .menu { opacity: 1; transform: none; }
.menu hr { border: 0; height: 1px; background: var(--line); margin: var(--s2) var(--s2); }
.menu-item { display: flex; align-items: center; gap: var(--s4); width: 100%; min-height: 36px; padding: 0 var(--s4); border-radius: 10px; font-size: var(--fs-2); font-weight: 500; }
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item.danger { color: var(--error); }
.menu-item .tick { margin-left: auto; }

#toasts { position: fixed; left: 50%; bottom: calc(var(--s5) + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: var(--s3); width: min(440px, calc(100vw - 2 * var(--s5))); z-index: 80; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s4); padding: var(--s3) var(--s5); border-radius: var(--r-pill); background: var(--text); color: var(--bg); font-size: var(--fs-2); font-weight: 500; opacity: 0; transform: translateY(12px); transition: opacity var(--d-small) var(--ease), transform var(--d-small) var(--ease); min-height: 36px; }
.toast.in { opacity: 1; transform: none; }
.toast.error { background: var(--error); color: var(--on-error); }
.toast span { flex: 1; overflow-wrap: anywhere; }
.toast-btn { font-weight: 700; padding: var(--s1) var(--s3); border-radius: var(--r-pill); text-decoration: underline; flex: none; min-height: 30px; }

/* ---------- login ---------- */
.login { height: 100dvh; display: grid; place-items: center; padding: var(--s5); }
.login-card { width: min(360px, 100%); padding: calc(var(--s5) * 2) var(--s5) var(--s5); border-radius: 18px; background: var(--card); text-align: center; display: grid; gap: var(--s3); }
.login-card h1 { margin: 0; font-size: var(--fs-4); font-weight: 700; }
.login-card p { margin: 0; font-size: var(--fs-2); }
.login-icon { width: 44px; height: 44px; margin: 0 auto var(--s2); border-radius: 50%; background: var(--raise); display: grid; place-items: center; color: var(--muted); }
.login-card input { margin-top: var(--s4); text-align: center; }
.login-card .btn { margin-top: var(--s3); min-height: 38px; }

/* ---------- touch sizing ---------- */
@media (pointer: coarse) {
  .icon-btn { width: 40px; height: 40px; }
  .row { min-height: 40px; }
  .btn, .chip { min-height: 38px; }
  .chip { height: 36px; }
  input, select { height: 44px; }
  .menu-item { min-height: 44px; }
  .more { width: 36px; height: 36px; }
  .seg { height: 40px; }
  .nav-item { min-height: 40px; }
}

/* ---------- narrow: drawer, bottom tab bar, sheets ---------- */
@media (max-width: 1179px) {
  .panel { display: block; position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 88vw); height: auto; z-index: 30; transform: translateX(100%); visibility: hidden; transition: transform var(--d-open) var(--ease), visibility 0s linear var(--d-open); }
  [data-overlay="panel"] .panel { transform: none; visibility: visible; transition-delay: 0s; }
  .no-panel .panel { display: none !important; }
}
@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-narrow { display: grid !important; }
  .only-wide, .crumbs .c, .search-field kbd { display: none; }
  .side { position: fixed; top: 0; left: 0; bottom: 0; width: min(86vw, 330px); z-index: 30; transform: translateX(-100%); visibility: hidden; transition: transform var(--d-open) var(--ease), visibility 0s linear var(--d-open); padding-top: env(safe-area-inset-top); }
  [data-overlay="side"] .side { transform: none; visibility: visible; transition-delay: 0s; }
  .side-foot { display: none; }
  .topbar { padding-left: var(--s2); padding-right: var(--s3); padding-top: calc(var(--s2) + env(safe-area-inset-top)); gap: var(--s1); }
  .seg button { min-width: 0; padding: 0 var(--s4); }
  .seg button span { display: none; }
  .status:not(.error) { display: none; }
  .page { padding: var(--s4) var(--s5) calc(72px + env(safe-area-inset-bottom) + var(--s5)); }
  #ta { padding: var(--s4) var(--s5); }
  .panel { top: auto; left: 0; right: 0; width: auto; max-height: 72dvh; height: auto; border-radius: 18px 18px 0 0; transform: translateY(100%); padding-bottom: calc(var(--s5) + env(safe-area-inset-bottom)); }
  [data-overlay="panel"] .panel { transform: none; }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; padding: var(--s2) var(--s3) calc(var(--s2) + env(safe-area-inset-bottom)); background: var(--card); }
  [data-edit="true"] .tabbar { display: none; }
  .tabbar a, .tabbar button { position: relative; display: grid; justify-items: center; gap: 2px; padding: var(--s2) 0; border-radius: var(--r-pill); color: var(--muted); font-size: var(--fs-1); font-weight: 500; text-decoration: none; text-align: center; min-height: 48px; align-content: center; }
  .tabbar a.on { color: var(--text); background: var(--tint); font-weight: 600; }
  .tabbar .fab { width: 48px; min-height: 48px; height: 48px; margin: 0 auto; border-radius: 50%; background: var(--accent); color: var(--on-accent); padding: 0; place-items: center; }
  .tabbar .fab:active { transform: scale(0.92); }
  .tabbar .badge { position: absolute; top: 2px; right: calc(50% - 22px); min-width: 16px; height: 16px; font-size: 10px; }
  .graph-hint { bottom: calc(72px + env(safe-area-inset-bottom)); }
  #toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
  [data-edit="true"] ~ #toasts, #shell[data-edit="true"] ~ #toasts { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .modal { place-items: end stretch; }
  .dialog { width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0; padding-bottom: calc(var(--s5) + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform var(--d-open) var(--ease); }
  .dialog.palette { align-self: stretch; margin: 0; width: 100%; height: 100dvh; max-height: none; border-radius: 0; padding: env(safe-area-inset-top) 0 0; }
  .pal-list { max-height: none; flex: 1; }
  .menu { left: 0; right: 0; top: auto; bottom: 0; min-width: 0; border-radius: 18px 18px 0 0; padding: var(--s3) var(--s3) calc(var(--s3) + env(safe-area-inset-bottom)); transform: translateY(100%); transform-origin: 50% 100% !important; }
  .menu-scrim { background: var(--veil); }
}
