:root {
  color-scheme: light;
  --app-height: 100dvh;
  --paper: #f4f1ea;
  --paper-bright: #fcf9f2;
  --paper-low: #f6f3ec;
  --paper-mid: #e5e2db;
  --ink: #1c1c18;
  --ink-soft: #444748;
  --line: rgba(28, 28, 24, 0.18);
  --line-strong: rgba(28, 28, 24, 0.42);
  --seal: #b52424;
  --jade: #2d5a27;
  --danger: #ba1a1a;
  --font-page-title: 18px;
  --font-content-title: 17px;
  --font-body: 16px;
  --font-button: 14px;
  --font-nav: 12px;
  --font-helper: 12px;
  --topbar-height: 54px;
  --bottom-nav-height: 64px;
  --tap-target: 44px;
  font-family: "Noto Serif SC", "Source Serif 4", serif;
}

html {
  overflow-x: clip;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: var(--app-height);
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg width='120' height='120' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='0.055'/%3E%3C/svg%3E");
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.secondary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap-target);
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--seal);
  color: var(--paper-bright);
  padding: 0 14px;
  text-decoration: none;
}

button:active {
  transform: translateY(1px);
}

.secondary-button,
.secondary-link,
.icon-button {
  background: transparent;
  color: var(--ink);
}

.icon-button {
  width: var(--tap-target);
  padding: 0;
}

.hidden {
  display: none !important;
}

.ui-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  background-color: currentColor;
  -webkit-mask: var(--ui-icon) center / contain no-repeat;
  mask: var(--ui-icon) center / contain no-repeat;
}

.icon-menu-book,
.icon-auto-stories {
  --ui-icon: url("/icons/ui/book.svg");
}

.icon-account-circle {
  --ui-icon: url("/icons/ui/user-avatar.svg");
}

.icon-download {
  --ui-icon: url("/icons/ui/download.svg");
}

.icon-key {
  --ui-icon: url("/icons/ui/key.svg");
}

.icon-logout {
  --ui-icon: url("/icons/ui/power-switch.svg");
}

.icon-search {
  --ui-icon: url("/icons/ui/search.svg");
}

.icon-more-horizontal {
  --ui-icon: url("/icons/ui/menu.svg");
}

.icon-refresh {
  --ui-icon: url("/icons/ui/refresh.svg");
}

.icon-add,
.icon-add-circle {
  --ui-icon: url("/icons/ui/plus.svg");
}

.icon-sync,
.icon-difference {
  --ui-icon: url("/icons/ui/change.svg");
}

.icon-arrow-back {
  --ui-icon: url("/icons/ui/arrow-left.svg");
}

.icon-arrow-forward {
  --ui-icon: url("/icons/ui/arrow-left.svg");
  transform: rotate(180deg);
}

.icon-edit-note {
  --ui-icon: url("/icons/ui/pencil.svg");
}

.icon-save {
  --ui-icon: url("/icons/ui/save.svg");
}

.icon-sync-alt {
  --ui-icon: url("/icons/ui/switch.svg");
}

.icon-format-list-bulleted-add {
  --ui-icon: url("/icons/ui/menu-add.svg");
}

.icon-history,
.icon-restore,
.icon-restore-from-trash {
  --ui-icon: url("/icons/ui/restore.svg");
}

.icon-call-split,
.icon-account-tree {
  --ui-icon: url("/icons/ui/branch.svg");
}

.icon-delete {
  --ui-icon: url("/icons/ui/trash.svg");
}

.icon-inventory-2 {
  --ui-icon: url("/icons/ui/chest.svg");
}

.icon-help {
  --ui-icon: url("/icons/ui/question-mark.svg");
}

.icon-add-notes,
.icon-draft,
.icon-notes,
.icon-document {
  --ui-icon: url("/icons/ui/document.svg");
}

.icon-visibility {
  --ui-icon: url("/icons/ui/visible.svg");
}

.icon-eyedropper {
  --ui-icon: url("/icons/ui/eyedropper.svg");
}

.icon-check-circle {
  --ui-icon: url("/icons/ui/tick.svg");
}

.icon-cancel,
.icon-close {
  --ui-icon: url("/icons/ui/cross.svg");
}

.icon-folder-open {
  --ui-icon: url("/icons/ui/folder.svg");
}

.icon-assignment {
  --ui-icon: url("/icons/ui/clipboard.svg");
}

.icon-send {
  --ui-icon: url("/icons/ui/paper-plane.svg");
}

.icon-arrow-upward {
  --ui-icon: url("/icons/ui/arrow-up.svg");
}

.icon-arrow-up {
  --ui-icon: url("/icons/ui/arrow-up.svg");
}

.icon-trash {
  --ui-icon: url("/icons/ui/trash.svg");
}

.icon-arrow-downward {
  --ui-icon: url("/icons/ui/arrow-down.svg");
}

.icon-content-copy {
  --ui-icon: url("/icons/ui/copy.svg");
}

.icon-merge {
  --ui-icon: url("/icons/ui/branch-02.svg");
}

.icon-record-voice-over {
  --ui-icon: url("/icons/ui/mic.svg");
}

.icon-warning {
  --ui-icon: url("/icons/ui/exclamation.svg");
}

.login-page {
  display: grid;
  min-height: var(--app-height);
  place-items: center;
  padding:
    max(20px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.login-shell {
  width: min(100%, 420px);
}

.login-panel {
  display: grid;
  gap: 18px;
  background: var(--paper-bright);
  border: 1px solid var(--line-strong);
  padding: 24px;
}

.login-panel h1,
.topbar h1 {
  margin: 0;
  font-family: "EB Garamond", "Noto Serif SC", serif;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 14px;
}

.field,
label {
  display: grid;
  gap: 7px;
}

.field span,
label span {
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  border-radius: 0;
  background: rgba(252, 249, 242, 0.72);
  color: var(--ink);
  padding: 10px 4px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.7;
}

input:focus,
textarea:focus,
select:focus {
  border-bottom-color: var(--seal);
}

.form-message {
  min-height: 22px;
  color: var(--danger);
}

.app-shell {
  min-height: var(--app-height);
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
}

.app-shell[data-work-view="read"] {
  --topbar-height: 46px;
}

.app-shell[data-work-view="read"] .topbar {
  gap: 6px;
  padding-inline: max(12px, env(safe-area-inset-left));
}

.app-shell[data-work-view="read"] #homeButton {
  width: 30px;
  min-height: 30px;
  border: 0;
}

.app-shell[data-work-view="read"] #homeButton .ui-icon {
  width: 16px;
  height: 16px;
}

.app-shell[data-work-view="read"] .topbar-context h1 {
  font-size: 14px;
  font-weight: 600;
}

.app-shell[data-work-view="read"] .topbar-context p,
.app-shell[data-work-view="read"] .account-menu,
.app-shell[data-work-view="read"] .topbar-primary-action .ui-icon {
  display: none;
}

.app-shell[data-work-view="read"] .topbar-primary-action {
  min-height: 28px;
  border: 1px solid var(--seal);
  border-radius: 4px;
  padding: 0 8px;
  font-size: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding:
    env(safe-area-inset-top)
    max(12px, env(safe-area-inset-right))
    0
    max(12px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(252, 249, 242, 0.94);
  backdrop-filter: blur(12px);
}

.topbar-context {
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-context h1 {
  margin: 0;
  overflow: hidden;
  font-family: "Noto Serif SC", "Source Serif 4", serif;
  font-size: var(--font-page-title);
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-context p {
  margin: 1px 0 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: var(--font-helper);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.topbar-primary-action {
  min-height: var(--tap-target);
  padding: 0 10px;
  background: transparent;
  color: var(--seal);
  border-color: transparent;
  font-size: var(--font-button);
}

.account-menu {
  position: relative;
  flex: 0 0 42px;
}

.account-menu > summary {
  list-style: none;
  cursor: pointer;
}

.account-menu > summary::-webkit-details-marker {
  display: none;
}

.account-menu[open] > summary {
  border-color: var(--seal);
  color: var(--seal);
}

.account-menu-panel {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 1200;
  display: grid;
  width: min(280px, calc(100vw - 24px));
  border: 1px solid var(--line-strong);
  background: var(--paper-bright);
  box-shadow: 0 14px 36px rgba(28, 28, 24, 0.18);
  padding: 8px;
}

.account-menu:not([open]) .account-menu-panel {
  display: none;
}

.account-menu-user {
  margin: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.account-menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
  text-decoration: none;
}

.account-menu-item:hover,
.account-menu-item:focus-visible {
  background: rgba(181, 36, 36, 0.08);
  outline: none;
}

.offline-banner {
  position: sticky;
  top: calc(var(--topbar-height) + env(safe-area-inset-top));
  z-index: 29;
  margin: 0;
  padding: 9px max(16px, env(safe-area-inset-right)) 9px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(186, 26, 26, 0.35);
  background: #fff0ee;
  color: var(--danger);
  text-align: center;
  font-size: 13px;
}

.workspace {
  width: min(100%, 920px);
  min-height: calc(var(--app-height) - var(--topbar-height) - var(--bottom-nav-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.screen {
  min-height: calc(var(--app-height) - var(--topbar-height) - var(--bottom-nav-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 16px;
  animation: view-in 140ms ease-out;
}

.reader-screen,
.input-screen,
.node-screen,
.task-screen,
.help-screen,
.chat-screen {
  min-height: calc(var(--app-height) - var(--topbar-height) - var(--bottom-nav-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

.input-screen {
  width: min(100%, 680px);
  margin-inline: auto;
}

.input-screen .screen-header {
  display: none;
}

.editor-form > .compact-field {
  grid-template-columns: 66px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
}

.editor-form > .compact-field input {
  min-width: 0;
  min-height: 34px;
  padding: 5px 3px;
  font-size: 14px;
}

.offline-page {
  display: grid;
  min-height: var(--app-height);
  place-items: center;
  padding:
    max(24px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.offline-card {
  width: min(100%, 520px);
  border: 1px solid var(--line-strong);
  background: var(--paper-bright);
  padding: 28px;
}

.offline-card h1 {
  margin: 0 0 14px;
  font-size: 28px;
}

.offline-card p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  line-height: 1.8;
}

.offline-card a {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  border: 1px solid var(--ink);
  background: var(--seal);
  color: var(--paper-bright);
  padding: 0 14px;
  text-decoration: none;
}

.search-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line-strong);
  margin-bottom: 16px;
}

.search-row input {
  border-bottom: 0;
  background: transparent;
}

.search-state {
  min-height: 18px;
  margin: -10px 0 12px;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.filter-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
}

.filter-tabs button {
  min-height: 32px;
  white-space: nowrap;
  border-color: var(--seal);
  background: transparent;
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.filter-tabs button.active {
  background: var(--seal);
  color: var(--paper-bright);
}

.task-filter-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding-bottom: 8px;
}

.task-filter-tabs button {
  min-height: 32px;
  white-space: nowrap;
  border-color: var(--seal);
  background: transparent;
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.task-filter-tabs button.active {
  background: var(--seal);
  color: var(--paper-bright);
}

.task-progress-filter {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  color: #6f737a;
  font-size: 11px;
}

.task-progress-filter select {
  min-height: 28px;
  max-width: 160px;
  padding: 2px 25px 2px 8px;
  border: 1px solid #d7d9de;
  border-radius: 7px;
  color: #35373b;
  background: rgba(255, 255, 255, 0.88);
  font-size: 11px;
}

.task-top-actions {
  position: sticky;
  top: 64px;
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: -2px 0 14px;
  padding: 10px 0;
  background: linear-gradient(to bottom, var(--paper) 78%, rgba(246, 240, 227, 0));
}

.task-top-actions button {
  min-height: 44px;
}

.intake-summary {
  margin-bottom: 14px;
  border: 1px solid var(--line-strong);
  background: rgba(252, 249, 242, 0.82);
}

.intake-summary details > summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 600;
}

.intake-summary-list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.intake-summary-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.intake-summary-item p,
.intake-summary-item small {
  margin: 0;
}

.intake-summary-item small {
  display: block;
  margin-top: 3px;
  color: var(--ink-soft);
}

.list-actions,
.save-row,
.document-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.list-actions {
  margin: 6px 0 14px;
}

.item-list,
.node-list,
.line-editor,
#choiceList,
.versions-list {
  display: grid;
  gap: 8px;
}

.item,
.node-item,
.line-row,
.choice-row,
.version-row {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(252, 249, 242, 0.76);
  color: var(--ink);
}

.item,
.node-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  min-height: 68px;
  height: auto;
  padding: 10px 2px 10px 12px;
  text-align: left;
  white-space: normal;
  overflow: hidden;
}

.item.active,
.node-item.active {
  border-color: var(--seal);
  box-shadow: inset 3px 0 0 var(--seal);
}

.item.editing:not(.active) {
  box-shadow: inset 3px 0 0 var(--jade);
}

.item-title,
.node-title {
  display: grid;
  gap: 4px;
  min-width: 0;
  align-self: start;
}

.item strong,
.node-item strong {
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 18px;
  line-height: 1.45;
  font-weight: 500;
}

.item small,
.node-item small {
  display: block;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.seal-tag {
  display: inline-grid;
  align-self: center;
  place-items: center;
  min-width: 40px;
  min-height: 28px;
  border: 1px solid var(--seal);
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.app-shell[data-work-view="list"] .topbar {
  display: none;
}

.app-shell[data-work-view="list"] .workspace,
.app-shell[data-work-view="list"] .list-screen {
  min-height: calc(var(--app-height) - var(--bottom-nav-height) - env(safe-area-inset-bottom));
}

.list-screen {
  padding-top: max(10px, env(safe-area-inset-top));
}

.directory-controls {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: calc(-1 * max(10px, env(safe-area-inset-top))) -16px 10px;
  padding:
    max(10px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    8px
    max(16px, env(safe-area-inset-left));
  background: linear-gradient(to bottom, var(--paper) 88%, rgba(244, 241, 234, 0));
}

.list-screen .filter-tabs {
  gap: 6px;
  margin: 0 -16px 6px;
  padding: 0 16px 2px;
  scrollbar-width: none;
}

.list-screen .filter-tabs::-webkit-scrollbar {
  display: none;
}

.list-screen .filter-tabs button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(252, 249, 242, 0.72);
  color: var(--ink-soft);
  padding: 0 13px;
  font-family: inherit;
  font-size: 13px;
}

.list-screen .filter-tabs button.active {
  border-color: var(--seal);
  background: var(--seal);
  color: var(--paper-bright);
  box-shadow: 0 5px 12px rgba(181, 36, 36, 0.16);
}

.directory-search-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.list-screen .search-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 4px;
  min-width: 0;
  min-height: 38px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(252, 249, 242, 0.88);
  padding: 0 9px;
  color: var(--ink-soft);
}

.list-screen .search-row input {
  min-width: 0;
  min-height: 36px;
  border: 0;
  background: transparent;
  padding: 7px 2px;
  font-size: 13px;
}

.directory-new-button {
  min-width: 74px;
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  box-shadow: 0 7px 16px rgba(181, 36, 36, 0.2);
  font-family: inherit;
  font-weight: 600;
}

.directory-list-toolbar {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 5px;
}

.list-screen .search-state {
  min-height: 0;
  margin: 0;
  font-family: inherit;
  font-size: 12px;
}

.directory-toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
}

.directory-sort {
  display: block;
}

.directory-sort select {
  width: auto;
  min-height: 32px;
  border: 0;
  background: transparent;
  padding: 2px 24px 2px 6px;
  color: var(--ink-soft);
  font-size: 12px;
}

.directory-more {
  position: relative;
}

.directory-more > summary {
  display: grid;
  width: 36px;
  min-height: 36px;
  list-style: none;
  cursor: pointer;
  place-items: center;
  border: 0;
}

.directory-more > summary::-webkit-details-marker {
  display: none;
}

.directory-more-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 40;
  display: grid;
  width: 170px;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-bright);
  box-shadow: 0 12px 28px rgba(28, 28, 24, 0.16);
  padding: 7px;
}

.directory-more:not([open]) .directory-more-menu {
  display: none;
}

.directory-more-menu button,
.directory-more-menu a {
  justify-content: flex-start;
  border: 0;
  border-radius: 7px;
  padding: 0 10px;
  font-size: 13px;
}

.list-screen .item-list {
  gap: 8px;
}

.list-screen .directory-card {
  --category-color: #77736b;
  --category-soft: #f0eeea;
  position: relative;
  display: block;
  min-height: 96px;
  border: 1px solid rgba(39, 36, 31, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 5px 15px rgba(31, 28, 24, 0.07);
  padding: 10px 12px 9px 16px;
  overflow: hidden;
}

.list-screen .directory-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--category-color);
}

.list-screen .directory-card[data-category-color="story"],
.list-screen .directory-card[data-category-color="story_text"] {
  --category-color: #dc292f;
  --category-soft: #fff0f0;
}

.list-screen .directory-card[data-category-color="vn_text"],
.list-screen .directory-card[data-category-color="vn_node"] {
  --category-color: #b4235a;
  --category-soft: #fff0f6;
}

.list-screen .directory-card[data-category-color="setting"] {
  --category-color: #2563eb;
  --category-soft: #eef4ff;
}

.list-screen .directory-card[data-category-color="mechanic_outline"] {
  --category-color: #079669;
  --category-soft: #eafaf4;
}

.list-screen .directory-card[data-category-color="creative_reference"] {
  --category-color: #e68a00;
  --category-soft: #fff6e5;
}

.list-screen .directory-card[data-category-color="character_setting"] {
  --category-color: #7c4dff;
  --category-soft: #f3efff;
}

.list-screen .directory-card[data-category-color="production_technical"] {
  --category-color: #0e8792;
  --category-soft: #eaf8f8;
}

.list-screen .directory-card.active {
  border-color: var(--category-color);
  box-shadow: 0 6px 18px rgba(31, 28, 24, 0.09);
}

.list-screen .directory-card.editing:not(.active) {
  box-shadow: 0 6px 18px rgba(31, 28, 24, 0.09), inset 0 0 0 1px var(--jade);
}

.list-screen .directory-card .item-title {
  gap: 3px;
}

.list-screen .directory-card strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.directory-summary {
  display: -webkit-box;
  overflow: hidden;
  color: #4d4a43;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.directory-location {
  display: -webkit-box;
  overflow: hidden;
  color: #6d6961;
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.directory-meta {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 1px;
}

.list-screen .directory-card .seal-tag {
  min-width: 0;
  min-height: 20px;
  border: 0;
  border-radius: 5px;
  background: var(--category-soft);
  color: var(--category-color);
  padding: 1px 6px;
  font-family: inherit;
  font-size: 10.5px;
}

.directory-meta time {
  overflow: hidden;
  color: #98948d;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.directory-card mark,
.search-match mark {
  border-radius: 2px;
  background: #ffe39a;
  color: inherit;
  padding: 0 1px;
}

.list-screen .search-match {
  color: #5d5850;
  font-size: 12px;
}

.directory-card-skeleton {
  display: grid !important;
  gap: 9px;
  pointer-events: none;
}

.directory-card-skeleton span {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ece9e2 25%, #f8f6f1 45%, #ece9e2 70%);
  background-size: 240% 100%;
  animation: directory-skeleton 1.2s ease-in-out infinite;
}

.directory-card-skeleton span:nth-child(1) {
  width: 74%;
  height: 16px;
}

.directory-card-skeleton span:nth-child(2) {
  width: 92%;
}

.directory-card-skeleton span:nth-child(3) {
  width: 63%;
}

.directory-card-skeleton span:nth-child(4) {
  width: 42%;
}

.directory-pagination {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  margin-top: 12px;
  padding-bottom: 4px;
}

.directory-pagination button {
  min-width: 0;
  min-height: 38px;
  border-radius: 9px;
  font-size: 13px;
}

.directory-pagination button:last-child {
  justify-self: stretch;
}

.directory-pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.directory-page-select {
  display: block;
}

.directory-page-select select {
  width: auto;
  min-width: 86px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--paper-bright);
  padding: 0 28px 0 10px;
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

@keyframes directory-skeleton {
  to {
    background-position: -240% 0;
  }
}

.screen-header {
  position: static;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.screen-header h2 {
  margin: 0;
  font-family: "Noto Serif SC", "Source Serif 4", serif;
  font-size: var(--font-content-title);
  line-height: 1.35;
}

.screen-header p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: var(--font-helper);
  overflow-wrap: anywhere;
}

.search-match {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.search-match b {
  margin-right: 7px;
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.editor-save-cluster,
.node-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.compact-save-button {
  min-height: 36px;
  padding: 7px 11px;
}

.reader-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.reader-previous-field select {
  width: min(260px, 42vw);
  min-height: 38px;
  padding: 7px 28px 7px 9px;
}

.reader-body {
  max-width: 680px;
  margin: 0 auto;
  padding: 2px 0 26px;
  font-size: 15px;
  line-height: 1.68;
}

.reader-flow-navigation {
  display: grid;
  gap: 10px;
  max-width: 680px;
  margin: 0 auto 24px;
  padding: 12px 0 22px;
}

.reader-flow-navigation h3,
.reader-flow-navigation p {
  margin: 0;
}

.reader-flow-navigation h3 {
  font-family: "EB Garamond", "Noto Serif SC", serif;
  font-size: 17px;
}

.reader-flow-player,
.reader-flow-next {
  display: grid;
  gap: 8px;
}

.reader-flow-player > h3,
.reader-flow-next > h3 {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.reader-flow-actions {
  display: grid;
  gap: 8px;
}

.reader-flow-button {
  --flow-color: var(--seal);
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  grid-template-rows: auto auto;
  width: 100%;
  min-width: 0;
  height: auto;
  min-height: 46px;
  align-items: center;
  justify-content: stretch;
  gap: 1px 8px;
  overflow: hidden;
  border: 1px solid rgba(28, 28, 24, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 10px rgba(31, 28, 24, 0.06);
  color: var(--ink);
  padding: 8px 10px 8px 16px;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}

.reader-flow-button::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--flow-color);
  content: "";
}

.reader-flow-button:nth-child(3n + 2) {
  --flow-color: #2563eb;
}

.reader-flow-button:nth-child(3n + 3) {
  --flow-color: #079669;
}

.reader-flow-label {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.reader-flow-button small {
  grid-column: 1;
  grid-row: 2;
  color: inherit;
  font-size: 10.5px;
  line-height: 1.35;
  opacity: 0.76;
}

.reader-flow-arrow {
  grid-column: 2;
  grid-row: 1 / 3;
  width: 16px;
  height: 16px;
  color: var(--ink-soft);
}

.reader-flow-button:disabled .reader-flow-arrow {
  display: none;
}

.reader-flow-system {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.reader-flow-system .reader-flow-button {
  border-style: dashed;
  box-shadow: none;
}

.reader-flow-end,
.reader-flow-error,
.reader-flow-loading {
  color: var(--ink-soft);
  line-height: 1.7;
}

.reader-flow-error {
  color: var(--danger);
}

.story-reader p {
  margin-bottom: 22px;
}

.reader-body h2,
.reader-body h3 {
  font-family: "EB Garamond", "Noto Serif SC", serif;
  line-height: 1.25;
}

.reader-line {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  min-width: 0;
  padding: 7px 0;
}

.reader-speaker-tag {
  display: block;
  width: fit-content;
  max-width: 48px;
  min-height: 20px;
  overflow: hidden;
  border-radius: 4px;
  background: color-mix(in srgb, var(--speaker-color) 11%, transparent);
  color: var(--speaker-color);
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-line.long .reader-speaker-tag {
  padding-inline: 4px;
  font-size: 9.5px;
}

.reader-line.very-long .reader-speaker-tag {
  max-height: 32px;
  padding: 2px 3px;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  text-overflow: clip;
  white-space: normal;
}

.reader-line.unrecognized .reader-speaker-tag {
  outline: 1px dashed color-mix(in srgb, var(--speaker-color) 58%, transparent);
  outline-offset: -1px;
}

.reader-line p {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  line-height: 1.68;
  overflow-wrap: anywhere;
}

.reader-body > p {
  margin: 0 0 16px;
}

.editor-form,
.node-form {
  display: grid;
  gap: 12px;
}

.editor-form,
.editor-form > *,
.editor-section {
  min-width: 0;
}

.compact-field {
  max-width: 720px;
}

.full-textarea {
  min-height: calc(var(--app-height) - 250px);
  border: 1px solid var(--line);
  background: rgba(252, 249, 242, 0.78);
  padding: 14px;
  font-size: 17px;
}

.document-tools {
  align-items: end;
}

.document-tools .field {
  flex: 1 1 220px;
}

.quick-split {
  display: block;
  border: 1px solid var(--line);
  background: rgba(246, 243, 236, 0.72);
  padding: 0;
}

.quick-split > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  color: var(--ink-soft);
  font-size: 12px;
}

.quick-split > summary::before {
  content: "＋";
  margin-right: 5px;
  color: var(--seal);
}

.quick-split[open] > summary {
  border-bottom: 1px solid var(--line);
}

.quick-split-body {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.quick-split textarea {
  min-height: 92px;
}

.speaker-quick-panel {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  background: rgba(252, 249, 242, 0.86);
  padding: 6px 7px;
}

.speaker-quick-heading {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.speaker-quick-heading > div {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
}

.speaker-quick-heading span,
.speaker-quick-heading p {
  color: var(--ink-soft);
  font-size: 12px;
}

.speaker-quick-heading strong {
  color: var(--speaker-color, var(--ink));
  font-size: 15px;
}

.speaker-quick-heading p {
  margin: 3px 0 0;
  line-height: 1.45;
}

.speaker-quick-list {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  gap: 5px;
  overflow: hidden;
}

.speaker-chip,
.speaker-add-button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 4px 9px;
  border-color: color-mix(in srgb, var(--speaker-color, var(--line-strong)) 64%, var(--line));
  background: color-mix(in srgb, var(--speaker-color, var(--paper-bright)) 7%, var(--paper-bright));
  color: var(--speaker-color, var(--ink));
  white-space: nowrap;
  font-size: 12px;
}

.speaker-chip.active {
  outline: 2px solid var(--speaker-color, var(--ink));
  outline-offset: -3px;
  font-weight: 600;
}

.speaker-add-button {
  border-style: dashed;
  color: var(--seal);
}

.speaker-link-state {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: -2px 0 0;
  color: var(--speaker-color, var(--ink-soft));
  font-size: 11px;
}

.speaker-link-state::before {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: var(--speaker-color, transparent);
  content: "";
}

.speaker-link-state.unrecognized {
  color: var(--danger);
}

.speaker-picker-dialog {
  width: min(520px, calc(100vw - 20px));
}

.speaker-picker-dialog .dialog-body {
  max-height: min(820px, calc(var(--app-height) - 24px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.speaker-picker-dialog .dialog-body > header {
  align-items: flex-start;
}

.speaker-picker-dialog .dialog-body > header p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
}

.speaker-picker-section {
  display: grid;
  gap: 8px;
}

.speaker-picker-section h3 {
  margin: 0;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 500;
}

.speaker-picker-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.speaker-picker-section:first-of-type .speaker-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.speaker-picker-entry {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 46px;
  gap: 7px;
  padding: 6px 8px;
  border-color: var(--line);
  background: rgba(252, 249, 242, 0.8);
  color: var(--ink);
  text-align: left;
}

.speaker-picker-recent-entry {
  display: inline-flex;
  width: auto;
  min-height: 30px;
  gap: 5px;
  border-radius: 999px;
  padding: 3px 9px;
}

.speaker-picker-recent-entry .speaker-color-mark {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
}

.speaker-picker-recent-entry .speaker-entry-copy strong {
  font-size: 12px;
  font-weight: 500;
}

.speaker-picker-recent-entry .speaker-entry-copy small,
.speaker-picker-recent-entry .speaker-line-count {
  display: none;
}

.speaker-picker-entry:hover,
.speaker-picker-entry:focus-visible {
  border-color: var(--speaker-color, var(--ink));
}

.speaker-picker-entry .speaker-color-mark {
  width: 10px;
  height: 28px;
  background: var(--speaker-color, var(--ink-soft));
}

.speaker-picker-entry .speaker-entry-copy {
  min-width: 0;
}

.speaker-picker-entry strong,
.speaker-picker-entry small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.speaker-picker-entry small,
.speaker-picker-entry .speaker-line-count {
  color: var(--ink-soft);
  font-size: 11px;
}

.speaker-picker-empty {
  grid-column: 1 / -1;
  margin: 0;
  border: 1px dashed var(--line);
  padding: 12px;
  color: var(--ink-soft);
  text-align: center;
}

.new-character-details {
  border: 1px dashed var(--line-strong);
  padding: 10px 12px;
}

.new-character-details summary {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--seal);
  font-weight: 600;
}

.new-character-details form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding-top: 12px;
}

.new-character-details .form-submit-line {
  grid-column: 1 / -1;
}

.speaker-color[data-color="ma-red"] { --speaker-color: #a51f24; }
.speaker-color[data-color="narration"] { --speaker-color: #5d6263; }
.speaker-color[data-color="plum"] { --speaker-color: #7a3254; }
.speaker-color[data-color="jade"] { --speaker-color: #28634e; }
.speaker-color[data-color="ochre"] { --speaker-color: #8a5a13; }
.speaker-color[data-color="cobalt"] { --speaker-color: #2d5195; }
.speaker-color[data-color="sky"] { --speaker-color: #267087; }
.speaker-color[data-color="violet"] { --speaker-color: #6745a0; }
.speaker-color[data-color="pine"] { --speaker-color: #315f35; }
.speaker-color[data-color="indigo"] { --speaker-color: #3e4788; }
.speaker-color[data-color="clay"] { --speaker-color: #85513b; }
.speaker-color[data-color="teal"] { --speaker-color: #246b67; }
.speaker-color[data-color="amber"] { --speaker-color: #8b6113; }
.speaker-color[data-color="rose"] { --speaker-color: #945166; }
.speaker-color[data-color="magenta"] { --speaker-color: #8a357a; }
.speaker-color[data-color="bronze"] { --speaker-color: #756126; }
.speaker-color[data-color="slate"] { --speaker-color: #526477; }

.line-tools-help {
  border: 1px dashed var(--line-strong);
  background: rgba(246, 243, 236, 0.55);
  padding: 9px 11px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.line-tools-help summary {
  cursor: pointer;
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
}

.line-tools-help p {
  margin: 8px 0 0;
}

.line-row,
.choice-row,
.version-row {
  display: grid;
  gap: 6px;
  padding: 9px 10px;
}

.line-row {
  position: relative;
  margin-bottom: 14px;
}

.line-head,
.choice-title,
.dialog-body header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.line-head strong {
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.line-row textarea {
  min-height: 0;
  padding: 6px 3px;
  font-size: 15px;
  line-height: 1.5;
}

.line-head-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.line-speaker-pill {
  min-height: 27px;
  border: 1px solid color-mix(in srgb, var(--speaker-color, var(--line-strong)) 58%, var(--line));
  background: color-mix(in srgb, var(--speaker-color, var(--paper-bright)) 7%, var(--paper-bright));
  color: var(--speaker-color, var(--ink));
  padding: 2px 7px;
  font-size: 11px;
}

.line-speaker-pill.unrecognized {
  color: var(--danger);
}

.line-tools-menu {
  position: relative;
}

.line-tools-toggle {
  display: grid;
  width: 30px;
  min-height: 30px;
  cursor: pointer;
  list-style: none;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.line-tools-toggle .ui-icon {
  width: 17px;
  height: 17px;
}

.line-tools-menu:not([open]) .line-tools {
  display: none;
}

.line-tools-menu .line-tools {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(4, 34px);
  width: auto;
  max-width: none;
  overflow: visible;
  border: 1px solid var(--line-strong);
  background: var(--paper-bright);
  box-shadow: 0 8px 20px rgba(28, 28, 24, 0.16);
  padding: 5px;
}

.line-speaker-manual {
  color: var(--ink-soft);
}

.line-speaker-manual > summary {
  display: none;
}

.line-speaker-manual[open] {
  display: grid;
  gap: 5px;
}

.line-speaker-field {
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  padding-top: 3px;
}

.line-speaker-field input {
  min-height: 31px;
  padding: 4px;
  font-size: 13px;
}

.save-state {
  border: 1px solid currentColor;
  padding: 4px 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.line-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
  overflow-x: auto;
  padding: 1px;
}

.line-tool-button {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 4px;
  border-color: var(--line-strong);
  background: transparent;
  color: var(--ink);
}

.line-tool-button .ui-icon {
  width: 19px;
  height: 19px;
  flex-basis: 19px;
}

.line-tool-button:disabled {
  opacity: 0.3;
}

.line-kind-button {
  color: var(--seal);
}

.danger-tool {
  color: var(--danger);
}

.line-length-state {
  margin: -2px 0 0;
  padding: 4px 6px;
  border-left: 3px solid var(--jade);
  background: rgba(28, 111, 89, 0.05);
  color: var(--jade);
  font-family: "JetBrains Mono", monospace;
  font-size: 9.5px;
  line-height: 1.4;
}

.line-length-state.warning {
  border-left-color: #9a650c;
  background: rgba(154, 101, 12, 0.07);
  color: #7a500a;
}

.insert-line-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 32px;
  min-height: 28px;
  position: absolute;
  bottom: -16px;
  left: 50%;
  z-index: 2;
  margin: 0;
  padding: 3px;
  border: 1px dashed var(--line-strong);
  background: rgba(246, 243, 236, 0.45);
  color: var(--seal);
  font-size: 11px;
  transform: translateX(-50%);
}

.insert-line-button:hover,
.insert-line-button:focus-visible {
  border-style: solid;
  background: rgba(137, 45, 35, 0.06);
}

.insert-line-button .ui-icon {
  width: 16px;
  height: 16px;
  flex-basis: 16px;
}

.insert-line-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.line-length-state.danger {
  border-left-color: var(--danger);
  background: rgba(137, 45, 35, 0.07);
  color: var(--danger);
}

.line-row[data-length-state="danger"] {
  border-color: rgba(137, 45, 35, 0.55);
}

.draft-state {
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

.draft-state.saving {
  color: var(--seal);
}

.draft-state.synced {
  color: var(--jade);
}

.draft-state.failed {
  color: var(--danger);
}

.dirty {
  color: var(--danger);
}

.clean {
  color: var(--jade);
}

.node-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.node-directory-controls {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(252, 249, 242, 0.68);
}

.node-filter-grid,
.node-resource-grid,
.choice-protagonist-grid,
.branch-dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.node-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.node-badges span {
  border: 1px solid rgba(181, 36, 36, 0.42);
  background: rgba(181, 36, 36, 0.06);
  color: var(--seal);
  padding: 2px 5px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  line-height: 1.25;
}

.node-item.deleted,
.deleted-node {
  opacity: 0.72;
}

.node-deleted-banner,
.node-diagnostics {
  border-left: 3px solid var(--danger);
  background: rgba(186, 26, 26, 0.07);
  padding: 10px 12px;
}

.node-diagnostics strong {
  display: flex;
  align-items: center;
  gap: 6px;
}

.node-diagnostics ul {
  margin: 8px 0 0;
  padding-left: 22px;
}

.node-diagnostics .diagnostics-ok {
  color: var(--jade);
}

.node-resource-editor,
.choice-protagonist-grid > section,
.identity-fieldset {
  border: 1px dashed var(--line-strong);
  background: rgba(252, 249, 242, 0.52);
  padding: 12px;
}

.node-resource-editor > summary,
.identity-fieldset legend {
  cursor: pointer;
  font-weight: 600;
}

.node-resource-editor > p,
.dialog-note,
.version-operation {
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.node-resource-grid {
  margin-top: 12px;
}

.choice-protagonist-grid > section {
  display: grid;
  align-content: start;
  gap: 8px;
}

.choice-effect-title,
.delta-row,
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.choice-effect-title {
  justify-content: space-between;
}

.choice-effect-title button {
  min-height: 34px;
}

.delta-row {
  display: grid;
  grid-template-columns: minmax(74px, 0.7fr) minmax(80px, 1fr) 42px;
}

.checkbox-field {
  grid-template-columns: auto 1fr;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.identity-fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.identity-fieldset legend {
  padding: 0 5px;
}

.choice-warning {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--danger);
}

.danger-button {
  border-color: var(--danger);
  color: var(--danger);
}

button.danger-button:not(.secondary-button) {
  background: var(--danger);
  color: var(--paper-bright);
}

button:disabled,
input:disabled,
textarea:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.node-action-dialog,
.node-versions-dialog {
  width: min(820px, calc(100vw - 24px));
}

.delete-impact {
  border: 1px solid rgba(186, 26, 26, 0.35);
  padding: 10px 12px;
}

.node-versions-list {
  display: grid;
  gap: 10px;
  max-height: min(66vh, 720px);
  overflow: auto;
}

.node-version-row {
  border: 1px solid var(--line);
  padding: 10px;
}

.node-version-row summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  cursor: pointer;
}

.node-version-row pre {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--paper-low);
  padding: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.node-list {
  align-content: start;
  max-height: min(280px, calc(var(--app-height) * 0.34));
  overflow: auto;
}

.node-form textarea {
  min-height: 82px;
}

.choice-row {
  background: rgba(246, 243, 236, 0.78);
  border-left: 3px solid var(--seal);
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.flag-preview {
  display: grid;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.flag-preview b {
  display: inline-block;
  min-width: 86px;
  margin-right: 8px;
  color: var(--ink);
  font-weight: 500;
}

.flag-chip {
  display: inline-block;
  margin: 2px 5px 2px 0;
  vertical-align: top;
}

.flag-chip summary {
  cursor: pointer;
  list-style: none;
  border: 1px solid rgba(181, 36, 36, 0.38);
  color: var(--seal);
  background: rgba(181, 36, 36, 0.05);
  padding: 2px 7px;
  font-size: 12px;
}

.flag-chip code {
  display: block;
  margin-top: 3px;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.empty-inline {
  color: var(--ink-soft);
}

.raw-flag-editor {
  border: 1px dashed rgba(28, 28, 24, 0.24);
  padding: 10px;
  background: rgba(252, 249, 242, 0.52);
}

.raw-flag-editor summary {
  cursor: pointer;
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.raw-flag-editor[open] {
  display: grid;
  gap: 10px;
}

dialog {
  width: min(720px, calc(100vw - 24px));
  border: 1px solid var(--line-strong);
  border-radius: 0;
  padding: 0;
  background: var(--paper-bright);
  color: var(--ink);
}

.task-list {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.task-card {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line-strong);
  background: rgba(252, 249, 242, 0.78);
}

.task-card.archived {
  border-color: var(--line);
  background: rgba(238, 235, 227, 0.72);
}

.task-card.archived .task-node {
  border-left-color: var(--ink-soft);
}

.task-card > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  padding: 14px;
}

.task-card > summary::-webkit-details-marker {
  display: none;
}

.task-summary-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.task-summary-title strong {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.task-summary-title small,
.task-meta-line {
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.task-card-body {
  display: grid;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
}

.task-copy {
  margin: 14px 0 0;
  font-size: 16px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.task-section h3,
.task-node h3 {
  margin: 0 0 8px;
  font-family: "EB Garamond", "Noto Serif SC", serif;
  font-size: 21px;
}

.task-section ul {
  margin: 0;
  padding-left: 22px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.task-documents,
.task-node-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.task-document-button,
.task-action-button {
  min-width: 0;
  max-width: 100%;
  min-height: 36px;
  height: auto;
  padding: 7px 10px;
  white-space: normal;
  text-align: left;
  overflow-wrap: anywhere;
}

.task-document-button.missing,
.task-action-button:disabled {
  border-color: var(--line);
  color: var(--ink-soft);
  opacity: 0.68;
}

.task-nodes {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.task-node {
  display: grid;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  border-left: 3px solid var(--seal);
  background: rgba(246, 243, 236, 0.78);
  padding: 12px;
}

.task-node-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(124px, 160px);
  gap: 12px;
  align-items: start;
  min-width: 0;
}

.task-node-head > * {
  min-width: 0;
}

.task-node-head p,
.task-node-brief {
  margin: 0;
}

.task-status-select {
  min-width: 0;
  max-width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  padding: 6px 8px;
}

.task-node-brief {
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.task-status-tag {
  min-width: 64px;
}

.task-top-actions #archivedTasksButton.active {
  border-color: var(--seal);
  background: rgba(143, 47, 39, 0.08);
  color: var(--seal);
}

.task-archive-count {
  min-width: 24px;
  padding-inline: 6px;
  text-align: center;
}

.help-header {
  position: static;
  align-items: flex-start;
}

.help-header > div {
  max-width: 720px;
}

.help-header h2 {
  margin-top: 3px;
}

.help-header p:not(.eyebrow) {
  max-width: 640px;
  line-height: 1.7;
}

.eyebrow {
  margin: 0;
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.help-jump-links {
  position: sticky;
  top: 64px;
  z-index: 10;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 18px;
  padding: 10px 0;
  background: var(--paper);
}

.help-jump-links a {
  flex: 0 0 auto;
  border: 1px solid var(--seal);
  padding: 7px 10px;
  color: var(--seal);
  font-size: 13px;
  text-decoration: none;
}

.help-section {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
  border: 1px solid var(--line-strong);
  background: rgba(252, 249, 242, 0.78);
  padding: clamp(15px, 3vw, 24px);
  scroll-margin-top: 126px;
}

.help-section > h3,
.feedback-section h3 {
  margin: 0;
  font-family: "EB Garamond", "Noto Serif SC", serif;
  font-size: clamp(24px, 5vw, 32px);
}

.help-section-intro {
  display: grid;
  gap: 6px;
}

.help-section-intro h3,
.help-section-intro p {
  margin: 0;
}

.help-section-intro h3 {
  font-family: "EB Garamond", "Noto Serif SC", serif;
  font-size: clamp(24px, 5vw, 32px);
}

.help-section-intro p:last-child {
  line-height: 1.75;
}

.pov-rule-banner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid rgba(179, 38, 30, 0.36);
  background: rgba(179, 38, 30, 0.07);
  padding: 13px 14px;
}

.pov-rule-banner .ui-icon {
  color: var(--seal);
}

.pov-rule-banner p {
  margin: 0;
  line-height: 1.75;
}

.vn-rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.vn-rule-card {
  border: 1px solid var(--line);
  border-top-width: 4px;
  background: var(--paper-bright);
  padding: 14px;
}

.vn-rule-card.allowed {
  border-top-color: #39704b;
}

.vn-rule-card.forbidden {
  border-top-color: var(--seal);
}

.rule-label {
  display: flex;
  gap: 7px;
  align-items: center;
  margin: 0 0 9px;
  font-weight: 700;
}

.allowed .rule-label {
  color: #2f6d42;
}

.forbidden .rule-label {
  color: var(--seal);
}

.rule-label .ui-icon {
  width: 20px;
  height: 20px;
  flex-basis: 20px;
}

.vn-rule-card ul,
.review-checklist ul,
.help-source-notes ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 21px;
  line-height: 1.7;
}

.writing-examples {
  display: grid;
  gap: 9px;
}

.writing-example {
  border-left: 4px solid var(--line-strong);
  background: var(--paper-bright);
  padding: 11px 13px;
}

.writing-example.bad-example {
  border-left-color: var(--seal);
}

.writing-example.good-example {
  border-left-color: #39704b;
}

.example-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.writing-example blockquote {
  margin: 6px 0 0;
  font-family: "EB Garamond", "Noto Serif SC", serif;
  font-size: 17px;
  line-height: 1.75;
}

.vn-writing-guide,
.help-faq,
.review-checklist {
  display: grid;
  gap: 10px;
}

.vn-writing-guide h4,
.help-faq h4,
.review-checklist h4 {
  margin: 0;
  font-size: 18px;
}

.help-faq details,
.help-source-notes {
  border: 1px solid var(--line);
  background: var(--paper-bright);
  padding: 11px 13px;
}

.help-faq summary,
.help-source-notes summary {
  cursor: pointer;
  font-weight: 700;
  line-height: 1.55;
}

.help-faq details[open] summary,
.help-source-notes[open] summary {
  margin-bottom: 8px;
}

.help-faq p,
.help-source-notes p {
  margin: 0;
  line-height: 1.75;
}

.review-checklist {
  border: 1px dashed var(--line-strong);
  background: rgba(32, 26, 23, 0.035);
  padding: 14px;
}

.help-source-notes a {
  color: var(--seal);
}

.plain-steps,
.help-notes {
  display: grid;
  gap: 9px;
  margin: 0;
  padding-left: 23px;
  line-height: 1.75;
}

.help-figure {
  margin: 0;
  border: 1px solid var(--line);
  background: var(--paper-bright);
}

.help-figure img {
  display: block;
  width: 100%;
  height: auto;
}

.help-figure > a {
  display: block;
}

.help-figure figcaption {
  border-top: 1px solid var(--line);
  padding: 9px 12px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.help-callout {
  border-left: 4px solid var(--seal);
  background: rgba(179, 38, 30, 0.06);
  padding: 12px 14px;
  line-height: 1.75;
}

.help-table-wrap {
  overflow-x: auto;
}

.help-table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
  background: var(--paper-bright);
}

.help-table th,
.help-table td {
  border: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
}

.help-table thead th {
  background: rgba(32, 26, 23, 0.07);
}

.function-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.function-grid article {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  background: var(--paper-bright);
  padding: 13px;
}

.function-grid h4,
.function-grid p {
  margin: 5px 0 0;
}

.function-grid .ui-icon {
  color: var(--seal);
}

.help-module-grid article p {
  flex: 1;
  line-height: 1.65;
}

.help-route-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  margin-top: 12px;
  border: 1px solid var(--seal);
  border-radius: 6px;
  background: transparent;
  padding: 7px 11px;
  color: var(--seal);
  font-size: 13px;
  font-weight: 700;
}

.help-route-button:hover,
.help-route-button:focus-visible {
  background: rgba(179, 38, 30, 0.08);
}

.help-route-button .ui-icon {
  width: 18px;
  height: 18px;
}

.help-route-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.help-route-actions .help-route-button {
  margin-top: 0;
}

.help-route-table th:first-child,
.help-settings-table th:first-child {
  width: 22%;
}

.feedback-section {
  grid-template-columns: minmax(180px, 0.65fr) minmax(280px, 1fr);
  align-items: start;
}

.feedback-section > div > p {
  line-height: 1.75;
}

.feedback-form {
  display: grid;
  gap: 12px;
}

.feedback-form textarea,
.intake-dialog textarea {
  min-height: 150px;
}

.form-submit-line {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.form-state {
  color: var(--ink-soft);
  font-size: 13px;
}

.form-state.success {
  color: #2f6d42;
}

.form-state.error {
  color: var(--seal);
}

.intake-dialog {
  width: min(620px, calc(100vw - 24px));
}

.intake-dialog .dialog-body > header > div p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  line-height: 1.5;
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-body h2 {
  margin: 0;
}

.draft-recovery-dialog {
  width: min(1040px, calc(100vw - 28px));
  max-width: 1040px;
}

.draft-recovery-dialog .dialog-body > header p {
  margin: 4px 0 0;
  color: var(--ink-soft);
}

.draft-conflict-notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  background: rgba(137, 45, 35, 0.07);
  color: var(--danger);
}

.draft-compare-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.draft-compare-panel section {
  min-width: 0;
}

.draft-compare-panel h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.draft-compare-panel pre {
  max-height: 50vh;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(246, 243, 236, 0.72);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.draft-recovery-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mobile-save-button {
  display: none;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  padding: 4px 4px max(4px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(252, 249, 242, 0.94);
  backdrop-filter: blur(12px);
  pointer-events: auto;
}

.bottom-nav button {
  position: relative;
  display: grid;
  gap: 3px;
  min-width: 0;
  min-height: 54px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: var(--font-nav);
  pointer-events: auto;
  touch-action: manipulation;
}

.bottom-nav button.active {
  color: var(--seal);
}

.bottom-nav button.active::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--seal);
  transform: translateX(-50%);
}

.chat-screen {
  display: grid;
  place-items: center;
}

.chat-placeholder {
  display: grid;
  width: min(100%, 520px);
  gap: 10px;
  justify-items: center;
  border: 1px solid var(--line);
  background: rgba(252, 249, 242, 0.76);
  padding: 28px 20px;
  text-align: center;
}

.chat-placeholder-icon {
  width: 32px;
  height: 32px;
  color: var(--seal);
}

.chat-placeholder h2,
.chat-placeholder p {
  margin: 0;
}

.chat-placeholder h2 {
  font-size: var(--font-content-title);
}

.chat-placeholder > p:not(.eyebrow) {
  color: var(--ink-soft);
  font-size: var(--font-body);
  line-height: 1.75;
}

.chat-placeholder-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.chat-placeholder-actions button:disabled {
  opacity: 0.55;
}

/* P1-030 Chat is intentionally phone-proportioned, including on desktop. */
.app-shell[data-work-view="chat"] {
  --topbar-height: 0px;
}

.app-shell[data-work-view="chat"] > .topbar,
.app-shell[data-work-view="chat"] > .offline-banner {
  display: none !important;
}

.app-shell[data-work-view="chat"] .workspace {
  width: min(100%, 430px);
  min-height: calc(var(--app-height) - var(--bottom-nav-height) - env(safe-area-inset-bottom));
  border-inline: 1px solid rgba(28, 28, 24, 0.08);
  background: rgba(248, 245, 238, 0.78);
}

.app-shell[data-work-view="chat"] .bottom-nav {
  left: 50%;
  right: auto;
  width: min(100%, 430px);
  transform: translateX(-50%);
}

.chat-screen {
  display: block;
  min-height: calc(var(--app-height) - var(--bottom-nav-height) - env(safe-area-inset-bottom));
  padding: 0;
}

.chat-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: calc(var(--app-height) - var(--bottom-nav-height) - env(safe-area-inset-bottom));
  max-height: calc(var(--app-height) - var(--bottom-nav-height) - env(safe-area-inset-bottom));
  overflow: hidden;
  background: rgba(250, 247, 241, 0.92);
}

.chat-topbar {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  min-height: calc(58px + env(safe-area-inset-top));
  padding:
    env(safe-area-inset-top)
    max(10px, env(safe-area-inset-right))
    0
    max(10px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(28, 28, 24, 0.11);
  background: rgba(252, 249, 243, 0.96);
  backdrop-filter: blur(12px);
}

.chat-icon-button,
.chat-text-button {
  min-height: 40px;
  border: 1px solid rgba(28, 28, 24, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  padding: 0;
}

.chat-icon-button {
  width: 40px;
}

.chat-text-button {
  width: auto;
  padding-inline: 8px;
  color: var(--seal);
  font-size: 13px;
}

.chat-topbar-spacer {
  width: 40px;
}

.chat-topbar-copy {
  min-width: 0;
  padding-inline: 8px;
}

.chat-topbar-copy h2,
.chat-topbar-copy p {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-topbar-copy h2 {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.chat-topbar-copy p {
  margin-top: 1px;
  color: #8b8b87;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.chat-page-scroll,
.chat-settings-form,
.chat-history-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-page-scroll {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px 16px 22px;
}

.chat-welcome-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid rgba(28, 28, 24, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  padding: 16px;
  box-shadow: 0 4px 14px rgba(28, 28, 24, 0.035);
}

.chat-welcome-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: rgba(217, 37, 37, 0.09);
  color: var(--seal);
  font-size: 16px;
  font-weight: 600;
}

.chat-welcome-card h3,
.chat-welcome-card p {
  margin: 0;
}

.chat-eyebrow {
  color: var(--seal);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.chat-welcome-card h3 {
  margin-top: 3px;
  font-size: 17px;
}

.chat-welcome-card p:last-child {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.chat-context-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 32px;
  gap: 9px;
  align-items: center;
  border: 1px solid rgba(181, 36, 36, 0.2);
  border-radius: 12px;
  background: rgba(181, 36, 36, 0.045);
  padding: 10px 9px 10px 12px;
}

.chat-context-card > .ui-icon {
  color: var(--seal);
}

.chat-context-card div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chat-context-card div span,
.chat-context-card div strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-context-card div span {
  color: var(--ink-soft);
  font-size: 10px;
}

.chat-context-card div strong {
  font-size: 13px;
}

.chat-context-card button {
  width: 30px;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0;
}

.chat-home-actions {
  display: grid;
  gap: 10px;
}

.chat-home-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 18px;
  gap: 11px;
  align-items: center;
  min-height: 76px;
  border: 1px solid rgba(28, 28, 24, 0.11);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
}

.chat-home-card.primary {
  border-left: 3px solid var(--seal);
}

.chat-card-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  background: rgba(217, 37, 37, 0.075);
  color: var(--seal);
}

.chat-home-card > span:nth-child(2) {
  display: grid;
  gap: 3px;
}

.chat-home-card strong {
  font-size: 14px;
}

.chat-home-card small {
  color: #858782;
  font-size: 11px;
  line-height: 1.45;
}

.chat-chevron {
  color: #a7adb6;
  font-family: sans-serif;
  font-size: 25px;
  line-height: 1;
}

.chat-privacy-note {
  margin: 0;
  padding-inline: 8px;
  color: #888b86;
  font-size: 10px;
  line-height: 1.55;
  text-align: center;
}

.chat-status-banner {
  margin: 0;
  padding: 7px 12px;
  border-bottom: 1px solid rgba(186, 26, 26, 0.15);
  background: #fff0ee;
  color: var(--danger);
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}

.chat-status-banner button {
  min-height: 24px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0 4px;
  text-decoration: underline;
}

.chat-settings-form {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 13px 14px 88px;
}

.chat-settings-section {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(28, 28, 24, 0.1);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.72);
  padding: 14px;
}

.chat-settings-section h3 {
  margin: 0;
  font-size: 14px;
}

.chat-setting-field {
  gap: 5px;
}

.chat-setting-field > span {
  color: var(--ink-soft);
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.chat-setting-field input,
.chat-setting-field select,
.chat-setting-field textarea {
  border: 1px solid rgba(28, 28, 24, 0.13);
  border-radius: 8px;
  background: rgba(252, 250, 246, 0.95);
  padding: 9px 10px;
  font-size: 12px;
}

.chat-setting-field input,
.chat-setting-field select {
  min-height: 40px;
}

.chat-setting-field small,
.chat-toggle-row small {
  color: #8a8d88;
  font-size: 9px;
  line-height: 1.45;
}

.chat-setting-field.unsupported {
  opacity: 0.58;
}

.chat-settings-pair,
.chat-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.chat-key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.chat-clear-key {
  min-height: 40px;
  border-color: rgba(186, 26, 26, 0.22);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  padding-inline: 10px;
  font-size: 11px;
}

.chat-inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-inline-actions button {
  min-height: 36px;
  border-color: rgba(28, 28, 24, 0.14);
  border-radius: 8px;
  padding-inline: 11px;
  font-size: 11px;
}

.chat-inline-actions button:disabled {
  opacity: 0.45;
}

.chat-form-state {
  min-height: 16px;
  margin: -3px 0 0;
  color: #777a76;
  font-size: 10px;
}

.chat-model-state {
  margin: -3px 0 0;
  overflow-wrap: anywhere;
  color: #8a4f15;
  font-size: 10px;
  line-height: 1.45;
}

.chat-model-state.ready {
  color: #08724e;
}

.chat-home-card:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.chat-toggle-row {
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
}

.chat-toggle-row input {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.chat-toggle-row > span {
  display: grid;
  gap: 3px;
}

.chat-toggle-row strong {
  color: var(--ink);
  font-size: 12px;
}

.chat-settings-savebar {
  position: sticky;
  bottom: -76px;
  z-index: 3;
  margin: 0 -14px -88px;
  padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(28, 28, 24, 0.1);
  background: rgba(252, 249, 243, 0.96);
  backdrop-filter: blur(10px);
}

.chat-settings-savebar button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: #df2828;
  color: white;
  font-size: 13px;
}

.chat-message-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 22px;
  scroll-behavior: smooth;
}

.chat-message {
  display: grid;
  max-width: 88%;
  margin-bottom: 14px;
}

.chat-message.assistant {
  margin-right: auto;
  justify-items: start;
}

.chat-message.user {
  margin-left: auto;
  justify-items: end;
}

.chat-message-author {
  margin: 0 5px 4px;
  color: #969893;
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
}

.chat-bubble {
  min-width: 42px;
  border: 1px solid rgba(28, 28, 24, 0.11);
  border-radius: 4px 15px 15px 15px;
  background: rgba(255, 255, 255, 0.86);
  padding: 11px 12px;
  box-shadow: 0 2px 6px rgba(28, 28, 24, 0.025);
}

.chat-message.user .chat-bubble {
  border-color: transparent;
  border-radius: 15px 4px 15px 15px;
  background: #df2828;
  color: white;
}

.chat-markdown {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.72;
}

.chat-markdown p,
.chat-markdown h3,
.chat-markdown h4,
.chat-markdown h5,
.chat-markdown ol {
  margin: 0 0 7px;
}

.chat-markdown > :last-child {
  margin-bottom: 0;
}

.chat-markdown h3,
.chat-markdown h4,
.chat-markdown h5 {
  font-size: 13px;
}

.chat-markdown ol {
  padding-left: 20px;
}

.chat-markdown code {
  border-radius: 4px;
  background: rgba(28, 28, 24, 0.08);
  padding: 1px 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
}

.chat-markdown pre {
  max-width: 100%;
  overflow-x: auto;
  border-radius: 7px;
  background: #252521;
  color: #f7f3ea;
  padding: 9px;
}

.chat-markdown pre code {
  background: transparent;
  padding: 0;
  white-space: pre;
}

.chat-external-link {
  color: #245ca8;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-message.user .chat-external-link {
  color: white;
}

.chat-source-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.chat-source-card {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 12px;
  gap: 7px;
  align-items: center;
  width: 100%;
  min-height: 43px;
  border: 1px solid rgba(28, 28, 24, 0.11);
  border-radius: 8px;
  background: #faf7f0;
  color: var(--ink);
  padding: 7px 8px;
  text-align: left;
}

.chat-source-card > .ui-icon {
  width: 17px;
  height: 17px;
  color: var(--seal);
}

.chat-source-card > span:nth-child(2) {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.chat-source-card strong,
.chat-source-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-source-card strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
}

.chat-source-card small {
  color: #8a8d88;
  font-size: 8px;
}

.chat-generation-state,
.chat-message-state {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 7px;
  color: #858782;
  font-size: 9px;
}

.chat-generation-state i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--seal);
  animation: chat-pulse 1s infinite alternate;
}

.chat-generation-state i:nth-child(2) {
  animation-delay: 150ms;
}

.chat-generation-state i:nth-child(3) {
  animation-delay: 300ms;
}

.chat-message-state.error {
  color: var(--danger);
}

.chat-retry-button {
  min-height: 30px;
  margin-top: 7px;
  border: 1px solid rgba(181, 36, 36, 0.18);
  border-radius: 7px;
  background: transparent;
  color: var(--seal);
  padding-inline: 8px;
  font-size: 9px;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: end;
  padding:
    9px
    max(12px, env(safe-area-inset-right))
    max(9px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  border-top: 1px solid rgba(28, 28, 24, 0.1);
  background: rgba(252, 249, 243, 0.97);
}

.chat-composer label {
  min-width: 0;
}

.chat-composer textarea {
  min-height: 42px;
  max-height: 144px;
  border: 1px solid rgba(28, 28, 24, 0.13);
  border-radius: 21px;
  background: rgba(255, 255, 255, 0.82);
  padding: 10px 14px;
  resize: none;
  font-size: 12px;
  line-height: 1.55;
}

.chat-send-button {
  width: 42px;
  min-height: 42px;
  border: 0;
  border-radius: 50%;
  background: #df2828;
  color: white;
  padding: 0;
  box-shadow: 0 4px 10px rgba(223, 40, 40, 0.22);
}

.chat-send-button.stop > span {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: white;
}

.chat-send-button:disabled {
  opacity: 0.42;
}

.chat-empty-state,
.chat-loading-state {
  display: grid;
  justify-items: center;
  gap: 7px;
  padding: 44px 18px;
  color: #838681;
  text-align: center;
}

.chat-empty-state h3,
.chat-empty-state p {
  margin: 0;
}

.chat-empty-state h3 {
  color: var(--ink);
  font-size: 14px;
}

.chat-empty-state p,
.chat-loading-state {
  font-size: 11px;
  line-height: 1.6;
}

.chat-history-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  padding: 12px 14px 9px;
}

.chat-history-search {
  position: relative;
}

.chat-history-search .ui-icon {
  position: absolute;
  left: 11px;
  top: 11px;
  z-index: 1;
  width: 15px;
  height: 15px;
  color: #a0a39e;
}

.chat-history-search input,
.chat-history-controls select {
  min-height: 38px;
  border: 1px solid rgba(28, 28, 24, 0.12);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.78);
  font-size: 10px;
}

.chat-history-search input {
  padding-left: 34px;
}

.chat-history-list {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 8px 14px 20px;
}

.chat-history-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(28, 28, 24, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
}

.chat-history-card::before {
  content: "";
  position: absolute;
  inset-block: 0;
  left: 0;
  width: 3px;
  background: var(--session-accent);
}

.chat-history-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 14px;
  gap: 6px 8px;
  width: 100%;
  min-height: 96px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 12px 34px 12px 17px;
  text-align: left;
}

.chat-history-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
}

.chat-history-title i {
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: var(--session-accent);
}

.chat-history-title strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-count-badge {
  border-radius: 4px;
  background: rgba(37, 99, 235, 0.07);
  color: #3167b4;
  padding: 3px 6px;
  font-size: 8px;
}

.chat-history-open p,
.chat-history-open small {
  grid-column: 1 / 3;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-open p {
  color: #666a65;
  font-size: 11px;
}

.chat-history-open small {
  color: #a0a39e;
  font-size: 9px;
}

.chat-history-open > .chat-chevron {
  grid-column: 3;
  grid-row: 1 / 4;
  align-self: center;
}

.chat-history-delete {
  position: absolute;
  right: 3px;
  top: 3px;
  width: 28px;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: #a0a39e;
  padding: 0;
}

.chat-history-delete .ui-icon {
  width: 14px;
  height: 14px;
}

.chat-load-more {
  min-height: 38px;
  border-color: rgba(28, 28, 24, 0.13);
  border-radius: 9px;
  font-size: 11px;
}

@keyframes chat-pulse {
  to {
    opacity: 0.25;
    transform: translateY(-2px);
  }
}

html[data-keyboard="open"] .app-shell[data-work-view="chat"] {
  padding-bottom: env(safe-area-inset-bottom);
}

html[data-keyboard="open"] .app-shell[data-work-view="chat"] .chat-page {
  min-height: var(--app-height);
  max-height: var(--app-height);
}

@media (max-width: 350px) {
  .chat-settings-pair,
  .chat-settings-grid {
    grid-template-columns: 1fr;
  }

  .chat-history-controls {
    grid-template-columns: 1fr;
  }

  .chat-message {
    max-width: 92%;
  }
}

.app-shell[data-work-view="chat"] .chat-screen {
  padding: 0;
}

html[data-keyboard="open"] .bottom-nav {
  display: none;
}

html[data-keyboard="open"] .app-shell {
  padding-bottom: env(safe-area-inset-bottom);
}

html[data-keyboard="open"] .mobile-save-button:not(.hidden) {
  bottom: max(8px, env(safe-area-inset-bottom));
}

@keyframes view-in {
  from {
    opacity: 0.55;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .workspace {
    width: 100%;
  }

  .screen {
    padding: 16px;
  }

  .list-screen {
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .list-screen .directory-card {
    min-height: 78px;
    padding: 12px 12px 10px 16px;
  }

  .list-screen .directory-card .item-title {
    gap: 8px;
  }

  .directory-summary,
  .directory-location {
    display: none;
  }

  .directory-meta {
    margin-top: 0;
  }

  .screen-header {
    margin: 0 0 12px;
    padding: 0 0 10px;
  }

  .screen-header h2 {
    font-size: var(--font-content-title);
  }

  .reader-screen:not(.has-reader-previous) > .screen-header {
    display: none;
  }

  .reader-screen.has-reader-previous > .screen-header {
    max-width: 680px;
    align-items: center;
    justify-content: flex-end;
    margin: 0 auto 5px;
    padding: 0;
    border: 0;
  }

  .reader-screen > .screen-header > div:first-child,
  .reader-screen #readerEditButton {
    display: none;
  }

  .input-screen .screen-header,
  .node-screen .screen-header,
  .reader-screen .screen-header {
    align-items: flex-start;
  }

  .reader-header-actions {
    width: 100%;
    max-width: 100%;
  }

  .reader-previous-field,
  .reader-previous-field select {
    width: 100%;
  }

  .reader-body {
    padding-top: 0;
    font-size: 14px;
  }

  .reader-screen {
    padding-top: 4px;
  }

  .reader-line {
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 16px;
    min-height: 45px;
    padding: 6px 0;
  }

  .reader-speaker-tag {
    max-width: 48px;
  }

  .reader-flow-navigation {
    padding-top: 10px;
  }

  .reader-flow-player .reader-flow-button small,
  .reader-flow-next .reader-flow-button small {
    display: none;
  }

  .reader-flow-button {
    min-height: 44px;
    padding-block: 7px;
  }

  .line-head {
    align-items: flex-start;
  }

  .speaker-quick-list {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .speaker-quick-list::-webkit-scrollbar {
    display: none;
  }

  .speaker-add-button {
    width: 32px;
    min-width: 32px;
    padding: 4px;
  }

  .speaker-add-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .speaker-picker-dialog {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: none;
    margin: 0;
    border-radius: 18px 18px 0 0;
  }

  .speaker-picker-dialog .dialog-body {
    max-height: min(78dvh, calc(var(--app-height) - 16px));
    gap: 10px;
    padding: 14px 16px max(14px, env(safe-area-inset-bottom));
  }

  .speaker-picker-dialog .dialog-body > header {
    align-items: center;
  }

  .speaker-picker-dialog .dialog-body > header h2 {
    font-size: 18px;
  }

  .speaker-picker-dialog .dialog-body > header p {
    display: none;
  }

  .speaker-picker-dialog .search-row {
    min-height: 38px;
    margin-bottom: 2px;
  }

  .speaker-picker-list {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .speaker-picker-entry {
    min-height: 42px;
    padding-block: 4px;
  }

  .new-character-details form {
    grid-template-columns: 1fr;
  }

  .new-character-details .form-submit-line {
    grid-column: 1;
  }

  .line-tools {
    justify-content: flex-start;
    max-width: calc(100vw - 94px);
  }

  .editor-save-cluster {
    max-width: 56%;
  }

  .editor-save-cluster .compact-save-button {
    display: none;
  }

  .node-header-actions {
    max-width: 58%;
  }

  .node-header-actions .editor-save-cluster {
    max-width: 100%;
  }

  .draft-state {
    width: 100%;
    text-align: right;
  }

  .mobile-save-button:not(.hidden) {
    position: fixed;
    right: 14px;
    bottom: calc(var(--bottom-nav-height) + 10px + env(safe-area-inset-bottom));
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 46px;
    padding: 10px 15px;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(28, 28, 24, 0.2);
  }

  .draft-compare-panel {
    grid-template-columns: 1fr;
  }

  .node-layout {
    grid-template-columns: 1fr;
  }

  .task-node-head {
    grid-template-columns: 1fr;
  }

  .task-card > summary {
    grid-template-columns: minmax(0, 1fr);
  }

  .task-top-actions,
  .task-documents,
  .task-node-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .task-document-button,
  .task-action-button {
    width: 100%;
  }

  .feedback-section,
  .intake-summary-item {
    grid-template-columns: 1fr;
  }

  .vn-rule-grid {
    grid-template-columns: 1fr;
  }

  .help-header {
    display: grid;
  }

  .help-header button {
    width: 100%;
  }

  .node-list {
    max-height: 220px;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }

  .node-filter-grid,
  .node-resource-grid,
  .choice-protagonist-grid,
  .branch-dialog-grid,
  .node-version-row summary {
    grid-template-columns: 1fr;
  }

  .full-textarea {
    min-height: calc(var(--app-height) - 250px);
  }
}

@media (max-width: 380px) {
  .topbar-primary-action {
    padding: 0 7px;
  }

  .topbar-primary-action span:last-child {
    display: none;
  }

  .bottom-nav button {
    font-size: 11px;
  }

  .directory-search-actions {
    gap: 7px;
  }

  .directory-new-button {
    min-width: 76px;
    padding: 0 10px;
  }
}

/* P1-028 reference-sized VN editor and long-press card sorting. */
.speaker-color[data-color="ma-red"] { --speaker-color: #dc2626; }
.speaker-color[data-color="narration"] { --speaker-color: #6b7280; }

.app-shell[data-work-view="input"] {
  --topbar-height: 44px;
  --bottom-nav-height: 64px;
  background: #faf7f2;
}

.app-shell[data-work-view="input"] .topbar {
  gap: 8px;
  padding:
    env(safe-area-inset-top)
    max(16px, env(safe-area-inset-right))
    0
    max(16px, env(safe-area-inset-left));
  border-bottom-color: #eae6df;
  background: #fff;
  backdrop-filter: none;
}

.app-shell[data-work-view="input"] #homeButton {
  width: 28px;
  min-height: 28px;
  border: 0;
  padding: 0;
}

.app-shell[data-work-view="input"] #homeButton .ui-icon {
  width: 16px;
  height: 16px;
}

.app-shell[data-work-view="input"] .topbar-context h1 {
  font-size: 14px;
  font-weight: 600;
}

.app-shell[data-work-view="input"] .topbar-context p,
.app-shell[data-work-view="input"] .account-menu,
.app-shell[data-work-view="input"] .topbar-primary-action .ui-icon {
  display: none;
}

.app-shell[data-work-view="input"] .topbar-primary-action {
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  background: #dc2626;
  color: #fff;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
}

.input-screen {
  width: min(100%, 390px);
  max-width: 390px;
}

.app-shell[data-work-view="input"] .input-screen {
  min-height: calc(var(--app-height) - var(--topbar-height) - var(--bottom-nav-height) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 0 0 52px;
  background: #faf7f2;
}

.editor-form:has(#vnEditor:not(.hidden)) {
  gap: 0;
}

.editor-form:has(#vnEditor:not(.hidden)) > .compact-field,
.editor-form:has(#vnEditor:not(.hidden)) > .save-row,
#vnEditor:not(.hidden) > .quick-split,
#vnEditor:not(.hidden) > .line-tools-help {
  display: none;
}

#vnEditor:not(.hidden) {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.speaker-quick-panel {
  position: sticky;
  top: calc(44px + env(safe-area-inset-top));
  z-index: 24;
  width: 100%;
  height: 44px;
  flex: 0 0 44px;
  gap: 8px;
  border: 0;
  border-bottom: 1px solid #eae6df;
  background: #fff;
  padding: 8px 16px;
}

.speaker-quick-list {
  gap: 8px;
}

.speaker-chip,
.speaker-add-button {
  min-height: 28px;
  border: 1px solid #eae6df;
  border-radius: 100px;
  background: #fff;
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1;
}

.speaker-chip.active {
  border-color: #dc2626;
  outline: 0;
  background: rgba(220, 38, 38, 0.07);
  color: #dc2626;
  font-weight: 500;
}

.speaker-add-button {
  width: 28px;
  min-width: 28px;
  padding: 5px;
  border-style: solid;
  color: #6b7280;
}

.line-editor {
  display: grid;
  gap: 0;
  width: 100%;
  padding: 12px 16px 64px;
}

.line-row {
  gap: 5px;
  width: 100%;
  margin: 0 0 24px;
  border: 1px solid #eae6df;
  border-radius: 8px;
  background: #fff;
  padding: 9px 11px 8px 14px;
  box-shadow: 0 1px 2px rgba(28, 27, 31, 0.03);
}

.line-row::before {
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: -1px;
  width: 4px;
  border-radius: 8px 0 0 8px;
  background: var(--speaker-color, #6b7280);
  content: "";
}

.line-head {
  min-height: 22px;
  gap: 8px;
  touch-action: none;
  cursor: grab;
}

.line-head strong {
  color: #9ca3af;
  font-size: 11px;
  font-weight: 400;
}

.line-head-actions {
  gap: 4px;
}

.line-speaker-pill {
  min-height: 22px;
  border-color: color-mix(in srgb, var(--speaker-color, #6b7280) 52%, #eae6df);
  border-radius: 4px;
  background: color-mix(in srgb, var(--speaker-color, #fff) 7%, #fff);
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
}

.line-tools-toggle {
  width: 24px;
  min-height: 24px;
  border: 0;
}

.line-tools-toggle .ui-icon {
  width: 15px;
  height: 15px;
}

.line-tools-menu .line-tools {
  grid-template-columns: repeat(3, 34px);
}

.line-row textarea {
  min-height: 31px;
  border-bottom: 1px solid #eae6df;
  background: #fff;
  padding: 3px 0 6px;
  color: #1c1b1f;
  font-size: 14px;
  line-height: 1.5;
}

.line-length-state {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: #a3a1a8;
  padding: 0;
  font-size: 10px;
  line-height: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
  touch-action: none;
  cursor: grab;
}

.line-length-state.warning,
.line-length-state.danger {
  border: 0;
  background: transparent;
  color: #a3a1a8;
}

.line-row[data-length-state="danger"] {
  border-color: #eae6df;
}

.insert-line-button {
  bottom: -21px;
  width: 18px;
  min-height: 18px;
  border: 1px solid #e5e7eb;
  border-radius: 50%;
  background: #fff;
  padding: 2px;
  color: #9ca3af;
}

.insert-line-button .ui-icon {
  width: 12px;
  height: 12px;
  flex-basis: 12px;
}

.bottom-composer {
  position: fixed;
  right: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom));
  z-index: 999;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 28px;
  align-items: center;
  width: min(100vw, 390px);
  height: 52px;
  gap: 8px;
  border-top: 1px solid #eae6df;
  background: #fff;
  padding: 8px 12px;
  transform: translateX(50%);
}

.composer-speaker {
  min-height: 28px;
  max-width: 92px;
  overflow: hidden;
  border: 1px solid #dc2626;
  border-radius: 6px;
  background: rgba(220, 38, 38, 0.07);
  color: #dc2626;
  padding: 4px 8px;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-entry {
  min-width: 0;
  min-height: 36px;
  overflow: hidden;
  justify-content: flex-start;
  border: 0;
  border-radius: 7px;
  background: #f5f3ee;
  color: #a3a1a8;
  padding: 0 10px;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-send {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: #1c1b1f;
  color: #fff;
}

.composer-send .ui-icon {
  width: 15px;
  height: 15px;
}

.app-shell[data-work-view="input"] .mobile-save-button {
  display: none !important;
}

.line-row-armed {
  border-color: color-mix(in srgb, var(--speaker-color, #6b7280) 45%, #eae6df);
}

.line-row-dragging {
  pointer-events: none;
  cursor: grabbing;
  opacity: 0.96;
  box-shadow: 0 12px 30px rgba(28, 27, 31, 0.2);
  transform-origin: center;
}

.line-drag-active,
.line-drag-active * {
  user-select: none;
}

.line-drop-placeholder {
  position: relative;
  width: 100%;
  margin: 0 0 24px;
  border: 1px dashed #dc2626;
  border-radius: 8px;
  background: rgba(220, 38, 38, 0.045);
}

.line-drop-placeholder::after {
  position: absolute;
  top: 50%;
  right: 12px;
  left: 12px;
  height: 2px;
  border-radius: 100px;
  background: #dc2626;
  content: "";
  transform: translateY(-50%);
}

.line-row-settled {
  animation: line-row-settled 420ms ease-out;
}

@keyframes line-row-settled {
  from { box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.38); }
  to { box-shadow: 0 1px 2px rgba(28, 27, 31, 0.03); }
}

.bottom-nav {
  height: calc(64px + env(safe-area-inset-bottom));
  gap: 0;
  border-top-color: #eae6df;
  background: #fff;
  padding: 0 16px env(safe-area-inset-bottom);
  backdrop-filter: none;
}

.bottom-nav button {
  gap: 4px;
  min-height: 64px;
  color: #1c1b1f;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 500;
}

.bottom-nav button .ui-icon {
  width: 20px;
  height: 20px;
}

.bottom-nav button.active {
  color: #dc2626;
  font-weight: 600;
}

.speaker-picker-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

@media (max-width: 760px) {
  .app-shell[data-work-view="input"] .input-screen {
    width: 100vw;
    max-width: none;
  }

  .speaker-picker-dialog {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    height: min(520px, 100dvh);
    max-width: none;
    max-height: 520px;
    overflow: hidden;
    border: 0;
    border-radius: 16px 16px 0 0;
    background: #fff;
    padding: 16px 0 0;
  }

  .speaker-picker-dialog::before {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 40px;
    height: 4px;
    border-radius: 100px;
    background: #d1d5db;
    content: "";
    transform: translateX(-50%);
  }

  .speaker-picker-dialog .dialog-body {
    display: flex;
    height: 100%;
    max-height: none;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 16px max(8px, env(safe-area-inset-bottom));
  }

  .speaker-picker-dialog .dialog-body > header {
    min-height: 50px;
    flex: 0 0 50px;
    align-items: center;
    padding: 12px 0;
  }

  .speaker-picker-dialog .dialog-body > header h2 {
    color: #1c1b1f;
    font-size: 16px;
    font-weight: 600;
  }

  .speaker-picker-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .speaker-picker-new-button {
    min-height: 28px;
    border: 0;
    border-radius: 6px;
    background: rgba(220, 38, 38, 0.07);
    color: #dc2626;
    padding: 4px 8px;
    font-size: 13px;
  }

  .speaker-picker-dialog #closeSpeakerPickerButton {
    width: 28px;
    min-height: 28px;
    border: 0;
  }

  .speaker-picker-dialog #closeSpeakerPickerButton .ui-icon {
    width: 20px;
    height: 20px;
  }

  .speaker-picker-dialog .search-row {
    width: 100%;
    height: 36px;
    min-height: 36px;
    flex: 0 0 36px;
    margin: 0 0 12px;
    border: 0;
    border-radius: 8px;
    background: #f5f3ee;
    padding: 0 10px;
  }

  .speaker-picker-dialog .search-row input {
    height: 36px;
    border: 0;
    background: transparent;
    padding: 0 4px;
    font-size: 13px;
  }

  .speaker-picker-section {
    gap: 8px;
    margin-bottom: 20px;
  }

  .speaker-picker-section h3 {
    color: #6b7280;
    font-size: 12px;
    font-weight: 500;
  }

  .speaker-picker-section:first-of-type .speaker-picker-list {
    gap: 8px;
  }

  .speaker-picker-entry {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    background: #fff;
    padding: 6px 8px;
  }

  .speaker-picker-entry strong {
    font-size: 14px;
  }

  .speaker-picker-entry .speaker-color-mark {
    width: 8px;
    height: 8px;
    border-radius: 50%;
  }

  .speaker-picker-recent-entry {
    min-height: 28px;
    border: 1px solid #eae6df;
    border-radius: 100px;
    padding: 5px 10px;
  }

  html[data-keyboard="open"] .bottom-composer {
    bottom: env(safe-area-inset-bottom);
  }
}

/* P1-029 character list, profile, color picker, and appearance records. */
.app-shell[data-work-view="characters"],
.app-shell[data-work-view="character"],
.app-shell[data-work-view="appearances"] {
  --topbar-height: 44px;
  --bottom-nav-height: 64px;
  background: #faf7f2;
}

.app-shell[data-work-view="characters"] .topbar {
  display: none;
}

.app-shell[data-work-view="characters"] .workspace,
.app-shell[data-work-view="characters"] .character-list-screen {
  min-height: calc(var(--app-height) - var(--bottom-nav-height) - env(safe-area-inset-bottom));
}

.app-shell[data-work-view="character"] .topbar,
.app-shell[data-work-view="appearances"] .topbar {
  width: min(100%, 390px);
  margin-inline: auto;
  gap: 8px;
  border-bottom-color: #eae6df;
  background: #fff;
  padding:
    env(safe-area-inset-top)
    max(16px, env(safe-area-inset-right))
    0
    max(16px, env(safe-area-inset-left));
  backdrop-filter: none;
}

.app-shell[data-work-view="character"] #homeButton,
.app-shell[data-work-view="appearances"] #homeButton {
  width: 28px;
  min-height: 28px;
  border: 0;
  padding: 0;
}

.app-shell[data-work-view="character"] #homeButton .ui-icon,
.app-shell[data-work-view="appearances"] #homeButton .ui-icon {
  width: 16px;
  height: 16px;
}

.app-shell[data-work-view="character"] .topbar-context h1,
.app-shell[data-work-view="appearances"] .topbar-context h1 {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
}

.app-shell[data-work-view="character"] .topbar-context p {
  display: none;
}

.app-shell[data-work-view="appearances"] .topbar-context {
  text-align: center;
}

.app-shell[data-work-view="appearances"] .topbar-context p {
  display: block;
  color: #9ca3af;
  font-family: inherit;
  font-size: 10px;
}

.app-shell[data-work-view="character"] .account-menu,
.app-shell[data-work-view="appearances"] .account-menu {
  display: none;
}

.app-shell[data-work-view="character"] .topbar-primary-action {
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  background: #dc2626;
  color: #fff;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}

.app-shell[data-work-view="character"] .topbar-primary-action .ui-icon {
  display: none;
}

.character-list-screen,
.character-detail-screen,
.appearance-records-screen {
  width: min(100%, 390px);
  max-width: 390px;
  margin-inline: auto;
  color: #1c1b1f;
}

.character-list-screen {
  padding: max(12px, env(safe-area-inset-top)) 16px 20px;
}

.character-list-controls {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  gap: 12px;
  margin: calc(-1 * max(12px, env(safe-area-inset-top))) -16px 16px;
  background: #fff;
  padding:
    max(12px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    12px
    max(16px, env(safe-area-inset-left));
}

.character-list-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.character-role-filter {
  display: block;
  width: auto;
}

.character-role-filter select {
  width: auto;
  min-width: 68px;
  height: 30px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  padding: 0 24px 0 10px;
  color: #1c1b1f;
  font-size: 12px;
}

.character-documents-button {
  min-height: 30px;
  gap: 5px;
  border: 0;
  border-radius: 6px;
  background: #dc2626;
  color: #fff;
  padding: 0 10px;
  font-size: 12px;
}

.character-documents-button .ui-icon {
  width: 14px;
  height: 14px;
}

.character-search-row {
  display: flex;
  align-items: center;
  height: 38px;
  gap: 6px;
  border: 1px solid #e5e1da;
  border-radius: 8px;
  background: #faf7f2;
  padding: 0 10px;
}

.character-search-row .ui-icon {
  width: 15px;
  height: 15px;
  color: #9ca3af;
}

.character-search-row input {
  height: 36px;
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 12px;
}

.character-create-link {
  justify-self: end;
  min-height: 20px;
  border: 0;
  background: transparent;
  color: #dc2626;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
}

.character-list-state {
  min-height: 18px;
  margin: -8px 0 8px;
  color: #9ca3af;
  font-size: 10px;
}

.character-card-list {
  display: grid;
  gap: 12px;
}

.character-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 116px;
  gap: 7px;
  overflow: hidden;
  border: 1px solid #e5e1da;
  border-radius: 10px;
  background: #fff;
  color: #1f2937;
  padding: 13px 14px 11px 19px;
  text-align: left;
}

.character-card-color {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--character-color);
}

.character-card-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.character-card-heading strong {
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-role-tag {
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--character-color) 38%, #f5dada);
  border-radius: 4px;
  background: color-mix(in srgb, var(--character-color) 7%, #fff);
  color: var(--character-color);
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 600;
}

.character-card-summary {
  display: -webkit-box;
  overflow: hidden;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.character-card-updated {
  align-self: end;
  color: #9ca3af;
  font-size: 9px;
}

.character-detail-screen,
.appearance-records-screen {
  padding: 16px;
}

#characterDetailForm,
#characterDetailBody {
  display: grid;
  gap: 14px;
}

.character-detail-card {
  border: 1px solid #e5e1da;
  border-radius: 10px;
  background: #fff;
  padding: 14px;
}

.character-detail-card h2,
.character-section-title {
  margin: 0;
  color: #1f2937;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
}

.character-basic-card {
  display: grid;
  gap: 12px;
}

.character-basic-grid {
  display: grid;
  gap: 9px;
}

.character-basic-grid label {
  grid-template-columns: 62px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.character-basic-grid label > span,
.character-basic-grid .character-color-button > span:nth-child(2) {
  color: #9ca3af;
  font-family: inherit;
  font-size: 11px;
}

.character-basic-grid input,
.character-basic-grid select {
  min-width: 0;
  height: 30px;
  border: 0;
  background: transparent;
  padding: 2px 0;
  font-size: 12px;
}

.character-color-button {
  display: grid;
  grid-template-columns: 16px 54px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 30px;
  gap: 8px;
  border: 0;
  background: transparent;
  color: #9ca3af;
  padding: 0;
  text-align: left;
}

.character-color-button:disabled {
  opacity: 1;
}

.character-color-button strong {
  color: #9ca3af;
  font-size: 11px;
  font-weight: 400;
}

.character-color-dot,
.relationship-color {
  display: block;
  border-radius: 50%;
  background: var(--character-color);
}

.character-color-dot {
  width: 16px;
  height: 16px;
}

.character-text-card label {
  gap: 10px;
}

.character-text-card textarea,
.character-hidden-card textarea {
  min-height: 56px;
  overflow: hidden;
  border: 0;
  background: transparent;
  padding: 0;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.75;
  resize: none;
}

.character-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.character-section-heading button,
.relationship-actions button,
.character-beat-row button {
  min-height: 24px;
  border: 0;
  background: transparent;
  color: #dc2626;
  padding: 0 4px;
  font-size: 10px;
}

#characterRelationshipList,
#characterBeatList {
  display: grid;
}

.character-relationship-row {
  display: grid;
  grid-template-columns: 8px 84px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid #eee9e1;
}

.character-relationship-row:last-child {
  border-bottom: 0;
}

.relationship-color {
  width: 7px;
  height: 7px;
  margin-top: 11px;
}

.character-relationship-row select,
.character-relationship-row textarea {
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 4px 0;
  color: #4b5563;
  font-size: 11px;
  line-height: 1.5;
}

.character-relationship-row textarea {
  resize: none;
}

.relationship-actions {
  grid-column: 2 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.character-empty-inline,
.character-helper {
  margin: 0;
  color: #9ca3af;
  font-size: 10px;
  line-height: 1.6;
}

.character-helper {
  margin: -5px 0 8px;
}

.character-appearance-heading {
  width: 100%;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: #1f2937;
  padding: 0;
  text-align: left;
}

.character-appearance-heading > span:first-child {
  display: grid;
  gap: 2px;
}

.character-appearance-heading strong {
  font-size: 14px;
}

.character-appearance-heading small {
  color: #9ca3af;
  font-size: 9px;
  font-weight: 400;
}

.character-appearance-heading .ui-icon {
  width: 17px;
  height: 17px;
  color: #9ca3af;
}

.character-appearance-preview {
  display: grid;
}

.character-appearance-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto 12px;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 32px;
  border: 0;
  border-bottom: 1px solid #eee9e1;
  background: transparent;
  color: #4b5563;
  padding: 5px 0;
  text-align: left;
}

.character-appearance-row:last-child {
  border-bottom: 0;
}

.character-appearance-row > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

.character-appearance-row small {
  color: #9ca3af;
  font-size: 9px;
}

.character-appearance-row .ui-icon {
  width: 12px;
  height: 12px;
}

.character-hidden-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  color: #1f2937;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.character-hidden-card summary::-webkit-details-marker {
  display: none;
}

.character-hidden-card summary span {
  color: #9ca3af;
  font-size: 9px;
  font-weight: 400;
}

.character-hidden-card[open] summary {
  margin-bottom: 12px;
}

.character-beat-row {
  display: grid;
  grid-template-columns: minmax(76px, 0.8fr) 72px minmax(90px, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid #eee9e1;
}

.character-beat-row input,
.character-beat-row select {
  min-width: 0;
  height: 30px;
  border: 1px solid #eee9e1;
  border-radius: 5px;
  background: #faf7f2;
  padding: 4px 6px;
  font-size: 10px;
}

.character-detail-state {
  position: sticky;
  bottom: calc(64px + env(safe-area-inset-bottom));
  z-index: 12;
  margin: 0;
  border: 1px solid #e5e1da;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #6b7280;
  padding: 8px 10px;
  font-size: 10px;
  text-align: center;
}

.character-detail-state[data-state="dirty"],
.character-detail-state[data-state="error"] {
  color: #dc2626;
}

.appearance-record-stats {
  margin: 0 0 10px;
  color: #9ca3af;
  font-size: 11px;
}

.appearance-record-list {
  display: grid;
  overflow: hidden;
  border: 1px solid #e5e1da;
  border-radius: 10px;
  background: #fff;
  padding: 6px 14px;
}

.appearance-record-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto 12px;
  align-items: center;
  min-width: 0;
  gap: 8px;
  border: 0;
  border-bottom: 1px solid #eee9e1;
  background: transparent;
  color: #1f2937;
  padding: 13px 0;
  text-align: left;
}

.appearance-record-item:last-child {
  border-bottom: 0;
}

.appearance-file-icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid #eee9e1;
  border-radius: 6px;
  background: #faf7f2;
  color: #dc2626;
}

.appearance-file-icon .ui-icon,
.appearance-record-item > .ui-icon {
  width: 13px;
  height: 13px;
}

.appearance-file-copy {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.appearance-file-copy strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appearance-file-copy small {
  display: -webkit-box;
  overflow: hidden;
  color: #6b7280;
  font-size: 10px;
  font-weight: 400;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.appearance-dialogue-count {
  color: #9ca3af;
  font-size: 9px;
  white-space: nowrap;
}

.character-page-loading,
.character-page-error,
.character-page-empty {
  margin: 0;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.7;
}

.character-page-error {
  color: #dc2626;
}

.character-color-dialog {
  width: min(calc(100% - 32px), 342px);
  max-width: 342px;
  max-height: min(620px, calc(var(--app-height) - 24px));
  overflow: auto;
  border: 0;
  border-radius: 18px;
  background: #faf7f2;
  padding: 0;
  box-shadow: 0 18px 46px rgba(28, 27, 31, 0.28);
}

.character-color-dialog::backdrop,
.character-create-dialog::backdrop {
  background: rgba(0, 0, 0, 0.48);
}

.character-color-dialog-body {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.character-color-dialog-body > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.character-color-dialog-body h2 {
  margin: 0;
  font-size: 17px;
}

.character-color-close {
  display: grid;
  width: 30px;
  min-height: 30px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #f1eee8;
  color: #4b5563;
  padding: 0;
}

.character-color-close .ui-icon {
  width: 15px;
  height: 15px;
}

.character-color-preview {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid #e5e1da;
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
}

.character-color-preview-dot {
  width: 38px;
  height: 38px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--character-color);
  box-shadow: 0 1px 4px rgba(28, 27, 31, 0.2);
}

.character-color-preview > span:last-child {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 3px 8px;
}

.character-color-preview strong {
  font-size: 13px;
}

.character-color-preview small {
  justify-self: start;
  border-radius: 3px;
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
  padding: 2px 4px;
  font-size: 8px;
}

.character-color-preview code {
  grid-column: 1 / -1;
  color: #9ca3af;
  font-size: 11px;
}

.character-color-section {
  display: grid;
  gap: 10px;
}

.character-color-section h3 {
  margin: 0;
  color: #6b7280;
  font-size: 11px;
}

.character-preset-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 13px 11px;
}

.character-preset-color {
  position: relative;
  width: 27px;
  min-height: 27px;
  justify-self: center;
  border: 0;
  border-radius: 50%;
  background: var(--character-color);
  padding: 0;
}

.character-preset-color.selected::after {
  position: absolute;
  inset: -4px;
  border: 2px solid #dc2626;
  border-radius: 50%;
  content: "";
}

.character-custom-color-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 18px;
  align-items: center;
  height: 42px;
  gap: 10px;
  border: 1px solid #e5e1da;
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
}

.character-custom-color-dot {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--character-color);
}

.character-custom-color-row input {
  height: 40px;
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
}

.character-custom-color-row > button {
  display: grid;
  width: 24px;
  min-height: 24px;
  place-items: center;
  border: 0;
  background: transparent;
  padding: 0;
}

.character-custom-color-row .ui-icon {
  width: 16px;
  height: 16px;
  color: #9a9288;
}

.character-color-state {
  min-height: 15px;
  margin: 0;
  color: #9a6a12;
  font-size: 9px;
  line-height: 1.5;
}

.character-color-confirm {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 24px;
  background: #dc2626;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.23);
}

.character-color-confirm:disabled {
  box-shadow: none;
  opacity: 0.42;
}

.character-create-dialog {
  width: min(calc(100% - 32px), 390px);
  border: 0;
  border-radius: 14px;
  padding: 0;
}

.reader-speaker-tag[data-character-id] {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.reader-line.reader-line-target {
  border-radius: 6px;
  background: rgba(220, 38, 38, 0.07);
  outline: 2px solid rgba(220, 38, 38, 0.16);
}

@media (max-width: 350px) {
  .character-preset-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .character-beat-row {
    grid-template-columns: minmax(72px, 1fr) 68px;
  }

  .character-beat-row [data-beat-value] {
    grid-column: 1 / -1;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .character-color-dialog {
    max-height: calc(var(--app-height) - 12px);
  }

  .character-color-dialog-body {
    gap: 12px;
    padding: 16px 20px max(16px, env(safe-area-inset-bottom));
  }
}

/* P1-031 creation task workflow */
.creation-task-list-page,
.creation-task-detail-page,
.creation-task-node-page,
.tracking-screen {
  width: min(100%, 760px);
  margin-inline: auto;
  padding: 10px 12px 92px;
}

.creation-task-list-controls {
  position: sticky;
  z-index: 4;
  top: var(--topbar-height, 54px);
  padding: 4px 0 8px;
  background: var(--paper, #f6f3ed);
}

.task-search-row {
  min-height: 38px;
  margin: 0 0 7px;
  border-radius: 10px;
  background: #f0f0f2;
  border-color: transparent;
}

.task-filter-tabs {
  display: flex;
  gap: 6px;
  margin: 0;
  overflow: visible;
}

.task-filter-tabs button {
  min-height: 28px;
  padding: 3px 13px;
  border: 0;
  border-radius: 999px;
  color: #6b7280;
  background: #ececee;
  font-size: 12px;
}

.task-filter-tabs button.active {
  color: #fff;
  background: #a91d22;
}

.task-list-utility-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 31px;
  margin-top: 6px;
}

.task-list-utility-row .compact-button {
  min-height: 28px;
  padding: 3px 8px;
  font-size: 11px;
}

.task-list-state {
  margin-left: auto;
  color: #7b7f86;
  font-size: 11px;
}

.tracking-intro {
  margin: 1px 0 9px;
  padding: 9px 11px;
  border: 1px solid #dddfe3;
  border-radius: 10px;
  color: #666a72;
  background: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  line-height: 1.5;
}

.tracking-intro strong {
  color: #991c21;
  font-weight: 600;
}

.tracking-list {
  display: grid;
  gap: 7px;
}

.tracking-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto 10px;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 9px 10px;
  border: 1px solid #dddfe3;
  border-radius: 11px;
  color: #292a2e;
  background: rgba(255, 255, 255, 0.92);
  text-align: left;
  box-shadow: none;
}

.tracking-card:hover,
.tracking-card:focus-visible {
  border-color: #b8bbc1;
  background: #fff;
}

.tracking-action {
  align-self: start;
  padding: 3px 0;
  border-radius: 999px;
  color: #fff;
  background: #787c84;
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
}

.tracking-action.action-created {
  background: #47705b;
}

.tracking-action.action-updated {
  background: #9b4b30;
}

.tracking-action.action-ai {
  background: #69439a;
}

.ai-origin-tag,
.ai-origin-inline {
  color: #5d3888;
  background: #eee4fb;
}

.ai-origin-inline {
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10px;
}

.tracking-card-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.tracking-card-copy strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tracking-card-copy small,
.tracking-card-copy span {
  overflow: hidden;
  color: #777b82;
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tracking-card time {
  align-self: end;
  color: #777b82;
  font-size: 10px;
  white-space: nowrap;
}

.tracking-card > b {
  color: #777b82;
  font-size: 20px;
  font-weight: 400;
}

.tracking-message {
  padding: 26px 14px;
  color: #74777e;
  font-size: 13px;
  text-align: center;
}

.tracking-message.error {
  color: #9b252a;
}

.tracking-message .secondary-button {
  display: block;
  margin: 10px auto 0;
}

.tracking-load-more {
  display: block;
  min-width: 120px;
  margin: 10px auto 0;
}

.task-list {
  display: grid;
  gap: 7px;
}

.creation-task-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  gap: 2px 8px;
  min-height: 72px;
  padding: 10px 12px 8px;
  border: 1px solid #dddfe3;
  border-radius: 11px;
  color: #242429;
  background: rgba(255, 255, 255, 0.92);
  text-align: left;
  box-shadow: none;
}

.creation-task-card:hover,
.creation-task-card:focus-visible {
  border-color: #b8bbc1;
  background: #fff;
}

.creation-task-card-title {
  display: -webkit-box;
  overflow: hidden;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.creation-task-card-arrow {
  color: #686b71;
  font-size: 22px;
  line-height: 18px;
  text-align: right;
}

.creation-task-card-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: #767b82;
  font-size: 10.5px;
}

.task-signal-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.creation-task-card > .task-signal-row {
  grid-column: 1 / -1;
}

.task-signal {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 17px;
  padding: 1px 5px;
  border-radius: 4px;
  color: #656970;
  background: #eceef1;
  font-size: 9.5px;
  line-height: 1.2;
}

.task-signal.signal-ai {
  color: #5d3888;
  background: #eee4fb;
}

.task-signal.signal-changed {
  color: #9b3e18;
  background: #ffe5d5;
}

.creation-task-assignee {
  overflow: hidden;
  margin-left: auto;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.creation-task-status {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 20px;
  padding: 1px 7px;
  border-radius: 4px;
  color: #8a4d00;
  background: #fff0b9;
  font-size: 10.5px;
}

.creation-task-status.status-review {
  color: #a10f21;
  background: #ffe0e3;
}

.creation-task-status.status-done {
  color: #08724e;
  background: #c9f4df;
}

.creation-task-progress {
  grid-column: 1 / -1;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6e7ea;
}

.creation-task-progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #b51f27;
  transition: width 160ms ease;
}

.creation-task-progress > span.complete {
  background: #24b87a;
}

.task-list-message {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 42px 16px;
  color: #73777e;
  text-align: center;
}

.task-list-message.error {
  color: #9e1d25;
}

.task-load-more {
  width: 100%;
  margin-top: 10px;
}

.task-overview-card,
.task-detail-card,
.task-node-overview-card {
  padding: 14px;
  border: 1px solid #dedfe2;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
}

.task-detail-content,
.task-node-detail-content {
  display: grid;
  gap: 12px;
}

.task-overview-title,
.task-section-heading,
.task-editor-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.task-overview-title h2,
.task-detail-card h3,
.task-section-heading h3,
.task-editor-section h3 {
  margin: 0;
  font-size: 14px;
}

.task-overview-title h2 {
  font-size: 16px;
}

.task-overview-meta,
.task-node-overview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  margin: 8px 0 10px;
  color: #767b82;
  font-size: 11px;
}

.task-detail-card > p,
.task-node-overview-card > p {
  margin: 9px 0 0;
  color: #34363a;
  font-size: 12px;
  line-height: 1.7;
}

.task-progress-message:empty {
  display: none;
}

.task-progress-message.error {
  color: #9e1d25;
}

.creation-task-node-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: stretch;
  min-height: 44px;
  border-bottom: 1px solid #ececef;
}

.creation-task-node-row:last-child {
  border-bottom: 0;
}

.creation-task-node-row.missing {
  opacity: 0.58;
}

.creation-task-node-check {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 4px 5px 0;
  color: #50545b;
  font-size: 10.5px;
}

.creation-task-node-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #a91d22;
}

.creation-task-node-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 5px 0 5px 6px;
  border: 0;
  color: #2d3035;
  background: transparent;
  text-align: left;
  box-shadow: none;
}

.creation-task-node-open span {
  display: grid;
  min-width: 0;
}

.creation-task-node-open strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.creation-task-node-open small {
  color: #8a8e94;
  font-size: 9.5px;
}

.creation-task-node-open small.task-signal-row {
  margin-top: 3px;
}

.task-related-links summary {
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.task-related-links > div {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.creation-task-link {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 2px 7px;
  padding: 8px 9px;
  border: 1px solid #e3e4e7;
  border-radius: 8px;
  color: #303238;
  background: #fafafa;
  text-align: left;
  box-shadow: none;
}

.creation-task-link span,
.creation-task-link small {
  color: #7a7e85;
  font-size: 10px;
}

.creation-task-link small {
  grid-column: 2;
}

.task-node-overview-card {
  border-left: 3px solid #bd252c;
}

.creation-task-node-status {
  padding: 1px 7px;
  border-radius: 4px;
  color: #8a4d00;
  background: #fff0b9;
}

.task-node-task-link {
  min-height: 26px;
  padding: 2px 5px;
  border: 0;
  color: #666b72;
  background: transparent;
  box-shadow: none;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.task-node-condition-summary {
  color: #7b7f86 !important;
  font-size: 10.5px !important;
}

.task-dialogue-list {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.task-dialogue-row {
  padding: 8px 10px;
  border-radius: 8px;
  background: #f7f7f9;
}

.task-dialogue-head {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #73777e;
  font-size: 10px;
}

.task-dialogue-head strong {
  padding: 2px 7px;
  border-radius: 4px;
  color: #a51620;
  background: #ffe2e4;
  font-size: 10px;
}

.task-dialogue-head button {
  width: 28px;
  min-height: 28px;
  margin-left: auto;
  padding: 0;
  border: 0;
  color: #5e6269;
  background: transparent;
  box-shadow: none;
  font-size: 18px;
}

.task-dialogue-row p {
  margin: 5px 0 0;
  font-size: 12px;
  line-height: 1.55;
}

.task-lines-more {
  width: 100%;
  margin-top: 9px;
}

.task-section-heading > button {
  min-height: 28px;
  padding: 3px 8px;
  border: 0;
  color: #a71921;
  background: transparent;
  box-shadow: none;
  font-size: 11px;
}

.task-connection-group {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 5px 8px;
  margin-top: 10px;
}

.task-connection-group h4 {
  grid-row: 1 / span 20;
  margin: 7px 0 0;
  color: #686c73;
  font-size: 11px;
}

.task-connection-group button {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid #e1e2e5;
  border-radius: 7px;
  color: #36383d;
  background: #f7f7f8;
  text-align: left;
  box-shadow: none;
}

.task-connection-group button small,
.task-connection-group p {
  color: #7b7f86;
  font-size: 10px;
}

.task-node-bottom-actions {
  position: fixed;
  z-index: 15;
  right: 0;
  bottom: calc(var(--bottom-nav-height, 58px) + env(safe-area-inset-bottom));
  left: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid #dedfe2;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.task-node-bottom-actions button {
  min-height: 36px;
  padding: 6px 13px;
  font-size: 11px;
}

.task-node-bottom-actions .completed {
  color: #08724e;
  background: #d4f7e6;
}

.accent-outline {
  border-color: #b51f27 !important;
  color: #a71921 !important;
}

.task-editor-dialog,
.task-line-dialog {
  width: min(calc(100% - 24px), 600px);
  max-height: calc(var(--app-height, 100dvh) - 24px);
  overflow: auto;
  border: 0;
  border-radius: 14px;
  padding: 0;
}

.task-editor-two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.task-editor-section {
  display: grid;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid #e5e1da;
}

.task-editor-section-head input {
  width: min(52%, 240px);
  min-height: 34px;
}

.task-editor-node-catalog {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  max-height: 170px;
  overflow: auto;
}

.task-editor-node-catalog button,
.task-editor-selected-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #e0ddd7;
  border-radius: 7px;
  color: #34363a;
  background: #faf9f6;
  text-align: left;
  box-shadow: none;
}

.task-editor-node-catalog button > span,
.task-editor-selected-node > span {
  display: grid;
  min-width: 0;
}

.task-editor-node-catalog small,
.task-editor-selected-node small {
  overflow: hidden;
  color: #7d8187;
  font-size: 9px;
  text-overflow: ellipsis;
}

.task-editor-selected-nodes,
.task-editor-links {
  display: grid;
  gap: 5px;
}

.task-editor-selected-node > div {
  display: flex;
  gap: 3px;
}

.task-editor-selected-node button,
.task-editor-link-row button {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid #dad7d1;
  color: #5e6269;
  background: #fff;
  box-shadow: none;
}

.task-editor-link-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.task-editor-link-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid #e0ddd7;
  border-radius: 7px;
  font-size: 11px;
}

.task-line-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

@media (max-width: 430px) {
  .creation-task-list-page,
  .creation-task-detail-page,
  .creation-task-node-page,
  .tracking-screen {
    padding-inline: 10px;
  }

  .task-editor-node-catalog {
    grid-template-columns: 1fr;
  }

  .task-editor-dialog {
    width: 100%;
    max-height: calc(var(--app-height, 100dvh) - 8px);
    margin-block: 4px;
    border-radius: 12px;
  }
}

@media (max-width: 350px) {
  .task-list-state {
    display: none;
  }

  .task-list-utility-row .compact-button .ui-icon {
    display: none;
  }

  .tracking-card {
    grid-template-columns: 32px minmax(0, 1fr) 10px;
  }

  .tracking-card time {
    display: none;
  }

  .creation-task-node-row {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .task-node-bottom-actions {
    gap: 5px;
    padding-inline: 6px;
  }

  .task-node-bottom-actions button {
    padding-inline: 8px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .creation-task-list-controls {
    position: static;
  }

  .task-editor-dialog,
  .task-line-dialog {
    max-height: calc(var(--app-height, 100dvh) - 8px);
  }
}
