*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Almanac Garden OS: cream desk, manila, sage, terracotta, dusty blue */
  --bg: #E4D8C4;
  --sidebar-bg: #D8C7A8;
  --surface: #F4EBD6;
  --border: #A48F72;
  --border-light: #C4B29A;
  --text: #1E1A12;
  --text-muted: #5A4F42;
  --text-faint: #8A7A68;
  --accent: #2F5C48;
  --accent-light: #C2D8C6;
  --accent-hover: #1E3D30;
  --garden-terracotta: #B85C3C;
  --garden-sage: #4A6B56;
  --garden-sky: #4A6F82;
  --garden-coral: #C87868;
  --tag-bg: #DED0B8;
  --danger: #A03830;
  --toolbar-bg: #CDB89E;
  --selection: #A8CDB8;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-editor: 'Nunito', 'DM Sans', system-ui, sans-serif;
  --font-almanac: 'Newsreader', 'Lora', Georgia, serif;
  --font-serif: 'Lora', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 12px;
  /* AI dock: match main cards; themes override --chat-panel-radius on html[data-theme="…"] */
  --chat-panel-radius: 14px;
  --card-lift: 0 10px 36px rgba(42, 32, 20, 0.14), 0 2px 0 rgba(255, 255, 255, 0.55) inset, 0 0 0 1px rgba(180, 155, 120, 0.45);
  --shadow: 0 2px 6px rgba(42, 32, 20, 0.1);
  --shadow-md: 0 12px 32px rgba(32, 24, 12, 0.18);
  --kashi-logo-url: url('/logos/favicon-128.png');
  --skeu-inset: inset 0 1px 3px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(0, 0, 0, 0.04);
  --skeu-raise: 0 1px 0 rgba(255, 255, 255, 0.5), 0 1px 2px rgba(0, 0, 0, 0.08);
  --skeu-frame: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 -1px 0 rgba(0, 0, 0, 0.08) inset;
  /* Writable tail below the note: ~20–25 body lines (tweak integer). Preview uses lh; editor uses em match. */
  --note-free-lines: 22;
  --note-writing-tail: calc(var(--note-free-lines) * 1.55em);
}

html[data-theme="garden"] {
  --font-body: 'Literata', Georgia, serif;
  --font-editor: 'Literata', Georgia, serif;
  --font-almanac: 'Literata', Georgia, serif;
  --font-serif: 'Literata', Georgia, serif;
}

html {
  height: 100%;
  overflow: hidden;
  /* AI chat: bubbles / inputs scale from --chat-panel-radius (themes set on html[data-theme]) */
  --chat-bubble-radius: max(0px, calc(var(--chat-panel-radius) * 0.65));
  --chat-control-radius: max(0px, calc(var(--chat-panel-radius) * 0.45));
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  transition: background 0.2s, color 0.2s;
}

/* TITLEBAR */
#titlebar {
  min-height: 44px;
  height: auto;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  padding: 0 12px 0 16px;
  gap: 8px 12px;
  flex-shrink: 0;
  user-select: none;
}

#titlebar-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

#titlebar .logo {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--text);
  letter-spacing: -0.3px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  max-width: min(200px, 28vw);
}

#titlebar .logo img.kashi-logo-img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  object-fit: contain;
  flex-shrink: 0;
  border: 1px solid rgba(164, 143, 114, 0.45);
  background: rgba(244, 235, 214, 0.5);
}

#titlebar .logo .logo-wordmark {
  color: var(--text);
}

#titlebar .logo .logo-wordmark>span {
  color: var(--accent);
}

h3.app-logo-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

h3.app-logo-heading::before {
  content: '';
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background: var(--kashi-logo-url) center / contain no-repeat;
  border-radius: 5px;
  border: 1px solid var(--border-light);
}

.palette-logo-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.palette-logo-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  background: var(--kashi-logo-url) center / contain no-repeat;
  border-radius: 4px;
  border: 1px solid var(--border-light);
}

#btn-toggle-sidebar {
  flex-shrink: 0;
}

#titlebar-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
  max-width: 100%;
}

.titlebar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
  align-self: center;
}

#titlebar .tb-mob {
  display: none;
}

#titlebar .tb-desk {
  display: inline;
}

.icon-btn {
  min-width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  padding: 0 6px;
  gap: 4px;
  font-family: var(--font-body);
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--border);
  color: var(--text);
}

.icon-btn.active {
  background: var(--accent-light);
  color: var(--accent);
}

.icon-btn .kbd {
  font-size: 10px;
  opacity: 0.6;
  font-family: var(--font-mono);
}

/* MAIN LAYOUT */
#app {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* SIDEBAR */
#sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.2s ease, margin 0.2s;
}

#sidebar.collapsed {
  width: 0;
  border: none !important;
  box-shadow: none !important;
}

#sidebar .binder-spine {
  flex: 0 0 16px;
  min-width: 16px;
}

#sidebar.collapsed .binder-spine {
  display: none;
}

#sidebar .sidebar-binder-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.binder-spine {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px 0;
  background: linear-gradient(90deg, #2C2418 0%, #1A1510 45%, #252018 100%);
  box-shadow: inset 3px 0 6px rgba(0, 0, 0, 0.3), 2px 0 4px rgba(0, 0, 0, 0.1);
  border-right: 1px solid #0A0806;
  border-radius: 10px 0 0 10px;
}

.binder-spine .binder-tab {
  flex: 1;
  margin: 2px 2px 2px 0;
  min-height: 28px;
  border-radius: 4px 0 0 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), -1px 0 2px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-right: none;
}

.binder-spine .binder-tab[data-tone="coral"] {
  background: linear-gradient(180deg, #E8A8A0 0%, #C45C50 100%);
}

.binder-spine .binder-tab[data-tone="sage"] {
  background: linear-gradient(180deg, #9AB8A0 0%, #4A6B50 100%);
}

.binder-spine .binder-tab[data-tone="sky"] {
  background: linear-gradient(180deg, #8CAAB8 0%, #3A5A6A 100%);
}

.binder-spine .binder-tab[data-tone="terracotta"] {
  background: linear-gradient(180deg, #D4A888 0%, #A86A3C 100%);
}



#sidebar-header {
  padding: 10px 10px 6px;
  display: flex;
  gap: 6px;
  align-items: stretch;
}

#sidebar-header .sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px;
  border-radius: 9px;
  border: 1px solid var(--border-light);
  background: rgba(244, 235, 214, 0.55);
  line-height: 0;
}

#sidebar-header .sidebar-logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
  display: block;
}

#new-note-btn {
  flex: 1;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}

#new-note-btn:hover {
  background: var(--accent-hover);
}

#search-wrap {
  padding: 0 10px 8px;
}

#search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px 6px 10px;
  font-size: 12.5px;
  font-family: var(--font-body);
  color: var(--text);
  outline: none;
  transition: border 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='13' viewBox='0 0 24 24' fill='none' stroke='%23A89F94' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 9px center;
}

#search-input:focus {
  border-color: var(--accent);
}

#search-input::placeholder {
  color: var(--text-faint);
}

#saved-search-wrap {
  padding: 0 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.saved-search-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.saved-search-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.btn-save-search {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-faint);
  border-radius: 5px;
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
}

.btn-save-search:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

#saved-search-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.saved-search-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.saved-search-chip:hover {
  background: var(--border-light);
  color: var(--text);
}

.saved-search-chip .del {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 11px;
}

.saved-search-chip .del:hover {
  color: var(--danger);
}

#sidebar-tabs {
  padding: 8px 10px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sidebar-tab {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 6px 4px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.sidebar-tab:hover {
  background: var(--border-light);
  color: var(--text);
}

.sidebar-tab.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(61, 107, 79, 0.25);
}

#tasks-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  gap: 8px;
}

#tasks-pane::-webkit-scrollbar {
  width: 4px;
}

#tasks-pane::-webkit-scrollbar-track {
  background: transparent;
}

#tasks-pane::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* NOTES PANE — whole pane scrolls as one unit */
#notes-pane {
  overflow-y: auto;
  overflow-x: hidden;
}

#notes-pane::-webkit-scrollbar {
  width: 4px;
}

#notes-pane::-webkit-scrollbar-track {
  background: transparent;
}

#notes-pane::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

#task-calendar-wrap {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  padding: 6px 8px 8px;
  flex-shrink: 0;
}

.task-cal-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.task-cal-label {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text);
  min-width: 0;
}

.task-cal-nav-btn {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 3px 8px;
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  line-height: 1.2;
}

.task-cal-nav-tight {
  font-size: 11px;
  padding: 3px 6px;
}

.task-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
  user-select: none;
}

.task-cal-dow {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-body);
  text-align: center;
  color: var(--text-faint);
  padding: 2px 0;
}

.task-cal-cell {
  position: relative;
  min-height: 36px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 3px 2px 14px;
  text-align: center;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.02);
}

.task-cal-cell.other-month {
  opacity: 0.38;
}

.task-cal-cell.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-light);
  background: var(--accent-light);
}

.task-cal-cell.task-cal-drop {
  border-color: var(--accent);
  background: rgba(61, 107, 79, 0.12);
}

.task-cal-daynum {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text);
}

.task-cal-count {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 9px;
  font-family: var(--font-body);
  line-height: 1;
  padding: 2px 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--btn-text-on-accent, #fff);
}

.template-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
}

.template-user-row:last-child {
  border-bottom: none;
}

.template-user-row-name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.template-user-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.template-user-act {
  font-size: 11px !important;
  padding: 3px 6px !important;
}

.template-user-input,
.template-user-textarea {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 6px 8px;
}

#task-filter-bar {
  display: flex;
  gap: 6px;
}

.task-filter-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-body);
  padding: 4px 8px;
  cursor: pointer;
}

.task-filter-btn.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(61, 107, 79, 0.3);
}

#task-filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-items: stretch;
}

#task-filter-row #task-project-select {
  grid-column: 1 / -1;
}

#task-filter-row select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
  font-family: var(--font-body);
}

#task-priority-row {
  display: flex;
  gap: 6px;
}

.task-priority-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font-body);
  padding: 4px 8px;
  cursor: pointer;
}

.task-priority-chip.active {
  border-color: rgba(61, 107, 79, 0.34);
  background: var(--accent-light);
  color: var(--accent);
}

#task-list-meta {
  font-size: 11px;
  color: var(--text-faint);
}

#task-list {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  min-height: 120px;
  max-height: 210px;
  overflow-y: auto;
}

.task-row {
  border-bottom: 1px solid var(--border-light);
  padding: 8px;
  cursor: pointer;
}

.task-row[draggable="true"] {
  cursor: grab;
}

.task-row[draggable="true"]:active {
  cursor: grabbing;
}

.task-row:last-child {
  border-bottom: none;
}

.task-row:hover {
  background: var(--border-light);
}

.task-row-title {
  font-size: 12.5px;
  color: var(--text);
  margin-bottom: 3px;
}

.task-row-meta {
  font-size: 10.5px;
  color: var(--text-faint);
}

#task-kanban-wrap {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  padding: 8px;
}

.task-kanban-head {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 6px;
}

#task-kanban {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.task-col {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  min-height: 72px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.01);
}

.task-col-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.task-card {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-size: 11px;
  color: var(--text);
  padding: 5px 6px;
  margin-bottom: 5px;
  cursor: grab;
}

.task-card.done {
  opacity: 0.72;
}

.task-col.drop-on {
  border-color: rgba(61, 107, 79, 0.45);
  background: var(--accent-light);
}

#sidebar-meta {
  padding: 0 16px 4px;
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  justify-content: space-between;
}

#notes-list {
  flex: 0 0 auto;
  max-height: 42%;
  overflow-y: auto;
  padding: 0 8px 8px;
}

#notes-list::-webkit-scrollbar {
  width: 4px;
}

#notes-list::-webkit-scrollbar-track {
  background: transparent;
}

#notes-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Notes are shown in folder hierarchy only */
#sidebar-meta,
#notes-list {
  display: none;
}

#sidebar-toc {
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  padding: 0 0 8px;
}

#sidebar-toc[hidden] {
  display: none !important;
}

.sidebar-toc-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 10px 4px;
  flex-shrink: 0;
  cursor: pointer;
  font-family: var(--font-body);
  transition: color 0.1s;
  text-align: left;
}

.sidebar-toc-title:hover {
  color: var(--text);
}

.sidebar-toc-chevron {
  font-size: 8px;
  flex-shrink: 0;
  transition: transform 0.18s ease;
  opacity: 0.7;
}

.sidebar-toc-title[aria-expanded="true"] .sidebar-toc-chevron {
  transform: rotate(90deg);
}

#toc-list.collapsed {
  display: none;
}

/* Folder list controls (Collapse All / Expand All) */
.folder-list-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 4px;
}

.folder-list-label {
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.folder-list-control-btns {
  display: flex;
  gap: 4px;
}

.folder-list-act-btn {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: 10px;
  font-family: var(--font-body);
  padding: 2px 6px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.folder-list-act-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

#toc-list {
  padding: 0 4px 0 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.toc-item {
  text-align: left;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.3;
  font-family: var(--font-body);
  padding: 4px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s, color 0.1s;
}

.toc-item:hover {
  background: var(--border-light);
  color: var(--text);
}

#password-pane {
  display: none;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
}

#password-pane::-webkit-scrollbar {
  width: 4px;
}

#password-pane::-webkit-scrollbar-track {
  background: transparent;
}

#password-pane::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Whiteboard popup (full-screen) */
.wb-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: none;
  align-items: stretch;
  justify-content: stretch;
  padding: 12px;
  box-sizing: border-box;
  background: rgba(24, 20, 16, 0.55);
  backdrop-filter: blur(4px);
}

.wb-modal.wb-modal-open {
  display: flex;
}

.wb-modal-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(175deg, #faf4ea 0%, #e8dcc8 100%);
  border: 1px solid #8a7a62;
  border-radius: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

/* Desktop: centered dialog sized to toolbar + 600×600 board (no extra empty flex below the canvas). */
@media (min-width: 701px) {
  .wb-modal {
    align-items: center;
    justify-content: center;
  }

  .wb-modal-inner {
    flex: 0 1 auto;
    width: fit-content;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Match canvas width (600px); do not stretch to the wider tool strip. */
  .wb-stage-scroll {
    flex: 0 0 auto;
    min-height: 0;
    align-self: center;
    width: 600px;
    max-width: calc(100% - 24px);
    margin-top: 10px;
    margin-bottom: 10px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
  }
}

.wb-modal-head {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 252, 246, 0.85);
}

.wb-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text);
}

.wb-modal-sub {
  font-size: 12px;
  color: var(--text-faint);
  flex: 1;
  min-width: 140px;
}

.wb-modal-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.wb-tool-strip {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.45);
}

.wb-strip-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.wb-strip-group.wb-strip-tools {
  align-items: center;
}

.wb-strip-group.wb-strip-legend {
  flex-direction: column;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 4px;
}

.wb-strip-legend {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1.2;
  margin: 0;
  cursor: default;
}

label.wb-strip-legend {
  cursor: pointer;
}

.wb-strip-legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.wb-strip-group.wb-strip-end {
  margin-left: auto;
}

.wb-strip-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 2px;
}

.wb-tb {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 6px 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 32px;
  box-sizing: border-box;
}

.wb-tb .wb-tb-icon {
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

.wb-tb:hover {
  background: var(--border-light);
  color: var(--text);
}

.wb-tb.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(61, 107, 79, 0.35);
}

.wb-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.wb-swatch:hover {
  transform: scale(1.06);
}

.wb-swatch.wb-swatch-on {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.wb-picker-wrap input[type="color"] {
  width: 30px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  vertical-align: middle;
}

#wb-stroke-size {
  width: 100px;
  accent-color: var(--accent);
}

.wb-text-size-wrap select {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
}

.wb-clear-btn {
  font-size: 12px;
}

.wb-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;
}

.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;
}

/* Fixed 600×600 board; scroll when the modal viewport is smaller (especially mobile). */
.wb-stage-scroll {
  flex: 1;
  min-height: 0;
  margin: 10px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

.wb-stage {
  position: relative;
  flex: 0 0 auto;
  width: 600px;
  height: 600px;
  margin: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  touch-action: none;
}

.wb-canvas-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

.wb-text-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.wb-text-item {
  position: absolute;
  min-width: 80px;
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px dashed transparent;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  font-family: var(--font-body);
  line-height: 1.35;
  outline: none;
  pointer-events: auto;
  cursor: text;
  box-sizing: border-box;
  word-wrap: break-word;
}

.wb-text-item.wb-text-selected {
  border-color: rgba(61, 107, 79, 0.65);
  box-shadow: 0 0 0 2px rgba(61, 107, 79, 0.2);
}

.wb-modal.wb-mode-pen .wb-canvas-layer,
.wb-modal.wb-mode-highlighter .wb-canvas-layer,
.wb-modal.wb-mode-eraser .wb-canvas-layer {
  cursor: crosshair;
}

.wb-modal.wb-mode-hand .wb-stage-scroll {
  cursor: grab;
}

.wb-modal.wb-mode-hand.wb-hand-panning .wb-stage-scroll {
  cursor: grabbing;
}

.wb-modal.wb-mode-hand .wb-canvas-layer,
.wb-modal.wb-mode-hand .wb-stage {
  cursor: grab;
}

.wb-modal.wb-mode-hand.wb-hand-panning .wb-canvas-layer,
.wb-modal.wb-mode-hand.wb-hand-panning .wb-stage {
  cursor: grabbing;
}

.wb-modal.wb-mode-text .wb-canvas-layer {
  cursor: text;
}

.wb-modal.wb-mode-select .wb-canvas-layer {
  cursor: default;
}

.wb-text-item.wb-mode-select-cursor {
  cursor: grab;
}

.wb-text-item.wb-mode-select-cursor:active {
  cursor: grabbing;
}

@media (max-width: 700px) {
  .wb-stage-scroll {
    scrollbar-width: thin;
  }

  .wb-stage-scroll::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  .wb-stage-scroll::-webkit-scrollbar-thumb {
    background: rgba(42, 32, 20, 0.35);
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: padding-box;
  }

  .wb-stage-scroll::-webkit-scrollbar-track {
    background: rgba(255, 252, 246, 0.5);
    border-radius: 5px;
  }
}

/* Right dock: AI chat (opened from editor toolbar) */
#ai-chat-panel {
  display: none;
  flex-direction: column;
  flex-shrink: 0;
  width: min(384px, 42vw);
  min-width: 260px;
  max-width: 100%;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--sidebar-bg);
  box-shadow: -4px 0 18px rgba(42, 32, 20, 0.06);
  border-radius: var(--chat-panel-radius);
  overflow: hidden;
}

#ai-chat-panel.open {
  display: flex;
}

.ai-chat-top {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.ai-chat-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ai-chat-top-actions {
  display: flex;
  flex-shrink: 0;
  gap: 6px;
  align-items: center;
}

.ai-chat-close-panel {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font-body);
  padding: 0;
  display: grid;
  place-items: center;
}

.ai-chat-close-panel:hover {
  color: var(--text);
  border-color: var(--accent);
}

.ai-chat-context {
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.ai-chat-clear {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  font-family: var(--font-body);
}

.ai-chat-clear:hover {
  color: var(--text);
  border-color: var(--accent);
}

.ai-chat-messages {
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-chat-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.45;
  padding: 4px 2px;
}

.ai-msg {
  max-width: 100%;
  padding: 8px 10px;
  border-radius: var(--chat-bubble-radius);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg-user {
  align-self: flex-end;
  background: var(--accent-light);
  color: var(--text);
  border: 1px solid rgba(61, 107, 79, 0.22);
}

.ai-msg-assistant-block {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.ai-msg-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.ai-msg-assistant strong {
  font-weight: 700;
  color: var(--text);
}

.ai-msg-assistant:not(.thinking) .ai-msg-md-root {
  white-space: normal;
  word-break: break-word;
}

.ai-msg-md-root {
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
}

.ai-msg-md-root p {
  margin: 0 0 0.5em;
}

.ai-msg-md-root p:last-child {
  margin-bottom: 0;
}

.ai-msg-md-root h1 {
  font-size: 1.55em;
  font-weight: 600;
  margin: 0.35em 0 0.25em;
  line-height: 1.25;
}

.ai-msg-md-root h2 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0.35em 0 0.2em;
}

.ai-msg-md-root h3 {
  font-size: 1.1em;
  font-weight: 600;
  margin: 0.3em 0 0.15em;
}

.ai-msg-md-root h4,
.ai-msg-md-root h5,
.ai-msg-md-root h6 {
  font-size: 1em;
  font-weight: 600;
  margin: 0.5em 0 0.15em;
}

.ai-msg-md-root ul,
.ai-msg-md-root ol {
  padding-left: 1.35em;
  margin: 0 0 0.45em;
}

.ai-msg-md-root li {
  margin-bottom: 0.12em;
}

.ai-msg-md-root a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-msg-md-root code {
  font-family: var(--font-mono), monospace;
  font-size: 0.88em;
  background: var(--tag-bg);
  padding: 1px 4px;
  border-radius: max(2px, calc(var(--chat-control-radius) * 0.5));
}

.ai-msg-md-root pre {
  margin: 0.45em 0;
  padding: 8px 10px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--surface) 92%, var(--tag-bg));
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  font-size: 11.5px;
  line-height: 1.4;
}

.ai-msg-md-root pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.ai-msg-md-root blockquote {
  margin: 0.4em 0;
  padding-left: 0.85em;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.ai-msg-md-root table {
  border-collapse: collapse;
  margin: 0.45em 0;
  font-size: 0.92em;
}

.ai-msg-md-root th,
.ai-msg-md-root td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}

.ai-msg-md-root hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.65em 0;
}

.ai-msg-md-root img {
  max-width: 100%;
  height: auto;
  border-radius: var(--chat-control-radius);
}

.ai-msg-md-root strong {
  font-weight: 700;
}

.ai-msg-md-root em {
  font-style: italic;
}

.ai-msg-md-root del {
  text-decoration: line-through;
  color: var(--text-muted);
}

.ai-msg-md-root mark {
  background: color-mix(in srgb, var(--accent-light) 55%, transparent);
  padding: 0 2px;
}

.ai-msg-assistant.thinking {
  min-height: 40px;
  border-style: dashed;
  animation: ai-thinking-pulse 1.6s ease-in-out infinite;
}

@keyframes ai-thinking-pulse {

  0%,
  100% {
    border-color: var(--border);
    box-shadow: none;
  }

  50% {
    border-color: rgba(61, 107, 79, 0.45);
    box-shadow: 0 0 0 1px rgba(61, 107, 79, 0.08);
  }
}

.ai-thinking-placeholder {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  user-select: none;
}

.ai-thinking-dots {
  display: inline-flex;
  gap: 2px;
}

.ai-thinking-dots span {
  display: inline-block;
  width: 0.35em;
  text-align: center;
  animation: ai-thinking-dot 1.15s ease-in-out infinite;
}

.ai-thinking-dots span:nth-child(1) {
  animation-delay: 0ms;
}

.ai-thinking-dots span:nth-child(2) {
  animation-delay: 120ms;
}

.ai-thinking-dots span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes ai-thinking-dot {

  0%,
  70%,
  100% {
    opacity: 0.2;
    transform: translateY(0);
  }

  35% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.ai-msg-usage {
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--text-faint);
  padding: 0 2px 2px;
  max-width: 100%;
}

.ai-msg-usage a {
  color: var(--accent);
  text-decoration: none;
}

.ai-msg-usage a:hover {
  text-decoration: underline;
}

.ai-usage-apex-host {
  min-height: 220px;
  width: 100%;
  position: relative;
}

.ai-usage-allowance-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: -2px 0 12px;
  line-height: 1.45;
}

.ai-usage-allowance-note strong {
  font-weight: 600;
  color: var(--text);
}

.ai-usage-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.ai-usage-stat-card {
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  padding: 10px 12px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-usage-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  line-height: 1.2;
}

.ai-usage-stat-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  word-break: break-word;
}

.ai-usage-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 4px 4px;
  line-height: 1.45;
}

.ai-usage-charts-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-usage-chart-block {
  min-width: 0;
}

.ai-usage-chart-caption {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.ai-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px 4px;
}

.ai-chat-apply-btn {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--chat-control-radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
}

.ai-chat-apply-btn:hover {
  border-color: rgba(61, 107, 79, 0.35);
  background: var(--accent-light);
}

.ai-chat-compose {
  border-top: 1px solid var(--border);
  padding: 8px;
  background: var(--sidebar-bg);
  flex-shrink: 0;
}

.ai-chat-top-row .ai-chat-model-wrap {
  flex: 1;
  min-width: 0;
  width: auto;
  max-width: none;
  position: relative;
}

.ai-chat-model-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  font-family: var(--font-body);
  font-size: 11px;
  line-height: 1.35;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.ai-chat-model-trigger-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.ai-chat-model-trigger-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat-model-trigger-chevron {
  flex-shrink: 0;
  font-size: 9px;
  opacity: 0.65;
}

.ai-chat-model-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.ai-chat-model-menu {
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  box-shadow: var(--shadow-md, 0 8px 28px rgba(0, 0, 0, 0.12));
}

.ai-chat-model-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 8px;
  border-radius: calc(var(--chat-control-radius) - 2px);
  cursor: pointer;
  font-size: 11px;
  color: var(--text);
}

.ai-chat-model-menu-item:hover {
  background: var(--accent-light);
}

.ai-chat-model-menu-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Relative cost “thermometer”: cool (tier 1) → hot (tier 5); not live $/token */
.ai-chat-cost-pill {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}

.ai-chat-cost-pill--1 {
  color: #0b5cab;
  background: linear-gradient(135deg, #d9f0ff 0%, #b8e0ff 100%);
  border-color: rgba(11, 92, 171, 0.25);
}

.ai-chat-cost-pill--2 {
  color: #1d6b3a;
  background: linear-gradient(135deg, #dff5e8 0%, #b8e8c8 100%);
  border-color: rgba(29, 107, 58, 0.28);
}

.ai-chat-cost-pill--3 {
  color: #8a5a00;
  background: linear-gradient(135deg, #fff4d6 0%, #ffe0a3 100%);
  border-color: rgba(138, 90, 0, 0.28);
}

.ai-chat-cost-pill--4 {
  color: #a63b0a;
  background: linear-gradient(135deg, #ffe8d6 0%, #ffc9a3 100%);
  border-color: rgba(166, 59, 10, 0.3);
}

.ai-chat-cost-pill--5 {
  color: #8f1024;
  background: linear-gradient(135deg, #ffe0e8 0%, #ffb8c8 100%);
  border-color: rgba(143, 16, 36, 0.35);
}

.ai-chat-status {
  font-size: 10px;
  color: var(--text-faint);
  min-height: 14px;
  margin-bottom: 6px;
}

.ai-chat-cap-notice {
  font-size: 12px;
  line-height: 1.35;
  color: var(--danger, #b42318);
  margin: -2px 0 8px;
  padding: 8px 10px;
  border-radius: var(--chat-control-radius);
  background: color-mix(in srgb, var(--danger, #b42318) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger, #b42318) 35%, var(--border));
}

.ai-chat-options {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
  gap: 14px;
  margin: 0 0 8px;
  padding: 0 2px;
}

.ai-chat-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.ai-chat-switch-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0.01;
}

.ai-chat-switch-track {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.ai-chat-switch-track::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface, #fff);
  top: 2px;
  left: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease;
}

.ai-chat-switch-input:focus-visible+.ai-chat-switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ai-chat-switch-input:checked+.ai-chat-switch-track {
  background: var(--accent);
}

.ai-chat-switch-input:checked+.ai-chat-switch-track::after {
  transform: translateX(16px);
}

.ai-chat-switch .ai-chat-switch-state {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  min-width: 1.5em;
}

.ai-chat-switch:has(.ai-chat-switch-input:checked) .ai-chat-switch-state {
  color: var(--accent);
}

.ai-chat-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#ai-chat-input {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12.5px;
}

.ai-chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.ai-chat-compose-inner {
  position: relative;
}

.ai-chat-mention-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 4px;
  max-height: min(200px, 38vh);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--chat-control-radius);
  background: var(--surface);
  box-shadow: 0 -4px 18px rgba(42, 32, 20, 0.12);
  z-index: 5;
  padding: 4px;
  font-size: 12px;
}

.ai-chat-mention-dropdown[hidden] {
  display: none !important;
}

.ai-chat-mention-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: var(--chat-control-radius);
  padding: 6px 8px;
  margin: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  cursor: pointer;
}

.ai-chat-mention-item:hover,
.ai-chat-mention-item[aria-selected="true"] {
  background: var(--accent-light);
}

.ai-chat-mention-item .ai-chat-mention-meta {
  font-size: 10px;
  color: var(--text-faint);
}

#pm-search-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

#pm-search-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12px;
  color: var(--text);
  font-family: var(--font-body);
  outline: none;
  transition: border 0.12s;
}

#pm-search-input:focus {
  border-color: var(--accent);
}

#pm-search-btn {
  width: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}

#pm-search-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

#pm-open-add {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}

#pm-open-add:hover {
  background: var(--accent-light);
  border-color: rgba(61, 107, 79, 0.35);
  color: var(--accent);
}

#pm-csv-io {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  padding: 7px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

#pm-csv-io:hover {
  background: var(--border-light);
  border-color: rgba(61, 107, 79, 0.35);
  color: var(--accent);
}

.pm-csv-modal-box {
  max-width: 420px;
  max-height: min(90vh, 640px);
  overflow-y: auto;
}

.pm-csv-lead {
  font-size: 12px !important;
  line-height: 1.5;
  margin-bottom: 14px !important;
}

.pm-csv-section {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-light);
}

.pm-csv-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 12px;
}

.pm-csv-section-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-body);
}

.pm-csv-steps {
  margin: 0 0 10px;
  padding-left: 1.2em;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
}

.pm-csv-steps li {
  margin-bottom: 4px;
}

.pm-csv-steps code {
  font-size: 11px;
  background: var(--border-light);
  padding: 1px 4px;
  border-radius: 4px;
}

.pm-csv-section .modal-btn {
  width: 100%;
  margin-top: 4px;
}

#pm-add-form {
  display: none;
  margin-bottom: 8px;
}

#pm-add-form.open {
  display: block;
}

.pm-input,
.pm-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 5px;
  font-size: 12.5px;
  color: var(--text);
  font-family: var(--font-body);
  margin-bottom: 6px;
  outline: none;
  transition: border 0.12s;
}

.pm-input:focus,
.pm-textarea:focus {
  border-color: var(--accent);
}

.pm-textarea {
  min-height: 56px;
  resize: vertical;
}

.pm-pass-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  margin-bottom: 6px;
}

.pm-pass-row .pm-input {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
}

#pm-gen-pass {
  flex: 0 0 40px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}

#pm-gen-pass:hover {
  background: var(--accent-light);
  border-color: rgba(61, 107, 79, 0.35);
}

#pm-add-btn {
  flex: 1;
  border: none;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12.5px;
  font-family: var(--font-body);
  color: white;
  background: var(--accent);
  cursor: pointer;
}

#pm-add-btn:hover {
  background: var(--accent-hover);
}

#pm-form-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

#pm-cancel-edit {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  display: none;
}

#pm-cancel-edit:hover {
  background: var(--border-light);
  color: var(--text);
}

#pm-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pm-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 7px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.pm-item:hover {
  background: var(--border-light);
}

.pm-item.open {
  border-color: rgba(61, 107, 79, 0.35);
  background: var(--accent-light);
}

.pm-item-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1px;
}

.pm-item-user {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 0;
}

.pm-item-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pm-item-main {
  flex: 1;
  min-width: 0;
}

.pm-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.pm-mini-btn {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  width: 26px;
  height: 24px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.pm-mini-btn:hover {
  background: var(--border);
  color: var(--text);
}

.pm-mini-btn.danger {
  border-color: rgba(184, 64, 64, 0.35);
  color: var(--danger);
}

.pm-mini-btn.danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.note-item {
  padding: 8px 10px 8px 4px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 2px;
  border: 1px solid transparent;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.note-item-pin {
  flex: 0 0 24px;
  width: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  padding: 0 0 0 1px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  align-self: flex-start;
  margin-top: 1px;
}

.note-item-pin:hover,
.note-item-pin.on {
  color: #C9A227;
}

.note-item-body {
  flex: 1;
  min-width: 0;
}

.note-item:hover {
  background: var(--border-light);
}

.note-item:hover .note-actions {
  opacity: 1;
}

.note-item.active {
  background: var(--accent-light);
  border-color: rgba(61, 107, 79, 0.15);
}

.note-title-row {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  padding-right: 32px;
}

.note-meta {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  align-items: center;
}

.note-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.note-actions {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}

.note-action-btn {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: var(--tag-bg);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}

.note-action-btn:hover {
  background: var(--border);
  color: var(--text);
}

.note-action-btn.del:hover {
  background: var(--danger);
  color: white;
}

/* EDITOR AREA */
#editor-area {
  position: relative;
  flex: 1;
  min-width: 0;
  /* flex row child: allow shrinking so column + status bar don’t spill past #app (Bento, Swiss, …) */
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

/* FIND BAR */
#find-bar {
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: none;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#find-bar.open {
  display: flex;
}

#find-input,
#replace-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12.5px;
  font-family: var(--font-body);
  color: var(--text);
  outline: none;
  width: 160px;
  transition: border 0.12s;
}

#find-input:focus,
#replace-input:focus {
  border-color: var(--accent);
}

#find-count {
  font-size: 11.5px;
  color: var(--text-faint);
  min-width: 60px;
}

.find-btn {
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}

.find-btn:hover {
  background: var(--border);
  color: var(--text);
}

.find-btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.find-btn.accent:hover {
  background: var(--accent-hover);
}

#find-close {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 16px;
  padding: 0 4px;
}

#find-close:hover {
  color: var(--text);
}

#find-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
}

/* TOOLBAR */
#toolbar {
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  overflow-x: auto;
}

#toolbar::-webkit-scrollbar {
  display: none;
}

.tb-btn {
  min-width: 28px;
  height: 28px;
  border: none;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12.5px;
  font-family: var(--font-mono);
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  flex-shrink: 0;
}

#toolbar .tb-btn[hidden],
#toolbar .tb-sep[hidden],
#toolbar #btn-toolbar-publish-link[hidden] {
  display: none !important;
}

.tb-btn:hover {
  background: var(--border);
  color: var(--text);
}

/* AI: floating action button (bottom-right; all viewports). Lives under #app, not #toolbar, so backdrop-filter on toolbar/editor doesn’t trap fixed positioning. */
#btn-ai-chat {
  position: fixed;
  right: max(27px, env(safe-area-inset-right, 0px));
  bottom: max(40px, calc(12px + env(safe-area-inset-bottom, 0px)));
  z-index: 150;
  pointer-events: auto;
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  align-self: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    none;
  border: none;
  background: transparent;
  color: #1a1008;
  transition: none;
}

#btn-ai-chat .tb-btn-ai-icon {
  display: block;
  width: 45px;
  height: 45px;
  object-fit: contain;
  pointer-events: none;
}

#btn-ai-chat.active {
  background: linear-gradient(180deg, #a0c0a8 0%, #4a6a50 100%);
  color: #0e1a10 !important;
  border-color: #1a3024;
}

#btn-ai-chat.active .tb-btn-ai-icon {
  filter: brightness(1.05) contrast(1.05);
}

.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

#toolbar-spacer {
  flex: 1;
}

/* ── Meeting Recorder ─────────────────────────────────────────────────── */
#btn-record {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 0 8px;
  gap: 4px;
  color: var(--text-muted);
}

#btn-record:hover {
  color: var(--text);
  background: var(--border);
}

#btn-record.rec-active {
  color: #ff5a5a;
  background: rgba(255, 79, 79, 0.1);
  animation: rec-btn-pulse 1.4s ease-in-out infinite;
}

#btn-record.rec-uploading {
  color: var(--accent);
  background: var(--accent-light, rgba(99, 102, 241, 0.12));
  animation: none;
}

@keyframes rec-btn-pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.55;
  }
}

/* Floating recording HUD */
#rec-panel {
  position: fixed;
  top: 48px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface, #1e2030);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: auto;
  user-select: none;
}

#rec-panel.hidden {
  display: none !important;
}

#rec-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint, #555);
  flex-shrink: 0;
  transition: background 0.2s;
}

#rec-indicator.on {
  background: #ff4f4f;
  animation: rec-btn-pulse 1s infinite;
}

#rec-indicator.warn {
  background: #f59e0b;
  animation: rec-btn-pulse 0.6s infinite;
}

#rec-panel-text {
  color: var(--text-muted);
  min-width: 62px;
}

#rec-panel-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  min-width: 32px;
}

#rec-silence-pill {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #f59e0b;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
}

#rec-panel-spacer {
  flex: 1;
  min-width: 6px;
}

.rec-act-btn {
  height: 24px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: background 0.12s;
  flex-shrink: 0;
}

#rec-pause-btn {
  background: var(--border);
  color: var(--text-muted);
}

#rec-pause-btn:hover {
  color: var(--text);
}

#rec-stop-btn {
  background: #ff4f4f;
  color: #fff;
}

#rec-stop-btn:hover {
  background: #ff6b6b;
}

#rec-autostop-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  color: var(--text-muted);
  border-left: 1px solid var(--border);
  padding-left: 8px;
  margin-left: 2px;
}

#rec-autostop-wrap label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
}

#rec-autostop-select {
  height: 20px;
  background: var(--border);
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 10px;
  padding: 0 3px;
  cursor: pointer;
  outline: none;
}

.tb-color {
  width: 26px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.tb-color::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.tb-color::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

/* Editor “page” scroll: panes + status bar (footer follows content in scroll order) */
#editor-page {
  flex: 1;
  min-width: 0;
  /* column flex child: panes must not force editor column wider than allocated width */
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* PANES — height follows content so #editor-page scrolls; status bar sits below (not viewport-pinned) */
#panes {
  flex: 0 0 auto;
  width: 100%;
  min-height: min(52vh, 420px);
  display: flex;
  align-items: stretch;
  overflow: visible;
}

#md-input-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: visible;
  display: flex;
  flex-direction: column;
}

#md-input {
  flex: 0 0 auto;
  min-height: min(48vh, 380px);
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 48px;
  padding-bottom: calc(32px + var(--note-writing-tail));
  font-family: var(--font-editor);
  font-size: 17px;
  line-height: 1.85;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  overflow-y: auto;
}

#md-input-wrap .CodeMirror {
  flex: 0 0 auto;
  height: auto !important;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  font-family: var(--font-editor) !important;
  font-size: 17px;
  line-height: 1.85 !important;
  background: var(--surface);
  color: var(--text);
}

#md-input-wrap .CodeMirror-scroll {
  min-height: min(48vh, 380px);
  height: auto !important;
  max-height: none !important;
  overflow-y: hidden !important;
  overflow-x: auto !important;
}

#md-input-wrap .CodeMirror pre.CodeMirror-line {
  padding: 0 2px;
  line-height: 1.85 !important;
}

/* Blank markdown lines: preview collapses extra gaps (renderMd); match density in the editor */
#md-input-wrap .CodeMirror .CodeMirror-code>div.ink-cm-empty-line pre.CodeMirror-line {
  line-height: 1.05 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  min-height: 0 !important;
}

#md-input-wrap .CodeMirror-lines {
  padding: 32px 24px;
  padding-bottom: calc(32px + var(--note-writing-tail));
}

#md-input-wrap .CodeMirror-cursor {
  border-color: var(--text);
}

#md-input-wrap .CodeMirror-line::selection,
#md-input-wrap .CodeMirror-line>span::selection {
  background: var(--selection);
}

#md-input-wrap .CodeMirror-selected {
  background: var(--selection);
}

#md-input::selection {
  background: var(--selection);
}

/* Markdown editor + slash menu: scrollbar thumb #3A3020, ~½ prior editor width (3px) */
#md-input::-webkit-scrollbar,
#md-input-wrap .CodeMirror-scroll::-webkit-scrollbar,
#md-input-wrap .CodeMirror-vscrollbar::-webkit-scrollbar,
#md-input-wrap .CodeMirror-hscrollbar::-webkit-scrollbar,
.slash-menu::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

#md-input::-webkit-scrollbar-track,
#md-input-wrap .CodeMirror-scroll::-webkit-scrollbar-track,
#md-input-wrap .CodeMirror-vscrollbar::-webkit-scrollbar-track,
#md-input-wrap .CodeMirror-hscrollbar::-webkit-scrollbar-track,
.slash-menu::-webkit-scrollbar-track {
  background: transparent;
}

#md-input::-webkit-scrollbar-thumb,
#md-input-wrap .CodeMirror-scroll::-webkit-scrollbar-thumb,
#md-input-wrap .CodeMirror-vscrollbar::-webkit-scrollbar-thumb,
#md-input-wrap .CodeMirror-hscrollbar::-webkit-scrollbar-thumb,
.slash-menu::-webkit-scrollbar-thumb {
  background: #3A3020;
  border-radius: 3px;
}

#md-input,
#md-input-wrap .CodeMirror-scroll,
.slash-menu {
  scrollbar-width: thin;
  scrollbar-color: #3A3020 transparent;
}

/* DIVIDER */
#pane-divider {
  width: 1px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
}

#pane-divider:hover,
#pane-divider.dragging {
  background: var(--accent);
}

#pane-divider::after {
  content: '';
  position: absolute;
  top: 0;
  left: -4px;
  width: 9px;
  height: 100%;
}

/* PREVIEW */
#preview-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view-split #editor-page {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.view-split #panes {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.view-split #md-input-wrap,
.view-split #preview-wrap {
  min-height: 0;
  overflow-y: auto;
}

#preview-wrap::-webkit-scrollbar {
  width: 6px;
}

#preview-wrap::-webkit-scrollbar-track {
  background: transparent;
}

#preview-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

#editor-page #preview {
  flex: 1 1 auto;
  width: 100%;
  max-width: 760px;
  margin: 0px auto;
  padding: 0px 16px;
  /* Match body line height: 1lh on #preview; 1.55em fallback where lh is unsupported */
  padding-bottom: calc(32px + var(--note-free-lines) * 1.55em);
  padding-bottom: calc(32px + var(--note-free-lines) * 1lh);
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: var(--shadow);
  outline: none;
}

/* Markdown: each blank source line is <p></p>; multiple blank lines = multiple empty <p> (visible spacers) */
#preview p {
  line-height: 1.55;
}

#preview p:empty {
  display: block;
  min-height: 1.55em;
  margin: 0 0 0.45em;
}

#preview h1 {
  font-size: 2em;
  font-weight: 600;
  line-height: 1.25;
  margin: 0.2em 0 0.2em;
}

#preview h2 {
  font-size: 1.4em;
  font-weight: 600;
  line-height: 1.3;
  margin: 0.1em 0 0.1em;
}

#preview h3 {
  font-size: 1.15em;
  font-weight: 600;
  line-height: 1.35;
  margin: 0.05em 0 0.05em;
}

#preview h4,
#preview h5,
#preview h6 {
  font-size: 1em;
  font-weight: 600;
  line-height: 1.4;
  margin: 0.85em 0 0.25em;
}

#preview a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

#preview .ink-file-host {
  display: block;
  margin: 0 0 0.75em;
  max-width: 100%;
  box-sizing: border-box;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
}

#preview .ink-file-card {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
  box-shadow: var(--shadow);
  box-sizing: border-box;
  min-height: 52px;
  max-width: 500px;
}

/* Attachment thumbnails by file kind (extension + stored type) */
#preview .ink-file-thumb {
  width: 46px;
  height: 54px;
  flex-shrink: 0;
  margin-right: 2px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  font-family: var(--font-body), system-ui, sans-serif;
  background: var(--surface);
}

#preview .ink-file-thumb-face {
  flex: 1;
  min-height: 0;
  position: relative;
}

#preview .ink-file-thumb-label {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1;
  padding: 5px 3px;
  text-transform: uppercase;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

#preview .ink-file-thumb--pdf .ink-file-thumb-face {
  background: linear-gradient(180deg, #e53935 0%, #e53935 40%, #fafafa 40%);
}

#preview .ink-file-thumb--pdf .ink-file-thumb-label {
  background: #fff;
  color: #b71c1c;
  border-top-color: rgba(229, 57, 53, 0.25);
}

#preview .ink-file-thumb--sheet .ink-file-thumb-face {
  background-color: #e8f5e9;
  background-image:
    linear-gradient(180deg, #2e7d32 0%, #2e7d32 30%, transparent 30%),
    repeating-linear-gradient(0deg, rgba(46, 125, 50, 0.14) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(90deg, rgba(46, 125, 50, 0.14) 0 1px, transparent 1px 9px);
}

#preview .ink-file-thumb--sheet .ink-file-thumb-label {
  background: #fff;
  color: #1b5e20;
}

#preview .ink-file-thumb--doc .ink-file-thumb-face {
  background: linear-gradient(180deg, #2b579a 0%, #2b579a 36%, #eef3fb 36%);
}

#preview .ink-file-thumb--doc .ink-file-thumb-label {
  background: #fff;
  color: #1565c0;
}

#preview .ink-file-thumb--slides .ink-file-thumb-face {
  background: linear-gradient(180deg, #d24726 0%, #d24726 34%, #fff5f0 34%);
}

#preview .ink-file-thumb--slides .ink-file-thumb-label {
  background: #fff;
  color: #bf360c;
}

#preview .ink-file-thumb--text .ink-file-thumb-face {
  background: linear-gradient(180deg, #607d8b 0%, #607d8b 32%, #eceff1 32%);
}

#preview .ink-file-thumb--text .ink-file-thumb-label {
  background: #fff;
  color: #455a64;
}

#preview .ink-file-thumb--data .ink-file-thumb-face {
  background: linear-gradient(180deg, #5e35b1 0%, #5e35b1 32%, #ede7f6 32%);
}

#preview .ink-file-thumb--data .ink-file-thumb-label {
  background: #fff;
  color: #4527a0;
}

#preview .ink-file-thumb--archive .ink-file-thumb-face {
  background: linear-gradient(180deg, #f9a825 0%, #f9a825 32%, #fff8e1 32%);
}

#preview .ink-file-thumb--archive .ink-file-thumb-label {
  background: #fff;
  color: #e65100;
}

#preview .ink-file-thumb--image .ink-file-thumb-face {
  background: linear-gradient(145deg, #ec407a 0%, #7e57c2 48%, #42a5f5 100%);
}

#preview .ink-file-thumb--image .ink-file-thumb-face::after {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 10px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.35);
  box-shadow: 0 -3px 0 4px rgba(255, 255, 255, 0.2);
}

#preview .ink-file-thumb--image .ink-file-thumb-label {
  background: rgba(255, 255, 255, 0.95);
  color: #ad1457;
}

#preview .ink-file-thumb--video .ink-file-thumb-face {
  background: linear-gradient(180deg, #37474f 0%, #263238 100%);
}

#preview .ink-file-thumb--video .ink-file-thumb-face::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-40%, -50%);
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.92);
}

#preview .ink-file-thumb--video .ink-file-thumb-label {
  background: #eceff1;
  color: #263238;
}

#preview .ink-file-thumb--audio .ink-file-thumb-face {
  background: linear-gradient(180deg, #3949ab 0%, #283593 100%);
}

#preview .ink-file-thumb--audio .ink-file-thumb-face::before {
  content: '';
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 10px;
  height: 18px;
  background: repeating-linear-gradient(90deg,
      rgba(255, 255, 255, 0.65) 0 3px,
      transparent 3px 7px);
  border-radius: 2px;
  opacity: 0.85;
}

#preview .ink-file-thumb--audio .ink-file-thumb-label {
  background: #e8eaf6;
  color: #1a237e;
}

#preview .ink-file-thumb--code .ink-file-thumb-face {
  background: linear-gradient(180deg, #263238 0%, #37474f 55%, #eceff1 55%);
}

#preview .ink-file-thumb--code .ink-file-thumb-face::after {
  content: '</>';
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono), monospace;
  color: rgba(236, 239, 241, 0.95);
  letter-spacing: -0.05em;
}

#preview .ink-file-thumb--code .ink-file-thumb-label {
  background: #fff;
  color: #37474f;
}

#preview .ink-file-thumb--web .ink-file-thumb-face {
  background: linear-gradient(180deg, #e65100 0%, #ef6c00 38%, #fff3e0 38%);
}

#preview .ink-file-thumb--web .ink-file-thumb-label {
  background: #fff;
  color: #e65100;
}

#preview .ink-file-thumb--generic .ink-file-thumb-face {
  background: linear-gradient(180deg, #8d6e63 0%, #8d6e63 30%, #efebe9 30%);
}

#preview .ink-file-thumb--generic .ink-file-thumb-label {
  background: #fff;
  color: #5d4037;
}

#preview .ink-file-meta {
  flex: 1 1 140px;
  min-width: 0;
  display: flex !important;
  flex-direction: column;
  gap: 6px;
}

#preview .ink-file-name {
  display: block;
  font-weight: 600;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
  color: var(--text);
}

#preview .ink-file-sub {
  display: block;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

#preview .ink-file-actions {
  display: flex !important;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
  pointer-events: auto;
}

#preview a.ink-file-open {
  display: inline-block;
  position: relative;
  z-index: 3;
  pointer-events: auto;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent) !important;
  text-decoration: none !important;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}

#preview a.ink-file-open:hover {
  filter: brightness(0.97);
}

#preview .ink-file-delete {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  background: var(--surface);
  color: var(--danger);
  font-family: var(--font-body);
  pointer-events: auto;
  position: relative;
  z-index: 3;
}

#preview .ink-file-delete:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

#preview .ink-file-delete:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Inline image attachments — Word-style preview + resize */
#preview .ink-file-host--image {
  display: block;
  margin: 0.5em 0 0.75em;
  max-width: 100%;
}

#preview .ink-file-image-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  margin: 0;
  line-height: 0;
  cursor: grab;
}

#preview .ink-file-host--image.ink-preview-widget--dragging,
#preview .ink-preview-widget--dragging {
  opacity: 0.42;
  pointer-events: none;
}

#preview .ink-file-host--image.ink-preview-widget--dragging .ink-file-image-wrap {
  cursor: grabbing;
}

.ink-preview-widget-drop-indicator {
  position: fixed;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
  z-index: 10000;
  display: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

#preview .ink-file-host:not(.ink-file-host--image) .ink-file-card,
#preview .ink-task-sticker,
#preview .ink-flashcard-host,
#preview .ink-whiteboard-sticker,
#preview .ink-chart-host,
#preview .ink-sheet-host,
#preview .ink-map-host,
#preview .ink-mermaid-host {
  cursor: grab;
}

#preview .ink-preview-widget--dragging {
  cursor: grabbing;
}

#preview .ink-file-image-preview {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
}

#preview .ink-file-host--image.ink-file-host--selected .ink-file-image-preview,
#preview .ink-file-host--image:hover .ink-file-image-preview,
#preview .ink-file-host--image.ink-file-host--resizing .ink-file-image-preview {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#preview .ink-file-image-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 2;
}

#preview .ink-file-host--image:hover .ink-file-image-toolbar,
#preview .ink-file-host--image.ink-file-host--selected .ink-file-image-toolbar,
#preview .ink-file-host--image.ink-file-host--resizing .ink-file-image-toolbar {
  opacity: 1;
  pointer-events: auto;
}

#preview .ink-file-image-toolbar .ink-file-open,
#preview .ink-file-image-toolbar .ink-file-delete,
#preview .ink-file-image-toolbar .ink-file-meta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  min-height: 28px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  line-height: 1;
  white-space: nowrap;
  border-radius: 999px;
  text-decoration: none !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  position: relative;
  z-index: 3;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}

#preview .ink-file-image-toolbar .ink-file-open {
  background: var(--accent-light);
  color: var(--accent) !important;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}

#preview .ink-file-image-toolbar .ink-file-open:hover {
  filter: brightness(0.97);
}

#preview .ink-file-image-toolbar .ink-file-meta-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

#preview .ink-file-image-toolbar .ink-file-meta-btn:hover {
  background: var(--tag-bg);
}

#preview .ink-file-image-toolbar .ink-file-delete {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
}

#preview .ink-file-image-toolbar .ink-file-delete:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

#preview .ink-file-image-toolbar .ink-file-delete:focus,
#preview .ink-file-image-toolbar .ink-file-meta-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#preview .ink-file-image-toolbar .ink-file-meta-btn--pending,
#preview .ink-file-host--image.ink-file-host--analyzing .ink-file-image-toolbar .ink-file-meta-btn {
  opacity: 0.85;
  cursor: wait;
}

.ink-image-meta-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  max-height: min(52vh, 420px);
  overflow: auto;
}

.ink-image-meta-empty {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-muted);
}

.ink-image-meta-section {
  margin: 0 0 14px;
}

.ink-image-meta-section h4 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.ink-image-meta-section p {
  margin: 0;
}

.ink-image-meta-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ink-image-meta-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--tag-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.ink-image-meta-foot {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-faint);
}

#preview .ink-file-image-resize {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 2px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 3;
  box-sizing: border-box;
}

#preview .ink-file-host--image:hover .ink-file-image-resize,
#preview .ink-file-host--image.ink-file-host--selected .ink-file-image-resize,
#preview .ink-file-host--image.ink-file-host--resizing .ink-file-image-resize {
  opacity: 1;
}

#preview strong {
  font-weight: 600;
}

#preview em {
  font-style: italic;
}

#preview del {
  text-decoration: line-through;
  color: var(--text-muted);
}

#preview ul,
#preview ol {
  padding-left: 1.5em;
  margin: 0 0 0.5em;
  line-height: 1.55;
}

#preview li {
  margin-bottom: 0.1em;
}

#preview li input[type=checkbox] {
  margin-right: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

#preview li input.ink-task-cb {
  flex-shrink: 0;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker {
  margin: 0 0 0.65em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 92%, var(--tag-bg));
  padding: 10px 12px;
  width: fit-content;
  box-sizing: border-box;
  cursor: pointer;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-inner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-marker {
  flex-shrink: 0;
  width: 5px;
  align-self: stretch;
  min-height: 2.25em;
  border-radius: 3px;
  background: var(--accent);
  opacity: 0.85;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker[data-inktask-status="done"] .ink-task-sticker-marker,
:is(#preview, #ai-chat-messages) .ink-task-sticker[data-inktask-checked="1"] .ink-task-sticker-marker {
  background: var(--text-faint);
  opacity: 0.55;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker[data-inktask-status="backlog"] .ink-task-sticker-marker {
  background: var(--text-faint);
}

:is(#preview, #ai-chat-messages) .ink-task-sticker[data-inktask-status="doing"] .ink-task-sticker-marker {
  background: color-mix(in srgb, var(--accent) 70%, var(--tag-bg));
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-body {
  flex: 1;
  min-width: 0;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-title {
  font-weight: 400;
  font-size: 0.98em;
  color: var(--text);
  line-height: 1.35;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-title.done {
  text-decoration: line-through;
  opacity: 0.78;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.45;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

:is(#preview, #ai-chat-messages) .ink-task-sticker-chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--tag-bg);
  color: var(--text);
  font-size: 10.5px;
}

/* Whiteboard sticker in note — opens full modal on click */
#preview .ink-whiteboard-sticker {
  margin: 8px 0;
  display: inline-block;
  max-width: 100%;
  vertical-align: middle;
}

#preview .ink-wb-sticker-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 252, 246, 0.98), rgba(236, 226, 210, 0.65));
  box-shadow: 0 2px 8px rgba(42, 32, 20, 0.08);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: border-color 0.12s, box-shadow 0.12s;
}

#preview .ink-wb-sticker-btn:hover {
  border-color: rgba(61, 107, 79, 0.45);
  box-shadow: 0 4px 14px rgba(42, 32, 20, 0.12);
}

#preview .ink-wb-sticker-icon {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
}

#preview .ink-wb-sticker-label {
  flex: 1;
  min-width: 0;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-host {
  margin: 0 0 0.7em;
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  font-family: var(--font-serif);
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  order: 2;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, #fff 6%);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 11.5px;
  padding: 5px 8px;
  min-width: 54px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-btn:hover {
  background: color-mix(in srgb, var(--accent-light) 50%, var(--surface));
  color: var(--text);
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-btn.del {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-btn.del:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  --flashcard-bg-a: color-mix(in srgb, var(--surface) 82%, #fff 18%);
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 58%, var(--surface));
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 78%, var(--accent-light));
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: color-mix(in srgb, var(--border) 70%, var(--surface) 30%);
  --flashcard-shadow: var(--shadow-md, var(--shadow)), 0 1px 0 color-mix(in srgb, #fff 22%, transparent);
  --flashcard-shadow-hover: var(--shadow-md, var(--shadow)), 0 18px 40px color-mix(in srgb, var(--accent) 12%, transparent);
  --flashcard-glow: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 1px solid var(--flashcard-border);
  border-radius: 18px;
  background:
    radial-gradient(140% 100% at 100% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 52%),
    radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--surface) 40%, transparent), transparent 58%),
    linear-gradient(155deg, var(--flashcard-bg-a), var(--flashcard-bg-b));
  box-shadow: var(--flashcard-shadow);
  min-width: min(315px, calc((100vw - 84px) * 0.75));
  max-width: min(510px, calc((100vw - 84px) * 0.75));
  min-height: 172px;
  padding: 0;
  cursor: pointer;
  position: relative;
  display: block;
  perspective: 1200px;
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.22s ease, border-color 0.2s ease;
  font-family: inherit;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card:hover {
  transform: translateY(-2px) scale(1.006);
  box-shadow: var(--flashcard-shadow-hover);
  border-color: color-mix(in srgb, var(--accent) 38%, var(--flashcard-border));
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card::before {
  content: '';
  position: absolute;
  inset: -35% auto auto -22%;
  width: 64%;
  aspect-ratio: 1 / 1;
  background: radial-gradient(circle at center, var(--flashcard-glow), transparent 72%);
  pointer-events: none;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card::after {
  content: '';
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg,
      transparent,
      color-mix(in srgb, var(--accent) 70%, transparent),
      transparent);
  opacity: 0.75;
  pointer-events: none;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  min-height: calc(100% - 24px);
  max-height: calc(100% - 24px);
  border: 1px solid color-mix(in srgb, var(--flashcard-border) 45%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 88%, var(--tag-bg) 12%);
  padding: 4px 4px 3px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 0.72, 0.24, 1), opacity 0.22s ease;
  opacity: 1;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 35%, transparent);
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-front .ink-flashcard-text.ink-flashcard-q {
  font-size: 1.12em;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.36;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-text.ink-flashcard-answer {
  font-weight: 650;
  font-size: 1.04em;
  letter-spacing: -0.015em;
  line-height: 1.42;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-detail-wrap {
  margin-top: 4px;
  padding: 10px 0 0;
  border-top: 1px solid color-mix(in srgb, var(--flashcard-border) 50%, transparent);
  width: 100%;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-text.ink-flashcard-detail {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-muted);
  font-weight: 450;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-pill {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--flashcard-pill-text);
  background: var(--flashcard-pill-bg);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 2px 7px;
  font-weight: 600;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-text {
  white-space: pre-wrap;
  line-height: 1.48;
  color: var(--text);
  font-size: 15.5px;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-hint {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-faint);
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-front {
  transform: rotateY(0deg);
  text-align: center;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-back {
  transform: rotateY(180deg);
  justify-content: center;
  text-align: center;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-host.is-flipped .ink-flashcard-front {
  transform: rotateY(180deg);
  opacity: 0;
}

:is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-host.is-flipped .ink-flashcard-back {
  transform: rotateY(360deg);
  opacity: 1;
}

#flashcard-from-slash-modal .flashcard-modal-preview-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}

#flashcard-from-slash-modal .flashcard-modal-preview-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 6px;
}

#flashcard-from-slash-modal .flashcard-modal-preview-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
  margin: 0 0 10px;
}

#flashcard-from-slash-live-preview .flashcard-modal-preview-placeholder {
  padding: 20px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.45;
  border: 1px dashed color-mix(in srgb, var(--border) 80%, var(--accent) 20%);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 94%, var(--tag-bg));
}

#flashcard-from-slash-live-preview .ink-flashcard-host {
  margin-bottom: 0;
  width: 100%;
  max-width: 100%;
}

#flashcard-from-slash-live-preview .ink-flashcard-card {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  min-height: 148px;
}

/* Theme-specific flash cards: derived from each theme’s tokens (+ small character tweaks). */
html[data-theme="garden"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  --flashcard-bg-a: color-mix(in srgb, var(--surface) 52%, #fff 48%);
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 72%, var(--garden-sage) 10%);
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 82%, var(--garden-terracotta) 6%);
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: color-mix(in srgb, var(--border) 78%, var(--garden-sage) 12%);
  --flashcard-glow: color-mix(in srgb, var(--accent) 24%, transparent);
  --flashcard-shadow: var(--shadow-md);
  --flashcard-shadow-hover: 0 14px 36px rgba(42, 32, 20, 0.18);
}

html[data-theme="calm"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  -webkit-backdrop-filter: blur(12px) saturate(1.05);
  backdrop-filter: blur(12px) saturate(1.05);
  --flashcard-bg-a: color-mix(in srgb, var(--surface) 88%, #fff 12%);
  --flashcard-bg-b: color-mix(in srgb, var(--accent-light) 48%, var(--surface));
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 65%, var(--accent-light));
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: color-mix(in srgb, var(--border) 55%, var(--accent) 18%);
  --flashcard-glow: color-mix(in srgb, var(--accent) 20%, transparent);
  --flashcard-shadow: var(--shadow-md);
  --flashcard-shadow-hover: var(--shadow-md);
}

html[data-theme="glass"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  -webkit-backdrop-filter: var(--glass-blur-light, blur(22px)) var(--glass-sat, saturate(1.1));
  backdrop-filter: var(--glass-blur-light, blur(22px)) var(--glass-sat, saturate(1.1));
  --flashcard-bg-a: color-mix(in srgb, var(--surface) 92%, #fff 8%);
  --flashcard-bg-b: color-mix(in srgb, var(--surface) 55%, var(--accent-light) 45%);
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 70%, var(--accent-light));
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: color-mix(in srgb, var(--border) 70%, #fff 30%);
  --flashcard-glow: color-mix(in srgb, var(--garden-sage) 22%, transparent);
  --flashcard-shadow: var(--shadow-md), var(--card-lift);
  --flashcard-shadow-hover: 0 22px 48px rgba(15, 55, 48, 0.16);
}

html[data-theme="neu"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border: none;
  border-radius: 20px;
  --flashcard-bg-a: var(--surface);
  --flashcard-bg-b: color-mix(in srgb, var(--surface) 72%, var(--tag-bg));
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 80%, var(--accent-light));
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: transparent;
  --flashcard-glow: color-mix(in srgb, var(--accent) 16%, transparent);
  --flashcard-shadow: var(--neu-out-sm);
  --flashcard-shadow-hover: var(--neu-out);
}

html[data-theme="neu"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  border: none;
  border-radius: 14px;
  box-shadow: var(--neu-in-sm);
  background: color-mix(in srgb, var(--surface) 94%, #fff 6%);
}

html[data-theme="bento"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border-radius: var(--bento-radius-sm, 14px);
  --flashcard-bg-a: color-mix(in srgb, var(--surface) 94%, var(--accent-light));
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 42%, var(--surface));
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 88%, var(--accent) 8%);
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: color-mix(in srgb, var(--border) 80%, var(--accent) 20%);
  --flashcard-glow: color-mix(in srgb, var(--accent) 14%, transparent);
  --flashcard-shadow: var(--shadow-md);
  --flashcard-shadow-hover: var(--shadow-md);
}

html[data-theme="terminal"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border-radius: 4px;
  --flashcard-bg-a: var(--surface);
  --flashcard-bg-b: color-mix(in srgb, var(--surface) 65%, var(--tag-bg));
  --flashcard-border: var(--border);
  --flashcard-pill-bg: var(--tag-bg);
  --flashcard-pill-text: var(--accent);
  --flashcard-glow: color-mix(in srgb, var(--text) 12%, transparent);
  --flashcard-shadow: var(--shadow-md), 0 0 28px color-mix(in srgb, var(--text) 6%, transparent);
  --flashcard-shadow-hover: var(--shadow-md), 0 0 40px color-mix(in srgb, var(--accent) 10%, transparent);
}

html[data-theme="terminal"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  background: color-mix(in srgb, var(--surface) 88%, var(--tag-bg));
  border: 1px dashed color-mix(in srgb, var(--border) 75%, transparent);
  border-radius: 2px;
}

html[data-theme="terminal"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-pill {
  border-color: var(--border);
  color: var(--accent);
  background: var(--tag-bg);
}

html[data-theme="terminal"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-text {
  color: var(--text);
  text-shadow: 0 0 12px color-mix(in srgb, var(--text) 22%, transparent);
}

html[data-theme="terminal"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-hint {
  color: var(--text-faint);
}

html[data-theme="paper"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  --flashcard-bg-a: color-mix(in srgb, var(--surface) 88%, var(--bg));
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 62%, var(--surface));
  --flashcard-pill-bg: color-mix(in srgb, var(--tag-bg) 75%, var(--accent-light));
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: color-mix(in srgb, var(--border) 85%, var(--accent) 15%);
  --flashcard-glow: color-mix(in srgb, var(--accent) 14%, transparent);
  --flashcard-shadow: var(--shadow-md);
  --flashcard-shadow-hover: var(--shadow-md);
}

html[data-theme="paper"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  border-style: solid;
  border-width: 1px;
  border-color: color-mix(in srgb, var(--border) 90%, var(--accent) 10%);
}

html[data-theme="swiss"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border-radius: 0;
  border-width: 2px;
  --flashcard-bg-a: var(--surface);
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 35%, var(--surface));
  --flashcard-pill-bg: var(--text);
  --flashcard-pill-text: var(--surface);
  --flashcard-border: var(--border);
  --flashcard-glow: transparent;
  --flashcard-shadow: none;
  --flashcard-shadow-hover: none;
}

html[data-theme="swiss"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card::before {
  display: none;
}

html[data-theme="swiss"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card::after {
  display: none;
}

html[data-theme="swiss"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-pill {
  border-color: var(--border);
  border-width: 2px;
}

html[data-theme="swiss"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  border-style: solid;
  border-width: 2px;
  border-color: var(--border);
  border-radius: 0;
  background: var(--surface);
}

html[data-theme="swiss"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card:hover {
  transform: none;
  border-color: var(--accent);
  box-shadow: 4px 4px 0 var(--accent);
}

html[data-theme="magazine"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border-left: 4px solid var(--accent);
  --flashcard-bg-a: var(--surface);
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 38%, var(--surface));
  --flashcard-pill-bg: color-mix(in srgb, var(--accent-light) 55%, var(--tag-bg));
  --flashcard-pill-text: var(--accent);
  --flashcard-border: var(--border);
  --flashcard-glow: color-mix(in srgb, var(--accent) 10%, transparent);
  --flashcard-shadow: var(--shadow-md);
  --flashcard-shadow-hover: var(--shadow-md);
}

html[data-theme="memphis"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border-radius: 0;
  border: var(--memphis-outline);
  --flashcard-bg-a: var(--surface);
  --flashcard-bg-b: color-mix(in srgb, var(--garden-sky) 14%, color-mix(in srgb, var(--tag-bg) 30%, var(--surface)));
  --flashcard-pill-bg: var(--tag-bg);
  --flashcard-pill-text: var(--text);
  --flashcard-border: var(--border);
  --flashcard-glow: color-mix(in srgb, var(--accent) 18%, transparent);
  --flashcard-shadow: var(--card-lift);
  --flashcard-shadow-hover: var(--shadow-md);
}

html[data-theme="memphis"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-pill {
  border-width: 2px;
  border-color: var(--border);
}

html[data-theme="memphis"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  border-radius: 0;
  border: 2px dashed var(--border);
  background: color-mix(in srgb, var(--surface) 92%, var(--garden-sky) 8%);
}

html[data-theme="cartoon"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
  border-radius: var(--cartoon-radius-sm);
  border: 2px solid var(--border);
  --flashcard-bg-a: var(--surface);
  --flashcard-bg-b: color-mix(in srgb, var(--tag-bg) 32%, var(--surface));
  --flashcard-pill-bg: var(--tag-bg);
  --flashcard-pill-text: var(--text-muted);
  --flashcard-border: var(--border);
  --flashcard-glow: color-mix(in srgb, var(--accent) 20%, transparent);
  --flashcard-shadow: none;
  --flashcard-shadow-hover: none;
}

html[data-theme="cartoon"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--border);
  border-color: var(--accent);
}

html[data-theme="cartoon"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-pill {
  border-width: 2px;
  border-color: var(--border);
}

html[data-theme="cartoon"] :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-face {
  border: 2px solid color-mix(in srgb, var(--border) 85%, var(--accent) 15%);
  border-radius: var(--cartoon-radius-sm);
  background: color-mix(in srgb, var(--surface) 90%, var(--garden-sky) 10%);
}

@media (max-width: 700px) {
  :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-host {
    width: 100%;
    max-width: 100%;
  }

  #btn-ai-chat .tb-btn-ai-icon {
    width: 50px;
    height: 50px;
  }

  :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-card {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-side {
    gap: 4px;
  }

  :is(#preview, #flashcard-from-slash-live-preview, #ai-chat-messages) .ink-flashcard-btn {
    min-width: 48px;
    padding: 5px 6px;
    font-size: 11px;
  }
}

#preview .ink-math-wrap {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  vertical-align: middle;
}

#preview .ink-math-wrap[data-ink-display="1"] {
  display: block;
  margin: 0.6em auto;
  text-align: center;
}

#preview .ink-math-error {
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

#preview .katex {
  font-size: 1.05em;
  color: var(--text);
}

#preview .katex-display {
  margin: 0.6em 0;
}

#preview sup.footnote-ref {
  font-size: 0.72em;
  vertical-align: super;
  line-height: 0;
}

#preview sup.footnote-ref a {
  text-decoration: none;
  color: var(--accent);
  font-weight: 600;
}

#preview sup.footnote-ref a:hover {
  text-decoration: underline;
}

#preview .ink-footnotes {
  margin-top: 1.5em;
  padding-top: 0.75em;
  font-size: 0.92em;
  color: var(--text-muted);
  user-select: text;
}

#preview .ink-fn-sep {
  margin: 0 0 0.75em;
  border: none;
  border-top: 1px solid var(--border);
}

#preview .ink-fn-list {
  padding-left: 1.2em;
  margin: 0;
}

#preview .ink-fn-list li {
  margin: 0.35em 0;
  position: relative;
  padding-right: 1.5em;
}

#preview .ink-fn-backwrap {
  position: absolute;
  right: 0;
  top: 0;
}

#preview .ink-fn-backref {
  font-size: 0.85em;
  text-decoration: none;
  color: var(--accent);
}

.preview-float-toc {
  position: absolute;
  top: 10px;
  right: 8px;
  z-index: 4;
  max-width: min(200px, 42%);
  pointer-events: none;
}

.preview-float-toc-inner {
  pointer-events: auto;
  text-align: right;
}

.preview-float-toc-toggle {
  font-family: var(--font-body);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.preview-float-toc-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
}

.preview-float-toc-list {
  margin-top: 6px;
  max-height: min(42vh, 280px);
  overflow-y: auto;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow-md);
  text-align: left;
  font-size: 11px;
  line-height: 1.35;
}

.preview-float-toc-list button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 2px;
  border-radius: 4px;
  font-family: var(--font-body);
}

.preview-float-toc-list button:hover {
  background: var(--accent-light);
  color: var(--text);
}

#preview blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 0.55em;
  padding: 0.35em 0.9em;
  line-height: 1.55;
  background: var(--accent-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-muted);
}

#preview code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--tag-bg);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--text);
}

#preview pre {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85em 1em;
  overflow-x: auto;
  margin: 0 0 0.55em;
  line-height: 1.45;
}

#preview pre code {
  background: none;
  padding: 0;
  font-size: 0.88em;
}

#preview .ink-code-block-host {
  margin: 0 0 0.55em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--tag-bg);
  overflow: hidden;
  max-width: 100%;
}

#preview .ink-code-block-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
}

#preview .ink-code-copy-all {
  font-family: var(--font-body);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  color: var(--text-muted);
  cursor: pointer;
}

#preview .ink-code-copy-all:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-light);
}

#preview .ink-code-block-main {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: 0;
}

#preview .ink-code-line-gutter {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0.85em 0 0.85em 4px;
  user-select: none;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

#preview .ink-code-line-gutter-row {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  min-height: calc(1.45 * 1em);
  line-height: 1.45;
}

#preview .ink-code-copy-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5em;
  height: 1.45em;
  padding: 0 2px;
  margin: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.72em;
  line-height: 1;
  cursor: pointer;
  opacity: 0.4;
}

#preview .ink-code-line-gutter-row:hover .ink-code-copy-line,
#preview .ink-code-copy-line:focus {
  opacity: 1;
  color: var(--accent);
  background: var(--accent-light);
}

#preview .ink-code-block-main>pre {
  flex: 1 1 auto;
  margin: 0;
  border: none;
  border-radius: 0;
  min-width: 0;
}

:is(#preview, #ai-chat-messages) .ink-mermaid-host {
  margin: 0 0 0.7em;
  overflow-x: auto;
  position: relative;
}

:is(#preview, #ai-chat-messages) .ink-mermaid-host textarea.ink-mermaid-source {
  display: none !important;
}

:is(#preview, #ai-chat-messages) .ink-mermaid-host svg {
  max-width: 100%;
  height: auto;
}

/* Chart.js blocks: ```chart … ``` — JSON config, rendered in preview + AI chat */
:is(#preview, #ai-chat-messages) .ink-chart-host {
  margin: 0 0 0.7em;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-sizing: border-box;
}

:is(#preview, #ai-chat-messages) .ink-chart-host textarea.ink-chart-source {
  display: none !important;
}

:is(#preview, #ai-chat-messages) .ink-chart-canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 220px;
  max-height: min(420px, 55vh);
}

:is(#preview, #ai-chat-messages) .ink-chart-error {
  margin: 0.35em 0 0;
  color: var(--danger);
  font-size: 0.86em;
  font-family: var(--font-body);
}

#ai-chat-messages .ink-chart-host {
  max-width: min(382px, 100%);
}

.ink-chart-toolbar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  border-radius: 4px;
  background: transparent;
  transition: opacity 0.18s ease, background 0.18s ease;
  z-index: 3;
  pointer-events: none;
}

#preview .ink-chart-host:hover .ink-chart-toolbar {
  opacity: 1;
}

.ink-chart-toolbar button {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
  backdrop-filter: blur(2px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.ink-chart-toolbar button:hover {
  background: var(--tag-bg);
}

.ink-chart-delete-btn:hover {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
}

/* `{inkmap:…}` — Leaflet + OSM (see /maps modal) */
:is(#preview, #ai-chat-messages) .ink-map-host {
  margin: 0 0 0.7em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-sizing: border-box;
  overflow: hidden;
  width: 325px;
  height: 325px;
}

:is(#preview, #ai-chat-messages) .ink-map-canvas-wrap {
  position: relative;
  width: 100%;
  height: min(240px, 42vh);
  min-height: 180px;
}

:is(#preview, #ai-chat-messages) .ink-map-leaflet {
  width: 100%;
  height: 100%;
}

:is(#preview, #ai-chat-messages) .ink-map-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  border-top: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--tag-bg) 40%, var(--surface));
  flex-direction: column;
}

:is(#preview, #ai-chat-messages) .ink-map-caption a {
  font-weight: 600;
}

:is(#preview, #ai-chat-messages) .ink-map-label {
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

#ai-chat-messages .ink-map-host {
  max-width: min(382px, 100%);
}

.maps-modal-map-outer {
  width: 100%;
  height: 240px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 4px;
  background: var(--tag-bg);
}

.maps-modal-leaflet {
  width: 100%;
  height: 100%;
}

.maps-slash-modal-box .leaflet-container {
  font-family: var(--font-body), system-ui, sans-serif;
}

.maps-from-slash-field-wrap {
  position: relative;
  width: 100%;
  margin-bottom: 10px;
}

.maps-from-slash-field-wrap .maps-from-slash-input {
  width: 100%;
  box-sizing: border-box;
}

.maps-from-slash-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 10;
  margin-top: 2px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.maps-from-slash-suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
  border: none;
  border-bottom: 1px solid var(--border-light);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body), system-ui, sans-serif;
}

.maps-from-slash-suggest-item:last-child {
  border-bottom: none;
}

.maps-from-slash-suggest-item:hover,
.maps-from-slash-suggest-item.active {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

/* ```sheet — JSON grid + =SUM / cell refs */
:is(#preview, #ai-chat-messages) .ink-sheet-host {
  margin: 0 0 0.7em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-sizing: border-box;
  overflow: hidden;
}

/* Workbook (x-spreadsheet) preview: shrink-wrap to grid viewport — not full note width */
:is(#preview, #ai-chat-messages) .ink-sheet-host.ink-sheet-host--xs-preview {
  width: fit-content;
  width: -moz-fit-content;
  max-width: 100%;
}

:is(#preview, #ai-chat-messages) .ink-sheet-host textarea.ink-sheet-source {
  display: none !important;
}

.ink-sheet-topbar {
  display: flex;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-light);
  background: color-mix(in srgb, var(--tag-bg) 50%, var(--surface));
}

.ink-sheet-head-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

:is(#preview, #ai-chat-messages) .ink-sheet-table-wrap {
  position: relative;
  padding: 8px 10px 40px;
  max-height: min(380px, 52vh);
  overflow: auto;
}

/* Workbook preview: viewport up to 15×10, shrinks with data (+2 rows / +1 col padding), no inner scrollbars */
:is(#preview, #ai-chat-messages) .ink-sheet-host.ink-sheet-host--xs-preview .ink-sheet-table-wrap,
:is(#preview, #ai-chat-messages) .ink-sheet-host:has(.ink-sheet-xs-preview-mount) .ink-sheet-table-wrap {
  overflow: hidden;
  max-height: none;
}

/* Read-only x-spreadsheet embed (formatting persisted in JSON `workbook`) */
:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount {
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--surface);
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet {
  font-size: 12px;
  font-family: var(--font-body), system-ui, sans-serif;
  background: var(--surface) !important;
  color: var(--text) !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-sheet {
  background: var(--surface);
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-selector .x-spreadsheet-selector-area {
  border-color: var(--accent) !important;
  background: color-mix(in srgb, var(--accent) 14%, transparent) !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-selector .x-spreadsheet-selector-corner {
  border-color: var(--surface) !important;
  background: var(--accent) !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-selector .x-spreadsheet-selector-clipboard {
  border-color: var(--accent) !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-selector .x-spreadsheet-selector-autofill {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--text-muted)) !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 72%, var(--border-light));
  outline-offset: 2px;
}

:is(#preview, #ai-chat-messages) .ink-sheet-xs-preview-mount .x-spreadsheet-resizer .x-spreadsheet-resizer-line {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border-light)) !important;
}

:is(#preview, #ai-chat-messages) .ink-sheet-table {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 100%;
  min-width: 280px;
}

:is(#preview, #ai-chat-messages) .ink-sheet-table th,
:is(#preview, #ai-chat-messages) .ink-sheet-table td {
  border: 1px solid var(--border-light);
  padding: 4px 8px;
  text-align: right;
  background: var(--surface);
  color: var(--text);
}

:is(#preview, #ai-chat-messages) .ink-sheet-table th.ink-sheet-corner,
:is(#preview, #ai-chat-messages) .ink-sheet-table th.ink-sheet-col-h,
:is(#preview, #ai-chat-messages) .ink-sheet-table th.ink-sheet-row-h {
  background: color-mix(in srgb, var(--tag-bg) 70%, var(--surface));
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  user-select: none;
}

:is(#preview, #ai-chat-messages) .ink-sheet-cell--formula {
  font-style: italic;
  color: var(--text-muted);
}

:is(#preview, #ai-chat-messages) .ink-sheet-cell--err {
  color: var(--danger);
  font-weight: 600;
}

:is(#preview, #ai-chat-messages) .ink-sheet-error {
  margin: 0.35em 0 0;
  color: var(--danger);
  font-size: 0.86em;
  font-family: var(--font-body);
}

#ai-chat-messages .ink-sheet-host {
  max-width: min(382px, 100%);
}

.ink-sheet-toolbar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 8px;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.18s ease, background 0.18s ease;
  /* Above x-spreadsheet canvas/overlayer (z-index ~12) so ✏ / ✕ stay clickable */
  z-index: 30;
  pointer-events: none;
}

#preview .ink-sheet-host:hover .ink-sheet-toolbar {
  opacity: 1;
}

.ink-sheet-toolbar button {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
  backdrop-filter: blur(2px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.ink-sheet-toolbar button:hover {
  background: var(--tag-bg);
}

.ink-sheet-delete-btn:hover {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
}

.sheet-editor-modal-box {
  width: min(1680px, 99.5vw);
  max-height: min(96vh, 1220px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* x-spreadsheet host inside sheet modal */
.sheet-editor-grid-scroll.sheet-editor-xs-sheet {
  flex: 1;
  min-height: min(440px, 52vh);
  height: min(72vh, 900px);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: var(--surface);
}

#sheet-editor-modal .sheet-editor-xs-sheet>.x-spreadsheet {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  box-sizing: border-box;
  font-family: var(--font-body), system-ui, sans-serif !important;
  background: var(--surface) !important;
  color: var(--text) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-sheet {
  width: 100%;
  background: var(--surface);
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-toolbar,
#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-bottombar {
  background: color-mix(in srgb, var(--tag-bg) 88%, var(--surface)) !important;
  border-color: var(--border-light) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-toolbar {
  border-bottom: 1px solid var(--border-light) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-toolbar-divider {
  border-right-color: var(--border-light) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-menu>li {
  color: var(--text-muted) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-menu>li.active {
  background-color: var(--surface) !important;
  color: var(--text) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-toolbar-btn:hover,
#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-toolbar-btn.active {
  background: color-mix(in srgb, var(--text) 10%, transparent) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-selector .x-spreadsheet-selector-area {
  border-color: var(--accent) !important;
  background: color-mix(in srgb, var(--accent) 14%, transparent) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-selector .x-spreadsheet-selector-corner {
  border-color: var(--surface) !important;
  background: var(--accent) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-selector .x-spreadsheet-selector-clipboard {
  border-color: var(--accent) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-selector .x-spreadsheet-selector-autofill {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--text-muted)) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-resizer .x-spreadsheet-resizer-line {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border-light)) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-scroll button {
  background: var(--tag-bg) !important;
  border-color: var(--border-light) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-contextmenu,
#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-suggest,
#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-sort-filter {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-light) !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-modal {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border-light) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-modal-header {
  background: color-mix(in srgb, var(--tag-bg) 90%, var(--surface)) !important;
  border-bottom: 1px solid var(--border-light) !important;
  color: var(--text) !important;
}

#sheet-editor-modal .sheet-editor-xs-sheet .x-spreadsheet-dropdown-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border-light) !important;
}

/* Panels sometimes render under `body` while the modal is open */
body:has(#sheet-editor-modal:not([hidden])) .x-spreadsheet-contextmenu,
body:has(#sheet-editor-modal:not([hidden])) .x-spreadsheet-suggest {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border-light) !important;
}

body:has(#sheet-editor-modal:not([hidden])) .x-spreadsheet-modal {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border-light) !important;
}

#sheet-editor-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 1.2em;
  margin: 0;
}

#sheet-editor-modal[hidden] {
  display: none !important;
}

:is(#preview, #ai-chat-messages) .ink-mermaid-error {
  margin: 0.45em 0 0;
  color: var(--danger);
  font-size: 0.86em;
  font-family: var(--font-body);
}

/* Hide the temporary render containers mermaid v10 injects as direct children of <body>.
   Scoped to body > to avoid hiding the SVG elements mermaid puts inside our preview host. */
body>[id^="ink-mermaid-"] {
  visibility: hidden !important;
  position: absolute !important;
  top: -9999px !important;
  left: -9999px !important;
  pointer-events: none !important;
}

/* ink-mermaid-svg shrink-wraps the SVG so the overlay is scoped to the diagram area */
:is(#preview, #ai-chat-messages) .ink-mermaid-host .ink-mermaid-svg {
  display: inline-block;
  position: relative;
  max-width: 100%;
}

/* ~25% narrower than note-preview-style cap (matches flashcard max scale in chat). */
#ai-chat-messages .ink-mermaid-host--ai-chat {
  max-width: min(382px, 100%);
  box-sizing: border-box;
}

#ai-chat-messages .ink-mermaid-host--ai-chat .ink-mermaid-svg {
  max-width: 100%;
}

.ink-mermaid-toolbar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  border-radius: 4px;
  background: transparent;
  transition: opacity 0.18s ease, background 0.18s ease;
  z-index: 3;
  pointer-events: none;
  /* let clicks reach the SVG text elements underneath */
}

#preview .ink-mermaid-host:hover .ink-mermaid-toolbar {
  opacity: 1;
}

.ink-mermaid-toolbar button {
  pointer-events: auto;
  /* buttons themselves must be clickable */
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
  backdrop-filter: blur(2px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.ink-mermaid-toolbar button:hover {
  background: var(--tag-bg);
}

.ink-mermaid-delete-btn:hover {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
}

/* Inline label editor that floats over the clicked SVG text */
.ink-mermaid-inline-input {
  position: fixed;
  z-index: 310;
  padding: 2px 6px;
  border: 1.5px solid var(--accent, #7c6f5a);
  border-radius: 4px;
  background: var(--surface, #f5eedd);
  color: var(--text, #3a2f1e);
  font-family: var(--font-body, sans-serif);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  outline: none;
  box-sizing: border-box;
  width: auto;
  min-width: 0;
  max-width: min(90vw, 720px);
  transform: translateY(-50%);
}

.mermaid-editor-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.mermaid-editor-pane-label {
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
  color: var(--text-muted);
}

#mermaid-editor-input {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}

#mermaid-editor-preview {
  min-height: 280px;
  max-height: 58vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px;
}

#mermaid-editor-preview svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

#mermaid-editor-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 1.2em;
  margin: 0 0 8px;
}

#chart-editor-input {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}

#chart-editor-preview {
  min-height: 280px;
  max-height: 58vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 10px;
}

#chart-editor-preview canvas {
  max-width: 100% !important;
  height: auto !important;
  display: block;
  margin: 0 auto;
}

#chart-editor-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 1.2em;
  margin: 0 0 8px;
}

@media (max-width: 860px) {
  .mermaid-editor-grid {
    grid-template-columns: 1fr;
  }
}

#preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25em 0;
}

#preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 0.55em;
  font-size: 0.92em;
  line-height: 1.45;
}

#preview .ink-table-host {
  margin: 0 0 0.55em;
  max-width: 100%;
}

#preview .ink-table-host>table {
  margin: 0;
  width: 100%;
}

#preview .ink-table-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
  user-select: none;
}

#preview .ink-table-toolbar button {
  font-family: var(--font-body);
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

#preview .ink-table-toolbar button:hover {
  background: var(--tag-bg);
}

#preview .ink-table-toolbar .ink-table-rem-col,
#preview .ink-table-toolbar .ink-table-rem-row {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

#preview .ink-table-toolbar .ink-table-rem-col:hover,
#preview .ink-table-toolbar .ink-table-rem-row:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

#preview .ink-table-toolbar .ink-table-delete {
  margin-left: auto;
  font-weight: 600;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

#preview .ink-table-toolbar .ink-table-delete:hover {
  background: color-mix(in srgb, var(--danger) 18%, var(--surface));
  color: var(--danger);
}

#preview th,
#preview td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

#preview th {
  background: var(--tag-bg);
  font-weight: 600;
  font-family: var(--font-body);
}

#preview img {
  max-width: 100%;
  border-radius: var(--radius);
}

#preview mark {
  background: #FFF176;
  border-radius: 2px;
  padding: 1px 2px;
}

/* STATUS BAR — flex footer of #editor-area (after #editor-page); matches column width, no absolute positioning */
#statusbar {
  height: 26px;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  flex-shrink: 0;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  font-size: 11.5px;
  color: var(--text-faint);
  font-family: var(--font-body);
}

#statusbar span {
  display: flex;
  align-items: center;
  gap: 4px;
}

#status-sync-wrap {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

#statusbar .btn-cloud-save {
  min-width: 0;
  height: 20px;
  padding: 0 7px;
  font-size: 11px;
}

#inkwell-auth-tabs .modal-btn {
  font-size: 12px;
}

#inkwell-auth-tabs .modal-btn.accent {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.inkwell-auth-input {
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.inkwell-auth-form label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
}

.inkwell-auth-form label:first-of-type {
  margin-top: 0;
}

#inkwell-auth-modal[hidden] {
  display: none !important;
}

#pdf-upload-modal[hidden] {
  display: none !important;
}

#task-from-slash-modal[hidden] {
  display: none !important;
}

#flashcard-from-slash-modal[hidden] {
  display: none !important;
}

#mermaid-editor-modal[hidden] {
  display: none !important;
}

#inkwell-e2ee-modal[hidden] {
  display: none !important;
}

#inkwell-e2ee-recovery-modal[hidden] {
  display: none !important;
}

#sync-merge-modal[hidden] {
  display: none !important;
}

#sync-explain-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text);
  flex-wrap: wrap;
}

#sync-explain-banner[hidden] {
  display: none !important;
}

#sync-explain-banner .sync-explain-text {
  flex: 1;
  min-width: 200px;
  line-height: 1.45;
}

#sync-explain-banner button {
  flex-shrink: 0;
}

#sync-merge-conflict-detail {
  max-height: 160px;
  overflow-y: auto;
  margin: 0 0 12px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
}

.sync-conflict-row {
  margin-bottom: 8px;
}

.sync-conflict-row:last-child {
  margin-bottom: 0;
}

.sync-conflict-meta {
  display: block;
  color: var(--text-muted);
  font-weight: normal;
  margin-top: 2px;
}

#status-sync-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

#btn-inkwell-account {
  font-family: var(--font-body);
}

#btn-inkwell-account.logged-in {
  color: var(--accent);
  border-color: rgba(47, 92, 72, 0.35);
  background: var(--accent-light);
}

#word-goal-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

#word-goal-progress {
  width: 60px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

#word-goal-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* VIEW MODES */
.view-editor #preview-wrap {
  display: none;
}

.view-editor #pane-divider {
  display: none;
}

.view-preview #md-input-wrap {
  display: none;
}

.view-preview #pane-divider {
  display: none;
}

.view-split #md-input-wrap,
.view-split #preview-wrap {
  flex: 1;
}

/* FOCUS MODE */
body.focus-mode #app {
  padding: 0;
  gap: 0;
}

body.focus-mode #titlebar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  margin: 0;
  border-radius: 0;
}

body.focus-mode #toolbar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

body.focus-mode #btn-ai-chat {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

body.focus-mode #sidebar {
  width: 0 !important;
}

body.focus-mode #ai-chat-panel {
  display: none !important;
}

body.focus-mode #statusbar {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

body.focus-mode #editor-area {
  margin-left: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
}

body.focus-mode #md-input {
  padding: 60px 15%;
  padding-bottom: calc(60px + var(--note-writing-tail));
  max-width: 100%;
}

body.focus-mode #md-input-wrap .CodeMirror-lines {
  padding: 60px 15%;
  padding-bottom: calc(60px + var(--note-writing-tail));
  max-width: 100%;
}

body.focus-mode:hover #titlebar,
body.focus-mode:hover #toolbar,
body.focus-mode:hover #statusbar,
body.focus-mode:hover #btn-ai-chat {
  opacity: 1;
  pointer-events: auto;
}

/* Note rename input */
#note-title-input {
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 30px;
  color: var(--text-faint);
  flex: 1;
  min-width: 0;
  width: auto;
  text-align: center;
  cursor: text;
  transition: color 0.18s;
}

#note-title-input:focus {
  color: var(--text);
}

/* Loading shimmer while note data is hydrating on page load */
@keyframes note-title-shimmer {
  0% {
    opacity: 0.18;
  }

  50% {
    opacity: 0.38;
  }

  100% {
    opacity: 0.18;
  }
}

#titlebar-top[data-note-loading] #note-title-input {
  pointer-events: none;
  color: transparent !important;
  border-radius: 6px;
  background: linear-gradient(90deg,
      color-mix(in srgb, var(--text-faint) 22%, transparent) 25%,
      color-mix(in srgb, var(--text-faint) 38%, transparent) 50%,
      color-mix(in srgb, var(--text-faint) 22%, transparent) 75%);
  background-size: 200% 100%;
  animation: note-title-shimmer 1.4s ease-in-out infinite;
  min-width: 180px;
  max-width: 320px;
  height: 34px;
  flex: 0 0 auto;
}

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

/* Cloud encrypt (Account modal, logged-in) */
#inkwell-auth-e2ee-wrap {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
}

.inkwell-auth-e2ee-options {
  margin: 0;
  padding: 0;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.inkwell-auth-e2ee-switch {
  flex: 1;
  min-width: 0;
}

.inkwell-auth-e2ee-unlock-btn {
  flex-shrink: 0;
  margin: 0;
  padding: 4px 8px;
  font-size: 11px;
  font-family: var(--font-body);
  color: var(--accent);
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
  border-radius: 8px;
  cursor: pointer;
}

.inkwell-auth-e2ee-unlock-btn:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.inkwell-auth-e2ee-hint {
  margin: 6px 0 0;
  font-size: 10px;
  line-height: 1.4;
  color: var(--text-faint);
}

#folder-list-wrap {
  padding: 4px 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 4px 4px;
}

/* Shared with me — notes invited by other users */
.shared-notes-wrap {
  margin: 8px 4px 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.shared-notes-wrap[hidden] {
  display: none !important;
}

.shared-notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 6px 6px;
}

.shared-notes-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.shared-notes-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  background: color-mix(in srgb, var(--border-light) 70%, transparent);
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.5;
}

.shared-notes-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 2px;
}

.shared-note-item {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}

.shared-note-item:hover {
  background: color-mix(in srgb, var(--border-light) 55%, transparent);
}

.shared-note-item.active {
  background: var(--accent-light);
  border-color: color-mix(in srgb, var(--accent) 18%, transparent);
}

.shared-note-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 4px 7px 8px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
}

.shared-note-icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: var(--accent);
  opacity: 0.85;
}

.shared-note-item.active .shared-note-icon {
  opacity: 1;
}

.shared-note-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shared-note-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.shared-note-item.active .shared-note-title {
  color: var(--accent);
}

.shared-note-meta {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--text-faint);
}

.shared-note-owner {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shared-note-sep {
  flex: 0 0 auto;
  opacity: 0.55;
}

.shared-note-time {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shared-note-leave {
  flex: 0 0 auto;
  align-self: center;
  margin-right: 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  padding: 4px 7px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.1s, color 0.1s, border-color 0.1s;
}

.shared-note-item:hover .shared-note-leave,
.shared-note-item:focus-within .shared-note-leave {
  opacity: 1;
}

.shared-note-leave:hover {
  color: var(--danger);
  border-color: rgba(200, 60, 60, 0.24);
  background: rgba(200, 60, 60, 0.1);
}

@media (hover: none),
(max-width: 700px) {
  .shared-note-leave {
    opacity: 1;
  }
}

#folder-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.folder-list .folder-panel-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.folder-list .folder-panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.folder-list .folder-quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.folder-list .folder-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 4px 1px 0;
}

.folder-list .folder-item {
  display: flex;
  align-items: center;
  min-width: 0;
  border-radius: 11px;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.12s;
}

.folder-list .folder-item.is-special {
  min-height: 54px;
}

.folder-list .folder-item.is-special .folder-name-btn {
  padding: 8px 9px;
}

.folder-list .folder-item:hover {
  color: var(--text);
}

.folder-list .folder-item.active {
  color: var(--accent);
  font-weight: 400;
}

.folder-list .folder-item.drop-target {
  border-color: color-mix(in srgb, var(--accent) 58%, transparent);
  border-style: dashed;
  background: color-mix(in srgb, var(--accent-light) 68%, transparent);
  color: var(--accent);
}

.folder-list .folder-user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.folder-list .folder-node {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.folder-list .folder-name-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
}

.folder-list .folder-name-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.folder-list .folder-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.25;
}

.folder-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  background: color-mix(in srgb, var(--surface) 65%, #fff 35%);
  color: color-mix(in srgb, var(--text) 85%, var(--accent) 15%);
  opacity: 0.9;
  margin-right: 0;
  font-size: 11px;
  flex-shrink: 0;
}

.folder-list .folder-item.active .folder-icon {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent-light) 85%, #fff 15%);
  color: var(--accent);
}

.folder-list .folder-count {
  font-size: 10.5px;
  color: color-mix(in srgb, var(--text-faint) 75%, var(--text));
  background: color-mix(in srgb, var(--tag-bg) 86%, #fff 14%);
  border: 1px solid color-mix(in srgb, var(--border-light) 70%, transparent);
  border-radius: 999px;
  padding: 1px 8px;
  flex-shrink: 0;
}

.folder-list .folder-del {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  opacity: 0.78;
}

.folder-list .folder-item:hover .folder-del {
  color: var(--danger);
}

.folder-list .folder-del:hover {
  background: rgba(200, 60, 60, 0.12);
  border-color: rgba(200, 60, 60, 0.24);
}

.folder-list .folder-item:not(.is-user) .folder-del {
  visibility: hidden;
  width: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.folder-list .folder-children {
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px dashed color-mix(in srgb, var(--border) 62%, transparent);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.folder-list .folder-children.collapsed {
  display: none;
}


.folder-list .folder-note-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.folder-list .folder-note-row[draggable="true"] {
  cursor: grab;
}

.folder-list .folder-note-row[draggable="true"]:active {
  cursor: grabbing;
}

.folder-list .folder-note-row.dragging-note {
  opacity: 0.55;
}

.folder-list .folder-note-btn {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 11.5px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-list .folder-note-btn:hover {

  color: var(--accent);
}

.folder-list .folder-note-btn.active {
  color: var(--accent);
}

.folder-list .folder-note-act {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.folder-list .folder-note-row:hover .folder-note-act {
  color: var(--text-muted);
}

.folder-list .folder-note-act.pin.on {
  color: #C9A227;
}

.folder-list .folder-note-act:hover {
  background: color-mix(in srgb, var(--border-light) 64%, transparent);
  color: var(--text);
}

.folder-list .folder-note-act.del:hover {
  color: var(--danger);
  border-color: rgba(200, 60, 60, 0.24);
  background: rgba(200, 60, 60, 0.12);
}

.folder-list .folder-child-empty {
  font-size: 10.5px;
  color: var(--text-faint);
  padding: 2px 8px 5px;
}

.folder-list .folder-empty {
  font-size: 11.5px;
  color: var(--text-faint);
  border: 1px dashed var(--border-light);
  border-radius: 9px;
  padding: 8px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  line-height: 1.35;
}

.btn-new-folder {
  align-self: stretch;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border) 55%);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent-light) 72%, #fff 28%), color-mix(in srgb, var(--accent-light) 50%, transparent));
  color: color-mix(in srgb, var(--accent) 80%, var(--text) 20%);
  font-family: var(--font-body);
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
}

.btn-new-folder:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent-light) 84%, #fff 16%), color-mix(in srgb, var(--accent-light) 62%, transparent));
}

.note-item .note-folder-tag {
  font-size: 10px;
  color: var(--text-faint);
  margin-left: 4px;
}

.note-item.dragging {
  opacity: 0.55;
}

.note-tags-inline {
  display: inline-flex;
  gap: 4px;
  margin-left: 6px;
  max-width: 120px;
  overflow: hidden;
}

.note-tag-chip {
  font-size: 10px;
  line-height: 1.2;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid rgba(61, 107, 79, 0.2);
  background: var(--accent-light);
  color: var(--accent);
  white-space: nowrap;
}

#sidebar-links {
  border-top: 1px solid var(--border);
  padding: 6px 8px 0;
}

#sidebar-links[hidden] {
  display: none !important;
}

.sidebar-links-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 2px 2px 4px;
}

.backlink-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: 5px;
  font-size: 11.5px;
  padding: 4px 6px;
  cursor: pointer;
}

.backlink-btn:hover {
  background: var(--border-light);
  border-color: var(--border);
  color: var(--text);
}

.wiki-link {
  color: var(--accent);
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.cmd-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-family: var(--font-body);
}

.cmd-item:hover,
.cmd-item.active {
  background: var(--accent-light);
  border-color: rgba(61, 107, 79, 0.22);
}

.cmd-kbd {
  color: var(--text-faint);
  font-size: 10.5px;
  font-family: var(--font-mono);
}

.slash-menu {
  position: fixed;
  z-index: 120;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  box-sizing: border-box;
  min-width: 0;
  width: max-content;
  max-width: min(300px, calc(100vw - 24px));
  max-height: min(220px, 42vh);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
  font-family: var(--font-body);
}

.slash-item {
  width: 100%;
  box-sizing: border-box;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 6px;
  padding: 7px 9px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
}

.slash-item:hover,
.slash-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.template-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  width: 100%;
  font-size: 12.5px;
}

.template-item:hover {
  background: var(--accent-light);
  border-color: rgba(61, 107, 79, 0.2);
}

#template-modal .modal-box {
  font-family: var(--font-body, ui-sans-serif, system-ui, sans-serif);
}

#template-modal .template-item {
  font-family: inherit;
}

#template-modal .template-user-summary,
#template-modal .template-user-row-name {
  font-family: inherit;
}

#template-modal .template-placeholders-hint code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.95em;
}

.ink-sheet-xls-rowhead {
  width: 0px;
}

/* MODAL */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal-overlay.open {
  display: flex;
}

#app-dialog-modal[hidden] {
  display: none !important;
}

#app-dialog-modal.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  max-width: 100%;
  box-sizing: border-box;
  box-shadow: var(--shadow-md);
  font-family: var(--font-body);
}

.modal-box h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  font-family: inherit;
}

.modal-box p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 7px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  transition: background 0.12s;
}

.modal-btn:hover {
  background: var(--tag-bg);
}

.modal-btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.modal-btn.danger:hover {
  background: #9B3535;
}

.modal-btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.modal-btn.accent:hover {
  background: var(--accent-hover);
}

.modal-input,
.modal-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12.5px;
  padding: 8px 10px;
  outline: none;
}

.modal-textarea {
  min-height: 70px;
  resize: vertical;
}

.modal-input:focus,
.modal-textarea:focus {
  border-color: var(--accent);
}

.modal-inline-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0;
}

.modal-inline-row>.modal-btn {
  flex: 1;
}

.modal-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  display: block;
}

/* Collaborators modal — member list */
.collab-members-section {
  margin-bottom: 14px;
}

.collab-member-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding: 2px;
}

.collab-list-empty {
  font-size: 12px;
  color: var(--text-faint);
  border: 1px dashed var(--border-light);
  border-radius: 9px;
  padding: 12px 10px;
  text-align: center;
  line-height: 1.4;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}

.collab-list-empty-error {
  color: var(--text-muted);
  border-style: solid;
  border-color: color-mix(in srgb, var(--danger) 22%, var(--border));
}

.collab-member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 92%, var(--border-light));
  transition: background 0.12s, border-color 0.12s;
}

.collab-member-row:hover {
  background: color-mix(in srgb, var(--border-light) 45%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 16%, var(--border));
}

.collab-member-avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent-light) 75%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}

.collab-member-email {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.collab-member-remove {
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  padding: 5px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s, background 0.1s, color 0.1s, border-color 0.1s;
}

.collab-member-row:hover .collab-member-remove,
.collab-member-row:focus-within .collab-member-remove {
  opacity: 1;
}

.collab-member-remove:hover {
  color: var(--danger);
  border-color: rgba(200, 60, 60, 0.24);
  background: rgba(200, 60, 60, 0.1);
}

@media (hover: none),
(max-width: 700px) {
  .collab-member-remove {
    opacity: 1;
  }
}

#graph-canvas {
  width: 100%;
  height: min(62vh, 540px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.graph-empty {
  font-size: 12px;
  color: var(--text-faint);
  border: 1px dashed var(--border-light);
  border-radius: 8px;
  padding: 10px;
}

/* Shortcuts modal */
#shortcuts-modal .modal-box {
  width: min(440px, calc(100vw - 28px));
  max-width: 100%;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border-light);
}

.shortcut-row:last-child {
  border-bottom: none;
}

.shortcut-key {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--tag-bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-muted);
}

.shortcut-label {
  font-size: 12px;
  color: var(--text-faint);
}

.shortcut-section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 10px 0 4px;
  grid-column: 1/-1;
}

/* Getting started (onboarding) */
#onboarding-modal {
  position: fixed;
  inset: 0;
  z-index: 190;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: rgba(32, 24, 12, 0.42);
  box-sizing: border-box;
}

#onboarding-modal.open {
  display: flex;
}

#onboarding-modal .onboarding-modal-box {
  width: min(480px, calc(100vw - 24px));
  max-height: min(88vh, 640px);
  overflow-y: auto;
  margin: 0;
  text-align: left;
}

#onboarding-modal .onboarding-lead {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 14px;
}

#onboarding-modal .onboarding-list {
  margin: 0;
  padding: 0 0 0 1.15em;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}

#onboarding-modal .onboarding-list li {
  margin: 0 0 10px;
}

#onboarding-modal .onboarding-list strong {
  color: var(--text);
}

/* Goal modal */
#goal-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
  transition: border 0.12s;
}

#goal-input:focus {
  border-color: var(--accent);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--surface);
  font-size: 12.5px;
  padding: 7px 16px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  font-family: var(--font-body);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.ink-sheet-row-h {
  width: 0px;
}

#io-menu {
  position: absolute;
  top: 56px;
  right: 14px;
  z-index: 140;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  box-sizing: border-box;
  min-width: 0;
  width: max-content;
  max-width: min(248px, calc(100vw - 28px));
  padding: 4px;
  font-family: var(--font-body);
}

.io-menu-item {
  border: none;
  background: transparent;
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
}

.io-menu-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ALMANAC / Garden OS: cream desk, binder, floating paper, earthy palette */
html:not([data-theme="calm"]):not([data-theme="glass"]):not([data-theme="neu"]):not([data-theme="bento"]):not([data-theme="terminal"]):not([data-theme="paper"]):not([data-theme="swiss"]):not([data-theme="magazine"]):not([data-theme="memphis"]):not([data-theme="cartoon"]):not([data-theme="obsidian"]) {
  body {
    background:
      radial-gradient(ellipse 120% 80% at 50% -20%, rgba(255, 248, 235, 0.75) 0%, transparent 55%),
      linear-gradient(170deg, #ECE2D0 0%, #D0C0A4 40%, #B8A88C 100%);
    box-shadow: inset 0 0 100px rgba(60, 48, 30, 0.06);
  }

  #app {
    padding: 10px 12px 12px 10px;
    gap: 10px;
    align-items: stretch;
    background: transparent;
  }

  #titlebar {
    margin: 0 10px;
    border-radius: 0 0 12px 12px;
    background: linear-gradient(180deg, #E8DCC4 0%, #C4B29A 100%);
    border: 1px solid #8A7A64;
    border-top: 1px solid #D8C8B0;
    box-shadow: 0 4px 12px rgba(50, 38, 24, 0.1), 0 1px 0 rgba(255, 255, 255, 0.55) inset;
  }

  #titlebar .logo {
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  }

  #note-title-input {
    font-family: var(--font-almanac);
    font-weight: 500;
    font-size: 30px;
    color: #3A3220 !important;
    letter-spacing: 0.02em;
  }

  #note-title-input:focus {
    color: #1A1008 !important;
  }

  #sidebar {
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.22) 0%, rgba(0, 0, 0, 0.04) 100%),
      linear-gradient(100deg, #CDB99A 0%, #A89272 4%, #B8A48A 12%, #C4AE92 100%);
    border: 1px solid #6A5A40;
    border-radius: 16px 16px 16px 16px;
    box-shadow: var(--card-lift);
  }

  .sidebar-binder-content {
    background: linear-gradient(180deg, rgba(250, 242, 230, 0.35) 0%, rgba(0, 0, 0, 0.02) 100%);
  }

  #sidebar.collapsed+#editor-area,
  #sidebar.collapsed~#editor-area {
    margin-left: 0px !important;
  }

  #app:has(#sidebar.collapsed) {
    gap: 0;
  }

  #app:has(#sidebar.collapsed) #editor-area {
    margin-left: 0px !important;
  }

  #editor-area {
    position: relative;
    background: linear-gradient(175deg, #FDF6EA 0%, #E2D2BC 100%);
    border: 1px solid #9A8A6E;
    border-radius: 14px;
    margin-left: 2px;
    overflow: hidden;
    box-shadow: var(--card-lift);
  }

  #editor-area::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0;
    z-index: 0;
    opacity: 0.4;
    border-radius: inherit;
    background:
      repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(180, 150, 110, 0.04) 23px, rgba(180, 150, 110, 0.04) 24px);
  }

  /* Toolbar + find bar above #editor-page so a fixed mobile AI FAB (in toolbar) isn’t covered by the editor hit-area */
  #editor-page {
    position: relative;
    z-index: 0;
  }

  #md-input-wrap,
  #statusbar,
  #panes,
  #preview-wrap {
    position: relative;
    z-index: 1;
  }

  #find-bar,
  #toolbar {
    position: relative;
    z-index: 2;
  }

  #md-input-wrap .CodeMirror {
    background: transparent !important;
    color: var(--text) !important;
  }

  #md-input {
    background: transparent;
  }

  #toolbar,
  #find-bar {
    background: linear-gradient(180deg, #B8A892 0%, #9A8874 100%);
    border-color: #5A4A3A;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  }

  #statusbar {
    background: linear-gradient(90deg, #D4B860 0 3px, #B8A890 3px, #9A8870 100%);
    border-top: 1px solid #5A4A3A;
    color: #3A3020;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset;
  }

  #pane-divider {
    background: linear-gradient(90deg, #3A2E24, #7A6A50, #3A2E24);
    box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.35);
    border: none;
  }

  #pane-divider::after {
    left: -3px;
    width: 8px;
  }

  #new-note-btn {
    background: linear-gradient(180deg, #4A8060 0%, #285038 100%) !important;
    border: 1px solid #1A3024 !important;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 2px 0 rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.12) !important;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    font-weight: 600;
  }

  #new-note-btn:hover {
    background: linear-gradient(180deg, #508868 0%, #2A5840 100%) !important;
  }

  #new-note-btn:active {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25) !important;
    transform: translateY(1px);
  }

  .icon-btn {
    border: 1px solid #6A5848;
    border-radius: 8px;
    background: linear-gradient(180deg, #E8D8C4 0%, #B8A090 100%);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.45) inset, var(--skeu-raise);
  }

  .icon-btn:hover {
    background: linear-gradient(180deg, #EEDCC8 0%, #C0A890 100%);
    border-color: #4A3A2A;
    color: var(--text) !important;
  }

  .icon-btn.active {
    background: linear-gradient(180deg, #A0C0A8 0%, #4A6A50 100%);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
    color: #0E1A10 !important;
    border-color: #2A4030;
  }

  .tb-btn {
    background: linear-gradient(180deg, #C8B8A4 0%, #988878 100%);
    border: 1px solid #4A3A30;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset;
    border-radius: 5px;
  }

  .tb-btn:hover {
    background: linear-gradient(180deg, #D0C0AC 0%, #A09080 100%);
    color: #1A1008 !important;
  }

  .tb-color {
    border: 1px solid #3A2E20;
    box-shadow: var(--skeu-inset);
    background: linear-gradient(180deg, #A89888, #807060);
  }

  #search-input,
  #pm-search-input,
  .pm-input,
  .pm-textarea,
  #find-input,
  #replace-input,
  #goal-input,
  #command-input,
  #task-filter-row select {
    box-shadow: var(--skeu-inset);
    border: 1px solid #3A2E20 !important;
    border-top-color: #1A0E0A !important;
    background: linear-gradient(180deg, #A89888 0%, #D8C8B4 100%) !important;
  }

  #search-input:focus,
  #pm-search-input:focus,
  .pm-input:focus,
  .pm-textarea:focus,
  #find-input:focus,
  #replace-input:focus,
  #goal-input:focus,
  #command-input:focus,
  #task-filter-row select:focus {
    border-color: var(--garden-sage) !important;
    border-top-color: var(--garden-sage) !important;
  }

  #search-input {
    background: linear-gradient(180deg, #B8A898 0%, #E0D0BC 100%) !important;
  }

  #pm-gen-pass,
  #pm-search-btn,
  #pm-open-add,
  #pm-csv-io,
  #pm-cancel-edit,
  .find-btn:not(.accent),
  .modal-btn:not(.accent):not(.danger) {
    box-shadow: var(--skeu-raise);
    background: linear-gradient(180deg, #D4C0A4 0%, #A89078 100%) !important;
    border: 1px solid #3A2E20 !important;
    border-radius: 6px;
    color: #1A0E0A;
  }

  #pm-open-add:hover,
  #pm-csv-io:hover,
  .find-btn:not(.accent):hover,
  .modal-btn:not(.accent):not(.danger):hover {
    background: linear-gradient(180deg, #DCC8A8, #B09880) !important;
  }

  #pm-search-btn,
  #pm-gen-pass {
    min-height: 30px;
  }

  .find-btn.accent,
  .modal-btn.accent,
  #pm-add-btn {
    background: linear-gradient(180deg, #3A6A4A, #1E3A2A) !important;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 1px 2px rgba(0, 0, 0, 0.15);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
    border: 1px solid #0E1A10 !important;
    color: #F8F4E8 !important;
  }

  #pm-add-btn {
    border: 1px solid #0E1A10 !important;
  }

  .find-btn.accent:hover,
  .modal-btn.accent:hover,
  #pm-add-btn:hover {
    background: linear-gradient(180deg, #3E7454, #224030) !important;
  }

  .modal-btn.danger {
    background: linear-gradient(180deg, #A83830, #681818) !important;
    border: 1px solid #3A0A0A !important;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
    color: #F8E8E0 !important;
  }

  .modal-btn.danger:hover {
    background: linear-gradient(180deg, #882828, #401010) !important;
  }

  .sidebar-tab {
    box-shadow: var(--skeu-raise);
    background: linear-gradient(180deg, #CDB89E 0%, #A89078 100%) !important;
    border: 1px solid #3A2E20 !important;
    border-bottom-color: #1A0E0A;
    color: #3A3020;
    font-weight: 500;
  }

  .sidebar-tab:hover {
    background: linear-gradient(180deg, #D2BEA4, #A89682) !important;
  }

  .sidebar-tab.active {
    background: linear-gradient(180deg, #5A7A5E 0%, #2A3E30 100%) !important;
    color: #E8F0E4 !important;
    border: 1px solid #1A2A1E !important;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15);
  }

  .task-filter-btn,
  .task-priority-chip,
  .saved-search-chip,
  .pm-mini-btn,
  .pm-item {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset;
    border: 1px solid var(--border) !important;
    background: linear-gradient(180deg, #D8C8B0, #B8A890) !important;
    border-radius: 8px;
  }

  .task-filter-btn:hover,
  .task-priority-chip:hover,
  .saved-search-chip:hover,
  .pm-mini-btn:hover,
  .pm-item:hover {
    background: linear-gradient(180deg, #E0D0B4, #C0A888) !important;
  }

  #folder-list-wrap {
    box-shadow: var(--skeu-inset);
    background: var(--tag-bg) !important;
    border: 1px solid #5A4A38;
    border-radius: 14px;
  }

  #task-list,
  #task-kanban-wrap {
    box-shadow: var(--skeu-inset);
    background: linear-gradient(180deg, #A89880, #C4B49A) !important;
    border-radius: 10px;
  }

  .task-card,
  .pm-item.open {
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 2px 4px rgba(0, 0, 0, 0.08) !important;
  }

  .note-item {
    box-shadow: 0 1px 2px rgba(40, 32, 20, 0.08);
    border: 1px solid transparent;
  }

  .note-item.active {
    background: linear-gradient(180deg, #6A9880 0%, #3A5A40 100%) !important;
    color: #F4FAF0;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid #1A2A1E;
  }

  .note-item:hover:not(.active) {
    background: linear-gradient(180deg, #D0B89E 0%, #B89A7E 100%) !important;
  }

  .note-item .note-title-row {
    color: inherit;
  }

  .note-item.active .note-title-row {
    color: #F8F8F0;
  }

  .note-item.active .note-meta,
  .note-item.active .note-preview,
  .note-item.active .note-folder-tag {
    color: #C8E0C8;
    opacity: 0.95;
  }

  .note-item.active .note-item-pin,
  .note-item.active .note-action-btn {
    color: #E0F0D8;
  }

  .note-item.active .note-tag-chip {
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(0, 0, 0, 0.12);
    color: #E8F0E0;
  }

  #modal-overlay {
    background: rgba(32, 24, 12, 0.45);
  }

  .modal-box {
    box-shadow: 0 20px 48px rgba(30, 22, 10, 0.2), 0 1px 0 rgba(255, 255, 255, 0.45) inset;
    background: linear-gradient(180deg, #E8D4B8 0%, #C8A88C 100%) !important;
    border: 1px solid #5A4030;
    border-top-color: #7A5A40;
    border-radius: 14px;
    font-family: var(--font-body);
  }

  #toast {
    background: linear-gradient(180deg, #1A0E0A, #0A0604);
    color: #E8DCC0;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
    border: 1px solid #3A2A20;
    border-radius: 999px;
  }

  .slash-menu,
  #io-menu,
  .cm-tooltip,
  .cm-s-inkwell-hint,
  .ink-dialog {
    background: linear-gradient(180deg, #E0D0B8 0%, #B8A088 100%) !important;
    box-shadow: var(--shadow-md), 0 1px 0 rgba(255, 255, 255, 0.35) inset !important;
    border: 1px solid #3A2820 !important;
    border-top-color: #5A4838;
    border-radius: 10px;
    font-family: var(--font-body);
  }

  .titlebar-sep,
  .tb-sep,
  #find-sep {
    background: linear-gradient(90deg, transparent, #2A2018, #6A5848, #2A2018, transparent);
  }

  #word-goal-bar #word-goal-progress,
  #word-goal-progress {
    background: #2A1E10;
    box-shadow: var(--skeu-inset);
    border: 1px solid #0A0804;
    border-radius: 4px;
    height: 5px;
  }

  #word-goal-fill {
    background: linear-gradient(180deg, #4A7A5A, #1A3020);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1) inset;
  }

  #preview h1,
  #preview h2 {
    font-family: var(--font-almanac);
  }

  #preview {
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  }

  #preview blockquote {
    background: linear-gradient(100deg, #B8C8A8 0%, #A0B090 100%);
    border-left: 4px solid var(--garden-terracotta);
    color: #2A3020;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
  }

  #preview a {
    color: #1E5038;
  }

  #preview pre {
    border: 1px solid #4A3E2E;
    background: #E0D0BC !important;
  }

  #preview code {
    background: #D4C4B0;
  }

  #md-input,
  #md-input-wrap .CodeMirror {
    text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.2);
  }

  #notes-list::-webkit-scrollbar-thumb,
  #preview-wrap::-webkit-scrollbar-thumb {
    background: linear-gradient(90deg, #3A3020, #6A5840, #3A3020);
    border: 1px solid #0A0A0A;
    background-clip: padding-box;
  }

}

/* Dark — simple white on black (neutral grays, no warm gold) */













































/* Dark: clean type (no faux-emboss on glyphs) */



















/* Slightly larger type in the sidebar (after almanac theme so it wins the cascade) */
#sidebar #new-note-btn {
  font-size: 14px;
}

#sidebar #search-input {
  font-size: 13.5px;
}

#sidebar .saved-search-title {
  font-size: 11px;
}

#sidebar .btn-save-search {
  font-size: 11px;
}

#sidebar .saved-search-chip {
  font-size: 12px;
}

#sidebar .saved-search-chip .del {
  font-size: 12px;
}

#sidebar .sidebar-tab {
  font-size: 11px;
}

#sidebar .task-filter-btn {
  font-size: 12px;
}

#sidebar #task-filter-row select {
  font-size: 13px;
}

#sidebar .task-priority-chip {
  font-size: 12px;
}

#sidebar #task-list-meta {
  font-size: 12px;
}

#sidebar .task-row-title {
  font-size: 13.5px;
}

#sidebar .task-row-meta {
  font-size: 11.5px;
}

#sidebar .task-kanban-head {
  font-size: 12px;
}

#sidebar .task-col-title {
  font-size: 11px;
}

#sidebar .task-card {
  font-size: 12px;
}

#sidebar #sidebar-meta {
  font-size: 12px;
}

#sidebar .sidebar-toc-title {
  font-size: 12px;
}

#sidebar .toc-item {
  font-size: 13px;
}

#sidebar .note-title-row {
  font-size: 14px;
}

#sidebar .note-meta {
  font-size: 12.5px;
}

#sidebar .note-item-pin {
  font-size: 15px;
}

#sidebar .note-action-btn {
  font-size: 12px;
}

#sidebar .note-folder-tag {
  font-size: 11px;
}

#sidebar .note-tag-chip {
  font-size: 11px;
}

#sidebar .folder-list .folder-section-title {
  font-size: 11px;
}

#sidebar .folder-list .folder-name-btn {
  font-size: 12.5px;
}

#sidebar .folder-list .folder-count {
  font-size: 11px;
}

#sidebar .shared-note-title {
  font-size: 12.5px;
}

#sidebar .shared-note-meta {
  font-size: 10.5px;
}

#sidebar .btn-new-folder {
  font-size: 12px;
}

#sidebar .sidebar-links-title {
  font-size: 12px;
}

#sidebar .backlink-btn {
  font-size: 12.5px;
}

#pm-search-input {
  font-size: 13px;
}

#pm-open-add {
  font-size: 13.5px;
}

#password-pane .pm-input,
#password-pane .pm-textarea {
  font-size: 13.5px;
}

#pm-add-btn,
#pm-cancel-edit {
  font-size: 13.5px;
}

#password-pane .pm-item-title {
  font-size: 13px;
}

#password-pane .pm-item-user {
  font-size: 12px;
}

#password-pane .pm-mini-btn {
  font-size: 13px;
  width: 28px;
  height: 26px;
}

#toolbar {
  border-radius: 0px !important;
}

#findbar {
  border-radius: 0px !important;
}

/* Responsive */
@media (max-width: 700px) {
  :root {
    --note-free-lines: 20;
  }

  .tb-btn {
    min-width: 23px !important;
    height: 25px !important;
  }

  #toolbar {
    height: 30px;
    border-radius: 0px !important;
  }

  #findbar {
    border-radius: 0px !important;
  }

  #app {
    padding: 4px !important;
    gap: 1px !important;
  }

  #titlebar {
    margin: 0 4px;
    border-radius: 0 0 8px 8px;
  }

  #sidebar {
    width: 256px;
  }

  #md-input {
    padding: 24px 20px;
    padding-bottom: calc(24px + var(--note-writing-tail));
  }

  #md-input-wrap .CodeMirror-lines {
    padding: 24px 10px;
    padding-bottom: calc(24px + var(--note-writing-tail));
  }

  #editor-page #preview {
    margin: 0 auto;
    padding: 8px 6px;
    padding-bottom: calc(24px + var(--note-free-lines) * 1.55em);
    padding-bottom: calc(24px + var(--note-free-lines) * 1lh);
    font-size: 13px !important;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  #titlebar .logo img.kashi-logo-img {
    width: 23px;
    height: 23px;
  }

  .icon-btn {
    min-width: 23px;
    height: 23px;
  }

  #titlebar {
    flex-direction: column;
    align-items: stretch;
    padding: 4px 5px 2px;
    gap: 2px;
    margin-left: 2px !important;
    margin-right: 2px !important;
    position: relative;
  }

  #titlebar-top {
    gap: 6px;
    height: 22px;
    padding-right: 95px;
  }

  #titlebar .logo {
    font-size: 15px;
  }

  #titlebar .logo .logo-wordmark {
    display: none;
  }

  #note-title-input {
    text-align: left;
    font-size: 12.5px !important;
  }

  #titlebar-actions {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    scrollbar-width: thin;
    height: 30px;
  }

  #titlebar-actions .icon-btn {
    flex-shrink: 0;
    min-width: 20px;
    height: 25px;
  }

  #btn-view-split {
    display: none !important;
  }

  #titlebar-actions .icon-btn-tight {
    min-width: auto;
    padding: 0 8px;
    font-size: 12px;
  }

  #btn-io-menu {
    position: absolute !important;
    top: 4px;
    right: 32px;
    height: 22px;
    z-index: 10;
  }

  #btn-shortcuts {
    position: absolute !important;
    top: 4px;
    right: 5px;
    width: 23px;
    height: 22px;
    z-index: 10;
  }

  #btn-inkwell-account {
    margin-left: auto !important;
  }

  #sep-before-io,
  #sep-after-io {
    display: none !important;
  }

  #titlebar .tb-mob {
    display: inline;
  }

  #titlebar .tb-desk {
    display: none;
  }

  #titlebar-actions::-webkit-scrollbar {
    height: 4px;
  }

  #titlebar-actions::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
  }

  #io-menu {
    position: fixed;
    left: auto;
    right: 32px;
    top: 32px;
    bottom: auto;
    width: max-content;
    max-width: min(248px, calc(100vw - 16px));
    min-width: 0;
    border-radius: 12px;
    padding: 5px;
  }

  .io-menu-item {
    padding: 9px 11px;
    font-size: 12.5px;
  }

  #task-kanban {
    grid-template-columns: 1fr;
  }

  /* Touch targets: outline, floating TOC, preview scroll */
  #toc-list {
    gap: 6px;
    padding: 4px 6px 8px;
  }

  .toc-item {
    min-height: 44px;
    padding: 10px 10px;
    font-size: 14px;
    border-radius: 8px;
    -webkit-tap-highlight-color: rgba(47, 92, 72, 0.15);
  }

  .sidebar-toc-title {
    padding: 10px 12px 6px;
    font-size: 12px;
  }

  .preview-float-toc-toggle {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 13px;
    -webkit-tap-highlight-color: rgba(47, 92, 72, 0.15);
  }

  .preview-float-toc-list {
    padding: 8px 10px;
    max-height: min(50vh, 320px);
  }

  .preview-float-toc-list button {
    min-height: 44px;
    padding: 10px 8px;
    font-size: 14px;
    border-radius: 8px;
    -webkit-tap-highlight-color: rgba(47, 92, 72, 0.12);
  }

  /* Do not set overscroll-behavior-y: contain or touch-action on the wrap: in preview-only
     mode the wrap usually grows with content (no local overflow), and those properties
     trap vertical pans so #editor-page never scrolls. Split view still scrolls the wrap via overflow-y. */
  #preview-wrap {
    -webkit-overflow-scrolling: touch;
  }

  /* WebKit often keeps vertical pans for caret/selection unless pan-y is explicit. */
  #preview[contenteditable="true"] {
    touch-action: pan-y pinch-zoom;
  }

  #note-history-modal .modal-btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .note-history-row .note-history-restore {
    flex-shrink: 0;
    align-self: center;
    min-height: 44px;
    padding: 10px 14px;
  }

  #note-history-list .note-history-row {
    padding: 12px 10px !important;
    gap: 10px !important;
  }

  /* Status bar: one scrollable row (not a two-line “dock” pinned to the home indicator) */
  #statusbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    gap: 8px;
    padding: 4px 8px;
    min-height: 20px;
    max-height: none;
    max-width: none;
    width: 100%;
    font-size: 9px;
    height: 20px;

  }

  #statusbar::-webkit-scrollbar {
    height: 3px;
  }

  #statusbar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
  }

  #status-sync-wrap {
    flex-shrink: 0;
    margin-left: auto;
    flex-wrap: nowrap;
    gap: 6px;
  }

  #btn-goal {
    display: none !important;
  }

  #statusbar .btn-cloud-save {
    flex-shrink: 0;
    height: auto;
    padding: 3px 3px;
    font-size: 9px;
    height: 18px !important;
  }

  /* Home indicator: pad scrollable editor page */
  #editor-page {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* AI FAB: higher on narrow viewports (home indicator / thumb reach) */
  #btn-ai-chat {
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: max(30px, calc(14px + env(safe-area-inset-bottom, 0px)));
    background: transparent;
    border: none;
    box-shadow: none;
    margin: 0;
    padding: 0;
    cursor: pointer;
    transition: none;
    opacity: 1;
  }

  /* AI chat: full-screen overlay on small viewports (toolbar strip was unusably narrow) */
  #ai-chat-panel.open {
    position: fixed;
    inset: 0;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    min-height: 0;
    height: 100dvh;
    max-height: 100dvh;
    z-index: 125;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
  }

  #ai-chat-panel.open .ai-chat-messages {
    flex: 1;
    min-height: 0;
  }

  #ai-chat-panel.open .ai-chat-top {
    padding: 10px 12px;
  }

  #ai-chat-panel.open .ai-chat-context {
    font-size: 12px;
  }

  #ai-chat-panel.open #ai-chat-input {
    max-height: min(200px, 38vh);
    font-size: 16px;
  }
}

html.ai-chat-mobile-open,
body.ai-chat-mobile-open {
  overflow: hidden;
}

/* ── TAB BAR (open notes) ───────────────────────────────────────────────────
   Theme-agnostic: uses --surface / --border / --text / --accent so every
   theme stylesheet inherits a coherent tab strip without per-theme overrides.
   Hidden when there are zero tabs (additive feature; never forced on).
*/
#tab-bar {
  display: none;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  /* same layer as #toolbar / #find-bar so theme #editor-area::after never paints over tabs */
  align-items: stretch;
  gap: 0;
  height: 32px;
  padding: 0 0px;
  background: var(--toolbar-bg, var(--bg));
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  user-select: none;
}

#tab-bar.has-tabs {
  display: flex;
}

#tab-bar::-webkit-scrollbar {
  height: 4px;
}

#tab-bar::-webkit-scrollbar-thumb {
  background: var(--border-light, var(--border));
  border-radius: 2px;
}

#tab-bar .tab-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 200px;
  min-width: 200px;
  height: 32px;
  padding: 0 6px 0 12px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

#tab-bar .tab-item:hover {
  background: var(--surface);
  color: var(--text);
}

#tab-bar .tab-item.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 -1px 0 var(--accent) inset;
}

#tab-bar .tab-item.active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 1px;
  background: var(--surface);
}

#tab-bar .tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
  height: 16px;
}

#tab-bar .tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
  flex-shrink: 0;
}

#tab-bar .tab-item.active .tab-close,
#tab-bar .tab-item:hover .tab-close {
  opacity: 1;
}

#tab-bar .tab-close:hover {
  background: var(--border-light, var(--border));
  color: var(--text);
}

/* Drag-and-drop reordering */
#tab-bar .tab-item.dragging {
  opacity: 0.55;
  cursor: grabbing;
}

#tab-bar .tab-item.drop-before {
  box-shadow: -2px 0 0 var(--accent);
}

#tab-bar .tab-item.drop-after {
  box-shadow: 2px 0 0 var(--accent);
}

@media (max-width: 640px) {
  #tab-bar {
    height: 24px;
    padding: 0 2px;
  }

  #tab-bar .tab-item {
    min-width: 72px;
    max-width: 160px;
    height: 24px;
    padding: 0 4px 0 10px;
    font-size: 11px;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   NOTE COLOR LABELS
   ─────────────────────────────────────────────────────────────────────────── */

/* Color pip / jewel dot */
.note-color-dot {
  display: none;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}

.folder-note-row[data-note-color] .note-color-dot {
  display: inline-block;
}

/* Colored row: left accent bar via border-left + soft tinted background */
.folder-note-row[data-note-color] {
  border-left: 4px solid transparent;
  border-radius: 0 6px 6px 0;
  padding-left: 2px;
  position: relative;
  transition: background 0.12s, border-left-color 0.12s;
}

/* Per-color: accent bar color + tinted background wash */
.folder-note-row[data-note-color="rose"] {
  border-left-color: #d95f5f;
  background: linear-gradient(90deg, rgba(217, 95, 95, 0.10) 0%, rgba(217, 95, 95, 0.04) 100%);
}

.folder-note-row[data-note-color="amber"] {
  border-left-color: #d4923a;
  background: linear-gradient(90deg, rgba(212, 146, 58, 0.10) 0%, rgba(212, 146, 58, 0.04) 100%);
}

.folder-note-row[data-note-color="lime"] {
  border-left-color: #52ab4d;
  background: linear-gradient(90deg, rgba(82, 171, 77, 0.10) 0%, rgba(82, 171, 77, 0.04) 100%);
}

.folder-note-row[data-note-color="sky"] {
  border-left-color: #4488c0;
  background: linear-gradient(90deg, rgba(68, 136, 192, 0.10) 0%, rgba(68, 136, 192, 0.04) 100%);
}

.folder-note-row[data-note-color="violet"] {
  border-left-color: #8860bf;
  background: linear-gradient(90deg, rgba(136, 96, 191, 0.10) 0%, rgba(136, 96, 191, 0.04) 100%);
}

.folder-note-row[data-note-color="slate"] {
  border-left-color: #6a8090;
  background: linear-gradient(90deg, rgba(106, 128, 144, 0.10) 0%, rgba(106, 128, 144, 0.04) 100%);
}

/* Dot colors */
.note-color-dot[data-color="rose"] {
  background: radial-gradient(circle at 35% 35%, #f08080, #c04848);
}

.note-color-dot[data-color="amber"] {
  background: radial-gradient(circle at 35% 35%, #f0b060, #c07830);
}

.note-color-dot[data-color="lime"] {
  background: radial-gradient(circle at 35% 35%, #78cc70, #3a9038);
}

.note-color-dot[data-color="sky"] {
  background: radial-gradient(circle at 35% 35%, #68aede, #2e6fa8);
}

.note-color-dot[data-color="violet"] {
  background: radial-gradient(circle at 35% 35%, #aa80e0, #6840b0);
}

.note-color-dot[data-color="slate"] {
  background: radial-gradient(circle at 35% 35%, #8aa4b4, #4a6878);
}

/* Subtle glow on the dot when the row is hovered */
.folder-note-row:hover .note-color-dot {
  transform: scale(1.18);
}

.folder-note-row[data-note-color="rose"]:hover .note-color-dot {
  box-shadow: 0 0 0 3px rgba(217, 95, 95, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.folder-note-row[data-note-color="amber"]:hover .note-color-dot {
  box-shadow: 0 0 0 3px rgba(212, 146, 58, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.folder-note-row[data-note-color="lime"]:hover .note-color-dot {
  box-shadow: 0 0 0 3px rgba(82, 171, 77, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.folder-note-row[data-note-color="sky"]:hover .note-color-dot {
  box-shadow: 0 0 0 3px rgba(68, 136, 192, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.folder-note-row[data-note-color="violet"]:hover .note-color-dot {
  box-shadow: 0 0 0 3px rgba(136, 96, 191, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.folder-note-row[data-note-color="slate"]:hover .note-color-dot {
  box-shadow: 0 0 0 3px rgba(106, 128, 144, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.folder-note-act.clr {
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.12s;
}

.folder-note-row:hover .folder-note-act.clr,
.folder-note-row:focus-within .folder-note-act.clr {
  opacity: 1;
}

.note-color-picker {
  position: fixed;
  z-index: 220;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.1);
  padding: 8px 10px;
  display: flex;
  gap: 6px;
  align-items: center;
  animation: kashi-picker-pop 0.15s ease;
}

@keyframes kashi-picker-pop {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(4px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.note-color-picker-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
}

.note-color-picker-swatch:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 2px var(--accent);
}

.note-color-picker-swatch.active {
  box-shadow: 0 0 0 2.5px var(--accent);
  transform: scale(1.15);
}

.note-color-picker-clear {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px dashed var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: border-color 0.12s, color 0.12s;
}

.note-color-picker-clear:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ─────────────────────────────────────────────────────────────────────────────
   FOCUS / AMBIENT SOUNDS
   ─────────────────────────────────────────────────────────────────────────── */
#focus-sounds-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 215;
  padding: 16px;
  box-sizing: border-box;
  backdrop-filter: blur(3px);
}

#focus-sounds-modal.open {
  display: flex;
}

.focus-sounds-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--card-lift);
  width: min(460px, 96vw);
  max-height: 90vh;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: kashi-modal-rise 0.2s ease;
}

@keyframes kashi-modal-rise {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

.focus-sounds-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.focus-sounds-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-body);
  color: var(--text);
}

.focus-sounds-close {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 0.12s, color 0.12s;
}

.focus-sounds-close:hover {
  border-color: var(--accent);
  color: var(--text);
}

.sound-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.sound-card {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  padding: 14px 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, transform 0.12s, box-shadow 0.15s;
  user-select: none;
}

.sound-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.09);
}

.sound-card.active {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 2px var(--accent);
}

.sound-card-emoji {
  font-size: 26px;
  line-height: 1;
}

.sound-card-name {
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text);
  text-align: center;
}

.sound-wave-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  visibility: hidden;
}

.sound-card.active .sound-wave-bars {
  visibility: visible;
}

.sound-wave-bars span {
  display: block;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: kashi-wave-bounce 0.9s ease-in-out infinite;
}

.sound-wave-bars span:nth-child(1) {
  animation-delay: 0s;
  height: 5px;
}

.sound-wave-bars span:nth-child(2) {
  animation-delay: 0.15s;
  height: 10px;
}

.sound-wave-bars span:nth-child(3) {
  animation-delay: 0.3s;
  height: 7px;
}

.sound-wave-bars span:nth-child(4) {
  animation-delay: 0.1s;
  height: 13px;
}

.sound-wave-bars span:nth-child(5) {
  animation-delay: 0.25s;
  height: 4px;
}

@keyframes kashi-wave-bounce {

  0%,
  100% {
    transform: scaleY(0.4);
  }

  50% {
    transform: scaleY(1.0);
  }
}

.focus-sounds-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
  border-top: 1px solid var(--border-light);
}

.focus-sounds-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--text-muted);
}

.focus-sounds-row label {
  flex-shrink: 0;
  min-width: 52px;
}

#focus-volume-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

#focus-timer-select {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
}

#focus-timer-countdown {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 600;
  min-width: 44px;
}

/* btn-focus-sounds active state when playing */
#btn-focus-sounds.playing {
  color: var(--accent);
  background: var(--accent-light);
  animation: kashi-pulse-border 2s ease-in-out infinite;
}

@keyframes kashi-pulse-border {

  0%,
  100% {
    box-shadow: none;
  }

  50% {
    box-shadow: 0 0 0 2px var(--accent-light);
  }
}

/* ==========================================================================
   MARKDOWN DATABASES (NOTION-LIKE TABLES) STYLES
   ========================================================================== */

#preview .ink-db-host {
  margin: 1.5em 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: var(--text);
  font-family: var(--font-body);
}

.ink-db-host button,
.ink-db-host input,
.ink-db-host select,
.ink-db-host textarea {
  font-family: inherit;
}

.ink-db-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--sidebar-bg) 60%, var(--surface));
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  user-select: none;
}

.ink-db-toolbar-left,
.ink-db-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* View tabs / switcher segment control */
.ink-db-view-tabs {
  display: inline-flex;
  background: color-mix(in srgb, var(--border) 40%, var(--surface));
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
}

.ink-db-view-tab {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s ease, color 0.15s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.ink-db-view-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Buttons in toolbar */
.ink-db-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: var(--font-body);
}

.ink-db-btn:hover {
  background: var(--tag-bg);
  border-color: var(--accent);
}

.ink-db-btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border));
}

.ink-db-btn.danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.ink-db-btn.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* Filters & Sorts active area */
.ink-db-active-configs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--sidebar-bg) 20%, var(--surface));
  border-bottom: 1px solid var(--border-light);
  font-size: 11.5px;
}

.ink-db-config-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--tag-bg);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
}

.ink-db-config-chip .remove-btn {
  cursor: pointer;
  color: var(--danger);
  font-weight: bold;
  padding-left: 2px;
}

/* Database Table View */
.ink-db-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.ink-db-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  font-size: 13px;
}

.ink-db-table th,
.ink-db-table td {
  padding: 10px 12px;
  border: 1px solid var(--border-light);
  text-align: left;
  position: relative;
}

.ink-db-table th {
  background: color-mix(in srgb, var(--sidebar-bg) 30%, var(--surface));
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.ink-db-table th:hover {
  background: var(--tag-bg);
}

.ink-db-header-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ink-db-header-type-icon {
  opacity: 0.6;
  font-size: 12px;
  display: inline-flex;
}

.ink-db-cell-input {
  border: none;
  background: transparent;
  width: 100%;
  padding: 0;
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
}

.ink-db-cell-input:focus {
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
  box-shadow: 0 0 0 2px var(--accent-light);
  border-radius: 3px;
  padding: 2px 4px;
  margin: -2px -4px;
}

/* Dropdown popover for column config, sorting, filtering options */
.ink-db-popover {
  position: fixed;
  z-index: 500;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 8px 0;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  animation: ink-db-popover-in 0.15s ease-out;
  font-family: var(--font-body), system-ui, sans-serif;
}

@keyframes ink-db-popover-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ink-db-popover-item {
  padding: 8px 14px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--text);
  transition: background 0.1s;
  font-family: var(--font-body), system-ui, sans-serif;
}

.ink-db-popover-item:hover {
  background: var(--tag-bg);
}

.ink-db-popover-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

.ink-db-popover-input {
  margin: 4px 10px;
  padding: 5px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: var(--font-body), system-ui, sans-serif;
}

.ink-db-popover-input:focus {
  border-color: var(--accent);
}

/* Badges for Select and Tags column types */
.ink-db-badges-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.ink-db-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 550;
  border-radius: 12px;
  line-height: 1.35;
  white-space: nowrap;
}

/* Harmonious Tag Colors (Notion-like) */
.ink-db-badge.color-gray {
  background: rgba(120, 120, 120, 0.16);
  color: var(--text);
}

.ink-db-badge.color-brown {
  background: rgba(139, 90, 43, 0.16);
  color: #8d5524;
}

.ink-db-badge.color-orange {
  background: rgba(245, 124, 0, 0.16);
  color: #e65100;
}

.ink-db-badge.color-yellow {
  background: rgba(245, 191, 0, 0.2);
  color: #b58900;
}

.ink-db-badge.color-green {
  background: rgba(76, 175, 80, 0.16);
  color: #2e7d32;
}

.ink-db-badge.color-blue {
  background: rgba(33, 150, 243, 0.16);
  color: #1565c0;
}

.ink-db-badge.color-purple {
  background: rgba(156, 39, 176, 0.16);
  color: #6a1b9a;
}

.ink-db-badge.color-pink {
  background: rgba(233, 30, 99, 0.16);
  color: #c2185b;
}

.ink-db-badge.color-red {
  background: rgba(244, 67, 54, 0.16);
  color: #d32f2f;
}

/* Interactive Tag Select/Dropdown when editing cell */
.ink-db-tag-editor-popover {
  position: fixed;
  z-index: 510;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 8px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ink-db-tag-options-list {
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ink-db-tag-option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
}

.ink-db-tag-option-row:hover {
  background: var(--tag-bg);
}

.ink-db-tag-option-row.selected {
  background: var(--accent-light);
  color: var(--accent);
}

/* List View styles */
.ink-db-list-wrap {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: color-mix(in srgb, var(--sidebar-bg) 10%, var(--surface));
}

.ink-db-list-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  cursor: pointer;
}

.ink-db-list-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
  border-color: var(--accent);
}

.ink-db-list-card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 6px 0;
  color: var(--text);
}

.ink-db-list-card-props {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.ink-db-list-prop-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ink-db-list-prop-label {
  font-weight: 550;
  color: var(--text-faint);
}

/* Kanban Board View styles */
.ink-db-kanban-wrap {
  padding: 14px;
  display: flex;
  gap: 14px;
  overflow-x: auto;
  align-items: flex-start;
  background: color-mix(in srgb, var(--sidebar-bg) 10%, var(--surface));
  min-height: 280px;
}

.ink-db-kanban-column {
  flex: 0 0 260px;
  background: color-mix(in srgb, var(--sidebar-bg) 30%, var(--surface));
  border: 1px solid var(--border-light);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  max-height: 520px;
}

.ink-db-kanban-column-header {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ink-db-kanban-column-cards {
  padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 80px;
  /* drop zone */
}

.ink-db-kanban-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  cursor: grab;
  transition: transform 0.1s, box-shadow 0.1s, border-color 0.15s;
}

.ink-db-kanban-card:active {
  cursor: grabbing;
}

.ink-db-kanban-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.ink-db-kanban-card.dragging {
  opacity: 0.4;
  border: 1.5px dashed var(--accent);
}

.ink-db-kanban-card-title {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--text);
}

.ink-db-kanban-card-props {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--text-muted);
}

.ink-db-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  gap: 8px;
}

/* ── Published Toggle & Banner ───────────────────────────────────────── */
#btn-toolbar-publish.is-published {
  background: var(--accent) !important;
  color: white !important;
  font-weight: 600 !important;
  border-radius: 5px !important;
}

#btn-toolbar-publish.is-published:hover {
  background: var(--accent-hover) !important;
}

#note-title-input.note-title-readonly {
  cursor: default !important;
  pointer-events: none !important;
  color: var(--text-faint) !important;
}

#note-title-input.note-title-readonly:focus {
  outline: none !important;
}

.published-banner {
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--accent);
  font-family: inherit;
}

@media (max-width: 700px) {
  .published-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
  }

  .published-banner .pub-banner-actions-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    justify-content: flex-start;
  }
}

.published-banner[hidden] {
  display: none !important;
}

.pub-banner-text {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pub-banner-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  font-family: inherit;
}

.pub-banner-btn:hover {
  background: var(--accent-hover);
}

.note-published #toolbar .tb-btn:not(#btn-find):not(#btn-focus-sounds):not(#btn-toolbar-publish):not(#btn-toolbar-publish-link) {
  opacity: 0.5;
  pointer-events: none;
}

.preview-readonly .ink-sheet-edit-btn,
.preview-readonly .ink-sheet-delete-btn,
.preview-readonly .ink-chart-edit-btn,
.preview-readonly .ink-chart-delete-btn,
.preview-readonly .ink-mermaid-edit-btn,
.preview-readonly .ink-mermaid-delete-btn,
.preview-readonly .ink-flashcard-btn,
.preview-readonly .ink-file-delete,
.preview-readonly .ink-table-add-col,
.preview-readonly .ink-table-add-row,
.preview-readonly .ink-table-rem-col,
.preview-readonly .ink-table-rem-row,
.preview-readonly .ink-table-delete {
  display: none !important;
}

/* Enable side-by-side floating layout for artifacts that don't fill the full note width */
#preview .ink-file-host,
#preview .ink-mermaid-host,
#preview .mermaid,
#preview .ink-chart-host,
#preview .ink-sheet-host,
#preview .ink-map-host,
#preview .ink-table-host,
#preview .ink-task-sticker,
#preview .ink-flashcard-host,
#preview .ink-whiteboard-sticker,
#preview img {
  float: left;
  clear: none;
  margin-right: 16px;
  margin-bottom: 12px;
}

/* Allow standard tables to shrink to content and float so text or other artifacts can sit next to them */
#preview table {
  width: auto;
  max-width: 100%;
  float: left;
  clear: none;
  margin-right: 16px;
  margin-bottom: 12px;
}

/* Headings, dividers, code blocks, math, and blockquotes should always clear floated elements and start on a new line */
#preview h1,
#preview h2,
#preview h3,
#preview h4,
#preview h5,
#preview h6,
#preview hr,
#preview pre,
#preview blockquote,
#preview .katex-display {
  clear: both;
}

/* User Profile settings UI styling */
.profile-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
}

.profile-avatar-wrap {
  position: relative;
  width: 76px;
  height: 76px;
}

.profile-img {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: block;
}

.profile-photo-label {
  position: absolute;
  bottom: 0;
  right: 0;
  background: var(--accent);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  transition: background 0.12s, transform 0.12s;
}

.profile-photo-label:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.profile-field-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-field-wrap label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Eisenhower Decision Matrix (matrix) --- */
.ink-matrix-host {
  display: block;
  width: 100%;
  clear: both;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  padding-top: 36px;
  box-sizing: border-box;
  position: relative;
}

.ink-matrix-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .ink-matrix-grid {
    grid-template-columns: 1fr;
  }
}

.ink-matrix-quadrant {
  border: 1px solid var(--border-light);
  border-radius: calc(var(--radius) * 0.8);
  background: rgba(120, 120, 120, 0.02);
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

.ink-matrix-quadrant[data-quadrant="do-first"] {
  border-left: 3px solid #ff5a5a;
}

.ink-matrix-quadrant[data-quadrant="schedule"] {
  border-left: 3px solid #3498db;
}

.ink-matrix-quadrant[data-quadrant="delegate"] {
  border-left: 3px solid #f1c40f;
}

.ink-matrix-quadrant[data-quadrant="eliminate"] {
  border-left: 3px solid #7f8c8d;
}

.ink-matrix-quadrant-header {
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ink-matrix-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex-grow: 1;
}

.ink-matrix-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 5px;
  border-radius: 4px;
  margin-bottom: 4px;
  font-size: 13px;
  background: transparent;
  transition: background 0.12s;
  cursor: grab;
}

.ink-matrix-item:active {
  cursor: grabbing;
}

.ink-matrix-item.dragging {
  opacity: 0.4;
  background: var(--border-light);
}

.ink-matrix-item:hover {
  background: var(--border-light);
}

.ink-matrix-item-text {
  flex-grow: 1;
  outline: none;
  min-width: 10px;
  color: var(--text);
}

.ink-matrix-item-text[contenteditable="true"]:focus {
  background: var(--bg);
  border-bottom: 1px solid var(--accent);
}

.ink-matrix-item-del {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.1s;
}

.ink-matrix-item:hover .ink-matrix-item-del {
  opacity: 1;
}

.ink-matrix-item-del:hover {
  color: var(--danger);
}

.ink-matrix-add-btn {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 4px;
  font-size: 11.5px;
  cursor: pointer;
  margin-top: auto;
  text-align: center;
  transition: background 0.1s, color 0.1s;
}

.ink-matrix-add-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

/* --- Vertical Timeline (timeline) --- */
.ink-timeline-host {
  display: block;
  width: 100%;
  clear: both;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  box-sizing: border-box;
  position: relative;
}

.ink-timeline-container {
  position: relative;
  margin-top: 10px;
}

.ink-timeline-line {
  position: absolute;
  left: 20px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
  z-index: 1;
}

.ink-timeline-item {
  position: relative;
  padding-left: 45px;
  margin-bottom: 20px;
  z-index: 2;
  display: flex;
  flex-direction: column;
}

.ink-timeline-dot {
  position: absolute;
  left: 15px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  z-index: 3;
}

.ink-timeline-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.ink-timeline-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 2px 8px;
  border-radius: 12px;
  outline: none;
  min-width: 40px;
}

.ink-timeline-item-del {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.1s;
}

.ink-timeline-item:hover .ink-timeline-item-del {
  opacity: 1;
}

.ink-timeline-item-del:hover {
  color: var(--danger);
}

.ink-timeline-content {
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  padding: 4px 0;
  min-width: 50px;
  line-height: 1.45;
}

.ink-timeline-date[contenteditable="true"]:focus,
.ink-timeline-content[contenteditable="true"]:focus {
  background: var(--bg);
  border-bottom: 1px solid var(--accent);
}

.ink-timeline-add-btn {
  margin-left: 45px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.ink-timeline-add-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

/* --- Calculator Scratchpad (calc) --- */
.ink-calc-host {
  display: block;
  width: 100%;
  clear: both;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
  padding: 16px;
  padding-top: 36px;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.ink-calc-main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ink-calc-screen {
  background: color-mix(in srgb, var(--text) 3%, var(--surface));
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Ink Calc Rows Container */
.ink-calc-rows {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}

.ink-calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding: 12px 16px;
  gap: 16px;
  background: var(--bg);
  min-height: 48px;
  box-sizing: border-box;
}

.ink-calc-row:last-child {
  border-bottom: none;
}

.ink-calc-row-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  padding: 0;
  font-family: inherit;
}

.ink-calc-row-input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.ink-calc-row-output {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  font-family: inherit;
}

.ink-calc-row.active {
  background: color-mix(in srgb, var(--accent) 3%, var(--bg));
}

.ink-calc-row.active .ink-calc-row-output {
  color: var(--accent);
}

.ink-calc-row-output.error {
  color: var(--danger);
}

.ink-calc-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}

.ink-calc-deg-btn,
.ink-calc-rad-btn,
.ink-calc-keypad-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.ink-calc-deg-btn.active,
.ink-calc-rad-btn.active {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

.ink-calc-deg-btn:hover:not(.active),
.ink-calc-rad-btn:hover:not(.active),
.ink-calc-keypad-toggle:hover {
  background: var(--border-light);
  color: var(--text);
}

.ink-calc-keypad {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px dashed var(--border-light);
  padding-top: 12px;
  animation: inkCalcSlideDown 0.2s ease-out;
}

@keyframes inkCalcSlideDown {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ink-calc-keypad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

.ink-calc-tabs {
  display: flex;
  gap: 4px;
}

.ink-calc-tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.ink-calc-tab-btn:hover {
  color: var(--text);
}

.ink-calc-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.ink-calc-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ink-calc-toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.ink-calc-toggle-group button {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.1s ease;
  font-family: inherit;
}

.ink-calc-toggle-group button.active,
.ink-calc-toggle-group button:active {
  background: var(--accent);
  color: var(--surface);
}

.ink-calc-icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.12s;
  font-family: inherit;
}

.ink-calc-icon-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

.ink-calc-clear-all-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: color 0.12s;
  font-family: inherit;
}

.ink-calc-clear-all-btn:hover {
  color: var(--danger);
}

.ink-calc-pane.main-pane {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.ink-calc-pane.abc-pane {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ink-abc-row {
  display: flex;
  gap: 6px;
}

.ink-abc-row .ink-calc-btn {
  flex: 1;
  min-width: 0;
  padding-left: 2px;
  padding-right: 2px;
}

.ink-abc-row-center {
  padding: 0 4.5%;
}

.ink-abc-wide {
  flex: 1.5 !important;
}

.ink-calc-pane.func-pane {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.ink-calc-btn {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.12s ease;
  background: var(--surface);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  font-family: inherit;
}

.ink-calc-btn.num {
  background: color-mix(in srgb, var(--text) 4%, var(--surface));
  font-weight: 600;
}

.ink-calc-btn.fn {
  background: var(--surface);
  font-style: italic;
}

.ink-calc-btn.op {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

.ink-calc-btn.action {
  background: color-mix(in srgb, var(--text) 8%, var(--surface));
  color: var(--text);
}

.ink-calc-btn.backspace {
  font-weight: 600;
}

.ink-calc-btn.eval {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
  font-weight: 600;
}

.ink-calc-btn:hover {
  background: color-mix(in srgb, var(--text) 8%, var(--surface));
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.ink-calc-btn.num:hover {
  background: color-mix(in srgb, var(--text) 10%, var(--surface));
}

.ink-calc-btn.eval:hover {
  background: color-mix(in srgb, var(--accent) 85%, black);
  border-color: color-mix(in srgb, var(--accent) 85%, black);
}

.ink-calc-btn:active {
  transform: translateY(0);
  box-shadow: none;
}

@media (max-width: 600px) {

  .ink-calc-pane.main-pane,
  .ink-calc-pane.abc-pane,
  .ink-calc-pane.func-pane {
    gap: 4px;
  }

  .ink-calc-btn {
    font-size: 11px;
    padding: 8px 2px;
  }

  .ink-calc-keypad-header {
    gap: 6px;
  }
}

/* --- Kanban Board (kanban) --- */
.ink-kanban-host {
  display: block;
  width: 100%;
  clear: both;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  padding-top: 10px;
  box-sizing: border-box;
  overflow-x: auto;
  position: relative;
}

.ink-kanban-board {
  display: flex;
  gap: 4px;
  align-items: flex-start;
}

.ink-kanban-column {
  flex: 1;
  min-width: 200px;
  background: rgba(120, 120, 120, 0.02);
  border: 1px solid var(--border-light);
  border-radius: calc(var(--radius) * 0.8);
  padding: 10px;
  display: flex;
  flex-direction: column;
  max-height: 500px;
}

.ink-kanban-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-light);
}

.ink-kanban-column-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  outline: none;
}

.ink-kanban-column-count {
  font-size: 11px;
  background: var(--border);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.ink-kanban-cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex-grow: 1;
  min-height: 80px;
  padding-bottom: 8px;
}

.ink-kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 5px;
  font-size: 13px;
  color: var(--text);
  cursor: grab;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.1s, border-color 0.1s;
}

.ink-kanban-card:active {
  cursor: grabbing;
}

.ink-kanban-card.dragging {
  opacity: 0.4;
  background: var(--border-light);
}

.ink-kanban-card-cb {
  margin-top: 2px;
  flex-shrink: 0;
}

.ink-kanban-card-text {
  flex-grow: 1;
  outline: none;
  min-width: 10px;
  word-break: break-word;
}

.ink-kanban-card-text[contenteditable="true"]:focus {
  background: var(--bg);
}

.ink-kanban-card-del {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0;
  transition: opacity 0.1s;
}

.ink-kanban-card:hover .ink-kanban-card-del {
  opacity: 1;
}

.ink-kanban-card-del:hover {
  color: var(--danger);
}

.ink-kanban-add-card-btn {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 5px;
  font-size: 11.5px;
  cursor: pointer;
  text-align: center;
  transition: background 0.1s, color 0.1s;
}

.ink-kanban-add-card-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

.ink-kanban-add-column-btn {
  flex-shrink: 0;
  width: 200px;
  border: 1px dashed var(--border);
  background: none;
  border-radius: calc(var(--radius) * 0.8);
  padding: 10px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  transition: background 0.1s, color 0.1s;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ink-kanban-add-column-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

/* Hide action buttons in read-only preview mode */
.preview-readonly .ink-matrix-add-btn,
.preview-readonly .ink-matrix-item-del,
.preview-readonly .ink-timeline-add-btn,
.preview-readonly .ink-timeline-item-del,
.preview-readonly .ink-kanban-add-card-btn,
.preview-readonly .ink-kanban-card-del,
.preview-readonly .ink-kanban-add-column-btn,
.preview-readonly .ink-calc-toolbar,
.preview-readonly .ink-calc-keypad {
  display: none !important;
}

.preview-readonly .ink-calc-row-input {
  pointer-events: none;
  cursor: default;
}

.ink-widget-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 550;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
  z-index: 2;
}

.ink-widget-delete-btn:hover {
  background: color-mix(in srgb, var(--danger) 8%, var(--surface));
  color: var(--danger);
  border-color: var(--danger);
}

.preview-readonly .ink-widget-delete-btn {
  display: none !important;
}

/* Enforce font inheritance for all input and button elements inside widget hosts */
.ink-matrix-host button,
.ink-matrix-host input,
.ink-timeline-host button,
.ink-timeline-host input,
.ink-calc-host button,
.ink-calc-host input,
.ink-kanban-host button,
.ink-kanban-host input {
  font-family: inherit;
}

/* Calculator History Pane and Items */
.ink-calc-pane.history-pane {
  display: none;
  grid-template-columns: 1fr;
  max-height: 180px;
  overflow-y: auto;
  gap: 6px;
  padding: 4px;
}

.ink-calc-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.1s ease;
  text-align: left;
  box-sizing: border-box;
}

.ink-calc-history-item:hover {
  background: var(--border-light);
  border-color: var(--border);
}

.ink-calc-history-expr {
  color: var(--text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ink-calc-history-res {
  color: var(--accent);
  font-weight: 600;
  margin-left: 12px;
  flex-shrink: 0;
}

.ink-calc-history-empty {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 16px 0;
  font-style: italic;
}

/* Redesigned Sidebar Tabs Segmented Control */
#sidebar-tabs {
  margin: 10px 10px 6px !important;
  padding: 3px !important;
  background: rgba(0, 0, 0, 0.08) !important;
  border-radius: calc(var(--radius) - 4px) !important;
  border: 1px solid var(--border-light) !important;
  box-shadow: var(--skeu-inset) !important;
  display: flex !important;
  gap: 2px !important;
}

#sidebar-tabs .sidebar-tab {
  flex: 1 !important;
  min-width: 0 !important;
  border: none !important;
  border-radius: calc(var(--radius) - 6px) !important;
  background: transparent !important;
  color: var(--text-muted) !important;
  font-family: var(--font-body) !important;
  font-size: 12.5px !important;
  font-weight: 600;
  padding: 6px 4px !important;
  cursor: pointer !important;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
  outline: none !important;
  box-shadow: none !important;
}

#sidebar-tabs .sidebar-tab:hover {
  color: var(--text) !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border: none !important;
}

#sidebar-tabs .sidebar-tab.active {
  color: var(--accent) !important;
  background: var(--surface) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), var(--skeu-raise) !important;
  border: none !important;
}