/* blank-page — a distraction-free writing space with pages */

:root {
  --bg: #fdfcfa;
  --fg: #1c1c19;
  --muted: #8c8c82;
  --soft: #6f6f66;
  --line: #e6e4dd;
  --hover: #f1efe9;
  --card: #ffffff;
  --side: #f8f6f1;
  --mark: #1c1c19;
  --accent: #1c1c19;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-write: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --measure: 46rem;
  --side-w: 240px;
  --ease: 260ms cubic-bezier(.2, .7, .3, 1);
}

html.dark {
  --bg: #131311;
  --fg: #e9e8e1;
  --muted: #7f7f74;
  --soft: #a5a59a;
  --line: #2a2a25;
  --hover: #232320;
  --card: #1b1b18;
  --side: #171715;
  --mark: #e9e8e1;
  --accent: #e9e8e1;
}

html.serif {
  --font-write: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- chrome ---------- */

.chrome {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  color: var(--muted);
  transition: opacity var(--ease);
}

.chrome-top {
  height: calc(54px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}

.chrome-bottom {
  padding-top: 4px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  font-size: 0.75rem;
  letter-spacing: 0.01em;
}

/* while writing, the top bar gets out of the way (mouse move brings it back) */
body.typing .chrome-top { opacity: 0; }
body.typing .chrome-bottom { opacity: .45; }

.chrome-group { display: flex; align-items: center; gap: 8px; min-width: 0; }

.chrome-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* The wordmark belongs to the pages sidebar: shut the sidebar and the bar is
   left with just its toggles, the way a collapsed chat sidebar behaves. */
html.left-closed .chrome-brand { display: none; }

.home {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 4px 2px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  border-radius: 8px;
}

.home:hover .home-label { text-decoration: underline; text-underline-offset: 3px; }
.home:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.home-mark {
  position: relative;
  width: 20px; height: 20px;
  border-radius: 6px;
  background: var(--mark);
  flex: none;
}

.home-mark::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.8px solid var(--bg);
  border-bottom-color: transparent;
  border-right-color: transparent;
  transform: rotate(45deg);
}

.bar-title {
  margin: 0;
  color: var(--fg);
  font-size: 0.9375rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.bar-title::before {
  content: "/";
  margin-right: 10px;
  color: var(--line);
  font-weight: 400;
}

.controls { display: flex; align-items: center; gap: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 550;
  cursor: pointer;
  transition: color var(--ease), background-color var(--ease), border-color var(--ease), opacity var(--ease);
}

.btn:hover { background: var(--hover); border-color: color-mix(in srgb, var(--fg) 18%, var(--line)); }
.btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* the toggle reads as "on" while its panel is open */
html:not(.left-closed) #toggle-pages,
html:not(.right-closed) #toggle-community { color: var(--fg); background: var(--hover); }

.icon { width: 16px; height: 16px; }

.btn-label { padding-right: 2px; }

/* ---------- save menu ---------- */

/* Nothing to save while the page is blank, so the button only appears once
   there is a word in it. */
.save {
  position: relative;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity var(--ease), transform var(--ease), visibility var(--ease);
}

body.has-text .save { visibility: visible; opacity: 1; transform: none; }

.chev {
  width: 14px;
  height: 14px;
  margin-left: -2px;
  opacity: .55;
}

.save-options {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 192px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 2px 4px rgba(20, 20, 18, .05), 0 18px 36px -20px rgba(20, 20, 18, .4);
}

.save-options[hidden] { display: none; }

.save-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

.save-item:hover { background: var(--hover); }
.save-item:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
.save-ext { color: var(--muted); font-size: 0.75rem; }

/* ---------- layout ---------- */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

/* ---------- sidebars ---------- */

.side {
  flex: none;
  width: var(--side-w);
  overflow: hidden;
  background: var(--side);
  transition: width var(--ease), visibility 0s;
}

.side-left { border-right: 1px solid var(--line); }
.side-right { border-left: 1px solid var(--line); }

html.left-closed .side-left,
html.right-closed .side-right {
  width: 0;
  border-right-width: 0;
  border-left-width: 0;
  /* gone from the tab order, but only after the collapse finishes */
  visibility: hidden;
  transition: width var(--ease), visibility 0s linear var(--ease);
}

.side-clip {
  width: var(--side-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 8px 14px;
}

/* ---------- page search ---------- */

.side-search {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  margin: 0 10px 6px;
}

.search-icon {
  position: absolute;
  left: 9px;
  width: 13px;
  height: 13px;
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 30px;
  padding: 0 26px 0 27px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--hover);
  color: var(--fg);
  font: inherit;
  font-size: 0.78125rem;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: background-color var(--ease), border-color var(--ease);
}

.search-input::-webkit-search-cancel-button { display: none; }
.search-input::placeholder { color: var(--muted); }
.search-input:hover { background: color-mix(in srgb, var(--hover) 70%, var(--line)); }
.search-input:focus { background: var(--card); border-color: var(--line); }

.search-clear {
  position: absolute;
  right: 4px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.search-clear[hidden] { display: none; }
.search-clear:hover { color: var(--fg); background: var(--line); }
.search-clear:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
.search-clear svg { width: 12px; height: 12px; }

.page-empty {
  padding: 14px 10px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

.page-meta mark,
.page-snippet mark {
  background: transparent;
  color: var(--fg);
  font-weight: 600;
}

.page-snippet {
  display: block;
  font-size: 0.6875rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-head h2 {
  margin: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color var(--ease), background-color var(--ease);
}

.mini-btn:hover { color: var(--fg); background: var(--hover); }
.mini-btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; color: var(--fg); }
.mini-btn svg { width: 12px; height: 12px; }

/* ---------- page list ---------- */

.page-list {
  list-style: none;
  margin: 0;
  padding: 2px 8px 8px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.page-list::-webkit-scrollbar { width: 8px; }
.page-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.page-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: 8px;
  margin-bottom: 1px;
  transition: background-color var(--ease);
}

.page-item:hover { background: var(--hover); }
.page-item.is-active { background: var(--hover); }

.page-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.page-open:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }

.page-name {
  display: block;
  max-width: 100%;
  font-size: 0.8125rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-item.is-active .page-name { font-weight: 600; }

.page-meta {
  display: block;
  font-size: 0.6875rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-actions {
  flex: none;
  display: flex;
  gap: 0;
  padding-right: 4px;
  opacity: 0;
  transition: opacity var(--ease);
}

.page-item:hover .page-actions,
.page-item:focus-within .page-actions,
.page-item.is-active .page-actions { opacity: 1; }

@media (hover: none) {
  .page-actions { opacity: 1; }
}

.page-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--ease), background-color var(--ease);
}

.page-actions button:hover { color: var(--fg); background: rgba(0, 0, 0, .06); }
html.dark .page-actions button:hover { background: rgba(255, 255, 255, .08); }
.page-actions button:focus-visible { outline: 2px solid var(--fg); outline-offset: -1px; color: var(--fg); }
.page-actions svg { width: 14px; height: 14px; }

.page-rename {
  width: 100%;
  margin: 4px;
  padding: 4px 6px;
  border: 1px solid var(--fg);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  outline: none;
}

.side-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 0.6875rem;
  color: var(--muted);
}

/* ---------- community panel ---------- */

.side-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 14px 16px;
  font-size: 0.8125rem;
  color: var(--soft);
}

.side-copy { margin: 0 0 14px; line-height: 1.55; }

.side-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  margin: 0 -9px 2px;
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.8125rem;
  transition: background-color var(--ease), color var(--ease);
}

.side-link:hover { background: var(--hover); }
.side-link:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; }
.side-link svg { width: 13px; height: 13px; margin-left: auto; color: var(--muted); }

.side-link-strong { font-weight: 600; }

.side-rule {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.side-body h3 {
  margin: 0 0 8px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.shortcuts { margin: 0; font-size: 0.75rem; }

.shortcuts > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
}

.shortcuts dt {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.6875rem;
  color: var(--fg);
  background: var(--hover);
  border-radius: 4px;
  padding: 1px 5px;
  white-space: nowrap;
}

.shortcuts dd { margin: 0; color: var(--muted); text-align: right; }

.side-note {
  margin: 16px 0 0;
  font-size: 0.6875rem;
  line-height: 1.5;
  color: var(--muted);
}

/* ---------- options panel ---------- */

.side-section {
  padding: 13px 0 6px;
  border-top: 1px solid var(--line);
}

.side-section:first-child { padding-top: 2px; border-top: 0; }

.side-label { margin-top: 14px !important; }

.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--hover);
}

.seg-btn {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 26px;
  padding: 0 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--ease), background-color var(--ease), box-shadow var(--ease);
}

.seg-btn svg { width: 13px; height: 13px; flex: none; }
.seg-btn:hover { color: var(--fg); }
.seg-btn:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

.seg-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(20, 20, 18, .08);
}

.seg-serif { font-family: Georgia, "Times New Roman", serif; font-size: 0.8125rem; }

.row-switch {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 8px;
  font-size: 0.8125rem;
  line-height: 1.35;
  cursor: pointer;
}

.row-label { display: block; }

.row-label small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.6875rem;
  line-height: 1.4;
}

input.switch {
  flex: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 1px 0 0;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background-color var(--ease);
}

input.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(20, 20, 18, .25);
  transition: transform var(--ease), background-color var(--ease);
}

input.switch:checked { background: var(--fg); }
input.switch:checked::before { transform: translateX(14px); background: var(--bg); }
input.switch:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

/* ---------- editor ---------- */

main {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
}

/* The textarea fills the whole pane and centres the column with its padding,
   so the scrollbar rides the right edge of the screen instead of stopping at
   the end of a narrow, centred text box. */
#editor {
  width: 100%;
  height: 100%;
  max-width: none;
  padding: 12px max(22px, calc((100% - var(--measure)) / 2)) 36px;
  overflow-y: auto;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-write);
  font-size: 1.125rem;
  line-height: 1.75;
  letter-spacing: 0.003em;
  caret-color: var(--fg);
  overflow-wrap: break-word;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

#editor:focus-visible { outline: none; }

/* leave room under the last line for the floating formatting bar */
html.format-on #editor { padding-bottom: 88px; }

#editor.is-empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  opacity: .7;
  pointer-events: none;
}

/* ---------- what the editor can hold ---------- */

#editor div,
#editor p { margin: 0; }

#editor p { margin-bottom: .6em; }

#editor h2 {
  margin: 1.1em 0 .35em;
  font-size: 1.35em;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.015em;
}

#editor h2:first-child { margin-top: 0; }

#editor ul,
#editor ol {
  margin: 0 0 .7em;
  padding-left: 1.4em;
}

#editor li { margin: .1em 0; }

#editor blockquote {
  margin: 0 0 .8em;
  padding-left: .9em;
  border-left: 2px solid var(--line);
  color: var(--soft);
}

#editor a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#editor strong, #editor b { font-weight: 650; }

#editor code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
  background: var(--hover);
  border-radius: 4px;
  padding: .08em .3em;
}

#editor pre {
  margin: 0 0 .8em;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--hover);
  overflow-x: auto;
  font-size: .875em;
}

#editor pre code { background: none; padding: 0; font-size: inherit; }

#editor img { max-width: 100%; border-radius: 8px; }

#editor::-webkit-scrollbar { width: 8px; }
#editor::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
#editor::-webkit-scrollbar-track { background: transparent; }

/* ---------- formatting bar ---------- */

.format-bar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 6;
  display: none;
  align-items: center;
  gap: 1px;
  padding: 5px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 13px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 2px rgba(20, 20, 18, .04), 0 18px 34px -20px rgba(20, 20, 18, .5);
}

html.format-on .format-bar { display: flex; }

.fmt {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--soft);
  font: inherit;
  font-size: 0.875rem;
  line-height: 1;
  cursor: pointer;
  transition: color var(--ease), background-color var(--ease);
}

.fmt:hover { color: var(--fg); background: var(--hover); }
.fmt:active { transform: scale(.96); }
.fmt:focus-visible { outline: 2px solid var(--fg); outline-offset: -2px; color: var(--fg); }
.fmt svg { width: 16px; height: 16px; }

.fmt-bold { font-weight: 750; }
.fmt-italic { font-style: italic; font-family: Georgia, "Times New Roman", serif; font-size: 1rem; }
.fmt-strike { text-decoration: line-through; }

.fmt-sep {
  width: 1px;
  height: 17px;
  margin: 0 4px;
  background: var(--line);
}

.fmt-close { color: var(--muted); }
.fmt-close svg { width: 13px; height: 13px; }

.chrome-bottom p { margin: 0; }

.status { transition: opacity var(--ease); }

/* ---------- small screens: sidebars become drawers ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(20, 20, 18, .32);
  opacity: 0;
  transition: opacity var(--ease);
}

.scrim[hidden] { display: none; }
body.drawer-open .scrim { opacity: 1; }

@media (max-width: 860px) {
  .side {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 30;
    width: min(286px, 86vw);
    box-shadow: 0 0 40px rgba(20, 20, 18, .18);
    transition: transform var(--ease);
  }

  .side-clip { width: 100%; }

  .side-left { left: 0; transform: translateX(0); }
  .side-right { right: 0; transform: translateX(0); }

  html.left-closed .side-left { width: min(286px, 86vw); transform: translateX(-102%); border-right-width: 1px; }
  html.right-closed .side-right { width: min(286px, 86vw); transform: translateX(102%); border-left-width: 1px; }

  .side-head { padding-top: max(12px, env(safe-area-inset-top)); }
  .side-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  .chrome { padding-left: 12px; padding-right: 12px; }
  .chrome-group { gap: 6px; }
  .home-label { display: none; }
  .bar-title { font-size: 0.875rem; }
  .bar-title::before { content: none; }
  #editor {
    padding-top: 10px;
    padding-left: 20px;
    padding-right: 20px;
    font-size: 1.0625rem;
    line-height: 1.7;
  }
  html.format-on #editor { padding-bottom: 96px; }
  .btn-label { display: none; }
  .save .btn { width: 34px; padding: 0; }
  .save .chev { display: none; }
  .format-bar { bottom: 8px; gap: 0; padding: 4px; }
  .fmt { width: 30px; height: 30px; }
  .fmt-sep { margin: 0 2px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
