@font-face {
  font-family: "Castle Display";
  src: url("/fonts/title.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Castle Reader";
  src: url("/fonts/writer.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: "Castle Reader", Georgia, serif;
  color: var(--ink);
  background: #f7f4ef;
  --paper: #fff;
  --stone: #f1ece5;
  --ink: #20201f;
  --muted: #77736e;
  --line: #ded8cf;
  --accent: #7e2636;
  --accent-soft: #f3e7e8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-editor-size: 19px;
  --mobile-editor-line: 1.72;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--stone);
}

button,
input,
textarea {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

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

.mobile-shell {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-rows: calc(58px + var(--safe-top)) minmax(0, 1fr);
  background: var(--paper);
}

.topbar {
  position: relative;
  z-index: 13;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: var(--safe-top) 18px 0;
  color: #393532;
  border-bottom: 1px solid var(--line);
  background: var(--stone);
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  color: inherit;
  text-decoration: none;
}

.brand .monogram,
.castle-menu-button .monogram,
.pairing-monogram,
.empty-monogram {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  border-radius: 8px;
  background: var(--accent);
  font-family: "Castle Display", Georgia, serif;
  font-size: 21px;
}

.castle-menu-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 11px;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

.castle-menu-button .monogram {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;
}

.castle-menu-button:active .monogram,
.castle-menu-button[aria-expanded="true"] .monogram {
  transform: scale(0.94);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.brand strong {
  display: block;
  font-family: "Castle Display", Georgia, serif;
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: #7e7770;
  font-family: system-ui, sans-serif;
  font-size: 7px;
  font-weight: 750;
  letter-spacing: 0.22em;
}

.connection-status {
  display: flex;
  margin-left: auto;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 10px;
  font-weight: 600;
}

.connection-status span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c99b41;
}

.connection-status.online span {
  background: #4d9b6d;
}

.connection-status.offline span {
  background: #a6a09a;
}

.workspace {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
}

.library-view {
  display: flex;
  min-height: 0;
  padding: 0;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--stone);
}

.library-content {
  position: relative;
  min-height: 0;
  padding: 28px 20px 18px;
  flex: 1 1 auto;
  overflow: auto;
}

.library-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.library-heading-copy {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.library-heading-copy > div {
  min-width: 0;
}

.library-heading-copy h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-back-button {
  display: grid;
  width: 30px;
  height: 34px;
  padding: 0;
  flex: 0 0 auto;
  place-items: center;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.library-back-button:active {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.library-back-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.eyebrow {
  color: var(--accent);
  font-family: system-ui, sans-serif;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.library-heading h1,
.pairing-card h1 {
  margin: 3px 0 0;
  font-family: "Castle Display", Georgia, serif;
  font-size: 31px;
  font-weight: 400;
  line-height: 1.05;
}

.new-button,
.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.56);
}

.new-button svg,
.icon-button svg,
.search svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

.back-button {
  display: none;
}

.search {
  display: flex;
  height: 42px;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
}

.search svg {
  width: 17px;
  color: var(--muted);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

.work-list,
.document-list {
  display: grid;
  gap: 7px;
  margin-top: 15px;
}

.work-card {
  display: grid;
  width: 100%;
  min-height: 70px;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 11px 10px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
}

.work-card:active,
.work-card.selected {
  border-color: color-mix(in srgb, var(--line) 88%, transparent);
  background: color-mix(in srgb, var(--paper) 84%, transparent);
}

.work-card-icon {
  display: grid;
  width: 32px;
  height: 40px;
  place-items: center;
  color: var(--accent);
  border-radius: 3px 7px 7px 3px;
  background: color-mix(in srgb, var(--accent) 9%, var(--paper));
}

.work-card-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.45;
}

.work-card-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.work-card-copy strong {
  overflow: hidden;
  font-family: "Castle Display", Georgia, serif;
  font-size: 16px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.work-card-copy small,
.work-card-chevron {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.work-card-chevron {
  font-size: 17px;
}

.document-card {
  position: relative;
  width: 100%;
  padding: 13px 13px 12px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
}

.document-card.scene {
  margin-left: 21px;
  width: calc(100% - 21px);
}

.document-card-header {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
}

.document-kind {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: var(--muted);
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  font-family: "Castle Display", Georgia, serif;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.document-kind.scene {
  background: transparent;
  font-size: 20px;
}

.document-card:active,
.document-card.selected {
  border-color: #d7cfc5;
  background: rgba(255, 255, 255, 0.82);
}

.document-card strong {
  display: block;
  overflow: hidden;
  font-family: "Castle Display", Georgia, serif;
  font-size: 15px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-card p {
  display: -webkit-box;
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.document-meta {
  display: flex;
  margin-top: 8px;
  justify-content: space-between;
  color: #918b84;
  font-family: system-ui, sans-serif;
  font-size: 9px;
}

.mobile-new-menu {
  position: absolute;
  z-index: 4;
  top: 81px;
  right: 20px;
  width: min(246px, calc(100% - 40px));
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 97%, transparent);
  box-shadow: 0 12px 32px rgba(25, 20, 18, 0.14);
  backdrop-filter: blur(18px);
}

.mobile-new-menu button {
  display: grid;
  width: 100%;
  min-height: 47px;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  text-align: left;
  border: 0;
  border-radius: 7px;
  background: transparent;
}

.mobile-new-menu button:active {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.new-kind-mark {
  display: grid;
  width: 25px;
  place-items: center;
  color: var(--accent);
  font-family: "Castle Display", Georgia, serif;
  font-size: 18px;
}

.new-kind-mark.scene {
  font-size: 26px;
}

.mobile-new-menu strong,
.mobile-new-menu small {
  display: block;
  font-family: system-ui, sans-serif;
}

.mobile-new-menu strong {
  font-size: 12px;
  font-weight: 650;
}

.mobile-new-menu small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.mobile-profile-button {
  display: grid;
  width: 42px;
  height: 42px;
  min-height: 0;
  margin: 0 12px 12px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
}

.mobile-profile-button:active {
  color: var(--ink);
  border-color: var(--line);
  background: var(--paper);
}

.mobile-profile-button > svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.55;
}

.profile-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  border-radius: 9px;
  background: var(--accent);
  font-family: "Castle Display", Georgia, serif;
  font-size: 22px;
}

.profile-avatar.large {
  width: 43px;
  height: 43px;
  border-radius: 11px;
  font-size: 27px;
}

.profile-copy {
  display: block;
  min-width: 0;
  flex: 1;
}

.profile-copy strong,
.profile-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-copy strong {
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 680;
}

.profile-copy small {
  margin-top: 2px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.profile-more {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  color: var(--muted);
  fill: currentColor;
}

.library-empty,
.editor-empty {
  display: grid;
  min-height: 45vh;
  place-content: center;
  justify-items: center;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.library-empty > span {
  font-family: "Castle Display", Georgia, serif;
  font-size: 45px;
  color: var(--accent);
}

.library-empty h2,
.editor-empty h2 {
  margin: 12px 0 5px;
  color: var(--ink);
  font-family: "Castle Display", Georgia, serif;
  font-size: 25px;
  font-weight: 400;
}

.library-empty p,
.editor-empty p {
  max-width: 320px;
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.editor-view {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--paper);
}

.editor-page {
  display: flex;
  width: min(100%, 780px);
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(42px, 8vh, 82px) clamp(34px, 8vw, 90px) 45vh;
  flex-direction: column;
}

.title-input,
.body-input {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.title-input {
  flex: 0 0 auto;
  margin-bottom: 23px;
  font-family: "Castle Display", Georgia, serif;
  font-size: clamp(42px, 7vw, 62px);
  font-weight: 400;
  line-height: 1.03;
}

.body-input {
  min-height: 55vh;
  flex: 1 0 auto;
  overflow: hidden;
  resize: none;
  field-sizing: content;
  color: var(--ink);
  font-family: "Castle Reader", Georgia, serif;
  font-size: var(--mobile-editor-size);
  font-variant-ligatures: none;
  line-height: var(--mobile-editor-line);
}

.body-input::placeholder {
  color: #b4afa9;
}

.body-editor-host {
  width: 100%;
  min-height: 55vh;
  flex: 1 0 auto;
  color: var(--ink);
  font-family: "Castle Reader", Georgia, serif;
  font-size: var(--mobile-editor-size);
  font-variant-ligatures: none;
  line-height: var(--mobile-editor-line);
}

.body-editor-host .cm-editor {
  min-height: 55vh;
  color: inherit;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.body-editor-host .cm-editor.cm-focused {
  outline: 0;
}

.body-editor-host .cm-scroller {
  overflow: visible;
  font-family: inherit;
  line-height: inherit;
}

.body-editor-host .cm-content {
  min-height: 55vh;
  padding: 0 0 28vh !important;
  caret-color: var(--accent);
  font-family: inherit;
  font-variant-ligatures: none;
  line-height: inherit;
}

.body-editor-host .cm-line {
  padding: 0 !important;
}

.body-editor-host .cm-cursor,
.body-editor-host .cm-dropCursor {
  width: 1.5px !important;
  border-left: 1.5px solid var(--accent) !important;
}

.body-editor-host .cm-selectionBackground {
  background: color-mix(in srgb, var(--accent) 18%, transparent) !important;
}

.body-editor-host .cm-placeholder {
  color: #b4afa9;
  font-style: normal;
}

.body-editor-host .tok-emphasis {
  font-style: italic;
}

.body-editor-host .tok-strong {
  font-weight: 650;
}

.body-editor-host .tok-link,
.body-editor-host .castle-rendered-link {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 34%, transparent);
  text-underline-offset: 0.16em;
}

.body-editor-host .cm-line[class*="castle-heading-"],
.body-editor-host .tok-heading {
  font-family: "Castle Display", Georgia, serif;
  font-weight: 400;
  font-synthesis: none;
}

.body-editor-host .cm-line.castle-heading-1 {
  padding: 0.25em 0 0.48em !important;
  font-size: 2em;
  line-height: 1.06;
}

.body-editor-host .cm-line.castle-heading-2 {
  padding: 0.78em 0 0.22em !important;
  font-size: 1.48em;
  line-height: 1.12;
}

.body-editor-host .cm-line.castle-heading-3 {
  padding: 0.62em 0 0.16em !important;
  font-size: 1.22em;
  line-height: 1.18;
}

.body-editor-host .cm-line.castle-heading-4,
.body-editor-host .cm-line.castle-heading-5,
.body-editor-host .cm-line.castle-heading-6 {
  padding: 0.46em 0 0.1em !important;
  font-size: 1.05em;
}

.body-editor-host .castle-list-bullet,
.body-editor-host .castle-list-number {
  display: inline-block;
  color: var(--accent);
  font-family: "Castle Reader", Georgia, serif;
  font-weight: 600;
}

.body-editor-host .castle-list-bullet {
  min-width: 0.72em;
  font-size: 0.85em;
}

.body-editor-host .castle-list-number {
  min-width: 1.35em;
  font-variant-numeric: tabular-nums;
}

.body-editor-host .cm-line.castle-list-line {
  padding-left: 0.3em !important;
}

.body-editor-host .cm-line.castle-quote-line {
  margin: 0.32em 0;
  padding: 0.06em 0 0.06em 0.9em !important;
  color: color-mix(in srgb, var(--ink) 78%, var(--muted));
  border-left: 2px solid color-mix(in srgb, var(--accent) 42%, var(--line));
  font-style: italic;
}

.body-editor-host .castle-inline-code {
  padding: 0.06em 0.24em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  font-size: 0.86em;
}

.body-editor-host .castle-horizontal-rule {
  display: block;
  width: 100%;
  height: 1px;
  background: var(--line);
}

.writing-meter {
  position: fixed;
  z-index: 9;
  right: 9px;
  bottom: 2px;
  display: grid;
  min-width: 72px;
  height: 15px;
  padding: 0 3px 2px;
  grid-template-columns: minmax(20px, auto) 7px minmax(20px, auto);
  align-items: center;
  justify-content: end;
  color: var(--muted);
  background: transparent;
  font-family: system-ui, sans-serif;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  transition: opacity 180ms ease;
  pointer-events: auto;
}

.meter-value {
  min-width: 20px;
  height: 14px;
  padding: 0 1px;
  color: inherit;
  text-align: right;
  border: 0;
  border-radius: 2px;
  background: transparent;
  font-size: inherit;
  line-height: 1;
}

.meter-value.goal {
  grid-column: 3;
  color: color-mix(in srgb, var(--muted) 74%, transparent);
  text-align: left;
}

.meter-divider {
  color: color-mix(in srgb, var(--muted) 55%, transparent);
  text-align: center;
}

.meter-goal-input {
  grid-column: 3;
  width: 46px;
  height: 18px;
  padding: 0 2px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  outline: 0;
  background: var(--paper);
  font-size: 10px;
}

.meter-progress {
  position: absolute;
  right: 3px;
  bottom: 0;
  left: 3px;
  height: 1px;
  overflow: hidden;
  background: color-mix(in srgb, var(--line) 72%, transparent);
}

.meter-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 220ms ease;
}

.pairing-screen,
.dialog-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(28, 25, 23, 0.34);
  backdrop-filter: blur(8px);
}

.pairing-card,
.conflict-card {
  width: min(100%, 410px);
  padding: 34px 28px 28px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 22px 70px rgba(33, 27, 22, 0.2);
}

.pairing-monogram {
  width: 54px;
  height: 54px;
  margin: 0 auto 22px;
  border-radius: 14px;
  font-size: 35px;
}

.pairing-card p,
.conflict-card p {
  margin: 12px auto 22px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.pairing-progress {
  width: 92px;
  height: 2px;
  margin: -6px auto 20px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.pairing-progress i {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: pairing-progress 1.1s ease-in-out infinite alternate;
}

@keyframes pairing-progress {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(138%);
  }
}

.pairing-card input {
  width: 100%;
  height: 49px;
  padding: 0 14px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  font-family: system-ui, sans-serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pairing-card button,
.conflict-card button {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  font-family: system-ui, sans-serif;
  font-size: 14px;
  font-weight: 680;
}

.pairing-card button,
.conflict-card .primary {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.pairing-card small {
  display: block;
  margin-top: 15px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.conflict-card h2 {
  margin: 7px 0 0;
  font-family: "Castle Display", Georgia, serif;
  font-size: 28px;
  font-weight: 400;
}

.sheet-backdrop {
  position: fixed;
  z-index: 24;
  inset: 0;
  display: flex;
  padding: 18px;
  align-items: flex-end;
  justify-content: center;
  background: rgba(28, 25, 23, 0.32);
  backdrop-filter: blur(5px);
}

.profile-sheet {
  width: min(100%, 500px);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 22px 70px rgba(30, 25, 21, 0.26);
  animation: sheet-in 180ms ease-out;
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 2px auto 9px;
  border-radius: 99px;
  background: var(--line);
}

.profile-sheet-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 11px;
  padding: 10px 11px 13px;
}

.sheet-separator {
  height: 1px;
  margin: 3px 7px;
  background: var(--line);
}

.sheet-action {
  display: flex;
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  align-items: center;
  gap: 11px;
  text-align: left;
  border: 0;
  border-radius: 11px;
  background: transparent;
}

.sheet-action:active {
  background: var(--stone);
}

.sheet-action.active,
.sheet-action[aria-current="page"] {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  box-shadow: inset 2px 0 0 color-mix(in srgb, var(--accent) 68%, transparent);
}

.sheet-action.active > svg,
.sheet-action[aria-current="page"] > svg {
  color: var(--accent);
}

.sheet-action.active small,
.sheet-action[aria-current="page"] small {
  color: color-mix(in srgb, var(--accent) 62%, var(--muted));
}

.sheet-action.active > .chevron,
.sheet-action[aria-current="page"] > .chevron {
  opacity: 0.72;
}

.sheet-action > svg {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.sheet-action > span {
  display: block;
  min-width: 0;
  flex: 1;
}

.sheet-action strong,
.sheet-action small {
  display: block;
  font-family: system-ui, sans-serif;
}

.sheet-action strong {
  font-size: 13px;
  font-weight: 650;
}

.sheet-action small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.sheet-action > .chevron {
  width: 17px;
  height: 17px;
}

.sheet-action.compact {
  min-height: 44px;
}

.sheet-action.danger,
.sheet-action.danger > svg {
  color: #b2454d;
}

.settings-screen {
  position: fixed;
  z-index: 19;
  inset: 0;
  display: grid;
  grid-template-rows: calc(68px + var(--safe-top)) minmax(0, 1fr);
  background: var(--stone);
  animation: settings-in 180ms ease-out;
}

@keyframes settings-in {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
}

.settings-topbar {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: var(--safe-top) 16px 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--stone) 94%, transparent);
}

.settings-topbar .icon-button {
  flex: 0 0 auto;
  border-color: transparent;
  background: transparent;
}

.settings-topbar h1 {
  margin: 2px 0 0;
  font-family: "Castle Display", Georgia, serif;
  font-size: 25px;
  font-weight: 400;
  line-height: 1;
}

.settings-content {
  width: min(100%, 680px);
  min-height: 0;
  margin: 0 auto;
  padding: 18px 16px calc(40px + var(--safe-bottom));
  overflow: auto;
}

.settings-profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}

.settings-profile-card .profile-copy small {
  white-space: normal;
  line-height: 1.35;
}

.settings-group {
  margin-top: 15px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}

.settings-group-heading {
  margin-bottom: 15px;
}

.settings-group-heading.with-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-group-heading h2 {
  margin: 3px 0 0;
  font-family: "Castle Display", Georgia, serif;
  font-size: 24px;
  font-weight: 400;
}

.theme-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--stone);
}

.theme-control button {
  min-height: 38px;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 600;
}

.theme-control button.selected {
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 1px 5px rgba(31, 27, 24, 0.13);
}

.range-setting,
.switch-setting {
  display: grid;
  min-height: 60px;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.range-setting {
  grid-template-columns: minmax(118px, 1fr) minmax(100px, 1.25fr) 34px;
}

.settings-group-heading + .range-setting,
.settings-group-heading + .switch-setting {
  border-top: 0;
}

.range-setting > span,
.switch-setting > span {
  min-width: 0;
}

.range-setting strong,
.range-setting small,
.switch-setting strong,
.switch-setting small,
.settings-list-button strong,
.settings-list-button small {
  display: block;
  font-family: system-ui, sans-serif;
}

.range-setting strong,
.switch-setting strong,
.settings-list-button strong {
  font-size: 12px;
  font-weight: 650;
}

.range-setting small,
.switch-setting small,
.settings-list-button small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.3;
}

.range-setting input {
  width: 100%;
  accent-color: var(--accent);
}

.range-setting output {
  color: var(--muted);
  text-align: right;
  font-family: system-ui, sans-serif;
  font-size: 11px;
}

.switch-setting {
  position: relative;
  grid-template-columns: minmax(0, 1fr) 46px;
}

.switch-setting input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-setting i {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 99px;
  background: #c9c3bc;
  transition: background 150ms ease;
}

.switch-setting i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  content: "";
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  transition: transform 150ms ease;
}

.switch-setting input:checked + i {
  background: var(--accent);
}

.switch-setting input:checked + i::after {
  transform: translateX(18px);
}

.settings-status {
  padding: 5px 8px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: system-ui, sans-serif;
  font-size: 9px;
  font-weight: 650;
}

.settings-status.online {
  color: #397652;
  border-color: color-mix(in srgb, #397652 30%, var(--line));
  background: color-mix(in srgb, #397652 8%, transparent);
}

.information-row {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  font-family: system-ui, sans-serif;
  font-size: 11px;
}

.information-row span {
  color: var(--muted);
}

.information-row strong {
  min-width: 0;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-action-button {
  width: 100%;
  min-height: 42px;
  margin-top: 10px;
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--accent);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 650;
}

.settings-action-button.secondary {
  color: var(--ink);
  border-color: var(--line);
  background: transparent;
}

.settings-list-button {
  display: flex;
  width: 100%;
  min-height: 57px;
  padding: 7px 0;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
}

.settings-group-heading + .settings-list-button {
  border-top: 0;
}

.settings-list-button > span {
  min-width: 0;
  flex: 1;
}

.settings-list-button > svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.settings-version {
  margin: 25px 0 0;
  color: var(--muted);
  text-align: center;
  font-family: system-ui, sans-serif;
  font-size: 9px;
}

.stats-screen {
  position: fixed;
  z-index: 19;
  inset: 0;
  display: grid;
  grid-template-rows: calc(68px + var(--safe-top)) minmax(0, 1fr);
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 0%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 31%),
    var(--stone);
  animation: settings-in 180ms ease-out;
}

.view-profile-button {
  position: fixed;
  z-index: 22;
  bottom: calc(10px + var(--safe-bottom));
  left: 12px;
  margin: 0;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  box-shadow: 0 8px 26px rgba(30, 25, 21, 0.12);
  backdrop-filter: blur(10px);
}

.stats-topbar {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: var(--safe-top) 16px 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--stone) 94%, transparent);
}

.stats-topbar .icon-button {
  flex: 0 0 auto;
  border-color: transparent;
  background: transparent;
}

.stats-topbar h1 {
  margin: 2px 0 0;
  font-family: "Castle Display", Georgia, serif;
  font-size: 25px;
  font-weight: 400;
  line-height: 1;
}

.stats-content {
  width: min(100%, 680px);
  min-height: 0;
  margin: 0 auto;
  padding: 16px 14px calc(40px + var(--safe-bottom));
  overflow: auto;
}

.stats-hero {
  padding: 24px 22px;
  color: #fff;
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.11), transparent 58%),
    var(--accent);
  box-shadow: 0 18px 42px color-mix(in srgb, var(--accent) 22%, transparent);
}

.stats-kicker {
  color: color-mix(in srgb, currentColor 72%, transparent);
  font-family: system-ui, sans-serif;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.stats-hero-value {
  display: flex;
  margin-top: 8px;
  align-items: baseline;
  gap: 8px;
}

.stats-hero-value strong {
  font-family: "Castle Display", Georgia, serif;
  font-size: clamp(56px, 18vw, 78px);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}

.stats-hero-value small,
.stats-hero > span:last-child {
  color: rgba(255, 255, 255, 0.72);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.stats-hero-progress {
  height: 2px;
  margin-top: 20px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.2);
}

.stats-hero-progress i {
  display: block;
  width: 0;
  height: 100%;
  background: #fff;
  transition: width 220ms ease;
}

.stats-hero > span:last-child {
  display: block;
  margin-top: 8px;
}

.stats-card {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--paper);
}

.stats-week-card,
.stats-trace-card {
  margin-top: 13px;
}

.stats-card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.stats-card .stats-kicker {
  color: var(--accent);
}

.stats-card-heading h2 {
  margin: 3px 0 0;
  font-family: "Castle Display", Georgia, serif;
  font-size: 22px;
  font-weight: 400;
}

.stats-card-heading > strong {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.stats-week-chart {
  display: grid;
  height: 142px;
  margin-top: 19px;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.stats-day {
  display: grid;
  min-width: 0;
  grid-template-rows: 17px minmax(0, 1fr) 16px;
  justify-items: center;
  gap: 5px;
}

.stats-day-value,
.stats-day small {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 8px;
  font-variant-numeric: tabular-nums;
}

.stats-day-track {
  display: flex;
  width: min(20px, 75%);
  height: 100%;
  align-items: flex-end;
  overflow: hidden;
  border-radius: 999px;
  background: var(--stone);
}

.stats-day-track i {
  width: 100%;
  min-height: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 58%, var(--muted));
}

.stats-day.today .stats-day-track i {
  background: var(--accent);
}

.stats-day.today small {
  color: var(--accent);
  font-weight: 750;
}

.stats-grid {
  display: grid;
  margin-top: 13px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  display: grid;
  min-height: 128px;
  align-content: start;
}

.metric-card > strong {
  margin-top: 17px;
  font-family: "Castle Display", Georgia, serif;
  font-size: 29px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.metric-card > small {
  margin-top: 4px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 9px;
}

.stats-trace-row {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  font-family: system-ui, sans-serif;
  font-size: 10px;
}

.stats-card-heading + .stats-trace-row {
  margin-top: 14px;
}

.stats-trace-row span {
  color: var(--muted);
}

.toast {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: calc(58px + var(--safe-bottom));
  left: 18px;
  width: fit-content;
  max-width: calc(100% - 36px);
  margin: auto;
  padding: 11px 15px;
  color: #fff;
  border-radius: 10px;
  background: #292624;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.drawer-backdrop {
  display: none;
}

@media (max-width: 700px) {
  .mobile-shell {
    display: block;
    height: 100dvh;
  }

  .topbar {
    position: fixed;
    z-index: 14;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    padding: calc(var(--safe-top) + 7px) 0 0 10px;
    border: 0;
    background: transparent;
    transition: opacity 180ms ease;
  }

  .workspace {
    display: block;
    width: 100%;
    height: 100dvh;
  }

  .editor-view {
    width: 100%;
    height: 100%;
    border: 0;
  }

  .library-view {
    position: fixed;
    z-index: 12;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 360px);
    height: auto;
    padding: 0;
    border-right: 1px solid var(--line);
    box-shadow: 18px 0 48px rgba(27, 23, 20, 0.18);
    transform: translateX(-105%);
    transition: transform 190ms ease-out;
  }

  .mobile-shell.drawer-open .library-view {
    transform: translateX(0);
  }

  .drawer-backdrop {
    position: fixed;
    z-index: 11;
    inset: 0;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(28, 25, 23, 0.28);
    backdrop-filter: blur(2px);
    animation: drawer-backdrop-in 180ms ease-out;
  }

  .library-content {
    padding: calc(var(--safe-top) + 62px) 16px 18px;
  }

  .mobile-new-menu {
    top: calc(var(--safe-top) + 115px);
    right: 16px;
  }

  .mobile-profile-button {
    align-self: flex-start;
    margin-right: 12px;
    margin-bottom: calc(10px + var(--safe-bottom));
    margin-left: 12px;
  }

  .editor-view {
    display: block;
    scroll-padding-top: calc(var(--safe-top) + 8px);
    scroll-padding-bottom: 0;
  }

  .editor-page {
    min-height: 100dvh;
    padding:
      calc(var(--safe-top) + 8px)
      24px
      2px;
  }

  .title-input {
    min-height: 48px;
    margin-bottom: 16px;
    padding-left: 40px;
    font-size: clamp(40px, 13vw, 55px);
  }

  .body-input,
  .body-editor-host,
  .body-editor-host .cm-editor,
  .body-editor-host .cm-content {
    min-height: calc(100dvh - var(--safe-top) - 94px);
  }

  .editor-empty {
    min-height: 100%;
  }

  .mobile-shell.writing-active .topbar,
  .mobile-shell.writing-active .writing-meter {
    opacity: 0.08;
    pointer-events: none;
  }

  .toast {
    bottom: calc(30px + var(--safe-bottom));
  }
}

@keyframes drawer-backdrop-in {
  from {
    opacity: 0;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1f1e1d;
  --stone: #292624;
  --ink: #eeeae5;
  --muted: #aaa39b;
  --line: #413c38;
  --accent: #b55b6b;
  --accent-soft: #3a292c;
}

:root[data-theme="dark"] .document-card:active,
:root[data-theme="dark"] .document-card.selected {
  border-color: #514a45;
  background: rgba(255, 255, 255, 0.055);
}

:root[data-theme="dark"] .new-button,
:root[data-theme="dark"] .icon-button,
:root[data-theme="dark"] .search {
  background: rgba(255, 255, 255, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #1f1e1d;
    --stone: #292624;
    --ink: #eeeae5;
    --muted: #aaa39b;
    --line: #413c38;
    --accent: #b55b6b;
    --accent-soft: #3a292c;
  }

  .brand .monogram,
  .pairing-monogram,
  .empty-monogram {
    color: #fff;
  }

  :root:not([data-theme="light"]) .document-card:active,
  :root:not([data-theme="light"]) .document-card.selected {
    border-color: #514a45;
    background: rgba(255, 255, 255, 0.055);
  }

  :root:not([data-theme="light"]) .new-button,
  :root:not([data-theme="light"]) .icon-button,
  :root:not([data-theme="light"]) .search {
    background: rgba(255, 255, 255, 0.04);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .editor-view,
  .library-view,
  .document-card {
    transition: background 150ms ease;
  }
}
