@font-face {
  font-family: "realitybox Mono";
  src: url("../assets/mono.ttf") format("truetype");
  font-display: swap;
}
:root {
  color-scheme: dark;
  --bg: #000;
  --panel: #070707;
  --paper: #000;
  --raised: #111;
  --fg: #eee;
  --body: #ccc;
  --muted: #a0a0a0;
  --faint: #808080;
  --line: #303030;
  --bright: #727272;
  --accent: #dedede;
  --danger: #e6aaa1;
  --manuscript-size: 18px;
  --mono: "realitybox Mono", "Adwaita Mono", "SFMono-Regular", Consolas, monospace;
  --reading-font: Georgia, "Liberation Serif", serif;
  --reading-line-height: 1.75;
  --page-width: 780px;
  --rail-width: 32%;
  --library-width: 224px;
  --header-height: 62px;
  font-family:
    "realitybox Mono", "Adwaita Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
  border-radius: 0;
}
button {
  border: 1px solid var(--line);
  background: transparent;
  padding: 9px 12px;
  cursor: pointer;
  transition:
    background 140ms,
    border-color 140ms,
    color 140ms;
}
button:hover {
  background: var(--raised);
  border-color: var(--bright);
}
button:active {
  background: var(--line);
}
button:disabled {
  opacity: 0.38;
  cursor: default;
}
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}
input,
select {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 10px;
  width: 100%;
  min-width: 0;
  outline: none;
}
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}
textarea {
  resize: none;
}
button.primary {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
button.primary:hover {
  background: var(--bg);
  color: var(--fg);
}
[hidden] {
  display: none !important;
}
.dim {
  color: var(--muted);
}
.eyebrow {
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.text-button {
  padding: 5px 7px;
  border-color: transparent;
  font-size: 10px;
  color: var(--muted);
}
.text-button:hover {
  color: var(--fg);
  border-color: var(--line);
}
.pixel-art {
  display: block;
  image-rendering: pixelated;
  flex: none;
}
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--bright);
  gap: 26px;
  padding-right: 24px;
}
.brand {
  width: var(--library-width);
  height: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  border-right: 1px solid var(--bright);
  padding: 0 21px;
  font-size: 20px;
  letter-spacing: -0.055em;
}
.tagline {
  font-size: 11px;
  color: var(--muted);
}
.header-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.header-actions button {
  font-size: 10px;
  min-height: 30px;
  padding: 6px 10px;
  border-color: transparent;
}
.header-actions button:hover {
  border-color: var(--line);
}
.header-actions .dim {
  margin-left: 10px;
  font-size: 9px;
  color: var(--faint);
}
.connection {
  font-size: 9px;
  color: var(--muted);
  margin-right: 15px;
  text-transform: lowercase;
}
.connection.ready::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  background: var(--fg);
  margin-right: 8px;
  vertical-align: 2px;
}
.workspace {
  height: calc(100vh - var(--header-height) - 30px);
  display: flex;
}
.library {
  width: var(--library-width);
  flex-shrink: 0;
  border-right: 1px solid var(--bright);
  padding: 28px 17px 0;
  display: flex;
  flex-direction: column;
}
.section-title {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  margin: 0 7px 22px;
  color: var(--muted);
}
.section-title span + span {
  font-size: 10px;
  color: var(--faint);
}
.new-document {
  text-align: left;
  padding: 11px 10px;
  font-size: 11px;
  border-color: var(--bright);
}
.new-document:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.search {
  border: 0;
  border-bottom: 1px solid var(--line);
  margin: 18px 0 10px;
  padding: 10px 7px;
  font-size: 10px;
}
.documents {
  flex: 1;
  overflow: auto;
  margin: 0 -5px;
  padding: 0 5px;
}
.doc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  padding: 12px 10px;
  margin: 5px 0;
}
.doc-item.active {
  background: var(--raised);
  color: var(--fg);
  box-shadow: inset 1px 0 var(--bright);
}
.doc-item .doc-name {
  display: block;
  font-size: 11px;
  line-height: 1.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-item .doc-date {
  display: block;
  color: var(--muted);
  font-size: 9px;
  margin-top: 7px;
}
.doc-item.active .doc-date {
  color: var(--muted);
}
.empty-library {
  color: var(--faint);
  line-height: 1.9;
  font-size: 11px;
  margin: 20px 7px;
}
.library-bottom {
  padding: 16px 0;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.library-bottom button {
  border: 0;
  font-size: 10px;
  padding: 5px 7px;
}
#main {
  min-width: 0;
  flex: 1;
  position: relative;
}
.welcome {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 24px 40px;
}
.welcome-mark {
  margin: 0 0 23px;
}
.welcome-mark img {
  width: 64px;
  height: 64px;
  opacity: 0.75;
}
.welcome h1 {
  font-size: 22px;
  letter-spacing: -0.04em;
  font-weight: 400;
  margin: 0;
}
.welcome .primary {
  margin-top: 22px;
  padding: 13px 17px;
  font-size: 11px;
  min-width: 240px;
  display: flex;
  justify-content: space-between;
  gap: 25px;
}
.editor {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.document-header {
  height: 84px;
  flex-shrink: 0;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.document-heading {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.document-heading > button {
  font-size: 22px;
  letter-spacing: -0.045em;
  border: 0;
  text-align: left;
  padding: 0;
  max-width: min(500px, 42vw);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.document-heading > button:hover {
  background: transparent;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 6px;
}
.document-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
  flex-shrink: 0;
}
.document-actions button {
  font-size: 10px;
  padding: 9px 11px;
}
#graph-button:focus-visible {
  outline: none;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
#document-more {
  font-size: 17px;
  border-color: transparent;
  padding: 4px 8px;
}
.loom {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 13px minmax(
      260px,
      var(--rail-width)
    );
  min-height: 0;
  flex: 1;
  padding: 0 20px 12px;
  gap: 0;
}
.manuscript-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding-right: 15px;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  font-size: 11px;
  color: var(--fg);
  flex-shrink: 0;
  gap: 8px;
}
.panel-heading > div {
  display: flex;
  gap: 5px;
}
.square {
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--fg);
  margin-right: 7px;
  vertical-align: 1px;
}
#thread-resume {
  color: var(--fg);
}
.reading-area {
  display: flex;
  flex: 1;
  min-height: 0;
  padding-top: 0;
}
.knot {
  display: inline-flex;
  vertical-align: middle;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 22px;
  padding: 0;
  margin: -2px 0 0;
  border: 0;
  background: transparent;
  color: var(--faint);
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}
.knot svg {
  width: 12px;
  height: 12px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
}
.knot:hover,
.knot:active,
.knot:focus-visible,
.knot[aria-expanded="true"] {
  background: transparent;
  color: var(--fg);
}
.knot-weave,
.knot-stitch,
.knot-thread {
  fill: currentColor;
}
.knot.active {
  color: var(--muted);
}
.knot::before {
  content: "";
  position: absolute;
  inset: -3px -2px;
}
.knot-path:focus-visible {
  outline-offset: -1px;
  background: var(--raised);
}
.manuscript-scroll {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 0 0 12px;
  background: var(--panel);
  scrollbar-gutter: stable;
}
.manuscript {
  font-family: var(--reading-font);
  font-size: var(--manuscript-size);
  line-height: var(--reading-line-height);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  min-height: 40px;
  letter-spacing: normal;
  font-weight: 400;
  color: var(--body);
}
.segment {
  transition:
    color 140ms,
    background 140ms;
}
.preview {
  color: inherit;
  text-decoration: none;
  background-color: transparent;
  /* Sparse, square-ended stitches sit on a single quiet baseline. */
  --stitch-ink: color-mix(in srgb, currentColor 32%, transparent);
  background-image: linear-gradient(
    to right,
    var(--stitch-ink) 4px,
    transparent 4px
  );
  background-size: 12px 1px;
  background-position: left bottom;
  background-repeat: repeat-x;
  box-decoration-break: clone;
  padding-bottom: 3px;
}
.preview-caret {
  display: inline-flex;
  align-items: center;
  width: 5px;
  height: 1lh;
  margin-left: 3px;
  vertical-align: top;
  animation: blink 1s steps(1) infinite;
}
.preview-caret::after {
  content: "";
  width: 100%;
  height: 1em;
  background: var(--fg);
}
/* The editing host stays in the same text flow as its read-only neighbors. */
.segment {
  cursor: text;
}
.empty-manuscript-edit {
  padding: 0;
  border: 0;
  color: var(--muted);
  font: inherit;
  line-height: inherit;
  vertical-align: baseline;
}
.empty-manuscript-edit::after {
  content: "[edit]";
}
.empty-manuscript-edit:hover {
  color: var(--body);
  background: transparent;
}
.segment:focus-visible {
  outline: 1px solid var(--muted);
  outline-offset: 3px;
}
.editing-chunk {
  outline: none;
  caret-color: var(--fg);
}
.editing-chunk.empty-chunk {
  display: inline-block;
  min-width: 1ch;
}

::highlight(chunk-find) {
  color: var(--fg);
  background: #8886;
}
.manuscript-meta {
  min-height: 37px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 8px;
  color: var(--faint);
  border-top: 1px solid var(--line);
}
.bookmarks {
  max-height: 136px;
  flex-shrink: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
}
.bookmarks .panel-heading {
  min-height: 40px;
}
.bookmarks .panel-heading .text-button {
  padding-left: 0;
}
.bookmark-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.bookmark {
  display: flex;
  max-width: 100%;
  border: 1px solid var(--line);
}
.bookmark button {
  font-size: 10px;
  border: 0;
  padding: 7px 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bookmark .remove {
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding: 6px;
}
.splitter {
  cursor: col-resize;
  position: relative;
}
.splitter::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 6px;
  width: 1px;
  background: var(--line);
}
.splitter::after {
  content: "";
  position: absolute;
  top: 45%;
  left: 4px;
  width: 5px;
  height: 30px;
  border-left: 1px solid var(--bright);
  border-right: 1px solid var(--bright);
  opacity: 0;
  transition: opacity 140ms;
}
.splitter:hover::after,
.splitter:focus-visible::after {
  opacity: 1;
}
.continuations-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding-left: 19px;
}
#generation-status {
  font-size: 8px;
  text-transform: lowercase;
  white-space: nowrap;
}
.cards {
  display: grid;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  flex: 1;
  min-height: 0;
  border-bottom: 1px solid var(--bright);
}
.continuation {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  width: 100%;
  min-height: 0;
  text-align: left;
  padding: 13px 12px 12px;
  transition: background 140ms;
}
.continuation:first-child {
  border-top-color: var(--bright);
}
.continuation:not(.placeholder):hover,
.continuation.previewed {
  background: var(--raised);
}
.continuation:not(.placeholder):hover::before,
.continuation.previewed::before {
  content: "";
  position: absolute;
  top: 13px;
  bottom: 13px;
  left: 0;
  width: 2px;
  background: var(--fg);
}
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8px;
  color: var(--faint);
  margin-bottom: 9px;
  flex-shrink: 0;
}
.card-index {
  color: var(--muted);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card-index::after {
  content: "─";
  color: var(--line);
}
.card-state {
  text-transform: lowercase;
}
.continuation.previewed .card-state {
  color: var(--fg);
}
.card-body {
  display: block;
  font-size: 12px;
  line-height: 1.8;
  white-space: normal;
  overflow: auto;
  min-height: 0;
  scrollbar-width: auto;
  overflow-wrap: anywhere;
  padding-right: 4px;
  color: var(--body);
}
.continuation[data-status="streaming"] .card-state {
  color: var(--fg);
}
.continuation[data-status="streaming"] .card-state::before {
  content: "▪ ";
  animation: blink 1s steps(1) infinite;
}
.continuation[data-status="error"] .card-state {
  color: var(--danger);
}
.card-error {
  font-size: 9px;
  color: var(--danger);
  line-height: 1.5;
}
.card-error:empty {
  display: none;
}
.placeholder {
  cursor: default;
}
.placeholder:hover {
  background: transparent;
}
.placeholder .card-body {
  color: var(--faint);
  font-size: 11px;
}
.generation-actions {
  display: flex;
  gap: 7px;
  padding-top: 17px;
  align-items: center;
  flex-shrink: 0;
}
.generation-actions > button {
  align-self: stretch;
  font-size: 10px;
  padding: 11px 14px;
}
#generate-button {
  background: var(--panel);
  color: var(--body);
  border-color: var(--line);
}
#generate-button:hover {
  background: var(--raised);
  color: var(--fg);
  border-color: var(--bright);
}
#generate-button:active {
  background: var(--line);
}
#delete-batch {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: auto;
  min-height: 0;
  align-self: stretch;
  padding: 0;
  flex-shrink: 0;
  color: var(--muted);
  background: var(--panel);
}
#delete-batch:hover, #delete-batch:focus-visible { color: var(--fg); }
#delete-batch[hidden] { display: grid !important; visibility: hidden; pointer-events: none; }
#delete-batch svg { position: absolute; width: 24px; height: 24px; overflow: visible; }
.void-orbit { transform-origin: 12px 12px; }
.void-swirling .void-orbit { animation: void-collapse 180ms steps(3, end); }
@keyframes void-collapse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.45); opacity: 0; }
}
.void-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 7px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font-size: 10px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}
#delete-batch:hover .void-tooltip, #delete-batch:focus-visible .void-tooltip { display: block; }
#undo-batch { padding: 8px 4px; }
.pagination {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pagination button {
  padding: 4px 7px;
  border: 0;
  font-size: 18px;
}
.pagination span {
  font-size: 9px;
  color: var(--muted);
  white-space: nowrap;
}
.app-footer {
  height: 30px;
  border-top: 1px solid var(--bright);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 0 22px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: 0.02em;
}
.status-dot {
  display: inline-block;
  width: 3px;
  height: 3px;
  background: var(--fg);
  vertical-align: 2px;
  margin-right: 7px;
}
.error-banner {
  position: absolute;
  z-index: 20;
  top: var(--header-height);
  left: var(--library-width);
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid var(--danger);
  color: var(--danger);
  padding: 12px 23px;
  gap: 20px;
  line-height: 1.6;
  font-size: 11px;
}
.error-banner button {
  border: 0;
}
.toast {
  position: fixed;
  bottom: 47px;
  left: 50%;
  transform: translateX(-50%);
  padding: 13px 20px;
  background: var(--fg);
  color: var(--bg);
  font-size: 11px;
  z-index: 100;
  max-width: 70vw;
  line-height: 1.6;
}
.checkpoint {
  position: fixed;
  inset: auto;
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  width: 340px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  box-shadow: 0 4px 20px #0003;
}
.checkpoint:popover-open {
  display: flex;
  flex-direction: column;
  animation: appear 120ms ease-out;
}
.checkpoint-heading {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 10px;
  color: var(--muted);
  padding: 0 0 6px 8px;
  border-bottom: 1px solid var(--line);
}
.checkpoint-heading button {
  border: 0;
  font-size: 17px;
  padding: 2px 7px;
}
.checkpoint-threads {
  min-height: 0;
  max-height: 216px;
  overflow: auto;
  margin: 0;
  scrollbar-width: auto;
}
.knot-path {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 12px;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  text-align: left;
}
.knot-path + .knot-path {
  border-top: 1px solid var(--line);
}
.knot-path-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  max-height: 2lh;
  overflow: hidden;
  padding-right: 4px;
  overflow-wrap: anywhere;
  font-size: 11px;
  line-height: 1.7;
  color: var(--body);
}
.knot-path-state {
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
}
.knot-path.followed .knot-path-state {
  color: var(--fg);
}
.checkpoint-empty {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
  margin: 12px 8px;
}
.checkpoint-context {
  flex-shrink: 0;
  margin: 8px;
  color: var(--muted);
  font-size: 10px;
}
.checkpoint-actions {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
}
.checkpoint-actions button {
  width: 100%;
  padding: 10px 8px 6px;
  border: 0;
  font-size: 10px;
  text-align: left;
}
dialog {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--bright);
  padding: 0;
  max-height: 90vh;
  max-width: 95vw;
  box-shadow:
    7px 7px 0 var(--bg),
    8px 8px 0 var(--line);
}
dialog::backdrop {
  background: #000b;
}
dialog[open] {
  animation: dialog-in 150ms ease-out;
}
.dialog-heading {
  padding: 24px 27px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.dialog-heading h2 {
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.05em;
  margin: 8px 0 4px;
}
.dialog-heading > button,
.dialog-heading > form > button {
  border: 0;
  font-size: 20px;
}
.dialog-actions {
  border-top: 1px solid var(--line);
  padding: 17px 27px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.dialog-actions button {
  font-size: 10px;
}
label {
  font-size: 11px;
  display: block;
  line-height: 1.7;
  color: var(--muted);
}
label input,
label select {
  display: block;
  margin-top: 7px;
  color: var(--fg);
}
.small-dialog {
  width: 440px;
}
.small-dialog label {
  margin: 22px 27px 6px;
}
.small-dialog #text-value {
  margin: 0 27px 26px;
  width: calc(100% - 54px);
}
.settings-dialog {
  width: 650px;
}
#settings-form {
  height: min(560px, calc(90vh - 2px));
  display: flex;
  flex-direction: column;
}
#settings-form > .dialog-heading,
#settings-form > .dialog-actions {
  flex: none;
}
#settings-form > .dialog-heading {
  padding-top: 18px;
  padding-bottom: 16px;
}
.settings-tabs {
  display: flex;
  gap: 24px;
  padding: 0 27px;
  border-bottom: 1px solid var(--line);
}
.settings-tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 13px 0 11px;
  color: var(--muted);
  font-size: 11px;
}
.settings-tabs button:hover {
  background: transparent;
  color: var(--fg);
}
.settings-tabs button[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--fg);
}
.settings-tabs button:focus-visible {
  outline-offset: -4px;
}
.settings-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 27px 18px;
}
#settings-error {
  flex: none;
  margin: 0;
  padding: 0 27px 14px;
}
#settings-error:empty {
  display: none;
}
.settings-section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.settings-section:last-of-type {
  border: 0;
}
.settings-section > .check-label {
  margin: 18px 0 0;
}
.settings-section h3 {
  margin: 0 0 14px;
  font-size: 10px;
  letter-spacing: 0.13em;
  font-weight: 400;
  color: var(--fg);
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 22px;
}
.settings-grid label .dim {
  font-size: 9px;
  color: var(--faint);
}
.field-note {
  font-size: 10px;
  line-height: 1.8;
  color: var(--faint);
  margin: 14px 0 0;
}
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 9px;
  margin: 5px 0 17px;
}
.check-label {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.check-label input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--fg);
}
.form-error {
  color: var(--danger);
  font-size: 11px;
  line-height: 1.7;
}
.help-dialog {
  width: 590px;
}
.help-dialog > p {
  margin: 23px 27px;
  line-height: 1.9;
  font-size: 11px;
}
.shortcuts {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  margin: 24px 27px;
  gap: 15px;
  font-size: 11px;
}
.shortcuts dt {
  color: var(--fg);
}
.shortcuts dd {
  margin: 0;
  color: var(--muted);
}
.graph-dialog {
  width: 94vw;
  height: 88vh;
  max-width: 1800px;
}
.graph-dialog[open] {
  display: flex;
  flex-direction: column;
}
.graph-body-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
.graph-body-layout .graph-viewport {
  min-width: 0;
}
.graph-info {
  cursor: pointer;
  color: var(--muted);
}
.graph-info.active {
  color: var(--bg);
}
.graph-info circle,
.graph-info path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  pointer-events: none;
}
.graph-info-target {
  fill: transparent;
  stroke: transparent;
}
.graph-info:hover .graph-info-target,
.graph-info:focus-visible .graph-info-target,
.graph-info[aria-pressed="true"] .graph-info-target {
  stroke: currentColor;
}
.generation-info {
  width: 322px;
  max-width: 46%;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-height: 0;
}
.generation-info-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.generation-info-heading h3 {
  font-size: 11px;
  font-weight: 400;
  margin: 0;
}
.generation-info-heading button {
  border: 0;
  padding: 3px 7px;
  font-size: 18px;
}
.generation-info-content {
  overflow: auto;
  padding: 0 18px 18px;
  flex: 1;
  min-height: 0;
}
.generation-model {
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  margin: 18px 0 12px;
}
.generation-info h4 {
  font-size: 10px;
  font-weight: 400;
  padding-top: 16px;
  margin: 16px 0 10px;
  border-top: 1px solid var(--line);
}
.generation-values {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 8px 12px;
  font-size: 10px;
  line-height: 1.5;
  margin: 12px 0;
}
.generation-values dt {
  color: var(--muted);
}
.generation-values dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-variant-numeric: tabular-nums;
}
.generation-values .unrecorded {
  color: var(--faint);
}
.generation-provider {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 16px;
}
.generation-provider summary,
#tune-advanced summary {
  font-size: 11px;
  cursor: pointer;
  color: var(--muted);
}
.generation-info-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.generation-info-actions button {
  flex: 1;
  font-size: 10px;
  padding: 9px 6px;
}
#generation-info-feedback {
  margin: 0;
  padding: 0 18px 12px;
  font-size: 10px;
  line-height: 1.6;
}
#generation-info-feedback:empty {
  display: none;
}
.tune-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 8px 0;
  margin: 0 0 6px;
  border: 0;
  color: var(--muted);
  font-size: 10px;
  text-align: left;
}
.loom-model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.loom-model-row select {
  flex: 1;
  min-width: 0;
  width: 0;
  padding: 8px 4px 8px 0;
  border: 0;
  color: var(--body);
  font-size: 10px;
  background-color: transparent;
}
/* Electron's customizable native select keeps keyboard navigation and form
   semantics while letting the open menu use the same ink and pixels as Loom. */
select.model-picker,
select.model-picker::picker(select) {
  appearance: base-select;
}
select.model-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
select.model-picker > button {
  display: flex;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}
select.model-picker selectedcontent {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
select.model-picker::picker-icon {
  content: "";
  width: 10px;
  height: 6px;
  flex: none;
  margin-left: auto;
  background: var(--muted);
  clip-path: polygon(
    0 0,
    2px 0,
    2px 2px,
    4px 2px,
    4px 4px,
    6px 4px,
    6px 2px,
    8px 2px,
    8px 0,
    10px 0,
    10px 2px,
    8px 2px,
    8px 4px,
    6px 4px,
    6px 6px,
    4px 6px,
    4px 4px,
    2px 4px,
    2px 2px,
    0 2px
  );
}
select.model-picker:open::picker-icon {
  rotate: 180deg;
}
select.model-picker::picker(select) {
  min-width: anchor-size(width);
  max-width: min(440px, calc(100vw - 24px));
  max-height: min(420px, 70vh);
  margin: 5px 0;
  padding: 5px;
  border: 1px solid var(--bright);
  border-radius: 0;
  background: var(--panel);
  color: var(--body);
  font:
    11px/1.5 "realitybox Mono",
    monospace;
  box-shadow: 0 6px 0 0 #0008;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
select.model-picker optgroup {
  padding: 0;
}
select.model-picker legend {
  padding: 9px 10px 4px;
  color: var(--faint);
  font-size: 9px;
  font-weight: normal;
  letter-spacing: 0.06em;
}
select.model-picker option {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 36px;
  padding: 9px 10px;
  border: 0;
  border-radius: 0;
  color: var(--body);
  background: transparent;
  font-weight: normal;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
}
select.model-picker option:checked {
  color: var(--fg);
}
select.model-picker option:enabled:hover,
select.model-picker option:enabled:focus {
  outline: none;
  color: var(--fg);
  background: var(--raised);
}
select.model-picker option:disabled {
  color: var(--faint);
  cursor: default;
}
select.model-picker option::checkmark {
  content: "";
  order: 1;
  flex: none;
  margin-left: auto;
  width: 10px;
  height: 8px;
  background: var(--muted);
  clip-path: polygon(
    0 2px,
    2px 2px,
    2px 4px,
    4px 4px,
    4px 2px,
    6px 2px,
    6px 0,
    10px 0,
    10px 2px,
    8px 2px,
    8px 4px,
    6px 4px,
    6px 6px,
    4px 6px,
    4px 8px,
    2px 8px,
    2px 6px,
    0 6px
  );
}
select.model-picker > option:last-child {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.loom-model-row .tune-button {
  width: auto;
  margin: 0;
  flex: 0 0 auto;
}
.loom-model-row #tune-summary {
  display: none;
}
#tune-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tune-label {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: var(--fg);
}
.tune-label svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  flex-shrink: 0;
}
.tune-dialog {
  width: 500px;
}
.tune-dialog .dialog-heading {
  padding: 16px 22px;
}
.tune-dialog .dialog-heading h2 {
  margin: 0;
  font-size: 18px;
}
.tune-scroll {
  padding: 0 22px 12px;
  max-height: calc(90vh - 140px);
  overflow: auto;
}
.tune-scroll > .field-note {
  margin: 16px 0 18px;
}
.tune-scroll .settings-grid {
  gap: 16px;
}
.full-field {
  grid-column: 1 / -1;
}
#tune-advanced {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
#tune-advanced[open] summary {
  margin-bottom: 18px;
}
.tune-dialog .dialog-actions {
  padding: 14px 22px;
}
#tune-reset {
  margin-right: auto;
  border-color: transparent;
  color: var(--muted);
  padding-left: 0;
}
.graph-dialog .dialog-heading {
  padding: 20px 25px;
  flex-shrink: 0;
}
.graph-dialog h2 {
  font-size: 21px;
}
.graph-tools {
  display: flex;
  align-items: center;
  gap: 7px;
}
.graph-tools input {
  width: 215px;
  font-size: 10px;
}
.graph-tools button {
  font-size: 9px;
}
.graph-tools #graph-zoom {
  font-size: 9px;
  color: var(--muted);
  min-width: 34px;
  text-align: center;
}
.graph-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: grab;
  background-image: radial-gradient(var(--line) 0.5px, transparent 0.5px);
  background-size: 24px 24px;
}
.graph-viewport.dragging {
  cursor: grabbing;
}
.graph-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 23px;
  font-size: 8px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.graph-edge {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
}
.graph-edge.on-path {
  stroke: var(--fg);
}
.graph-node {
  cursor: pointer;
  outline: none;
}
.graph-node rect {
  fill: var(--bg);
  stroke: var(--line);
  transition: stroke 120ms;
}
.graph-node:hover rect,
.graph-node:focus rect {
  stroke: var(--fg);
  fill: var(--raised);
}
.graph-node.matched rect {
  stroke: var(--fg);
  stroke-dasharray: 3 3;
}
.graph-node text {
  font-family: inherit;
  font-size: 10px;
  fill: var(--fg);
  pointer-events: none;
}
.graph-node .graph-caption {
  font-size: 7px;
  fill: var(--muted);
  letter-spacing: 0.06em;
}
.graph-node .graph-body {
  font-size: 10px;
}
.graph-node .graph-status {
  font-size: 7px;
  fill: var(--faint);
}
.graph-node.on-path rect {
  stroke: var(--bright);
}
.graph-node.active rect {
  fill: var(--fg);
  stroke: var(--fg);
}
.graph-node.active text {
  fill: var(--bg);
}
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-thumb {
  background: var(--line);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--bright);
}
::-webkit-scrollbar-button {
  display: none;
  height: 0;
  width: 0;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::selection {
  background: color-mix(in srgb, var(--fg) 20%, var(--bg));
  color: var(--fg);
}
@keyframes appear {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes blink {
  50% {
    opacity: 0.2;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
@media (max-width: 1200px) {
  :root {
    --library-width: 185px;
  }
  .brand {
    padding: 0 16px;
  }
  .library {
    padding-left: 12px;
    padding-right: 12px;
  }
  .document-header {
    padding-left: 24px;
    padding-right: 24px;
  }
  .document-heading > button {
    font-size: 23px;
    max-width: 310px;
  }
  .loom {
    padding: 0 20px 16px;
    grid-template-columns: minmax(230px, 1fr) 9px minmax(
        240px,
        var(--rail-width)
      );
  }
  .splitter::before {
    left: 4px;
  }
  .continuations-panel {
    padding-left: 14px;
  }
  .manuscript-panel {
    padding-right: 10px;
  }
  .tagline {
    display: none;
  }
  .manuscript-scroll {
    padding-right: 8px;
  }
  .graph-tools input {
    width: 150px;
  }
  .card-body {
    font-size: 11px;
  }
}
@media (max-width: 950px) {
  :root {
    --library-width: 157px;
  }
  .brand {
    gap: 8px;
    padding: 0 12px;
    font-size: 18px;
  }
  .connection {
    display: none;
  }
  .library {
    padding: 22px 10px 0;
  }
  .new-document {
    font-size: 9px;
    padding: 10px 7px;
  }
  .document-header {
    padding: 21px 18px;
    height: 103px;
  }
  .document-heading > button {
    font-size: 21px;
    max-width: 230px;
  }
  .document-actions {
    gap: 5px;
    margin-left: 10px;
  }
  .document-actions button {
    font-size: 9px;
    padding: 8px;
  }
  .loom {
    padding: 0 12px 12px;
    grid-template-columns: minmax(215px, 1fr) 7px minmax(
        220px,
        var(--rail-width)
      );
  }
  .manuscript-panel {
    padding-right: 6px;
  }
  .continuations-panel {
    padding-left: 9px;
  }
  .panel-heading {
    font-size: 10px;
  }
  .generation-actions > button {
    font-size: 9px;
    padding: 10px;
  }
  .pagination {
    gap: 3px;
  }
  .graph-dialog .dialog-heading {
    flex-wrap: wrap;
  }
  .graph-tools {
    width: 100%;
  }
  .graph-tools input {
    flex: 1;
  }
  .app-footer {
    font-size: 7px;
    padding: 0 14px;
  }
  .bookmarks .text-button {
    font-size: 9px;
  }
}
@media (max-height: 760px) {
  :root {
    --header-height: 54px;
  }
  .document-header {
    height: 88px;
    padding-top: 16px;
    padding-bottom: 16px;
  }
  .document-heading {
    gap: 8px;
  }
  .document-heading > button {
    font-size: 22px;
  }
  .panel-heading {
    min-height: 40px;
  }
  .reading-area {
    padding-top: 16px;
  }
  .continuation {
    padding: 9px 9px 8px;
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 7px;
  }
  .card-top {
    display: block;
    margin: 0;
  }
  .card-index {
    font-size: 10px;
  }
  .card-index::after,
  .card-state {
    display: none;
  }
  .card-body {
    font-size: 10px;
    line-height: 1.7;
  }
  .card-error {
    grid-column: 2;
  }
  .generation-actions {
    padding-top: 12px;
  }
  .generation-actions > button {
    padding: 9px 10px;
  }
  .loom {
    padding-bottom: 12px;
  }
  .welcome-mark {
    margin-bottom: 14px;
  }
}

/* A single manuscript page is shared by reading and direct editing. */
.manuscript-page {
  width: 100%;
  max-width: var(--page-width);
  min-height: 100%;
  margin: 0 auto;
  padding: 40px clamp(22px, 3vw, 48px) 44px;
  background: var(--paper);
  border: 1px solid var(--line);
  cursor: text;
}
.manuscript {
  tab-size: 4;
}
#manuscript-scroll:focus {
  outline: none;
}
.document-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  min-height: 49px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.toolbar-group + .toolbar-group {
  border-left: 1px solid var(--line);
  padding-left: 10px;
}
.document-toolbar button,
.document-toolbar select,
.document-toolbar input {
  width: auto;
  min-height: 30px;
  padding: 5px 8px;
  font-size: 10px;
}
#writing-size {
  width: 52px;
}
.document-toolbar button {
  border-color: transparent;
}
.document-toolbar button:hover {
  border-color: var(--line);
}
#save-edit {
  border-color: var(--line);
}
.document-toolbar select,
.document-toolbar input {
  background: transparent;
  border-color: transparent;
}
.document-toolbar select:hover,
.document-toolbar input:hover {
  border-color: var(--line);
}

.toolbar-end {
  margin-left: auto;
}
#focus-button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
}
.find-panel {
  padding: 10px;
  background: var(--raised);
  border: 1px solid var(--line);
  margin-bottom: 8px;
  flex-shrink: 0;
}
.find-row {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}
.find-row input {
  flex: 1;
  width: 0;
  font-size: 11px;
  padding: 7px;
}
.find-row button {
  font-size: 10px;
  padding: 5px 8px;
}
.find-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 9px;
  color: var(--muted);
}
.find-options label {
  display: flex;
  align-items: center;
  flex-direction: row;
  gap: 5px;
  margin: 0;
  font-size: 9px;
}
.find-options input {
  width: auto;
  margin: 0;
  accent-color: var(--fg);
}
#find-status {
  margin-left: auto;
}
body.is-writing .bookmarks {
  display: none;
}
#selection-count {
  color: var(--muted);
}
body.focus-mode .library,
body.focus-mode .continuations-panel,
body.focus-mode #splitter {
  display: none;
}
body.focus-mode .loom {
  grid-template-columns: minmax(0, 1fr);
}
body.focus-mode .manuscript-panel {
  padding-right: 0;
}
body.focus-mode .manuscript-scroll {
  padding: 16px 16px 28px;
}
body.focus-mode .manuscript-panel > .panel-heading,
body.focus-mode .manuscript-meta,
body.focus-mode .bookmarks,
body.focus-mode .find-panel {
  width: 100%;
  max-width: var(--page-width);
  margin-left: auto;
  margin-right: auto;
}
@media (max-width: 1100px) {
  .workspace {
    position: relative;
  }
  .document-header {
    height: 76px;
    padding: 12px 20px;
  }
  .document-heading {
    gap: 5px;
  }
  .document-heading > button {
    font-size: 21px;
    max-width: 330px;
  }
  .document-toolbar {
    gap: 7px;
    padding: 7px 14px;
  }
  .toolbar-group + .toolbar-group {
    padding-left: 7px;
  }
  .document-toolbar button,
  .document-toolbar select,
  .document-toolbar input {
    padding: 5px 6px;
  }
  .loom {
    padding: 0 14px 10px;
    grid-template-columns: minmax(300px, 1fr) 9px minmax(
        230px,
        var(--rail-width)
      );
  }
  .reading-area {
    padding-top: 0;
  }
  .manuscript-scroll {
    padding-right: 0;
  }
  .manuscript-page {
    padding: 28px 24px 36px;
  }
}
@media (max-height: 760px) {
  .document-header {
    height: 70px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .reading-area {
    padding-top: 0;
  }
  .manuscript-page {
    padding-top: 24px;
    padding-bottom: 28px;
  }
  .manuscript-meta {
    min-height: 30px;
  }
  .bookmarks .panel-heading {
    min-height: 30px;
  }
}

.document-menu:popover-open {
  position: fixed;
  inset: auto;
  margin: 0;
  width: 220px;
  display: grid;
  gap: 3px;
  padding: 5px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
}
.document-menu button {
  text-align: left;
  border-color: transparent;
}
.document-menu button:focus-visible {
  outline-offset: -1px;
}

/* The manuscript owns the full window height; tools live beside the page. */
.workspace {
  height: 100vh;
}
.app-sidebar {
  width: var(--library-width);
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.sidebar-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden auto;
}
.app-sidebar .app-header {
  height: 64px;
  flex: none;
  padding: 0;
  border-bottom: 1px solid var(--line);
}
.app-sidebar .brand {
  width: 100%;
  border: 0;
  padding: 0 18px;
  gap: 10px;
}
#document-controls {
  padding: 20px 16px 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.app-sidebar .document-header {
  height: auto;
  padding: 0;
  display: block;
  border: 0;
}
.app-sidebar .document-heading {
  gap: 9px;
}
.app-sidebar .document-heading > button {
  max-width: 100%;
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: -0.04em;
  white-space: normal;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.app-sidebar .document-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 24px;
  margin: 12px 0 10px;
  gap: 2px;
}
.app-sidebar .document-actions button {
  padding: 5px 2px;
  border-color: transparent;
  font-size: 10px;
}
.app-sidebar #document-more {
  margin: 0;
  font-size: 13px;
  letter-spacing: -2px;
  padding: 0;
}
.app-sidebar .document-toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  padding: 11px 0 6px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  min-height: 0;
}
.app-sidebar .toolbar-group {
  gap: 3px;
  margin: 0;
  padding: 0;
  border: 0;
}
.app-sidebar .document-toolbar button,
.app-sidebar .document-toolbar select,
.app-sidebar .document-toolbar input {
  padding: 5px 6px;
  min-height: 28px;
}
.app-sidebar .typography-tools select {
  flex: 1;
  min-width: 0;
}
.app-sidebar .typography-tools {
  border: 1px solid var(--line);
}
.app-sidebar #writing-size {
  width: 48px;
  border-left: 1px solid var(--line);
}
.app-sidebar .toolbar-end {
  justify-content: space-between;
}
#document-controls > .panel-heading {
  min-height: 28px;
  font-size: 9px;
  color: var(--faint);
  flex-wrap: wrap;
}
#document-controls > .panel-heading > span {
  display: none;
}
#document-controls > .panel-heading > div {
  width: 100%;
  justify-content: space-between;
}
.document-context:has(#thread-resume[hidden]) {
  display: none;
}
.app-sidebar .library {
  display: flex;
  position: static;
  width: 100%;
  min-height: 0;
  flex: 1 0 auto;
  padding: 18px 12px 0;
  border: 0;
  box-shadow: none;
}
.app-sidebar .section-title {
  margin: 0 5px 12px;
  font-size: 10px;
}
.app-sidebar .new-document {
  padding: 9px 7px;
  font-size: 10px;
}
.app-sidebar .search {
  margin: 8px 0;
  padding: 8px 5px;
}
.app-sidebar .documents {
  min-height: 0;
  flex: none;
  overflow: visible;
}
.app-sidebar .doc-item {
  padding: 9px 7px;
}
.app-sidebar .library-bottom {
  padding: 10px 0;
  flex: none;
  margin-top: auto;
}
.app-sidebar .bookmarks {
  margin: 0 16px;
  padding-bottom: 8px;
}
.app-sidebar .bookmarks .panel-heading {
  flex-wrap: wrap;
  gap: 0;
  padding: 5px 0;
  min-height: 32px;
}
.app-sidebar .bookmarks .text-button {
  font-size: 9px;
  padding: 5px 0;
}
.app-sidebar .bookmarks #bookmark-add {
  margin-left: auto;
}
.app-sidebar .app-footer {
  height: auto;
  margin-top: auto;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
  padding: 14px 16px 10px;
  font-size: 8px;
  border-color: var(--line);
}
.app-sidebar .connection {
  display: none;
}
.app-sidebar .header-actions {
  margin: 0;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.editor .loom {
  padding: 0;
  grid-template-columns: minmax(0, 1fr) 9px minmax(220px, var(--rail-width));
}
.editor .manuscript-panel {
  padding: 0;
}
.editor .reading-area {
  padding: 0;
}
.editor .manuscript-scroll {
  padding: 0;
  background: var(--bg);
}
.manuscript-page {
  border-top: 0;
  border-bottom: 0;
  border-color: transparent;
  padding: 40px clamp(24px, 3vw, 48px) 48px;
}
.editor .splitter::before {
  left: 4px;
}
.editor .splitter::after {
  left: 2px;
}
.editor .continuations-panel {
  padding: 0 18px 12px 14px;
}
.continuations-panel > .panel-heading {
  min-height: 56px;
}
.continuations-panel .manuscript-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 8px;
  margin-top: 12px;
  padding-top: 10px;
  min-height: 38px;
  flex: none;
}
.continuations-panel #knot-count {
  grid-column: 2;
  grid-row: 1;
}
#selection-count:empty {
  display: none;
}
.editor .find-panel {
  position: absolute;
  z-index: 4;
  top: 12px;
  right: 16px;
  width: min(380px, calc(100% - 32px));
  margin: 0;
  box-shadow: 0 6px 24px #0003;
}
.error-banner {
  position: fixed;
  top: 12px;
  left: calc(var(--library-width) + 16px);
  right: 16px;
  border: 1px solid var(--danger);
}
body.focus-mode .app-sidebar {
  width: 0;
  border: 0;
}
body.focus-mode .app-sidebar > :not(.sidebar-content),
body.focus-mode .sidebar-content > :not(#document-controls),
body.focus-mode #document-controls > :not(.document-toolbar),
body.focus-mode .document-toolbar > :not(.toolbar-end) {
  display: none;
}
body.focus-mode .sidebar-content {
  overflow: visible;
}
body.focus-mode #document-controls {
  position: fixed;
  bottom: 14px;
  right: 20px;
  z-index: 5;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--bg);
}
body.focus-mode .app-sidebar .document-toolbar {
  padding: 3px;
  border: 0;
}
body.focus-mode .editor .loom {
  grid-template-columns: minmax(0, 1fr);
}
body.focus-mode .manuscript-page {
  padding-bottom: 64px;
}
@media (max-width: 1200px) {
  :root {
    --library-width: 188px;
  }
  #document-controls {
    padding: 16px 12px 8px;
  }
  .app-sidebar .bookmarks {
    margin-left: 12px;
    margin-right: 12px;
  }
  .app-sidebar .document-toolbar button {
    padding-left: 4px;
    padding-right: 4px;
  }
  .editor .continuations-panel {
    padding-left: 10px;
    padding-right: 12px;
  }
}
@media (max-height: 760px) {
  .app-sidebar .app-header {
    height: 52px;
  }
  #document-controls {
    padding-top: 12px;
  }
  .app-sidebar .document-heading > .eyebrow {
    display: none;
  }
  .app-sidebar .document-actions {
    margin-top: 7px;
    margin-bottom: 5px;
  }
  .app-sidebar .document-toolbar {
    gap: 4px;
    padding-top: 7px;
  }
  .app-sidebar .library {
    padding-top: 12px;
  }
  .app-sidebar .app-footer {
    padding-top: 10px;
    gap: 5px;
  }
  .app-sidebar .doc-item .doc-date {
    margin-top: 3px;
  }
  .manuscript-page {
    padding-top: 28px;
  }
  .continuations-panel > .panel-heading {
    min-height: 44px;
  }
}

/* Audio is ink in the same line box as prose; the only transport is below. */
.manuscript-panel { position: relative; }
.audio-player {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 3px; width: max-content;
  max-width: calc(100% - 24px); padding: 0; border: 0;
  background: transparent; box-shadow: none; z-index: 4;
}
.audio-player button { width: 28px; height: 28px; padding: 0; border: 0; color: var(--muted); background: transparent; box-shadow: none; }
.audio-player button:hover, .audio-player button:focus-visible { color: var(--fg); background: transparent; }
.audio-passage { margin-top: 26px; color: var(--fg); }
.audio-passage-entry { display: flex; align-items: baseline; flex-wrap: wrap; gap: 12px; font: 10px var(--mono); }
.audio-passage-entry button { width: auto; min-height: 30px; padding: 5px 0; border-color: transparent; color: var(--muted); }
.audio-passage-entry button:hover, .audio-passage-entry button:focus-visible { color: var(--fg); border-bottom-color: var(--line); }
.audio-passage.drag-over { outline: 1px dashed var(--muted); outline-offset: 14px; }
.audio-passage-composer { margin-top: 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 12px 0 14px; }
.audio-passage.has-preview .audio-passage-entry { display: none; }
.audio-passage-heading { display: flex; gap: 12px; justify-content: space-between; align-items: center; font: 10px var(--mono); color: var(--muted); }
.audio-passage-heading span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-passage-heading button { width: 24px; height: 24px; padding: 0; border-color: transparent; }
.audio-passage-wave { height: 64px; position: relative; margin-top: 12px; overflow: hidden; }
.audio-passage-wave img { width: 100%; height: 64px; image-rendering: pixelated; object-fit: fill; }
.audio-passage-mask { position: absolute; top: 0; bottom: 0; background: var(--bg); opacity: .8; pointer-events: none; }
.audio-passage-mask.before { left: 0; } .audio-passage-mask.after { right: 0; }
.audio-passage-edge { position: absolute; top: 6px; bottom: 6px; width: 12px; transform: translateX(-50%); border: 0; padding: 0; background: transparent; cursor: col-resize; }
.audio-passage-edge::before { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.audio-passage-edge::after { content: ""; position: absolute; left: 2px; top: 0; width: 7px; height: 5px; background: var(--muted); }
.audio-passage-edge:hover { background: transparent; }
.audio-passage-edge:hover::before, .audio-passage-edge:hover::after, .audio-passage-edge:focus-visible::before, .audio-passage-edge:focus-visible::after { background: var(--fg); }
.audio-passage-trim { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 12px; font: 10px var(--mono); }
.audio-passage-trim button { width: 28px; height: 28px; padding: 0; }
.audio-passage-trim label { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.audio-passage-trim input { width: 68px; min-width: 0; padding: 4px; font: 10px var(--mono); }
.audio-passage-trim > span { font-size: 9px; }
.audio-passage-words { display: block; width: 100%; border: 0; padding: 0; resize: vertical; background: transparent; color: var(--body); margin: 20px 0; min-height: 1.6em; white-space: pre-wrap; outline: none; font-family: var(--reading-font); font-size: var(--manuscript-size); line-height: 1.6; }
.audio-passage-words::placeholder { color: var(--muted); opacity: .65; pointer-events: none; }
.audio-passage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font: 9px var(--mono); }
.audio-passage-actions button { width: auto; min-height: 30px; padding: 5px 7px; font-size: 10px; }
.audio-passage-actions > span { margin-left: auto; }
.audio-passage-message { margin: 10px 0 0; font: 10px/1.6 var(--mono); }
.audio-passage-message.invalid { color: var(--fg); }
.audio-branch-cancellations { display: flex; justify-content: space-between; gap: 3px; padding: 5px 0; }
.audio-branch-cancellations button { padding: 5px 3px; font-size: 9px; }

.audio-passage-pair { display: flex; gap: 7px; align-items: center; margin: 0 0 14px; font: 9px var(--mono); color: var(--muted); }
.audio-passage-pair input { width: 12px; height: 12px; flex: none; margin: 0; padding: 0; accent-color: var(--muted); }
.audio-passage-trim label input { margin-top: 0; }
.audio-passage-words { caret-color: var(--fg); }
.audio-passage-wave { cursor: col-resize; }

.manuscript, .card-body { position: relative; isolation: isolate; }
.audio-chunk.audio-only, .inline-audio { display: inline; width: auto; min-height: 0; margin: 0; padding: 0; border: 0; background: transparent; vertical-align: baseline; }
.card-body.audio-chunk { display: block; width: auto; white-space: pre-wrap; }
.audio-slice { display: inline-block; position: relative; width: var(--audio-slice-width); height: 1lh; margin: 0; padding: 0; border: 0; line-height: inherit; vertical-align: bottom; }
.audio-slice-space { visibility: hidden; }
/* A zero-height middle anchor follows the font's baseline and x-height,
   while the enclosing slice retains the existing prose line box. */
.audio-slice-ink { display: inline-block; position: relative; width: 0; height: 0; vertical-align: middle; }
.audio-slice .pixel-waveform { position: absolute; left: 0; top: -.5lh; display: block; width: var(--audio-slice-width); height: 1lh; pointer-events: none; }
.inline-audio:focus-visible { outline: 1px dotted var(--muted); outline-offset: 0; }
.audio-words, .timeline-text { margin: 0; padding: 0; border: 0; }
.audio-ink-layer { position: absolute; top: 0; left: 0; width: 0; height: 0; pointer-events: none; z-index: -1; }
.audio-ink-fragment { position: absolute; display: block; }
.audio-ink-fragment > svg { display: block; width: 100%; height: 100%; }
.audio-words { text-shadow: -1px 0 1px var(--bg), 1px 0 1px var(--bg), 0 -1px 1px var(--bg), 0 1px 1px var(--bg), 0 0 2px var(--bg), 0 0 4px var(--bg); }
.manuscript-playhead { position: absolute; width: 1px; margin: 0; padding: 0; background: var(--fg); opacity: .65; pointer-events: none; z-index: 2; }
.timeline-text.reading { background: color-mix(in srgb, var(--muted) 8%, transparent); }
.preview { padding-bottom: 0; }
.preview.audio-only .preview-caret { display: none; }

.mobile-navigation,
#mobile-tools-close,
#mobile-tools-backdrop {
  display: none;
}

@media (max-width: 960px) {
  body {
    --mobile-nav-height: calc(48px + env(safe-area-inset-top, 0px));
    min-height: 100dvh;
    height: auto;
    overflow: auto;
  }
  .mobile-navigation {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 4px;
    height: var(--mobile-nav-height);
    padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
    border-bottom: 1px solid var(--line);
    background: var(--bg);
  }
  .mobile-navigation button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 8px 4px;
    font-size: 11px;
    border-color: transparent;
  }
  .mobile-navigation button[aria-pressed="true"] {
    color: var(--fg);
    background: var(--raised);
    border-bottom-color: var(--fg);
  }
  #mobile-tools-button {
    flex: 0 0 auto;
    min-width: 64px;
  }
  .workspace {
    width: 100%;
    height: calc(var(--app-height, 100dvh) - var(--mobile-nav-height));
    min-height: 0;
  }
  #main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
  }
  #main > #editor {
    height: auto;
    min-height: 0;
    flex: 1;
  }
  .editor .loom {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    padding: 0;
  }
  .editor .splitter,
  .editor .continuations-panel {
    display: none;
  }
  body[data-mobile-pane="continuations"] .editor .manuscript-panel {
    display: none;
  }
  body[data-mobile-pane="continuations"] .editor .continuations-panel {
    display: flex;
  }
  .editor .manuscript-panel,
  .editor .reading-area,
  .editor .manuscript-scroll {
    min-height: 0;
    padding: 0;
  }
  .editor .manuscript-scroll {
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: auto;
    touch-action: pan-y pinch-zoom;
  }
  .manuscript-page,
  body.focus-mode .manuscript-page {
    padding: 24px max(16px, env(safe-area-inset-right, 0px)) calc(72px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  .editor .continuations-panel {
    padding: 0 max(12px, env(safe-area-inset-right, 0px)) max(8px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    overflow: auto;
    overscroll-behavior: contain;
  }
  .continuations-panel > .panel-heading {
    min-height: 40px;
    font-size: 12px;
  }
  .loom-model-row {
    flex: none;
    gap: 8px;
  }
  .loom-model-row select,
  .loom-model-row .tune-button {
    min-height: 44px;
    font-size: 12px;
  }
  .loom-model-row select {
    font-size: 16px;
  }
  select.model-picker::picker(select) {
    max-height: min(420px, calc(var(--app-height, 100dvh) - 80px));
    font-size: 14px;
    overscroll-behavior: contain;
  }
  select.model-picker option {
    min-height: 44px;
  }
  .cards {
    display: block;
    flex: 1 1 120px;
    min-height: 48px;
    overflow: auto;
    overscroll-behavior: contain;
  }
  .continuation {
    display: flex;
    min-height: 140px;
    padding: 14px 10px;
    gap: 0;
  }
  .card-top {
    display: flex;
    margin-bottom: 10px;
    font-size: 10px;
  }
  .card-index {
    font-size: 12px;
  }
  .card-index::after,
  .card-state {
    display: inline;
  }
  .card-body {
    overflow: visible;
    font-size: 13px;
    line-height: 1.8;
  }
  .generation-actions {
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 8px;
  }
  .generation-actions > button,
  .pagination button {
    min-height: 44px;
    min-width: 44px;
  }
  .generation-actions > button {
    padding: 9px 8px;
    font-size: 11px;
  }
  #delete-batch {
    width: 44px;
    min-height: 44px;
  }
  .pagination {
    gap: 0;
  }
  .continuations-panel .manuscript-meta {
    min-height: 30px;
    margin-top: 6px;
    padding-top: 6px;
  }
  .app-sidebar,
  body.focus-mode .app-sidebar {
    position: fixed;
    inset: 0 auto auto 0;
    z-index: 31;
    display: block;
    width: min(360px, calc(100vw - 24px));
    height: var(--app-height, 100dvh);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-right: 1px solid var(--bright);
    overflow: auto;
    overscroll-behavior: contain;
    transform: translateX(-100%);
    visibility: hidden;
    pointer-events: none;
  }
  body[data-mobile-tools="open"] .app-sidebar {
    transform: none;
    visibility: visible;
    pointer-events: auto;
  }
  body.focus-mode:not([data-page="loom"]) .workspace > .app-sidebar,
  body.focus-mode.laboratory-open .workspace > .app-sidebar {
    width: min(360px, calc(100vw - 24px));
    display: block;
  }
  #mobile-tools-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    width: 100%;
    height: var(--app-height, 100dvh);
    padding: 0;
    border: 0;
    background: #000b;
    cursor: default;
  }
  body[data-mobile-tools="open"] #mobile-tools-backdrop {
    display: block;
  }
  .app-sidebar .app-header,
  body.focus-mode .app-sidebar .app-header {
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 2;
    display: flex;
    height: 56px;
    background: var(--panel);
  }
  .app-sidebar .brand {
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 0 16px;
  }
  #mobile-tools-close {
    display: block;
    flex: none;
    min-width: 44px;
    min-height: 44px;
    margin-right: 8px;
    padding: 0;
    border-color: transparent;
    font-size: 20px;
  }
  .app-sidebar .sidebar-content,
  body.focus-mode .app-sidebar .sidebar-content {
    display: block;
    min-height: 0;
    overflow: visible;
  }
  .app-sidebar button,
  .app-sidebar input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  .app-sidebar select {
    min-height: 44px;
  }
  .app-sidebar .document-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }
  .app-sidebar .document-actions button,
  .app-sidebar .document-toolbar button {
    min-height: 44px;
    font-size: 11px;
    padding: 8px 4px;
  }
  .app-sidebar .toolbar-group {
    flex-wrap: wrap;
    gap: 4px;
  }
  .app-sidebar .typography-tools {
    flex-wrap: nowrap;
  }
  .app-sidebar .document-toolbar input,
  .app-sidebar .document-toolbar select,
  .app-sidebar .search {
    font-size: 16px;
  }
  .app-sidebar #writing-size {
    width: 64px;
  }
  .app-sidebar .doc-item {
    padding: 12px 8px;
  }
  .app-sidebar .app-footer,
  body.focus-mode .app-sidebar .app-footer {
    display: flex;
    padding: 10px 12px;
  }
  body.focus-mode .app-sidebar .workspace-navigation {
    display: flex;
  }
  body.focus-mode .sidebar-content > #library {
    display: flex;
  }
  body.focus-mode .app-sidebar > #saved-places,
  body.focus-mode .app-sidebar > #sidebar-together,
  body.focus-mode #document-controls > .document-header,
  body.focus-mode #document-controls > .sidebar-section-label {
    display: block;
  }
  body.focus-mode .app-sidebar .document-toolbar > .toolbar-group {
    display: flex;
  }
  body.focus-mode #document-controls,
  #document-controls {
    position: static;
    inset: auto;
    padding: 16px 12px 8px;
  }
  .welcome {
    overflow: auto;
    justify-content: safe center;
    padding: 16px;
  }
  .welcome .primary {
    min-height: 44px;
  }
  .audio-player {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .audio-player button,
  .audio-passage-heading button,
  .audio-passage-trim button,
  .audio-passage-actions button,
  .audio-passage-entry button,
  .audio-branch-cancellations button {
    min-width: 44px;
    min-height: 44px;
  }
  .audio-passage-trim input {
    min-height: 44px;
    font-size: 16px;
    width: 80px;
  }
  .audio-passage-edge {
    width: 44px;
  }
  .audio-passage-edge::before {
    left: 21px;
  }
  .audio-passage-edge::after {
    left: 18px;
  }
  dialog {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    bottom: auto;
    margin: 12px auto;
    max-width: calc(100vw - 24px);
    max-height: calc(var(--app-height, 100dvh) - 24px);
    overflow: auto;
  }
  dialog button,
  .checkpoint button,
  .document-menu button {
    min-height: 44px;
    min-width: 44px;
  }
  dialog input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  dialog select {
    min-height: 44px;
    font-size: 16px;
  }
  #settings-form {
    height: min(560px, calc(var(--app-height, 100dvh) - 26px));
  }
  .settings-tabs {
    gap: 16px;
    overflow: auto;
    flex: none;
  }
  .settings-tabs button {
    flex: none;
  }
  .tune-scroll {
    max-height: calc(var(--app-height, 100dvh) - 164px);
    overscroll-behavior: contain;
  }
  .graph-dialog {
    height: calc(var(--app-height, 100dvh) - 24px);
  }
  .graph-tools {
    flex-wrap: wrap;
  }
  .graph-tools input {
    min-width: 80px;
  }
  .checkpoint {
    width: min(340px, calc(100vw - 24px));
    max-height: calc(var(--app-height, 100dvh) - 24px);
  }
  .document-menu:popover-open {
    width: min(260px, calc(100vw - 24px));
    max-height: calc(var(--app-height, 100dvh) - 24px);
    overflow: auto;
  }
  .editor .find-panel {
    top: 8px;
    right: 8px;
    width: calc(100% - 16px);
  }
  .find-row input {
    font-size: 16px;
    min-height: 44px;
  }
  .find-row button {
    min-width: 44px;
    min-height: 44px;
    padding: 4px;
  }
  .error-banner {
    top: calc(var(--mobile-nav-height) + 8px);
    left: 8px;
    right: 8px;
    padding: 8px;
    gap: 8px;
  }
  .error-banner button {
    min-width: 44px;
    min-height: 44px;
  }
  .toast {
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 32px);
    padding: 10px 12px;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 600px) {
  .dialog-heading,
  .graph-dialog .dialog-heading,
  .tune-dialog .dialog-heading {
    padding: 12px 16px;
    gap: 12px;
  }
  .dialog-heading h2 {
    font-size: 20px;
    overflow-wrap: anywhere;
  }
  .dialog-actions,
  .tune-dialog .dialog-actions {
    padding: 12px 16px;
    flex-wrap: wrap;
  }
  .settings-scroll,
  .tune-scroll {
    padding-left: 16px;
    padding-right: 16px;
  }
  .settings-tabs {
    padding: 0 16px;
  }
  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .small-dialog label {
    margin-left: 16px;
    margin-right: 16px;
  }
  .small-dialog #text-value {
    margin-left: 16px;
    margin-right: 16px;
    width: calc(100% - 32px);
  }
  .graph-body-layout {
    flex-direction: column;
  }
  .generation-info {
    width: 100%;
    max-width: none;
    max-height: 55%;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .graph-footer {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
  }
  .audio-passage-trim {
    gap: 8px;
  }
}
