/* ============================================================
   4One — OneNote-style notebook app
   ============================================================ */

:root {
  /* Purple → cyan. Purple carries the chrome, cyan the accents and focus. */
  --purple: #7c3aed;
  --purple-deep: #5b21b6;
  --cyan: #06b6d4;
  --cyan-bright: #22d3ee;
  --grad: linear-gradient(115deg, #7c3aed 0%, #6366f1 45%, #06b6d4 100%);

  --accent: #6d28d9;
  --accent-2: #8b5cf6;
  --accent-soft: #f2ecfe;

  /* Logo tile. Swap these two for the original orange (#ff6a13 → #f04e00). */
  --logo-a: #7c3aed;
  --logo-b: #06b6d4;
  --logo-word: #2a1a4a;

  --bg: #f5f4fa;
  --bg-chrome: #ffffff;
  --bg-rail: #faf9fe;
  --bg-col: #ffffff;
  --bg-editor: #ffffff;
  --bg-hover: #f0edfb;
  --bg-active: #e7defd;

  --text: #1c1a2e;
  --text-soft: #59566f;
  --text-faint: #8b88a0;
  --border: #e5e2f0;
  --border-strong: #c9c4dd;

  --shadow-1: 0 1px 2px rgba(46, 16, 101, .08), 0 2px 8px rgba(46, 16, 101, .06);
  --shadow-2: 0 8px 28px rgba(46, 16, 101, .18);

  --rail-w: 208px;
  --sections-w: 210px;
  --pages-w: 236px;

  --radius: 6px;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-note: "Calibri", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "SF Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --purple: #a78bfa;
  --purple-deep: #7c3aed;
  --cyan: #22d3ee;
  --cyan-bright: #67e8f9;
  --grad: linear-gradient(115deg, #8b5cf6 0%, #6366f1 45%, #22d3ee 100%);

  --accent: #a78bfa;
  --accent-2: #c4b5fd;
  --accent-soft: #241b3d;

  --logo-a: #8b5cf6;
  --logo-b: #22d3ee;
  --logo-word: #f1eefc;

  --bg: #0f0e1a;
  --bg-chrome: #17162a;
  --bg-rail: #131226;
  --bg-col: #17162a;
  --bg-editor: #141324;
  --bg-hover: #232144;
  --bg-active: #2e2a5c;

  --text: #ece9fb;
  --text-soft: #b3aed4;
  --text-faint: #837ea8;
  --border: #2a2749;
  --border-strong: #3d3868;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5), 0 2px 10px rgba(0, 0, 0, .4);
  --shadow-2: 0 10px 32px rgba(0, 0, 0, .65);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* Touch polish: no grey flash on tap, no accidental text selection on
   long-press, and no 300ms double-tap-to-zoom delay on controls. */
button, .item, .auth-tab, .chip, .add-row {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.ico { width: 15px; height: 15px; fill: currentColor; display: block; }

#app {
  display: grid;
  grid-template-rows: 44px 40px 1fr 24px;
  height: 100%;
  animation: fadeIn .4s ease both;
}

/* ══ Motion ═════════════════════════════════════════════════ */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  0%   { opacity: 0; transform: scale(.86) translateY(10px); }
  60%  { opacity: 1; transform: scale(1.03) translateY(0); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes drawGlyph { to { stroke-dashoffset: 0; } }
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(0, -2.5%, 0) scale(1.06); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Staggered entrance: each element sets its own --d delay. */
.reveal {
  opacity: 0;
  animation: fadeUp .62s cubic-bezier(.22, .8, .28, 1) both;
  animation-delay: var(--d, 0ms);
}
.logo-lockup.reveal { animation-name: popIn; animation-duration: .78s; }

/* The mark draws itself in on the intro. Inherited stroke-dashoffset reaches
   the paths inside <use>, which is why it is set on the <svg> element. */
.screen-intro .logo-mark {
  stroke-dasharray: 640;
  stroke-dashoffset: 640;
  animation: drawGlyph 1.15s cubic-bezier(.6, .05, .3, 1) .34s forwards;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .screen-intro .logo-mark { stroke-dashoffset: 0; }
}

/* ══ Intro + auth screens ═══════════════════════════════════ */

.screen {
  position: relative;
  height: 100%;
  overflow-y: auto;
  background: var(--bg);
  animation: fadeIn .38s ease both;
}

/* Soft purple→cyan wash behind both screens. */
.intro-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  animation: drift 18s ease-in-out infinite;
  background:
    radial-gradient(52vw 46vw at 12% -8%, rgba(124, 58, 237, .28), transparent 62%),
    radial-gradient(46vw 44vw at 92% 8%, rgba(6, 182, 212, .24), transparent 60%),
    radial-gradient(60vw 50vw at 60% 108%, rgba(99, 102, 241, .18), transparent 65%);
}
[data-theme="dark"] .intro-glow {
  background:
    radial-gradient(52vw 46vw at 12% -8%, rgba(139, 92, 246, .30), transparent 62%),
    radial-gradient(46vw 44vw at 92% 8%, rgba(34, 211, 238, .20), transparent 60%),
    radial-gradient(60vw 50vw at 60% 108%, rgba(99, 102, 241, .22), transparent 65%);
}

/* ── the mark ──────────────────────────────────────────────── */
.logo-mark { width: 96px; height: 96px; display: block; overflow: visible; }
.logo-mark.tiny { width: 26px; height: 26px; }

/* On the gradient title bar the coloured tile would vanish, so it becomes a
   translucent white plate with the same white glyph. */
.titlebar .logo-mark {
  --logo-a: rgba(255, 255, 255, .32);
  --logo-b: rgba(255, 255, 255, .16);
}

.logo-lockup {
  display: flex; align-items: center; justify-content: center;
  gap: 10px;
}
.logo-word {
  font-size: clamp(38px, 7vw, 66px);
  font-weight: 700; letter-spacing: -1px;
  line-height: 1;
  color: var(--logo-word);
}

/* Hero lockup: one size drives both halves, so they stay in proportion.
   The mark's artwork is inset ~3% inside its own box, so the visual gap is a
   little wider than the flex gap — hence the tight value here. */
.screen-intro .logo-lockup {
  --mark: clamp(122px, 17vw, 196px);
  gap: calc(var(--mark) * .02);
  cursor: default;
}
.screen-intro .logo-mark { width: var(--mark); height: var(--mark); }
.screen-intro .logo-word {
  font-size: calc(var(--mark) * .58);
  letter-spacing: -.02em;
  transition: transform .45s cubic-bezier(.2, .8, .2, 1), letter-spacing .45s ease;
}

/* ── logo effects ──────────────────────────────────────────── */

.logo-tile { display: block; position: relative; line-height: 0; }

.screen-intro .logo-tile {
  animation: floaty 6.5s ease-in-out 1.4s infinite;
  transition: transform .45s cubic-bezier(.2, .8, .2, 1), filter .45s ease;
  filter: drop-shadow(0 14px 34px rgba(124, 58, 237, .34));
}
[data-theme="dark"] .screen-intro .logo-tile {
  filter: drop-shadow(0 14px 40px rgba(139, 92, 246, .45));
}

/* A specular sheen clipped to the tile's exact rounded-square shape.
   The artwork sits 16/512 in from the edge with a 116/512 corner radius. */
.screen-intro .logo-tile::after {
  content: "";
  position: absolute; inset: 0;
  clip-path: inset(3.125% round 22.6%);
  background: linear-gradient(102deg,
    transparent 34%, rgba(255, 255, 255, .55) 50%, transparent 66%);
  background-size: 260% 100%;
  background-position: 190% 0;
  pointer-events: none;
  opacity: 0;
}
.screen-intro .logo-lockup:hover .logo-tile::after,
.screen-intro .logo-tile.sheen::after {
  opacity: 1;
  animation: sheen 1.05s cubic-bezier(.35, 0, .25, 1);
}

.screen-intro .logo-lockup:hover .logo-tile {
  transform: scale(1.055) rotate(-2.2deg);
  filter: drop-shadow(0 20px 46px rgba(124, 58, 237, .48));
}
.screen-intro .logo-lockup:hover .logo-word {
  transform: translateX(3px);
  letter-spacing: -.005em;
}
.screen-intro .logo-lockup:active .logo-tile { transform: scale(.985); }

@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-9px); }
}
@keyframes sheen {
  from { background-position: 190% 0; }
  to   { background-position: -90% 0; }
}
.auth-brand { gap: 12px; margin: 6px 0 22px; }
.auth-brand .logo-mark { width: 42px; height: 42px; }
.auth-brand .logo-word { font-size: 30px; }

.grad-text {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}

/* ── intro ─────────────────────────────────────────────────── */
.intro-nav {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px clamp(18px, 6vw, 64px);
  color: var(--text);
}
.intro-nav-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn.ghost { color: var(--text-soft); }
.icon-btn.ghost:hover { background: var(--bg-hover); }

/* With only the logo, tagline and button left, centre the lot in the viewport. */
.screen-intro { display: flex; flex-direction: column; }
.intro-nav, .intro-foot { flex: none; }

.intro-hero {
  position: relative; z-index: 1;
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px clamp(18px, 6vw, 40px) 40px;
  text-align: center;
}

.intro-tagline {
  margin: clamp(20px, 3.4vh, 34px) auto clamp(26px, 4vh, 40px);
  font-size: clamp(16px, 2.3vw, 24px);
  font-weight: 500;
  letter-spacing: .1px;
  color: var(--text-soft);
}

.intro-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-lg { padding: 12px 26px; font-size: 14.5px; border-radius: 8px; }

.btn-login {
  min-width: 200px;
  padding: 14px 34px;
  font-size: 15px; font-weight: 600; letter-spacing: .3px;
  border-radius: 11px;
  position: relative;
  /* A wider gradient that drifts, so the button is never quite static.
     The glow lives in box-shadow rather than a blurred pseudo-element: the
     hover lift makes the button a stacking context, which would drag a
     negative-z-index halo in front of its own face. */
  background: linear-gradient(115deg, #7c3aed, #6366f1, #06b6d4, #6366f1, #7c3aed);
  background-size: 300% 100%;
  animation: gradientDrift 9s ease infinite;
  box-shadow: 0 6px 18px rgba(109, 40, 217, .26);
  transition: transform .24s cubic-bezier(.2, .8, .2, 1), box-shadow .24s ease;
}
.btn-login:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 34px rgba(109, 40, 217, .44), 0 0 22px rgba(34, 211, 238, .34);
}
.btn-login:active { transform: translateY(-1px) scale(.985); }
.btn-login:focus-visible { outline: 3px solid var(--cyan-bright); outline-offset: 3px; }

/* Light sweeping across the face, on a loop: a quick pass, then a rest. */
.btn-login::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(100deg,
    transparent 38%, rgba(255, 255, 255, .42) 50%, transparent 62%);
  background-size: 250% 100%;
  background-position: 180% 0;
  pointer-events: none;
  animation: sheenLoop 3.6s ease-in-out 1.2s infinite;
}
.btn-login:hover::after { animation-duration: 2.2s; animation-delay: 0s; }

@keyframes gradientDrift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}
@keyframes sheenLoop {
  0%        { background-position: 180% 0; }
  34%, 100% { background-position: -80% 0; }
}

.intro-foot {
  position: relative; z-index: 1;
  padding: 0 24px 34px;
  text-align: center;
}

/* "Powered by 4Keys" */
.powered {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 6px 4px;
}
.pw-label { font-size: 12.5px; color: var(--text-faint); }
.pw-logo {
  /* The key is roughly 1:2, so it needs height to read at all. */
  height: 38px; width: auto; display: block;
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), filter .35s ease;
}

/* The supplied wordmark is a 6000×3375 PNG whose lettering occupies only
   x 1204–4772, y 1184–2228. These ratios crop to exactly that region. */
.pw-name {
  --h: 21px;
  display: block;
  height: var(--h);
  width: calc(var(--h) * 3.4176);
  background-image: url("../img/4keys-name.png");
  background-repeat: no-repeat;
  background-size: calc(var(--h) * 5.7471) calc(var(--h) * 3.2328);
  background-position: calc(var(--h) * -1.1533) calc(var(--h) * -1.1341);
  /* The lettering is near-white metal — darken it to read on a light page. */
  filter: brightness(.34) contrast(1.35);
  transition: filter .35s ease;
}
[data-theme="dark"] .pw-name { filter: none; }
.powered:hover .pw-logo {
  transform: translateY(-2px) scale(1.06);
  filter: drop-shadow(0 6px 14px rgba(124, 58, 237, .45));
}

/* ── auth ──────────────────────────────────────────────────── */
.screen-auth { display: grid; place-items: center; padding: 28px 18px; }

.auth-card {
  position: relative; z-index: 1;
  width: min(420px, 100%);
  padding: 30px 30px 24px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-chrome);
  box-shadow: var(--shadow-2);
  animation: fadeUp .5s cubic-bezier(.22, .8, .28, 1) both;
}
.auth-back {
  position: absolute; top: 14px; left: 14px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--text-faint); font-size: 12.5px; padding: 4px 6px; border-radius: 4px;
}
.auth-back:hover { background: var(--bg-hover); color: var(--text); }
.auth-brand { justify-content: center; margin: 6px 0 22px; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin-bottom: 20px;
  background: var(--bg-hover); border-radius: 9px;
}
.auth-tab {
  padding: 8px; border: 0; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-soft); font-size: 13px; font-weight: 500;
  transition: background .24s ease, color .24s ease, box-shadow .24s ease;
}
.auth-tab.on { background: var(--bg-chrome); color: var(--text); font-weight: 600; box-shadow: var(--shadow-1); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field {
  display: flex; flex-direction: column; gap: 6px;
  animation: rise .34s ease both;
}
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.field input {
  padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--bg-editor); color: var(--text);
  outline: none;
}
.field input {
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.field input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, .18);
}
.hint { font-size: 11.5px; color: var(--text-faint); font-style: normal; }

/* Reveal-password control, sitting inside the field. */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; min-width: 0; padding-right: 44px; }
.pw-toggle {
  position: absolute; top: 50%; right: 5px;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--text-faint);
  cursor: pointer;
  transition: color .18s ease, background .18s ease;
}
.pw-toggle:hover { color: var(--text); background: var(--bg-hover); }
.pw-toggle:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }
.pw-toggle .ico { width: 17px; height: 17px; }
.pw-toggle .ico-off { display: none; }
.pw-toggle.on { color: var(--accent); }
.pw-toggle.on .ico-on { display: none; }
.pw-toggle.on .ico-off { display: block; }

.auth-error, .auth-note {
  margin: 0; padding: 9px 12px; border-radius: 8px; font-size: 12.5px;
  animation: rise .3s ease both;
}
.auth-error { background: #fde8ec; color: #a5203c; border: 1px solid #f5c2cd; }
.auth-note { background: #e0f7fb; color: #0b5f70; border: 1px solid #a9e6f2; }
[data-theme="dark"] .auth-error { background: #3d1520; color: #ffb3c4; border-color: #6b2436; }
[data-theme="dark"] .auth-note { background: #0c2f38; color: #9fe7f5; border-color: #17505f; }

.btn-block { width: 100%; padding: 11px; border-radius: 8px; font-size: 14px; }

/* ── account chip in the title bar ─────────────────────────── */
.avatar {
  width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  color: #fff; font-size: 12px; font-weight: 700;
  cursor: pointer; display: grid; place-items: center;
}
.avatar:hover { background: rgba(255, 255, 255, .34); }
.user-head { padding: 8px 10px 6px; }
.user-name { font-weight: 600; }
.user-mail { font-size: 11.5px; color: var(--text-faint); word-break: break-all; }

/* ── Title bar ─────────────────────────────────────────────── */
.titlebar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 10px 0 14px;
  background: var(--grad);
  color: #fff;
}

.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; letter-spacing: .2px; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 5px;
  background: rgba(255, 255, 255, .2);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
}
.brand-name { font-size: 15px; }

.breadcrumb {
  flex: 1;
  min-width: 0;
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, .82);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.breadcrumb .crumb { overflow: hidden; text-overflow: ellipsis; }
.breadcrumb .crumb.strong { color: #fff; font-weight: 600; }
.breadcrumb .sepc { opacity: .55; }

.titlebar-right { display: flex; align-items: center; gap: 6px; }

.searchbox {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 4px;
  padding: 0 8px;
  height: 28px;
  width: 270px;
  transition: background .15s, width .15s;
}
.searchbox:focus-within { background: #fff; width: 330px; }
.searchbox:focus-within .ico { fill: var(--text-soft); }
.searchbox .ico { fill: rgba(255, 255, 255, .9); flex: none; }
.searchbox input {
  border: 0; background: transparent; outline: none;
  width: 100%; color: #fff;
}
.searchbox input::placeholder { color: rgba(255, 255, 255, .75); }
.searchbox:focus-within input { color: var(--text); }
.searchbox:focus-within input::placeholder { color: var(--text-faint); }
.searchbox input::-webkit-search-cancel-button { filter: invert(1); }

.icon-btn {
  height: 28px; min-width: 28px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 4px;
  color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, .18); }
.titlebar .icon-btn:hover { background: rgba(255, 255, 255, .2); }

.menu-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 34px; z-index: 60;
  min-width: 232px; padding: 4px;
  background: var(--bg-chrome); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  transform-origin: top right;
  animation: menuIn .16s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes menuIn {
  from { opacity: 0; transform: scale(.96) translateY(-4px); }
  to   { opacity: 1; transform: none; }
}
.dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border: 0; border-radius: 4px;
  background: transparent; cursor: pointer;
}
.dropdown button:hover { background: var(--bg-hover); }
.dropdown .danger { color: #c4314b; }
.dropdown .sep, .ctxmenu .sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* ── Ribbon ────────────────────────────────────────────────── */
.ribbon {
  display: flex; align-items: center; gap: 2px;
  padding: 0 10px;
  background: var(--bg-chrome);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.ribbon::-webkit-scrollbar { display: none; }
.rgroup { display: flex; align-items: center; gap: 2px; }
.rsep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex: none; }
.rspacer { flex: 1; }

.tbtn {
  height: 28px; min-width: 28px; padding: 0 6px;
  display: inline-grid; place-items: center;
  background: transparent; border: 1px solid transparent; border-radius: 4px;
  cursor: pointer; color: var(--text); font-size: 13px; line-height: 1;
}
.tbtn:hover { background: var(--bg-hover); }
.tbtn.on { background: var(--bg-active); border-color: var(--border-strong); }
.tbtn[data-cmd="justifyRight"] { transform: scaleX(-1); }

.color-btn { position: relative; overflow: hidden; }
.color-btn input[type="color"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; padding: 0; border: 0;
}
.swatch {
  display: grid; place-items: center;
  width: 20px; height: 18px; border-radius: 3px;
  color: #fff; font-weight: 700; font-size: 11px;
  text-shadow: 0 0 2px rgba(0, 0, 0, .5);
}
.swatch.hl { color: rgba(0, 0, 0, .55); text-shadow: none; }

.tsel {
  height: 26px; padding: 0 4px;
  background: var(--bg-chrome);
  border: 1px solid var(--border); border-radius: 4px;
  cursor: pointer;
}
.tsel.narrow { width: 58px; }

.save-state { font-size: 11.5px; color: var(--text-faint); padding-right: 4px; white-space: nowrap; }
.save-state.busy { color: var(--accent-2); }

/* ── Workspace ─────────────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: auto 1fr;
  min-height: 0;
  background: var(--bg);
  position: relative;
}

.panes {
  display: grid;
  grid-template-columns: var(--rail-w) 4px var(--sections-w) 4px var(--pages-w) 4px;
  min-height: 0; min-width: 0;
}

.nav-toggle { display: none; }
.nav-scrim { display: none; }

.gutter { cursor: col-resize; background: transparent; position: relative; }
.gutter::after {
  content: ""; position: absolute; inset: 0 1px;
  background: var(--border);
}
.gutter:hover::after { background: var(--accent-2); }

.rail, .col {
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  background: var(--bg-col);
}
.rail { background: var(--bg-rail); }

.rail-head, .col-head {
  padding: 9px 12px 7px;
  font-size: 11px; font-weight: 600; letter-spacing: .6px;
  text-transform: uppercase; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.rail-list, .col-list { flex: 1; overflow-y: auto; overflow-x: hidden; padding-bottom: 6px; }

.add-row {
  margin: 6px 8px 10px;
  padding: 7px 10px;
  text-align: left;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-soft); cursor: pointer;
}
.add-row:hover { background: var(--bg-hover); color: var(--accent); border-color: var(--accent); }

/* list items */
.item {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px 7px 12px;
  margin: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background .16s ease, box-shadow .16s ease;
}
.item:hover { background: var(--bg-hover); }
.item.active { background: var(--bg-active); }
.item.active .item-name { font-weight: 600; }
.item.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.item.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.item.dragging { opacity: .45; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, .12) inset;
}
.bar { width: 4px; align-self: stretch; border-radius: 2px; flex: none; }

.item-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-name[contenteditable="true"] {
  outline: 1px solid var(--accent);
  border-radius: 3px; padding: 0 2px;
  background: var(--bg-chrome);
  text-overflow: clip;
}
.item-sub {
  display: block;
  font-size: 11px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.item-col { flex: 1; min-width: 0; }
.count { font-size: 11px; color: var(--text-faint); }
.badge { font-size: 11px; flex: none; opacity: .75; line-height: 1; }

/* ── share dialog ──────────────────────────────────────────── */
.share-intro { margin: 0 0 14px; color: var(--text-soft); }
.share-mode {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 9px;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}
.share-mode:hover { background: var(--bg-hover); }
.share-mode:has(input:checked) { border-color: var(--accent-2); background: var(--accent-soft); }
.share-mode input { margin-top: 3px; accent-color: var(--accent); }
.share-mode span { display: flex; flex-direction: column; gap: 2px; }
.share-mode em, .share-who em { font-style: normal; font-size: 11.5px; color: var(--text-faint); }

.share-people {
  margin-top: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  max-height: 240px; overflow-y: auto;
  transition: opacity .2s ease;
}
.share-people.disabled { opacity: .45; }
.share-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 2px; cursor: pointer;
}
.share-row input { accent-color: var(--accent); width: 16px; height: 16px; }
.share-who { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.share-who b { font-weight: 600; }
.share-empty { margin: 2px 0 8px; font-size: 12.5px; color: var(--text-faint); }
.share-invite { display: flex; gap: 8px; margin-top: 10px; }
.share-invite input {
  flex: 1; min-width: 0; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: var(--bg-editor); color: var(--text); outline: none;
}
.share-invite input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(6, 182, 212, .16); }
.share-invite .btn-ghost { padding: 8px 14px; border-radius: 7px; }
.share-note { margin: 8px 0 0; font-size: 12px; color: #c4314b; }
.more {
  opacity: 0; flex: none;
  width: 20px; height: 20px; border: 0; border-radius: 3px;
  background: transparent; color: var(--text-soft); cursor: pointer;
}
.item:hover .more, .item.active .more { opacity: 1; }
.more:hover { background: var(--border); }
.star { color: #d29200; flex: none; }

/* ── Editor pane ───────────────────────────────────────────── */
.editor-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg-editor);
  position: relative;
}

.page-header { padding: 22px 44px 4px; }
.page-title {
  width: 100%;
  border: 0; outline: 0; background: transparent;
  font-size: 27px; font-weight: 400; color: var(--accent);
  padding: 0 0 4px;
  border-bottom: 1px solid transparent;
}
.page-title:focus { border-bottom-color: var(--border); }
.page-title::placeholder { color: var(--text-faint); }

.page-sub {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-faint); font-size: 11.5px;
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--border);
}
.chip {
  border: 1px solid var(--border); background: transparent;
  border-radius: 999px; padding: 2px 9px; cursor: pointer;
  color: var(--text-soft); font-size: 11.5px;
}
.chip:hover { background: var(--bg-hover); }
.chip.on { background: #fff4ce; border-color: #e5c04a; color: #7a5b00; }
[data-theme="dark"] .chip.on { background: #4a3a10; border-color: #7a6320; color: #ffd97a; }

.editor-scroll { flex: 1; overflow-y: auto; padding: 14px 44px 120px; }

/* Brief settle when you switch to another page. */
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.page-enter .page-header { animation: pageIn .3s cubic-bezier(.22, .8, .28, 1) both; }
.page-enter .editor { animation: pageIn .34s cubic-bezier(.22, .8, .28, 1) .04s both; }

.editor {
  outline: none;
  font-family: var(--font-note);
  font-size: 15px;
  line-height: 1.55;
  min-height: 300px;
  caret-color: var(--accent);
}
.editor:empty::before {
  content: "Start typing…";
  color: var(--text-faint);
}

/* editor content styling */
.editor h1 { font-size: 24px; font-weight: 600; margin: 18px 0 8px; color: var(--text); }
.editor h2 { font-size: 20px; font-weight: 600; margin: 16px 0 6px; color: var(--text); }
.editor h3 { font-size: 17px; font-weight: 600; margin: 14px 0 6px; color: var(--text); }
.editor p, .editor div { margin: 0 0 6px; }
.editor ul, .editor ol { margin: 4px 0 8px; padding-left: 26px; }
.editor li { margin: 2px 0; }
.editor a { color: var(--accent-2); }
.editor blockquote {
  margin: 8px 0; padding: 4px 14px;
  border-left: 3px solid var(--accent-2);
  color: var(--text-soft); font-style: italic;
}
.editor pre {
  font-family: var(--font-mono); font-size: 13px;
  background: var(--bg-hover);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin: 8px 0;
  white-space: pre-wrap; word-break: break-word;
}
.editor code { font-family: var(--font-mono); font-size: .92em; background: var(--bg-hover); padding: 1px 4px; border-radius: 3px; }
.editor hr { border: 0; border-top: 1px solid var(--border-strong); margin: 14px 0; }
.editor img { max-width: 100%; height: auto; border-radius: 4px; margin: 4px 0; }
.editor table { border-collapse: collapse; margin: 10px 0; min-width: 260px; }
.editor td, .editor th {
  border: 1px solid var(--border-strong);
  padding: 5px 9px; min-width: 60px; vertical-align: top;
}
.editor th { background: var(--bg-hover); font-weight: 600; text-align: left; }

.editor ul.checklist { list-style: none; padding-left: 4px; }
.editor ul.checklist li { display: flex; align-items: flex-start; gap: 8px; }
.editor ul.checklist input[type="checkbox"] {
  margin: 4px 0 0; width: 15px; height: 15px;
  accent-color: var(--accent); flex: none; cursor: pointer;
}
.editor ul.checklist li.done > span { text-decoration: line-through; color: var(--text-faint); }
.editor .tag-star { color: #f59e0b; font-weight: 700; }
.editor mark { background: #a5f3fc; color: #0e2a30; }

/* empty state */
.empty-state {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: var(--bg-editor);
}
.empty-inner { text-align: center; color: var(--text-soft); }
.empty-mark {
  width: 66px; height: 66px;
  margin: 0 auto 16px;
  animation: popIn .5s cubic-bezier(.22, .8, .28, 1) both;
}
.empty-inner h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; color: var(--text); }
.empty-inner p { margin: 0 0 16px; }

.btn-primary {
  background: var(--grad); color: #fff;
  border: 0; border-radius: 4px; padding: 8px 16px; cursor: pointer;
  box-shadow: 0 1px 2px rgba(46, 16, 101, .2);
}
.btn-primary:hover { filter: brightness(1.08) saturate(1.05); }
.btn-primary:active { filter: brightness(.96); }
.btn-primary:disabled { opacity: .6; cursor: default; filter: none; }
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 4px;
  padding: 8px 16px; cursor: pointer;
}
.btn-ghost:hover { background: var(--bg-hover); }

/* ── Status bar ────────────────────────────────────────────── */
.statusbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--bg-chrome);
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-faint);
}
.grow { flex: 1; }

/* ── Search panel ──────────────────────────────────────────── */
.search-panel {
  position: fixed; top: 44px; right: 10px; z-index: 70;
  width: 420px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--bg-chrome);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.search-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.search-panel-head .icon-btn:hover { background: var(--bg-hover); }
.search-results { overflow-y: auto; padding: 4px; }
.sresult { padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.sresult:hover, .sresult.sel { background: var(--bg-hover); }
.sresult .st { font-weight: 600; margin-bottom: 2px; }
.sresult .sp { font-size: 11px; color: var(--text-faint); margin-bottom: 3px; }
.sresult .sx { font-size: 12px; color: var(--text-soft); }
.sresult mark { background: #a5f3fc; color: #0e2a30; border-radius: 2px; }
.search-empty { padding: 20px; text-align: center; color: var(--text-faint); }

/* ── Context menu ──────────────────────────────────────────── */
.ctxmenu {
  position: fixed; z-index: 90;
  min-width: 190px; padding: 4px;
  background: var(--bg-chrome);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  transform-origin: top left;
  animation: menuIn .14s cubic-bezier(.2, .8, .2, 1) both;
}
.ctxmenu .palette span { transition: transform .16s cubic-bezier(.2, .8, .2, 1); }
.ctxmenu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  padding: 7px 10px; border: 0; border-radius: 4px;
  background: transparent; cursor: pointer;
}
.ctxmenu button:hover { background: var(--bg-hover); }
.ctxmenu .danger { color: #c4314b; }
.ctxmenu .palette { display: flex; gap: 5px; padding: 7px 10px; flex-wrap: wrap; }
.ctxmenu .palette span {
  width: 17px; height: 17px; border-radius: 50%; cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15) inset;
}
.ctxmenu .palette span:hover { transform: scale(1.18); }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 8, 44, .42);
  display: grid; place-items: center;
  animation: fadeIn .18s ease both;
  backdrop-filter: blur(2px);
}
.modal {
  width: min(520px, 92vw); max-height: 80vh; overflow: auto;
  background: var(--bg-chrome);
  border-radius: 10px; box-shadow: var(--shadow-2);
  padding: 20px 22px;
  animation: modalIn .24s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal kbd {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px;
}
.modal .krow { display: flex; justify-content: space-between; gap: 20px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.modal .krow:last-child { border-bottom: 0; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 36px; left: 50%;
  z-index: 120;
  background: #2a1c46; color: #fff;
  padding: 9px 16px; border-radius: 20px;
  box-shadow: var(--shadow-2);
  font-size: 12.5px;
  animation: toastIn .28s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Scrollbars ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ══ Responsive ═════════════════════════════════════════════ */

/* Laptops / large tablets in landscape — same three columns, tighter. */
@media (max-width: 1180px) {
  .panes { grid-template-columns: 168px 4px 164px 4px 188px 4px; }
  .editor-scroll, .page-header { padding-left: 28px; padding-right: 28px; }
  .searchbox { width: 210px; }
  .searchbox:focus-within { width: 250px; }
}

/* Phones and tablets in portrait — the three panes become a drawer. */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }

  .panes {
    position: absolute; z-index: 40;
    top: 0; bottom: 0; left: 0;
    width: min(330px, 86vw);
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1.2fr;
    border-right: 1px solid var(--border);
    box-shadow: 8px 0 28px rgba(20, 8, 44, .18);
    transform: translateX(-102%);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1);
    will-change: transform;
  }
  .panes.open { transform: none; }

  .rail, .col { min-height: 0; border-bottom: 1px solid var(--border); }
  .gutter { display: none; }

  .nav-scrim {
    display: block;
    position: absolute; inset: 0; z-index: 35;
    background: rgba(20, 8, 44, .38);
    animation: fadeIn .22s ease both;
  }
  .nav-toggle { display: grid; }

  /* Room is tight: the breadcrumb duplicates what the drawer already shows. */
  .breadcrumb { display: none; }
  .titlebar { gap: 8px; padding: 0 6px 0 6px; }
  .searchbox { width: 168px; }
  .searchbox:focus-within { width: 190px; }
  .search-panel { width: calc(100vw - 16px); right: 8px; }

  .editor-scroll { padding: 12px 20px 140px; }
  .page-header { padding: 16px 20px 4px; }
  .page-title { font-size: 23px; }
}

/* Phones. */
@media (max-width: 560px) {
  #app { grid-template-rows: 44px 40px 1fr 0; }
  .statusbar { display: none; }
  .brand-name { display: none; }
  .searchbox { width: 40px; padding: 0 7px; }
  .searchbox input { width: 0; padding: 0; }
  .searchbox:focus-within { width: min(62vw, 250px); }
  .searchbox:focus-within input { width: 100%; }
  .editor-scroll { padding: 10px 16px 140px; }
  .page-header { padding: 14px 16px 4px; }
  .intro-nav { padding: 14px 16px; }
  .modal { padding: 18px 16px; }
}

/* Touch: bigger hit areas, and no hover-only affordances. */
@media (pointer: coarse) {
  .item { padding: 11px 10px 11px 12px; }
  .more { opacity: 1; }
  .tbtn { min-width: 34px; height: 34px; }
  .add-row { padding: 11px 10px; }
  .chip { padding: 5px 12px; }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  .titlebar, .ribbon, .workspace > .rail, .workspace > .col, .gutter,
  .statusbar, .page-sub, .search-panel { display: none !important; }
  #app { display: block; height: auto; }
  .workspace { display: block; }
  .editor-scroll { overflow: visible; padding: 0; }
  body, html { overflow: visible; height: auto; }
  .page-title { color: #000; font-size: 24px; }
}
