:root {
  --bg: #f3f2ef;
  --paper: #ffffff;
  --ink: #111111;
  --paper-max-width: 700px;
  --column-max-width: none;      /* text fills the paper; set e.g. 34em for a narrower measure */
  --paper-padding-top: 25px;
  --paper-padding-x: 25px;
  --font: Charter, "Iowan Old Style", Georgia, serif;
  --size: 17px;                  /* 13pt */
  --weight: 400;                 /* roman */
  --line-height: 1.6;
  --indent-size: 2em;            /* how far an indented first line moves */
  --indent: var(--indent-size);  /* current default: var(--indent-size) or 0 */
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
}

.paper {
  max-width: var(--paper-max-width);
  margin: 0 auto;
  min-height: 100vh;
  box-sizing: border-box;
  background: var(--paper);
  padding: var(--paper-padding-top) var(--paper-padding-x) 40vh;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.03);
}

#editor {
  max-width: var(--column-max-width);
  margin: 0 auto;
  outline: none;
  font-family: var(--font);
  font-size: var(--size);
  font-weight: var(--weight);
  font-style: normal;
  line-height: var(--line-height);
  color: var(--ink);
  caret-color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

#editor p {
  margin: 0;
  text-indent: var(--indent);
  min-height: 1lh;
}

/* Formatting popover: visible only with a non-empty selection */
#popover {
  position: fixed;
  top: 0;
  left: 0;
  background: #1f1f1f;
  color: #eee;
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 2px;
  font: 13px -apple-system, system-ui, sans-serif;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 10;
  opacity: 0;
  transition: opacity 120ms;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#popover.show {
  opacity: 1;
  pointer-events: auto;
}

#popover button {
  padding: 4px 8px;
  border-radius: 4px;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}

#popover button:hover {
  background: #333;
}

#popover button[aria-pressed="true"] {
  background: #444;
}

#popover .divider {
  width: 1px;
  height: 18px;
  background: #444;
  margin: 0 6px;
}

#popover .menu {
  position: relative;
}

#popover ul {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #1f1f1f;
  color: #eee;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  min-width: 100%;
}

#popover ul[hidden] {
  display: none;
}

#popover.menus-up ul {
  top: auto;
  bottom: calc(100% + 6px);
}

#popover ul li button {
  display: block;
  width: 100%;
  text-align: left;
}

#popover .swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  vertical-align: -2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

#popover #color-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: 120px;
  padding: 6px;
}

#popover #color-menu[hidden] {
  display: none;
}

#popover #color-menu li button {
  width: auto;
  padding: 3px;
}

#popover #color-menu input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

/* Synonyms: the last popover item, hidden when the server has no thesaurus */
#popover .synonyms-menu {
  display: flex;
  align-items: center;
}

#popover .synonyms-menu[hidden] {
  display: none;
}

#popover .synonyms {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  max-height: 340px;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 8px 10px;
  background: #1f1f1f;
  color: #eee;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  user-select: none;
  -webkit-user-select: none;
}

#popover .synonyms[hidden] {
  display: none;
}

#popover.menus-up .synonyms {
  top: auto;
  bottom: calc(100% + 6px);
}

#popover .synonyms .sense + .sense {
  margin-top: 10px;
}

#popover .synonyms p {
  margin: 0;
}

#popover .synonyms .gloss {
  color: #999;
  font-size: 12px;
  line-height: 1.35;
  margin-bottom: 4px;
}

#popover .synonyms .gloss em {
  color: #bbb;
  margin-right: 2px;
}

#popover .synonyms .words {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 0;
}

#popover .synonyms .words button {
  padding: 2px 6px;
}

#popover .synonyms .words button.near {
  color: #aaa;
}

#popover .synonyms .words button:hover {
  color: #fff;
}

#popover .synonyms .label {
  color: #777;
  font-size: 12px;
  margin-right: 2px;
}

#popover .synonyms .note {
  color: #aaa;
}

#popover .synonyms .credit {
  margin-top: 10px;
  color: #666;
  font-size: 11px;
}

/* Corner control: invisible until the pointer comes near */
#corner {
  position: fixed;
  right: 16px;
  bottom: 12px;
  font: 11px -apple-system, system-ui, sans-serif;
  color: var(--ink);
  opacity: 0;
  transition: opacity 200ms;
  user-select: none;
  -webkit-user-select: none;
}

#corner:hover,
body.corner-hot #corner {
  opacity: 0.45;
}

#corner button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

#corner button:hover {
  text-decoration: underline;
}

/* Toast: brief status message */
#toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  font: 13px system-ui, sans-serif;
  color: #555;
  background: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity 200ms;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
}

/* Notice: persistent status with actions, in the toast's quiet style */
#notice {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  font: 13px system-ui, sans-serif;
  color: #555;
  background: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
}

#notice[hidden] {
  display: none;
}

#notice button {
  font: inherit;
  color: #333;
  background: none;
  border: 0;
  padding: 0;
  margin-left: 12px;
  cursor: pointer;
}

#notice button:hover {
  text-decoration: underline;
}

/* Sidebar toggle: a quiet top-left button, hidden while the sidebar is open */
#sidebar-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  opacity: 0.3;
  transition: opacity 200ms;
  cursor: pointer;
  line-height: 0;
}

#sidebar-toggle:hover,
#sidebar-toggle:focus-visible {
  opacity: 0.7;
}

#sidebar-toggle[hidden] {
  display: none;
}

/* Page arrows: previous and next page, top right, quiet like the sidebar toggle */
#page-arrows {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 12px;
}

#page-arrows button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  opacity: 0.3;
  transition: opacity 200ms;
  cursor: pointer;
  line-height: 0;
}

#page-arrows button:hover,
#page-arrows button:focus-visible {
  opacity: 0.7;
}

#page-arrows button:disabled {
  opacity: 0.1;
  cursor: default;
}

/* Sidebar: slides over the paper from the left; hidden entirely when closed */
#sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 260px;
  box-sizing: border-box;
  overflow-y: auto;
  padding: 20px 20px 40px;
  font: 14px/1.5 var(--font);
  color: #666;
  background: var(--paper);
  box-shadow: 1px 0 12px rgba(0, 0, 0, 0.08);
  transform: translateX(0);
  transition: transform 150ms ease-out;
  z-index: 10;
}

@starting-style {
  #sidebar { transform: translateX(-100%); }
}

#sidebar[hidden],
#sidebar [hidden] {
  display: none;
}

#sidebar button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

#sidebar button:hover {
  color: #333;
}

#sidebar .project {
  position: relative;
  margin-bottom: 16px;
}

#project-button {
  color: #444;
}

#project-menu {
  position: absolute;
  top: 100%;
  left: -8px;
  min-width: 180px;
  margin: 4px 0 0;
  padding: 6px 8px;
  list-style: none;
  background: var(--paper);
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  z-index: 1; /* above the page list, which is positioned for the drop line */
}

#project-menu li + li {
  margin-top: 2px;
}

#sidebar ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

#page-list {
  position: relative;
  user-select: none;
}

/* Drag cues (spec 7): the ink colour at low opacity, nothing new */
#page-list .dragging {
  opacity: 0.4;
}

#page-list .drop-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  margin-top: -1px;
  background: var(--ink);
  opacity: 0.5;
  pointer-events: none;
}

#sidebar .move-pending {
  font: inherit;
  color: #999;
  margin: 0 0 12px;
}

#page-list h2 {
  font: inherit;
  color: #999;
  margin: 12px 0 2px;
}

#page-list li button {
  display: block;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#sidebar button[aria-current] {
  color: var(--ink);
}

#sidebar .actions {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#sidebar-form form {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#sidebar-form label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#sidebar-form label.choice {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

#sidebar-form input[type="text"],
#sidebar-form select {
  font: inherit;
  color: #444;
  background: none;
  border: 0;
  border-bottom: 1px solid #ddd;
  padding: 2px 0;
  outline: none;
}

#sidebar-form button[type="submit"] {
  align-self: flex-start;
  color: #444;
}

#editor .i { font-style: italic; }
#editor .b { font-weight: bold; }
#editor .u { text-decoration: underline; }

/* History view */
body.history-open .paper:not(#timeline .paper),
body.history-open #sidebar-toggle,
body.history-open #page-arrows,
body.history-open #corner,
body.history-open #popover,
body.history-open #sidebar,
body.history-open #comments { display: none; }

#timeline:not([hidden]) { animation: timeline-in 120ms; }
@keyframes timeline-in { from { opacity: 0; } to { opacity: 1; } }

/* The view's paper mirrors the editor's, with room below for the strip. */
#timeline .paper {
  max-width: var(--paper-max-width);
  margin: 0 auto;
  min-height: 100vh;
  box-sizing: border-box;
  background: var(--paper);
  padding: calc(var(--paper-padding-top) + 24px) var(--paper-padding-x) 120px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.03);
}

#timeline-paper {
  max-width: var(--column-max-width);
  margin: 0 auto;
  font-family: var(--font);
  font-size: var(--size);
  font-weight: var(--weight);
  font-style: normal;
  line-height: var(--line-height);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

#timeline p {
  margin: 0;
  text-indent: var(--indent);
  min-height: 1lh;
}

#timeline .i { font-style: italic; }
#timeline .b { font-weight: bold; }
#timeline .u { text-decoration: underline; }

#timeline ins {
  text-decoration: none;
  background: rgba(60, 150, 90, 0.16);
  box-shadow: inset 0 -2px 0 rgba(60, 150, 90, 0.55);
}
#timeline del {
  color: rgba(170, 40, 40, 0.55);
  text-decoration: line-through;
}
#timeline p.ghost { opacity: 0.6; }
#timeline p.restyled { box-shadow: -12px 0 0 rgba(60, 150, 90, 0.55); }

#timeline .following p:not(.followed) { opacity: .35; }
#timeline p.followed {
  background: #fbfaf4;
  box-shadow: -12px 0 0 #e0c86a, -10px 0 0 #fbfaf4, 10px 0 0 #fbfaf4;
}

#timeline header.bar,
#timeline #strip {
  font: 12px -apple-system, system-ui, sans-serif;
}

#timeline header.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px;
  background: rgba(243, 242, 239, 0.92);
  color: #444;
}

#timeline header.bar button,
#timeline #strip button {
  font: inherit;
  color: inherit;
  background: none;
  border: 1px solid #bbb;
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
}
#timeline header.bar button[aria-pressed="true"] { background: #1f1f1f; color: #fff; border-color: #1f1f1f; }
#timeline header.bar button:disabled { opacity: 0.4; cursor: default; }

#timeline #strip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  box-sizing: border-box;
  background: #1f1f1f;
  color: #ddd;
  padding: 12px 18px 10px;
  outline: none;
}
#timeline #strip button { border-color: #555; }
#timeline #strip button[aria-pressed="true"] { background: #ddd; color: #1f1f1f; border-color: #ddd; }
#timeline #strip button:disabled { opacity: 0.4; cursor: default; }

#timeline #track-viewport { overflow: hidden; position: relative; height: 36px; }
#timeline #track { position: relative; height: 100%; }

#timeline .day,
#timeline .block {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid #555;
}
#timeline .day .label,
#timeline .block .label {
  position: absolute;
  top: 22px;
  left: 4px;
  font-size: 10px;
  color: #888;
  white-space: nowrap;
}

#timeline .tick {
  position: absolute;
  top: 6px;
  width: 2px;
  height: 10px;
  background: #777;
}
#timeline .tick.session { height: 14px; top: 4px; background: #aaa; }
#timeline .tick.dim { background: #3a3a3a; }
#timeline .tick.lit { background: #e0c86a; height: 14px; top: 4px; }
#timeline .block.loading .tick { background: #444; }
/* Last, and as specific as each rule above: the current tick stays bright. */
#timeline .tick.now,
#timeline .block.loading .tick.now {
  background: #fff;
  width: 3px;
  height: 18px;
  top: 2px;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
}

#timeline .caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}
#timeline #timeline-unit,
#timeline #timeline-para-nav { display: flex; gap: 4px; }
#timeline #timeline-unit[hidden],
#timeline #timeline-para-nav[hidden] { display: none; }

#timeline #track-overview {
  position: relative;
  height: 3px;
  margin-top: 8px;
  background: #333;
}
#timeline #track-overview i {
  position: absolute;
  top: 0;
  bottom: 0;
  background: #aaa;
}

#timeline #track-tooltip {
  position: absolute;
  bottom: 100%;
  margin-left: 18px; /* the strip's horizontal padding */
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #000;
  color: #eee;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
}

/* Comment bubble: no text node, so the shape is a mask over a flat colour */
.comment-mark {
  --bubble: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 3h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-8l-5 4v-4H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z'/%3E%3C/svg%3E");
  display: inline-block;
  position: relative;
  top: .08em;
  width: .74em;
  height: .74em;
  margin: 0 .08em;
  background-color: #c4c4c4;
  -webkit-mask: var(--bubble) center / contain no-repeat;
  mask: var(--bubble) center / contain no-repeat;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.comment-mark:hover {
  background-color: #9a9a9a;
}

/* The outline sits outside the mask and may be clipped by it; checked in a real browser. */
.comment-mark.on {
  background-color: #7d7d7d;
  outline: 2px solid #fbf3e2;
}

#add-comment svg {
  display: block;
  width: 14px;
  height: 14px;
}

/* Comments bar: overlays the right of the page and never moves the text. Below the popover. */
#comments {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  box-sizing: border-box;
  overflow-y: auto;
  padding: 16px 14px;
  font: 13px/1.5 -apple-system, system-ui, sans-serif;
  color: #222;
  background: #faf9f6;
  border-left: 1px solid #e4e2dc;
  transform: translateX(0);
  transition: transform 160ms ease-out;
  z-index: 9;
}

@starting-style {
  #comments { transform: translateX(100%); }
}

body.comments-open #page-arrows,
body.comments-open #corner {
  display: none;
}

#comments header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12px;
  color: #777;
}

#comments button {
  padding: 3px 5px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: #888;
  line-height: 1;
  cursor: pointer;
}

#comments button:hover {
  background: #eeece6;
  color: #333;
}

#comments-close {
  font-size: 18px;
}

#comments-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#comments li {
  position: relative;
  margin-bottom: 6px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

#comments li:hover {
  background: #f1efe9;
}

#comments li.on {
  padding-bottom: 30px;
  background: #fbf3e2;
  border-color: #ecd9ae;
  cursor: default;
}

#comments textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: none;
  color: inherit;
  font: inherit;
}

#comments textarea::placeholder {
  color: #a59f91;
}

/* The bin shows only on the highlighted comment. */
#comments li button {
  display: none;
  position: absolute;
  right: 5px;
  bottom: 4px;
}

#comments li.on button {
  display: flex;
}

#comments li button svg {
  display: block;
  width: 14px;
  height: 14px;
}

#comments-empty {
  margin: 0;
  padding: 9px 10px;
  color: #999;
}

/* Start-up: nothing of the app shows until the account is decided (spec 5.3) */
body.booting > *:not(#gate),
body.gated > *:not(#gate):not(#account-notice) {
  display: none;
}

#gate {
  min-height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 16px;
  font: 15px/1.5 var(--font);
  color: #666;
  text-align: center;
}

#gate[hidden] {
  display: none;
}

#gate-logo {
  width: 104px;
  height: 104px;
  margin-bottom: 4px;
}

#gate h1 {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: normal;
  color: var(--ink);
}

#gate p {
  margin: 0;
}

#gate p:empty,
#gate button[hidden] {
  display: none;
}

#gate button {
  font: inherit;
  color: var(--ink);
  background: none;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px 18px;
  cursor: pointer;
}

#gate button:hover {
  border-color: #999;
}

/* Account notice: the same quiet style as #notice, above it so both can show.
   Its messages are long, so it wraps within the window (growing upward) rather
   than push its only way forward off-screen, and sits above the open sidebar. */
#account-notice {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  box-sizing: border-box;
  width: max-content; /* not the shrink-to-fit width, which left: 50% caps at half the window */
  max-width: calc(100vw - 32px);
  font: 13px system-ui, sans-serif;
  color: #555;
  background: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  white-space: normal;
  z-index: 11; /* #sidebar is 10 */
}

#account-notice[hidden] {
  display: none;
}

#account-notice button {
  font: inherit;
  color: #333;
  background: none;
  border: 0;
  padding: 0;
  margin-left: 12px;
  cursor: pointer;
  white-space: nowrap;
}

#account-notice button:hover {
  text-decoration: underline;
}

/* Account line: the signed-in account and Sign out, at the foot of the sidebar's list */
#sidebar #account:not([hidden]) {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  overflow-wrap: anywhere;
}
