.dialog:is(.editor-screen, .reader-screen) {
  --paper: #f6f2e9;
  --ink: #302b30;
  --ink-soft: #6d626c;
  --rule: #dcd4cb;
  --pen: #554264;
  color-scheme: light;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: none;
  scrollbar-width: thin;
  scrollbar-color: #c5b9b6 transparent;
}

.dialog:is(.editor-screen, .reader-screen)[open] {
  animation: paper-appear 190ms ease-out;
}

@keyframes paper-appear {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dialog:is(.editor-screen, .reader-screen)::backdrop {
  background: transparent;
  backdrop-filter: none;
}

.writing-layout {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.writing-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(max-content, 1fr);
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 10px clamp(22px, 5vw, 78px);
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.writing-location {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.writing-actions { display: flex; gap: 8px; align-items: center; justify-self: end; }
.writing-guide { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 7px; border-radius: 6px; color: var(--ink-soft); font-size: 12px; text-decoration: none; white-space: nowrap; }
.writing-guide:hover { color: var(--pen); background: #ebe2ec; }

.writing-bar :is(.writing-back, .writing-map) {
  display: inline-flex;
  justify-self: start;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.writing-bar :is(.writing-back, .writing-map):hover:not(:disabled) {
  border: 0;
  background: transparent;
  color: var(--pen);
}

.writing-bar .writing-map { padding: 0 8px; }

.writing-bar .writing-save,
.writing-bar .writing-edit {
  justify-self: end;
  min-height: 38px;
  padding: 0 15px;
  border: 1px solid var(--pen);
  border-radius: 8px;
  background: var(--pen);
  color: #fff9ff;
  box-shadow: none;
}

.writing-bar .writing-save:hover:not(:disabled) {
  border-color: #40304e;
  background: #40304e;
  color: #fff9ff;
}

.writing-bar .writing-edit {
  border-color: #cbbfc6;
  background: transparent;
  color: var(--pen);
}

.writing-bar .writing-edit:hover:not(:disabled) {
  border-color: #a997b2;
  background: #ebe2ec;
  color: var(--pen);
}

.writing-page {
  width: min(100% - 44px, 664px);
  margin: clamp(52px, 12vh, 136px) auto 82px;
}

.editor-screen .writing-page {
  width: min(calc(100% - clamp(40px, 8vw, 160px)), 1120px);
  margin: clamp(32px, 6vh, 72px) auto 72px;
}

.writing-page .writing-title,
.writing-page .writing-body {
  display: block;
}

.writing-page .writing-title input,
.writing-page h2.writing-title,
.writing-page h1.writing-title {
  margin: 0;
  padding: 0 0 22px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: clamp(30px, 5vw, 51px);
  font-weight: 600;
  letter-spacing: -.075em;
  line-height: 1.36;
  overflow-wrap: anywhere;
}

.writing-page .body-field,
.writing-page .reading-body {
  margin: 0;
  padding: 24px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: clamp(16px, 1.65vw, 19px);
  font-weight: 400;
  letter-spacing: -.028em;
  line-height: 2.05;
  overflow-wrap: anywhere;
}

.writing-page .body-field {
  min-height: min(36vh, 280px);
  white-space: pre-wrap;
  cursor: text;
}

.editor-screen .body-field {
  min-height: clamp(360px, 58dvh, 740px);
}

.body-field[data-empty]::before {
  content: attr(data-placeholder);
  color: var(--ink-soft);
  opacity: .72;
  pointer-events: none;
}

.writing-page .reading-body { white-space: pre-wrap; }

.writing-page .writing-title input::placeholder {
  color: #817780;
  opacity: 1;
}

.writing-page .reading-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 20px;
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.8;
  font-variant-numeric: tabular-nums;
}

.reading-dates > div { display: flex; gap: 7px; }
.reading-dates dt { font-weight: 500; white-space: nowrap; }
.reading-dates dd { margin: 0; }

.reading-publication,
.reading-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.reading-publication { margin-top: 15px; }

.reading-tags {
  margin: 0;
  padding: 0;
  list-style: none;
}

.reading-tags :is(a, span) {
  display: block;
  padding: 4px 9px;
  border: 1px solid var(--rule);
  border-radius: 20px;
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.reading-tags a:hover { background: #ede5ed; color: var(--pen); }

.reading-permalink {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px;
  color: var(--pen);
  font-size: 12px;
  text-underline-offset: 3px;
}

.reading-permalink svg { width: 13px; height: 13px; }

.writing-details {
  margin-top: 20px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.writing-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 53px;
  color: var(--pen);
  font-size: 13px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.writing-details summary::-webkit-details-marker { display: none; }

.writing-details summary::after {
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  content: '';
  transform: translateY(-2px) rotate(45deg);
}

.writing-body { position: relative; }
.mention-menu { position: fixed; inset: var(--mention-y, 8px) auto auto var(--mention-x, 8px); z-index: 2; display: grid; width: min(calc(100% - 16px), 355px, var(--mention-max-width, 100vw)); max-height: min(238px, 34dvh, var(--mention-max-height, 238px)); overflow-y: auto; padding: 4px; border: 1px solid #d2c4d1; border-radius: 9px; background: #fcf8f1; box-shadow: 0 8px 22px #49315126; scrollbar-width: thin; }
.mention-option { min-width: 0; display: grid; gap: 3px; width: 100%; padding: 8px 10px; text-align: left; border: 0; border-radius: 5px; background: transparent; color: var(--ink); overflow-wrap: anywhere; }
.mention-option:is(:hover,[aria-selected='true']) { background: #eee5ef; }
.mention-option-title { font-weight: 600; }
.mention-option-path, .mention-empty { color: var(--ink-soft); font-size: 11px; }
.mention-empty { margin: 0; padding: 9px 10px; }
.inline-mention { display: inline; padding: 0 2px; border: none; border-radius: 3px; background: #ede3ef; color: #5d3b6d; text-align: start; text-decoration: underline; text-underline-offset: .15em; text-decoration-color: #9d7dac; overflow-wrap: anywhere; }
.inline-mention:hover { background: #e2d1e7; }

.media-editor { margin-top: 28px; }
.media-editor-heading { margin: 0 0 10px; color: var(--ink); font-size: 14px; font-weight: 650; }
.writing-image-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 0 0;
}
.writing-image-tools p { margin: 0; color: #96384b; font-size: 12px; }
.writing-image-tools p:empty { display: none; }
.writing-image-tools:not(:has(p:not(:empty))) { display: none; }
.image-command-menu { width: min(calc(100% - 16px), 280px, var(--mention-max-width, 100vw)); }
.draft-image, .reading-image {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: .65em 0;
}
.draft-image { user-select: none; outline: 2px solid transparent; outline-offset: 3px; border-radius: 6px; }
.draft-image:is(.is-selected,:focus-visible,.is-resizing) { outline-color: #9471a3; }
:is(.draft-image, .reading-image) img {
  display: block;
  max-width: 100%;
  max-height: 68dvh;
  object-fit: contain;
  border-radius: 6px;
}
.draft-image--sized img, .reading-image--sized img { width: 100%; height: auto; max-height: none; }
.draft-image-pending { padding: 6px 12px; border-radius: 5px; background: #eee7ec; color: var(--ink-soft); font-size: 13px; overflow-wrap: anywhere; }
.draft-image-resize {
  position: absolute;
  bottom: -12px;
  right: -12px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  opacity: 0;
  cursor: nwse-resize;
  touch-action: none;
  outline: none;
}
.draft-image-resize::after { content: ''; width: 10px; height: 10px; border: 2px solid var(--paper); border-radius: 3px; background: #79558c; box-shadow: 0 0 0 1px #79558c; }
.draft-image:is(:hover,.is-selected,:focus-within,.is-resizing) .draft-image-resize { opacity: 1; }
.draft-image-resize:focus-visible::after { box-shadow: 0 0 0 3px #b29dc0; }
.media-editor .button { color: var(--pen); border-color: #cbbfc6; background: #faf6f5; }
.media-editor .button:hover:not(:disabled) { border-color: #a997b2; background: #ebe2ec; }
.media-editor-list { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.media-editor-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 12px;
  padding: 8px;
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.media-editor-preview {
  display: grid;
  place-items: center;
  width: 88px;
  min-height: 50px;
  overflow: hidden;
  border-radius: 4px;
  background: #e8dfdf;
}
.media-editor-preview :is(img, video) { display: block; width: 100%; max-height: 74px; object-fit: contain; }
.media-editor-preview video { background: #241f26; }
.media-editor-file-format { color: var(--pen); font-size: 12px; font-weight: 650; }
.media-editor-info { display: grid; gap: 3px; }
.media-editor-label { overflow-wrap: anywhere; font-size: 13px; }
.media-editor-meta { color: var(--ink-soft); font-size: 11px; }
.media-editor-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.media-editor-actions .button { min-width: 30px; min-height: 32px; padding-inline: 7px; }

.reading-media { display: grid; gap: 24px; margin: 24px 0 0; }
.reading-media figure { min-width: 0; margin: 0; }
.reading-media :is(img, video) { display: block; max-width: 100%; max-height: 68dvh; margin: auto; border-radius: 6px; }
.reading-media video { width: 100%; background: #201d21; }
.reading-media figcaption { margin-top: 9px; color: var(--ink-soft); font-size: 12px; overflow-wrap: anywhere; }
.reading-media a { color: var(--pen); text-underline-offset: .2em; }
.reading-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-size: 14px;
  text-decoration: none;
}
.reading-file:hover { background: #eee7ec; }
.reading-file svg { flex: 0 0 16px; width: 16px; height: 16px; }
.reading-file span { flex: 1; overflow-wrap: anywhere; }
.reading-file small { color: var(--ink-soft); }

.reading-references { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--rule); }
.reading-references h3 { margin: 0 0 8px; color: var(--ink-soft); font-size: 12px; font-weight: 600; }
.reading-references ul { margin: 0; padding: 0; list-style: none; }
.reading-references button { width: 100%; display: flex; align-items: center; gap: 8px; padding: 10px 3px; border: 0; border-bottom: 1px solid var(--rule); color: var(--pen); text-align: left; background: transparent; }
.reading-references button:hover { background: #eee7ec; }
.reading-references button span { flex: 1; overflow-wrap: anywhere; }
.reading-references small { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 11px; }

.writing-details[open] summary::after { transform: translateY(2px) rotate(225deg); }

.writing-fields {
  display: grid;
  gap: 14px;
  padding: 4px 0 22px;
}

.writing-fields label:not(.check),
.writing-tag-field,
.writing-created-at {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
}

.writing-created-at output {
  display: block;
  padding: 9px 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.writing-fields .check,
.writing-publication-choice .check {
  color: var(--ink);
}

.writing-page input[type='checkbox'] { accent-color: var(--pen); }

.writing-fields :is(input:not([type='checkbox']), select, textarea) {
  padding: 9px 11px;
  color: var(--ink);
  border: 1px solid #d1c6c3;
  border-radius: 6px;
  background: #faf7f0;
}

.writing-fields textarea { width: 100%; min-height: 58px; resize: vertical; }

.writing-fields small,
.writing-publication-choice p {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.65;
}

.writing-publication-choice { margin-top: 18px; }
.writing-publication-choice .check { width: fit-content; font-weight: 600; }
.writing-publication-choice p { margin: 5px 0 0 25px; }

.writing-page .form-error {
  margin-top: 16px;
  color: #96384b;
  font-size: 13px;
}

.discard-draft {
  color-scheme: light;
  width: min(390px, calc(100% - 30px));
  color: #302b30;
  background: #f6f2e9;
  border-color: #dcd4cb;
}
.discard-draft::backdrop { background: #30263050; backdrop-filter: none; }
.discard-draft h2 { margin: 0 0 8px; font-size: 21px; }
.discard-draft p { margin: 0 0 20px; color: #625660; }
.discard-draft .button { color: #554264; background: transparent; border-color: #cbbfc6; min-height: 38px; }
.discard-draft .button:hover { background: #ebe2ec; border-color: #a997b2; }
.discard-draft .button.danger { color: #a1394e; border-color: #dbb5b9; }
.discard-draft .button.danger:hover { background: #f3dfe1; }

.dialog:is(.editor-screen, .reader-screen) :is(a, button, input, select, textarea, summary):focus-visible {
  outline: 2px solid #9677ab;
  outline-offset: 4px;
}

.writing-page .writing-title input:focus-visible,
.writing-page .body-field:focus-visible {
  outline: none;
}

.writing-page .writing-title input:focus-visible { border-color: #a88daa; }
.writing-page .body-field:focus-visible { box-shadow: inset 0 -1px var(--rule); }

.dialog.reader-screen .writing-page h2.writing-title:focus { outline: none; }

@media (max-width: 620px) {
  .writing-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0 8px;
    min-height: 64px;
    padding: 8px 17px 10px;
  }

  .writing-location {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }

  .writing-actions { gap: 4px; }
  .writing-guide { min-width: 26px; padding-inline: 3px; }
  .writing-guide span { display: none; }
  .writing-guide::before { content: '?'; display: grid; place-items: center; width: 19px; height: 19px; border: 1px solid currentColor; border-radius: 50%; font-size: 12px; font-weight: 600; }
  .writing-bar .writing-map { padding-inline: 4px; }
  .writing-bar .writing-map svg { display: none; }

  .writing-page { margin: 48px auto 44px; }
  .writing-page .writing-title input { padding-bottom: 18px; }
  .writing-fields .field-line { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .topbar .map-published-link span { display: none; }
  .media-editor-item { grid-template-columns: auto minmax(0, 1fr); }
  .media-editor-actions { grid-column: 2; }
}

@media (max-width: 360px) {
  .topbar :is(.owner-published-link, .demo-mode-label) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dialog:is(.editor-screen, .reader-screen)[open] { animation: none; }
}
.reading-delete { margin-top: 70px; padding-top: 24px; border-top: 1px solid #ded6cd; }
