:root {
  /* Editor: yellow legal-pad paper. Surround: neutral cream. */
  --paper: #FFEF83;
  --paper-edge: #ecdc6a;
  --ink: #1a1a1a;
  --ink-soft: #6b6258;
  --rule: #6e96cf;
  --rule-faint: rgba(74, 110, 170, .35);
  --code-bg: #2b2a26;
  --code-fg: #f4ead5;
  --code-border: #3a382f;
  --tip-bg: #2b2722;
  --tip-fg: #fef3c7;
  --accent: #c0392b;
  --accent-soft: #f6dcd6;
  --bg: #8a5a2b;
  --panel: #b8804a;
  --panel-edge: #7a4f28;
  --toolbox-bg: #f5ead0;
  --toolbox-border: #c9a76d;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 12px 32px rgba(60, 40, 10, .08);
  --radius: 10px;
  --line-h: 36px;
  --pad-top: clamp(28px, 3.5vw, 50px);
  --pad-x: clamp(24px, 6vw, 72px);
  --pad-y: clamp(28px, 5vw, 56px);
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
}

[data-theme="dark"] {
  --paper: #1c1d22;
  --paper-edge: #14151a;
  --ink: #e7e3d8;
  --ink-soft: #9a958a;
  --rule: #2e2f36;
  --rule-faint: rgba(255, 220, 160, .07);
  --code-bg: #0e0f12;
  --code-fg: #d8d3c4;
  --code-border: #2a2c33;
  --tip-bg: #f3ecdb;
  --tip-fg: #2b2722;
  --accent: #f6b04a;
  --accent-soft: #2a2419;
  --bg: #0e0f12;
  --panel: #16171c;
  --panel-edge: #23252c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 16px 48px rgba(0,0,0,.5);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 22px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

/* ---------- Sidebar (slide-in overlay) ---------- */
#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--panel-edge);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform .18s ease;
  z-index: 30;
  box-shadow: var(--shadow);
}
body.show-sidebar #sidebar { transform: translateX(0); }
body.show-sidebar::after {
  content: "";
  position: fixed; inset: 0;
  background: rgba(0,0,0,.25);
  z-index: 25;
  animation: fade-in .18s ease;
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }

.side-head {
  display: flex;
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--panel-edge);
}

.side-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--panel-edge);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.side-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.side-btn.ghost { flex: 0 0 36px; }

#note-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}

#note-list li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}
#note-list li:hover { background: var(--paper); }
#note-list li.active { background: var(--paper); box-shadow: inset 0 0 0 1px var(--panel-edge); }
#note-list li .n-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#note-list li .n-meta {
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#note-list li .n-del {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  opacity: 0;
}
#note-list li:hover .n-del { opacity: 1; }
#note-list li .n-del:hover { background: var(--accent-soft); color: var(--accent); }

.side-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--panel-edge);
  font-size: 12px;
}
.muted { color: var(--ink-soft); }

/* ---------- Topbar ---------- */
#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  width: 100%;
}

#topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--panel-edge);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

#topbar .left  { display: flex; align-items: center; gap: 8px; justify-self: start; min-width: 0; }
#topbar .right { display: flex; align-items: center; gap: 4px; justify-self: end; }
.spacer { display: none; }

#title {
  border: 0;
  background: transparent;
  font: 600 22px/1.2 var(--font-sans);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 8px;
  width: 320px;
  outline: none;
}
#title:focus { background: var(--paper); }
#title::placeholder { color: var(--ink-soft); }

#toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--paper);
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  padding: 3px;
}
#toolbar button {
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 42px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}
#toolbar button:hover { background: var(--accent-soft); color: var(--accent); }
#toolbar button.active { background: var(--accent-soft); color: var(--accent); }
#toolbar .sep { width: 1px; height: 18px; background: var(--panel-edge); margin: 0 4px; }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 48px;
  height: 45px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg { width: 24px; height: 24px; }
#toolbar button svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

[data-theme="light"] #theme-btn .i-moon { display: none; }
[data-theme="dark"]  #theme-btn .i-sun  { display: none; }

/* ---------- Menus ---------- */
.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  padding: 6px;
  min-width: 200px;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.menu button {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.menu button:hover { background: var(--accent-soft); color: var(--accent); }
.menu button.danger { color: #b91c1c; }
[data-theme="dark"] .menu button.danger { color: #fb7185; }
.menu button.danger:hover { background: rgba(220,38,38,.1); color: #ef4444; }
.menu hr { border: 0; border-top: 1px solid var(--panel-edge); margin: 4px 2px; }

#slash-menu {
  position: fixed;
  min-width: 240px;
}
#slash-menu button { padding: 8px 12px; }
#slash-menu button span {
  display: inline-flex;
  width: 28px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--paper);
  border: 1px solid var(--panel-edge);
  font-size: 12px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
}
#slash-menu button em { font-style: normal; color: var(--ink); }
#slash-menu button.active { background: var(--accent-soft); color: var(--accent); }
#slash-menu button.active span { border-color: var(--accent); color: var(--accent); }

/* ---------- Paper / Editor ---------- */
#paper {
  background: var(--paper);
  display: flex;
  overflow-y: auto;
}

#editor {
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  min-height: calc(100vh - 140px);
  padding: var(--pad-top) clamp(24px, 4vw, 56px);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: var(--line-h);
  letter-spacing: .005em;
  caret-color: var(--accent);
  position: relative;
}

#editor.is-empty::before {
  content: attr(data-placeholder);
  color: var(--ink-soft);
  pointer-events: none;
  position: absolute;
}

/* All block elements snap to the line grid (no margins, line-height = rule spacing).
   Combined with the lined background, every text row sits exactly between two rules. */
#editor > *,
#editor li {
  margin: 0;
  line-height: var(--line-h);
}
#editor h1, #editor h2, #editor h3, #editor h4 {
  font-family: var(--font-sans);
  letter-spacing: -.01em;
  font-weight: 700;
  /* Heading fits in one line slot so rules never bisect the text */
  line-height: var(--line-h);
}
#editor h1 { font-size: 1.25em; }
#editor h2 { font-size: 1.12em; }
#editor h3 { font-size: 1.02em; }
#editor blockquote {
  padding: 0 0 0 14px;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
}
#editor pre {
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 6px 0;
  font-family: var(--font-mono);
  font-size: .88em;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.55;
  tab-size: 2;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.02);
}
#editor code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--code-border);
}
#editor pre code { background: transparent; padding: 0; border: 0; }
#editor a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
#editor ul, #editor ol {
  margin: 0;
  padding-left: 1.4em;
  line-height: var(--line-h);
}
#editor li {
  margin: 0;
  line-height: var(--line-h);
  min-height: var(--line-h);
}
/* execCommand sometimes wraps list-in-p; flatten visually so heights stay snapped */
#editor p > ul, #editor p > ol { display: block; }
#editor hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 0;
  height: var(--line-h);
  position: relative;
}
#editor img { max-width: 100%; border-radius: 6px; }

/* paper styles */
[data-paper="lined"] #editor {
  background-image: linear-gradient(to bottom, transparent calc(var(--line-h) - 1px), var(--rule-faint) calc(var(--line-h) - 1px), var(--rule-faint) var(--line-h), transparent var(--line-h));
  background-size: 100% var(--line-h);
  background-position: 0 var(--pad-top);
}
[data-paper="dotted"] #editor {
  background-image: radial-gradient(var(--rule) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: 14px 14px;
}
[data-paper="grid"] #editor {
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ---------- Statusbar ---------- */
#statusbar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 22px;
  border-top: 1px solid var(--panel-edge);
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 17px;
}
.status-spacer { flex: 1; }
.status-storage { white-space: nowrap; font-size: 13px; opacity: .75; letter-spacing: .02em; }
.status-link {
  background: transparent;
  border: 0;
  padding: 2px 4px;
  margin: 0;
  color: var(--ink-soft);
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
}
.status-link:hover { color: var(--accent); }

@media (max-width: 640px) {
  .status-storage { display: none; }
}
.dot { opacity: .5; }
#save-state.saving { color: var(--accent); }
#save-state.saved::before {
  content: "●";
  color: #16a34a;
  margin-right: 6px;
  font-size: 8px;
  vertical-align: middle;
}
[data-theme="dark"] #save-state.saved::before { color: #4ade80; }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
  max-width: 480px;
  width: 92vw;
}
dialog::backdrop { background: rgba(0,0,0,.4); backdrop-filter: blur(2px); }
dialog form { padding: 22px 26px; }
dialog h2 { margin: 0 0 14px; font-size: 16px; }
dialog dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
dialog dt { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); }
dialog dd { margin: 0; font-size: 14px; }
dialog kbd {
  background: var(--paper);
  border: 1px solid var(--panel-edge);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font: 600 11px/1 var(--font-mono);
}
dialog menu { display: flex; justify-content: flex-end; padding: 0; margin: 18px 0 0; }
dialog menu button {
  border: 1px solid var(--panel-edge);
  background: var(--paper);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
dialog menu button:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
  animation: toast-in .22s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Tooltips (custom, subtle) ---------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-2px);
  background: var(--tip-bg);
  color: var(--tip-fg);
  font: 500 11px/1 var(--font-sans);
  padding: 5px 8px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease .25s, transform .12s ease .25s;
  box-shadow: 0 4px 14px rgba(0,0,0,.14);
  z-index: 100;
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
[data-tip-side="left"]::after  { left: auto; right: calc(100% + 8px); top: 50%; transform: translateY(-50%) translateX(2px); }
[data-tip-side="left"]:hover::after  { transform: translateY(-50%) translateX(0); }
[data-tip-side="right"]::after { left: calc(100% + 8px); top: 50%; transform: translateY(-50%) translateX(-2px); }
[data-tip-side="right"]:hover::after { transform: translateY(-50%) translateX(0); }

/* ---------- About dialog ---------- */
#about-dialog { max-width: 560px; }
#about-dialog form { padding: 24px 22px; min-width: 360px; max-width: none; }
#about-dialog .about-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding: 0 4px; }
#about-dialog .about-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #e07a6a);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 700 18px/1 var(--font-sans);
  letter-spacing: -.02em;
  flex-shrink: 0;
}
#about-dialog h2 { margin: 0; font-size: 17px; font-weight: 700; }
#about-dialog .about-tag { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }

#about-dialog .about-links { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
#about-dialog .about-links a {
  display: grid;
  grid-template-columns: 16px max-content 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--panel-edge);
  transition: border-color .12s ease, transform .12s ease;
  width: 100%;
  box-sizing: border-box;
}
#about-dialog .about-links a:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
#about-dialog .about-links a svg { color: var(--ink-soft); }
#about-dialog .about-links a:hover svg { color: var(--accent); }
#about-dialog .about-label { color: var(--ink-soft); font-size: 12px; font-weight: 500; }
#about-dialog .about-value { font-size: 13px; text-align: right; color: var(--ink); justify-self: end; padding-right: 2px; }

#about-dialog menu { display: flex; justify-content: flex-end; padding: 0; margin: 18px 0 0; }
#about-dialog menu button.primary {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
  padding: 6px 14px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
[data-theme="dark"] #about-dialog menu button.primary { color: #1c1d22; }

/* ---------- Link modal ---------- */
#link-dialog form { padding: 22px 24px; min-width: 360px; }
#link-dialog .field { display: grid; gap: 6px; margin-bottom: 12px; }
#link-dialog .field span { font-size: 12px; color: var(--ink-soft); font-weight: 500; }
#link-dialog input {
  background: var(--paper);
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 6px;
  font: inherit;
  outline: none;
  transition: border-color .12s ease;
}
#link-dialog input:focus { border-color: var(--accent); }
#link-dialog menu button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
[data-theme="dark"] #link-dialog menu button.primary { color: #1c1d22; }
#link-dialog menu button.ghost { background: transparent; }

/* ---------- Wood desk (light theme only) ---------- */
[data-theme="light"] #topbar,
[data-theme="light"] #statusbar,
[data-theme="light"] #sidebar {
  background-color: #b8804a;
  background-image:
    /* darker grain streaks */
    repeating-linear-gradient(90deg,
      rgba(70, 40, 15, 0)   0px,
      rgba(70, 40, 15, 0)   28px,
      rgba(70, 40, 15, .12) 28px,
      rgba(70, 40, 15, .12) 30px),
    /* fine grain */
    repeating-linear-gradient(90deg,
      rgba(70, 40, 15, 0)  0px,
      rgba(70, 40, 15, .06) 1px,
      rgba(70, 40, 15, 0)  3px),
    /* knot / cloud shading */
    radial-gradient(ellipse 80% 60% at 15% 50%, rgba(60, 30, 10, .25), transparent 70%),
    radial-gradient(ellipse 60% 70% at 75% 30%, rgba(60, 30, 10, .20), transparent 70%),
    radial-gradient(ellipse 50% 50% at 50% 80%, rgba(255, 220, 170, .15), transparent 70%),
    /* base tone gradient */
    linear-gradient(180deg, #c79461, #a06d3a);
}
[data-theme="light"] #sidebar {
  background-image:
    repeating-linear-gradient(0deg,
      rgba(70, 40, 15, 0)   0px,
      rgba(70, 40, 15, 0)   28px,
      rgba(70, 40, 15, .12) 28px,
      rgba(70, 40, 15, .12) 30px),
    repeating-linear-gradient(0deg,
      rgba(70, 40, 15, 0)   0px,
      rgba(70, 40, 15, .06) 1px,
      rgba(70, 40, 15, 0)   3px),
    radial-gradient(ellipse 60% 80% at 50% 20%, rgba(60, 30, 10, .25), transparent 70%),
    radial-gradient(ellipse 70% 60% at 30% 75%, rgba(60, 30, 10, .20), transparent 70%),
    linear-gradient(90deg, #c79461, #a06d3a);
}

[data-theme="light"] #topbar,
[data-theme="light"] #statusbar { border-color: rgba(50, 25, 5, .35); }
[data-theme="light"] #sidebar { border-right-color: rgba(50, 25, 5, .35); }

/* Toolbar: cream pill, not yellow, sitting on the wood */
[data-theme="light"] #toolbar {
  background: var(--toolbox-bg);
  border-color: var(--toolbox-border);
}
[data-theme="light"] #toolbar .sep { background: var(--toolbox-border); }

/* Title input stays cream-on-wood so it's readable */
[data-theme="light"] #title { color: #fdf5d6; }
[data-theme="light"] #title::placeholder { color: rgba(253, 245, 214, .65); }
[data-theme="light"] #title:focus { background: rgba(255,255,255,.18); color: #fff; }

/* Icon buttons on wood: cream text with subtle hover */
[data-theme="light"] #topbar .icon-btn,
[data-theme="light"] #show-sidebar { color: #fdf5d6; }
[data-theme="light"] #topbar .icon-btn:hover,
[data-theme="light"] #show-sidebar:hover { background: rgba(255, 245, 220, .18); color: #fff; }

/* Statusbar text on wood */
[data-theme="light"] #statusbar { color: #f3e4c2; }
[data-theme="light"] .status-link { color: #f3e4c2; }
[data-theme="light"] .status-link:hover { color: #fff; background: rgba(255,245,220,.15); }
[data-theme="light"] #save-state.saved::before { color: #8be38b; }

/* Sidebar buttons on wood */
[data-theme="light"] .side-btn { background: var(--toolbox-bg); border-color: var(--toolbox-border); color: var(--ink); }
[data-theme="light"] #note-list li { color: #fdf5d6; }
[data-theme="light"] #note-list li .n-meta { color: rgba(253, 245, 214, .7); }
[data-theme="light"] #note-list li:hover,
[data-theme="light"] #note-list li.active {
  background: rgba(255, 245, 220, .15);
  box-shadow: none;
}
[data-theme="light"] .side-foot { color: rgba(253, 245, 214, .8); border-top-color: rgba(50,25,5,.35); }
[data-theme="light"] .side-head { border-bottom-color: rgba(50,25,5,.35); }

/* ---------- Selection ---------- */
::selection { background: var(--accent-soft); color: var(--ink); }

/* ---------- Print ---------- */
@media print {
  body { display: block; background: white; }
  #sidebar, #topbar, #statusbar, #toast, .menu, dialog { display: none !important; }
  #paper { padding: 0; background: white; }
  #editor {
    box-shadow: none;
    border: 0;
    background: white !important;
    background-image: none !important;
    color: black;
    width: 100%;
    padding: 0;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  /* Smaller base type so the 1.4x scaling doesn't crowd phones */
  :root {
    --line-h: 30px;
    --pad-top: 16px;
  }
  html, body { font-size: 18px; }

  #topbar {
    grid-template-columns: auto 1fr auto;
    gap: 4px;
    padding: 10px 12px;
  }
  #topbar .left { gap: 4px; min-width: 0; flex: 1; }
  #title {
    width: auto;
    flex: 1;
    min-width: 0;
    font-size: 17px;
    padding: 4px 6px;
  }
  #toolbar { display: none; }

  /* Hide the secondary right-side icons; keep only the More menu */
  #paper-btn, #theme-btn, #reset-btn { display: none; }

  .icon-btn { width: 38px; height: 36px; }
  .icon-btn svg { width: 20px; height: 20px; }

  #editor {
    padding: 18px 16px;
    font-size: 16px;
  }

  #statusbar {
    padding: 8px 12px;
    gap: 6px;
    font-size: 12px;
  }
  /* Hide the long "Notes stored locally..." text and the dot before About */
  .status-storage,
  #statusbar .status-storage + .dot { display: none; }

  /* Sidebar covers more of the screen */
  #sidebar { width: min(86vw, 320px); }

  /* Dialogs: edge-padded on small screens */
  dialog { width: 92vw; max-width: 92vw; }
  #about-dialog form,
  #link-dialog form { padding: 18px 18px; min-width: auto; }
  #about-dialog .about-links a {
    grid-template-columns: 18px 1fr auto;
    padding: 10px 12px;
  }
  #about-dialog .about-head { gap: 12px; }
  #about-dialog .about-avatar { width: 38px; height: 38px; font-size: 16px; }

  /* Custom tooltips can clip off the top of small screens — disable */
  [data-tip]::after { display: none !important; }
}

/* Tighter still on very small phones */
@media (max-width: 380px) {
  #title { font-size: 15px; }
  #statusbar { font-size: 11px; }
  #editor { padding: 14px 12px; font-size: 15.5px; }
}
