:root {
  --paper: #f7f0e4;
  --paper-deep: #eee2d1;
  --paper-light: #fffdf8;
  --paper-white: #fffaf2;
  --ink: #2e2923;
  --ink-soft: #756c61;
  --ink-faint: #9b9185;
  --line: #ddd1c1;
  --line-strong: #cbbba7;
  --brand: #9d5c3d;
  --brand-deep: #7f432b;
  --brand-soft: #f0d9c8;
  --sage: #63715d;
  --sage-soft: #e2e8dd;
  --gold: #b88a3f;
  --danger: #a84237;
  --danger-soft: #f6ded9;
  --warning: #8a6327;
  --warning-soft: #f6e9c9;
  --focus: #356aa0;
  --shadow-sm: 0 2px 10px rgba(69, 49, 31, 0.08);
  --shadow-md: 0 16px 45px rgba(69, 49, 31, 0.14);
  --shadow-lg: 0 28px 75px rgba(53, 38, 25, 0.2);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --sidebar-width: 296px;
  --ui-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --reading-font: "Iowan Old Style", "Noto Serif TC", "PMingLiU", Georgia, serif;
}

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

html {
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 4%, rgba(184, 138, 63, 0.09), transparent 27rem),
    var(--paper);
}

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

button,
select,
input[type="color"],
input[type="range"] {
  accent-color: var(--brand);
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

button:not(:disabled),
select:not(:disabled),
input[type="color"]:not(:disabled) {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

a {
  color: inherit;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 74%, white);
  outline-offset: 3px;
}

::selection {
  background: #ead2a7;
  color: #251f19;
}

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

.skip-link {
  position: fixed;
  inset: 12px auto auto 12px;
  z-index: 1000;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 160ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.text-btn,
.icon-btn,
.new-note-btn,
.tool-btn,
.aspect-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 10px;
  font-weight: 700;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.primary-btn {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fffdf8;
  box-shadow: 0 7px 18px rgba(125, 67, 43, 0.18);
}

.primary-btn:hover:not(:disabled) {
  border-color: var(--brand-deep);
  background: var(--brand-deep);
  transform: translateY(-1px);
}

.secondary-btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  background: var(--paper-light);
  color: var(--ink);
}

.secondary-btn:hover:not(:disabled),
.ghost-btn:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-deep);
}

.ghost-btn {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
}

.danger-btn {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--danger);
  background: var(--danger);
  color: white;
}

.danger-btn:hover:not(:disabled) {
  background: #8c3028;
}

.text-btn {
  min-height: 34px;
  padding: 4px 0;
  background: transparent;
  color: var(--brand-deep);
}

.text-btn:hover {
  text-decoration: underline;
}

.danger-text {
  color: var(--danger);
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.08rem;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
}

.compact-btn {
  min-height: 38px;
  padding-inline: 12px;
  font-size: 0.88rem;
}

.full-width {
  width: 100%;
}

.link-button {
  text-decoration: none;
}

/* Login */
.auth-view {
  position: relative;
  display: grid;
  grid-template-columns: minmax(380px, 540px) minmax(320px, 1fr);
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

.auth-view::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.62), transparent 46%),
    repeating-linear-gradient(0deg, rgba(91, 71, 50, 0.018) 0, rgba(91, 71, 50, 0.018) 1px, transparent 1px, transparent 5px),
    var(--paper);
  content: "";
}

.auth-view::after {
  position: absolute;
  inset: auto -10vw -28vh auto;
  z-index: -1;
  width: min(66vw, 900px);
  aspect-ratio: 1;
  border: 1px solid rgba(157, 92, 61, 0.14);
  border-radius: 50%;
  box-shadow: 0 0 0 90px rgba(157, 92, 61, 0.035), 0 0 0 180px rgba(157, 92, 61, 0.025);
  content: "";
}

.auth-card {
  align-self: center;
  width: min(100% - 48px, 440px);
  margin-inline: auto;
  padding: clamp(28px, 5vw, 52px);
  border: 1px solid rgba(203, 187, 167, 0.72);
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.86);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 42px;
}

.auth-brand-line {
  width: 54px;
  height: 1px;
  background: var(--line-strong);
}

.brand-mark {
  display: inline-grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 11px 11px 11px 3px;
  background: var(--brand);
  color: white;
  font-family: var(--reading-font);
  font-size: 1.25rem;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 5px 14px rgba(125, 67, 43, 0.2);
}

.brand-mark-large {
  width: 50px;
  height: 50px;
  border-radius: 15px 15px 15px 4px;
  font-size: 1.6rem;
}

.brand-mark.mini {
  width: 30px;
  height: 30px;
  border-radius: 9px 9px 9px 3px;
  font-size: 0.95rem;
}

.auth-card h1 {
  margin: 0;
  font-family: var(--reading-font);
  font-size: clamp(2rem, 5vw, 3.05rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.auth-lead {
  margin: 15px 0 34px;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form > label,
.dialog-body > label {
  font-size: 0.86rem;
  font-weight: 800;
}

.password-field {
  position: relative;
}

.password-field input,
.dialog-input,
.copy-field input {
  width: 100%;
  min-height: 48px;
  padding: 0 48px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.72);
  outline: 0;
}

.password-field input:focus,
.dialog-input:focus,
.copy-field input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(53, 106, 160, 0.14);
}

.password-toggle {
  position: absolute;
  inset: 4px 4px 4px auto;
  height: 40px;
}

.field-hint,
.form-error {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.79rem;
}

.field-hint {
  color: var(--ink-faint);
}

.form-error {
  color: var(--danger);
  font-weight: 650;
}

.auth-submit {
  justify-content: space-between;
  margin-top: 7px;
}

.auth-footnote {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 30px 0 0;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #74896c;
  box-shadow: 0 0 0 4px rgba(116, 137, 108, 0.13);
}

.auth-quote {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  padding: clamp(48px, 8vw, 120px);
}

.auth-quote p {
  margin: 0;
  color: rgba(46, 41, 35, 0.78);
  font-family: var(--reading-font);
  font-size: clamp(2.1rem, 4.2vw, 4.8rem);
  letter-spacing: -0.045em;
  line-height: 1.26;
  text-align: right;
}

.auth-quote span {
  margin-top: 24px;
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.2em;
}

/* Application shell */
.app-shell {
  --sidebar-width: 296px;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  transition: grid-template-columns 220ms ease;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100dvh;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(rgba(255, 253, 248, 0.9), rgba(248, 240, 228, 0.94)),
    repeating-linear-gradient(0deg, transparent 0, transparent 4px, rgba(80, 61, 42, 0.025) 5px);
  box-shadow: 7px 0 26px rgba(73, 51, 31, 0.045);
  transition: width 220ms ease, transform 220ms ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 15px 14px 14px 18px;
  border-bottom: 1px solid rgba(221, 209, 193, 0.72);
}

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

.brand-copy {
  display: grid;
  min-width: 0;
}

.brand-copy strong {
  font-family: var(--reading-font);
  font-size: 1.1rem;
  line-height: 1.15;
}

.brand-copy small {
  margin-top: 3px;
  color: var(--ink-faint);
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.15em;
}

.sidebar-toggle span {
  display: block;
  font-size: 1.6rem;
  transform: translateY(-1px);
  transition: transform 180ms ease;
}

.sidebar-primary-action {
  padding: 14px 14px 8px;
}

.new-note-btn {
  width: 100%;
  min-height: 46px;
  justify-content: flex-start;
  padding: 0 13px;
  border: 1px solid #c99b7f;
  background: var(--brand);
  color: white;
  box-shadow: 0 6px 15px rgba(125, 67, 43, 0.15);
}

.new-note-btn:hover {
  background: var(--brand-deep);
}

.new-note-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.sidebar-shortcut {
  margin-left: auto;
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.78);
  font-family: inherit;
  font-size: 0.62rem;
}

.sidebar-search {
  position: relative;
  margin: 4px 14px 10px;
}

.sidebar-search input {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.58);
  outline: 0;
  font-size: 0.84rem;
}

.sidebar-search input:focus {
  border-color: var(--brand);
  background: white;
  box-shadow: 0 0 0 3px rgba(157, 92, 61, 0.1);
}

.search-icon {
  position: absolute;
  inset: 7px auto auto 12px;
  z-index: 1;
  color: var(--ink-faint);
  font-size: 1.1rem;
}

.search-clear {
  position: absolute;
  inset: 6px 6px auto auto;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 1.1rem;
}

.search-clear:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

.sidebar-nav {
  overflow: hidden auto;
  padding: 0 8px 22px;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.sidebar-section {
  margin-top: 8px;
}

.shared-section {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid rgba(221, 209, 193, 0.75);
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar .section-heading-row {
  min-height: 35px;
  padding: 0 8px;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.section-icon {
  color: var(--brand);
  font-size: 0.9rem;
}

.count-badge {
  display: inline-grid;
  min-width: 23px;
  height: 20px;
  padding: 0 6px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink-faint);
  font-size: 0.65rem;
  font-weight: 800;
}

.section-toggle {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-align: left;
  text-transform: uppercase;
}

.section-chevron {
  margin-left: auto;
  font-size: 0.9rem;
  transition: transform 160ms ease;
}

.section-toggle[aria-expanded="false"] .section-chevron {
  transform: rotate(-90deg);
}

.note-list,
.shared-link-list,
.dialog-list {
  display: grid;
  gap: 4px;
  margin: 2px 0 0;
  padding: 0;
  list-style: none;
}

.note-list-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 11px;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.note-list-item:hover {
  background: rgba(255, 255, 255, 0.62);
}

.note-list-item.is-note-draggable {
  cursor: grab;
}

.note-list-item.is-note-draggable.is-dragging {
  opacity: 0.55;
}

.note-list-item[aria-selected="true"],
.note-list-item.is-active {
  border-color: #d2af97;
  background: #f5e2d2;
  box-shadow: inset 3px 0 0 var(--brand);
}

.note-select-btn {
  display: grid;
  min-width: 0;
  padding: 11px 8px 10px 11px;
  background: transparent;
  text-align: left;
}

.note-row-title,
.shared-link-title {
  overflow: hidden;
  font-size: 0.86rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-row-preview {
  overflow: hidden;
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 0.74rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-row-meta,
.shared-link-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  color: var(--ink-faint);
  font-size: 0.64rem;
}

.note-shared-badge,
.permission-badge {
  display: inline-flex;
  align-items: center;
  min-height: 19px;
  padding: 1px 7px;
  border: 1px solid #becab8;
  border-radius: 999px;
  background: var(--sage-soft);
  color: #4b6148;
  font-size: 0.62rem;
  font-weight: 800;
  white-space: nowrap;
}

.permission-badge[data-permission="edit"],
.permission-badge.is-edit {
  border-color: #ddbb81;
  background: #f6e8c9;
  color: #76531f;
}

.permission-badge.large {
  min-height: 30px;
  padding-inline: 11px;
  font-size: 0.75rem;
}

.note-row-menu-btn,
.shared-link-copy {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-faint);
}

.note-row-menu-btn:hover,
.shared-link-copy:hover {
  background: var(--paper-deep);
  color: var(--ink);
}

.sidebar-empty {
  display: grid;
  justify-items: center;
  margin: 12px 7px;
  padding: 25px 17px;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  color: var(--ink-faint);
  text-align: center;
}

.sidebar-empty > span:first-child {
  margin-bottom: 8px;
  color: var(--brand);
  font-size: 1.2rem;
}

.sidebar-empty strong {
  color: var(--ink-soft);
  font-size: 0.79rem;
}

.sidebar-empty span:last-child {
  margin-top: 3px;
  font-size: 0.69rem;
}

.sidebar-empty.compact {
  display: block;
  padding: 14px;
  font-size: 0.7rem;
}

.homepage-catalog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 8px 5px 5px;
}

.homepage-open-link,
.homepage-catalog-actions .text-btn {
  color: var(--brand);
  font-size: 0.7rem;
  font-weight: 750;
}

.homepage-catalog-status {
  margin: 5px 8px 8px;
  color: var(--ink-faint);
  font-size: 0.68rem;
  line-height: 1.45;
}

.homepage-catalog-list,
.homepage-catalog-children {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.homepage-catalog-list {
  margin: 0 5px 8px;
}

.homepage-catalog-children {
  margin: 3px 0 3px 10px;
  padding-left: 9px;
  border-left: 1px solid var(--line);
}

.homepage-catalog-folder summary {
  cursor: pointer;
  overflow: hidden;
  padding: 5px 4px;
  color: var(--ink-soft);
  font-size: 0.73rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.homepage-catalog-link a,
.homepage-catalog-link-button {
  display: block;
  width: 100%;
  overflow: hidden;
  padding: 4px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 0.69rem;
  text-align: left;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.homepage-catalog-link a:hover,
.homepage-catalog-link a:focus-visible,
.homepage-catalog-link-button:hover,
.homepage-catalog-link-button:focus-visible {
  background: var(--paper-deep);
  color: var(--brand);
}

.shared-link-item {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 30px;
  align-items: center;
  min-height: 52px;
  padding: 3px 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.34);
}

.shared-link-item:hover,
.shared-link-item.is-dragging {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.72);
}

.shared-link-item.is-dragging {
  opacity: 0.55;
}

.drag-handle {
  color: var(--ink-faint);
  cursor: grab;
  font-size: 0.85rem;
  text-align: center;
}

.shared-link-open {
  display: grid;
  min-width: 0;
  padding: 6px;
  background: transparent;
  text-align: left;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  padding: 10px 14px 10px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.7);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 650;
}

.sidebar-backdrop {
  display: none;
}

.app-shell.sidebar-collapsed,
.app-shell.is-sidebar-collapsed {
  --sidebar-width: 76px;
}

.sidebar.is-collapsed .brand-copy,
.sidebar.is-collapsed .sidebar-label,
.sidebar.is-collapsed .sidebar-shortcut,
.sidebar.is-collapsed .sidebar-search,
.sidebar.is-collapsed .sidebar-nav,
.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .sidebar-label,
.app-shell.sidebar-collapsed .sidebar-shortcut,
.app-shell.sidebar-collapsed .sidebar-search,
.app-shell.sidebar-collapsed .sidebar-nav,
.app-shell.is-sidebar-collapsed .brand-copy,
.app-shell.is-sidebar-collapsed .sidebar-label,
.app-shell.is-sidebar-collapsed .sidebar-shortcut,
.app-shell.is-sidebar-collapsed .sidebar-search,
.app-shell.is-sidebar-collapsed .sidebar-nav {
  display: none;
}

.sidebar.is-collapsed .sidebar-header,
.app-shell.sidebar-collapsed .sidebar-header,
.app-shell.is-sidebar-collapsed .sidebar-header {
  flex-direction: column;
  gap: 12px;
  padding: 14px 10px;
}

.sidebar.is-collapsed .sidebar-toggle span,
.app-shell.sidebar-collapsed .sidebar-toggle span,
.app-shell.is-sidebar-collapsed .sidebar-toggle span {
  transform: rotate(180deg) translateY(1px);
}

.sidebar.is-collapsed .sidebar-primary-action,
.app-shell.sidebar-collapsed .sidebar-primary-action,
.app-shell.is-sidebar-collapsed .sidebar-primary-action {
  padding: 12px 10px;
}

.sidebar.is-collapsed .new-note-btn,
.app-shell.sidebar-collapsed .new-note-btn,
.app-shell.is-sidebar-collapsed .new-note-btn {
  justify-content: center;
  padding: 0;
}

.sidebar.is-collapsed .sidebar-footer,
.app-shell.sidebar-collapsed .sidebar-footer,
.app-shell.is-sidebar-collapsed .sidebar-footer {
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 8px;
}

/* Main workspace */
.workspace {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
}

.workspace-header {
  position: relative;
  z-index: 18;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: center;
  gap: 22px;
  min-height: 88px;
  padding: 13px clamp(18px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 240, 228, 0.92);
  backdrop-filter: blur(16px);
}

.mobile-sidebar-toggle {
  display: none;
}

.workspace-title-block {
  min-width: 0;
}

.workspace-kicker {
  margin: 0 0 1px;
  color: var(--ink-faint);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.note-title-input,
.shared-title-input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--reading-font);
  font-size: clamp(1.3rem, 2.4vw, 1.82rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  outline: 0;
  text-overflow: ellipsis;
}

.note-title-input:focus-visible,
.shared-title-input:focus-visible {
  border-radius: 5px;
  outline: 3px solid rgba(53, 106, 160, 0.35);
  outline-offset: 4px;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-right: 8px;
  color: var(--ink-faint);
  font-size: 0.73rem;
  font-weight: 650;
  white-space: nowrap;
}

.save-status-icon {
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--sage-soft);
  color: var(--sage);
  font-size: 0.68rem;
}

.save-status.is-saving .save-status-icon {
  animation: pulse 1s ease-in-out infinite;
  background: var(--warning-soft);
  color: var(--warning);
}

.save-status.is-error {
  color: var(--danger);
}

.save-status.is-error .save-status-icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.action-menu {
  position: absolute;
  inset: calc(100% - 12px) 28px auto auto;
  z-index: 60;
  display: grid;
  width: 210px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-light);
  box-shadow: var(--shadow-md);
}

.action-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.action-menu button:hover {
  background: var(--paper-deep);
}

.action-menu hr {
  width: 100%;
  margin: 5px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.action-menu .danger-menu-item {
  color: var(--danger);
}

.editor-region {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 80% 12%, rgba(157, 92, 61, 0.06), transparent 25rem),
    repeating-linear-gradient(90deg, transparent 0, transparent 119px, rgba(100, 79, 57, 0.025) 120px),
    var(--paper);
}

.editor-region > .editor-toolbar {
  grid-row: 1;
}

.editor-region > .image-context-toolbar {
  grid-row: 2;
}

.editor-region > .editor-scroll {
  grid-row: 3;
}

.editor-region > .editor-footer {
  grid-row: 4;
}

/* Toolbars */
.editor-toolbar,
.image-context-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  padding: 8px clamp(12px, 2vw, 24px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.95);
  box-shadow: 0 4px 16px rgba(73, 51, 31, 0.04);
  backdrop-filter: blur(14px);
}

.editor-toolbar {
  position: relative;
  z-index: 15;
  flex-wrap: wrap;
}

.editor-toolbar.is-pinned,
.editor-toolbar[data-toolbar-mode="pinned"] {
  position: sticky;
  top: 0;
}

.editor-toolbar.is-floating,
.editor-toolbar[data-toolbar-mode="floating"] {
  position: fixed;
  z-index: 90;
  top: 108px;
  left: max(calc(var(--sidebar-width) + 24px), 24px);
  width: min(920px, calc(100vw - var(--sidebar-width) - 48px));
  max-height: min(54vh, 330px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}

.toolbar-drag-handle {
  display: none;
  align-self: stretch;
  width: 28px;
  min-height: 36px;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink-faint);
  cursor: grab;
  font-size: 1.05rem;
}

.is-floating .toolbar-drag-handle,
[data-toolbar-mode="floating"] .toolbar-drag-handle {
  display: inline-grid;
  place-items: center;
}

.toolbar-drag-handle:active {
  cursor: grabbing;
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 0 6px;
  border-right: 1px solid var(--line);
}

.toolbar-group:last-child,
.toolbar-mode-controls {
  border-right: 0;
}

.toolbar-spacer {
  flex: 1 1 6px;
}

.tool-btn {
  min-width: 34px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.tool-btn:hover:not(:disabled) {
  border-color: var(--line);
  background: var(--paper-deep);
  color: var(--ink);
}

.tool-btn[aria-pressed="true"],
.tool-btn.is-active {
  border-color: #d1a98f;
  background: var(--brand-soft);
  color: var(--brand-deep);
}

.tool-btn.typographic {
  font-family: Georgia, serif;
  font-size: 0.95rem;
}

.tool-btn-wide {
  min-width: auto;
  gap: 6px;
}

.danger-tool {
  color: var(--danger);
}

.tool-select,
.image-field-group select,
.image-field-group input {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-light);
  color: var(--ink-soft);
  outline: 0;
  font-size: 0.76rem;
}

.tool-select:focus,
.image-field-group select:focus,
.image-field-group input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(53, 106, 160, 0.12);
}

.font-select {
  width: 112px;
  padding: 0 26px 0 8px;
}

.size-select {
  width: 60px;
  padding-left: 6px;
}

.color-tools {
  gap: 5px;
}

.color-tool {
  position: relative;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: Georgia, serif;
  font-size: 0.88rem;
  font-weight: 800;
}

.color-tool:hover {
  border-color: var(--line);
  background: var(--paper-deep);
}

.color-tool input {
  position: absolute;
  inset: auto 5px 4px;
  width: 24px;
  height: 4px;
  padding: 0;
  border: 0;
  background: transparent;
}

.highlight-tool {
  background: linear-gradient(transparent 48%, rgba(243, 223, 159, 0.9) 48%, rgba(243, 223, 159, 0.9) 88%, transparent 88%);
}

.align-glyph {
  display: block;
  width: 15px;
  height: 12px;
  background: repeating-linear-gradient(to bottom, currentColor 0, currentColor 1px, transparent 1px, transparent 4px);
  opacity: 0.9;
}

.align-glyph.align-left {
  clip-path: polygon(0 0, 100% 0, 100% 14%, 0 14%, 0 29%, 70% 29%, 70% 43%, 0 43%, 0 57%, 92% 57%, 92% 71%, 0 71%, 0 86%, 65% 86%, 65% 100%, 0 100%);
}

.align-glyph.align-center {
  clip-path: polygon(0 0, 100% 0, 100% 14%, 0 14%, 15% 29%, 85% 29%, 85% 43%, 15% 43%, 5% 57%, 95% 57%, 95% 71%, 5% 71%, 18% 86%, 82% 86%, 82% 100%, 18% 100%);
}

.align-glyph.align-right {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 35% 100%, 35% 86%, 100% 86%, 100% 71%, 8% 71%, 8% 57%, 100% 57%, 100% 43%, 30% 43%, 30% 29%, 100% 29%, 100% 14%, 0 14%);
}

.align-glyph.align-justify {
  clip-path: none;
}

.image-context-toolbar {
  position: relative;
  z-index: 14;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom-color: #c9d2c4;
  background: rgba(242, 246, 239, 0.97);
}

.context-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-right: 8px;
  color: #4f614a;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.selection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 4px rgba(99, 113, 93, 0.12);
}

.image-field-group {
  gap: 6px;
}

.image-field-group label {
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 750;
  white-space: nowrap;
}

.image-field-group input {
  width: min(190px, 22vw);
  padding: 0 9px;
}

.compact-field select {
  width: 78px;
  padding: 0 5px;
}

/* Editor surface */
.editor-scroll {
  position: relative;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(22px, 4vw, 52px) clamp(14px, 4vw, 48px) 68px;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.paper-sheet,
.editor {
  width: min(100%, 920px);
  min-height: min(820px, calc(100dvh - 250px));
  margin: 0 auto;
  padding: clamp(38px, 6vw, 82px) clamp(28px, 8vw, 98px);
  border: 1px solid #dfd4c5;
  border-radius: 3px;
  background:
    linear-gradient(90deg, transparent 0, transparent 55px, rgba(167, 94, 69, 0.08) 56px, transparent 57px),
    repeating-linear-gradient(0deg, transparent 0, transparent 31px, rgba(94, 75, 55, 0.045) 32px),
    var(--paper-light);
  box-shadow: 0 18px 55px rgba(67, 47, 28, 0.1), 0 1px 2px rgba(67, 47, 28, 0.12);
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 1rem;
  line-height: 2;
  outline: 0;
  overflow-wrap: anywhere;
}

.editor:focus-visible {
  border-color: #aebdcd;
  box-shadow: 0 18px 55px rgba(67, 47, 28, 0.1), 0 0 0 4px rgba(53, 106, 160, 0.12);
}

.editor:empty::before {
  color: #aaa095;
  content: attr(data-placeholder);
  pointer-events: none;
}

.editor h1,
.editor h2,
.editor h3 {
  font-family: var(--reading-font);
  line-height: 1.35;
}

.editor h1 {
  font-size: 2.05em;
}

.editor h2 {
  font-size: 1.55em;
}

.editor h3 {
  font-size: 1.24em;
}

.editor p,
.editor ul,
.editor ol,
.editor blockquote {
  margin-block: 0 1em;
}

.editor blockquote {
  margin-inline: 0;
  padding: 6px 0 6px 19px;
  border-left: 3px solid var(--brand);
  color: var(--ink-soft);
  font-family: var(--reading-font);
  font-size: 1.08em;
}

.editor a {
  color: #315f86;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.editor img,
.editor figure {
  max-width: 100%;
}

.editor img {
  height: auto;
  border-radius: 9px;
  box-shadow: 0 8px 24px rgba(56, 41, 28, 0.13);
  cursor: pointer;
}

.editor img.is-selected,
.editor figure.is-selected img,
.editor [data-image-selected="true"] {
  outline: 3px solid var(--sage);
  outline-offset: 5px;
}

.editor figure {
  margin: 1.8em auto;
}

.editor figure.note-image {
  position: relative;
  clear: both;
  width: 100%;
  transition: width 160ms ease, opacity 160ms ease;
}

.editor figure.note-image.align-left {
  margin-right: auto;
  margin-left: 0;
}

.editor figure.note-image.align-center {
  margin-right: auto;
  margin-left: auto;
}

.editor figure.note-image.align-right {
  margin-right: 0;
  margin-left: auto;
}

.editor figure.note-image.is-dragging {
  opacity: 0.45;
}

.editor figcaption {
  display: none;
  margin-top: 6px;
  color: var(--ink-faint);
  font-size: 0.76rem;
  line-height: 1.5;
  text-align: center;
}

.empty-workspace {
  display: grid;
  width: min(100%, 680px);
  min-height: calc(100dvh - 290px);
  margin: 0 auto;
  place-content: center;
  justify-items: center;
  color: var(--ink-soft);
  text-align: center;
}

.empty-workspace h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--reading-font);
  font-size: clamp(1.65rem, 3.2vw, 2.45rem);
  letter-spacing: -0.03em;
}

.empty-workspace > p:not(.eyebrow) {
  margin: 11px 0 26px;
  font-size: 0.9rem;
}

.empty-illustration {
  position: relative;
  width: 112px;
  height: 94px;
  margin-bottom: 28px;
}

.empty-illustration span {
  position: absolute;
  inset: 0;
  border: 1px solid var(--line-strong);
  border-radius: 4px 12px 4px 4px;
  background: var(--paper-light);
  box-shadow: var(--shadow-sm);
}

.empty-illustration span:nth-child(1) {
  transform: rotate(-8deg) translate(-15px, 5px);
}

.empty-illustration span:nth-child(2) {
  transform: rotate(7deg) translate(14px, 4px);
}

.empty-illustration span:nth-child(3) {
  display: block;
  transform: rotate(0);
}

.empty-illustration span:nth-child(3)::after {
  position: absolute;
  inset: 24px 22px;
  background: repeating-linear-gradient(to bottom, var(--line-strong) 0, var(--line-strong) 1px, transparent 1px, transparent 12px);
  content: "";
}

.image-drop-overlay {
  position: absolute;
  inset: 18px;
  z-index: 40;
  display: grid;
  place-items: center;
  border: 2px dashed var(--brand);
  border-radius: 18px;
  background: rgba(255, 250, 242, 0.92);
  color: var(--brand-deep);
  backdrop-filter: blur(8px);
}

.image-drop-overlay div {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.image-drop-overlay span {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-soft);
  font-size: 1.8rem;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 35px;
  padding: 0 clamp(18px, 4vw, 42px);
  border-top: 1px solid rgba(221, 209, 193, 0.75);
  background: rgba(247, 240, 228, 0.92);
  color: var(--ink-faint);
  font-size: 0.67rem;
}

/* Dialogs */
.modal-dialog {
  width: min(calc(100% - 32px), 590px);
  max-height: min(88dvh, 820px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--paper-light);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.modal-dialog[open] {
  animation: dialog-in 180ms ease-out;
}

.modal-dialog::backdrop {
  background: rgba(39, 31, 24, 0.52);
  backdrop-filter: blur(4px);
}

.compact-dialog {
  width: min(calc(100% - 32px), 470px);
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 22px;
}

.dialog-header {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 0;
  font-family: var(--reading-font);
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.dialog-header .eyebrow {
  margin-bottom: 3px;
  font-size: 0.61rem;
}

.dialog-body {
  max-height: calc(88dvh - 150px);
  padding: 22px;
  overflow: auto;
}

.dialog-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  background: #fbf6ed;
}

.permission-fieldset {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  border: 0;
}

.permission-fieldset legend {
  margin-bottom: 9px;
  font-size: 0.82rem;
  font-weight: 800;
}

.permission-card {
  position: relative;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 12px;
  min-height: 78px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.58);
  cursor: pointer;
}

.permission-card:hover {
  border-color: #c8a78f;
}

.permission-card:has(input:checked) {
  border-color: var(--brand);
  background: #fbede2;
  box-shadow: 0 0 0 2px rgba(157, 92, 61, 0.08);
}

.permission-card input {
  position: absolute;
  opacity: 0;
}

.permission-card input:focus-visible + .permission-icon {
  outline: 3px solid rgba(53, 106, 160, 0.5);
  outline-offset: 3px;
}

.permission-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  background: var(--paper-deep);
  color: var(--brand);
  font-size: 1.1rem;
}

.permission-card strong,
.permission-card small {
  display: block;
}

.permission-card strong {
  font-size: 0.88rem;
}

.permission-card small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 0.73rem;
  font-weight: 400;
}

.radio-mark {
  display: block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px var(--paper-light);
}

.permission-card:has(input:checked) .radio-mark {
  border-color: var(--brand);
  background: var(--brand);
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-top: 15px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.notice > span:first-child,
.notice-icon {
  display: grid;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--brand);
  font-weight: 900;
}

.notice p {
  margin: 0;
}

.notice strong {
  color: var(--ink);
}

.notice.warning {
  border-color: #dfc591;
  background: var(--warning-soft);
  color: #6c542b;
}

.notice.warning > span:first-child {
  background: #ead29b;
  color: #75551f;
}

.share-result {
  margin-top: 18px;
  padding: 15px;
  border: 1px solid #bdc9b8;
  border-radius: 13px;
  background: #f0f5ec;
}

.share-result > label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.76rem;
  font-weight: 800;
}

.copy-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.copy-field input {
  min-height: 42px;
  padding: 0 10px;
  background: white;
  font-size: 0.77rem;
}

.share-result-actions {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
}

.existing-shares {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.existing-shares h3 {
  margin: 0;
  font-size: 0.84rem;
}

.dialog-list {
  margin-top: 10px;
}

.dialog-list > li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.dialog-empty {
  margin: 10px 0 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--ink-faint);
  font-size: 0.76rem;
  text-align: center;
}

.dialog-message {
  margin: 0;
  color: var(--ink);
  font-size: 0.98rem;
}

.dialog-detail {
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-size: 0.81rem;
}

.dialog-input {
  margin-top: 8px;
  padding-right: 14px;
}

/* Image editor */
.image-editor-dialog {
  width: min(calc(100% - 28px), 1040px);
  max-height: 92dvh;
}

.image-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  min-height: min(610px, calc(92dvh - 146px));
}

.image-editor-stage {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 420px;
  padding: 22px;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(45deg, #d8d3cb 25%, transparent 25%),
    linear-gradient(-45deg, #d8d3cb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d3cb 75%),
    linear-gradient(-45deg, transparent 75%, #d8d3cb 75%),
    #ece8e1;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.image-editor-stage img {
  display: block;
  max-width: 100%;
  max-height: 68dvh;
}

.image-editor-controls {
  padding: 18px;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #fbf6ed;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper-deep);
}

.segmented-control button {
  min-height: 36px;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.segmented-control button.is-active,
.segmented-control button[aria-selected="true"] {
  background: var(--paper-light);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.image-control-panel {
  margin-top: 22px;
}

.image-control-panel h3 {
  margin: 20px 0 9px;
  font-size: 0.76rem;
}

.aspect-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.aspect-btn {
  min-width: 0;
  min-height: 38px;
  padding: 0 5px;
  border: 1px solid var(--line);
  background: var(--paper-light);
  color: var(--ink-soft);
  font-size: 0.7rem;
}

.aspect-btn:hover,
.aspect-btn.is-active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-deep);
}

.button-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.button-pair .secondary-btn {
  padding-inline: 8px;
  font-size: 0.72rem;
}

.range-control {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.range-control > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
}

.range-control output {
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.range-control input {
  width: 100%;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background: rgba(42, 36, 30, 0.82);
  color: white;
  text-align: center;
  backdrop-filter: blur(5px);
}

.processing-overlay span:last-child {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78rem;
}

.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(157, 92, 61, 0.22);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.large-spinner {
  width: 42px;
  height: 42px;
  border-width: 4px;
}

/* Shared note page */
.share-page {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 7% 3%, rgba(184, 138, 63, 0.11), transparent 26rem),
    repeating-linear-gradient(0deg, transparent 0, transparent 5px, rgba(80, 61, 42, 0.018) 6px),
    var(--paper);
}

.share-site-header {
  position: sticky;
  z-index: 50;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 11px clamp(18px, 5vw, 64px);
  border-bottom: 1px solid rgba(221, 209, 193, 0.82);
  background: rgba(247, 240, 228, 0.9);
  backdrop-filter: blur(16px);
}

.share-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-main {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: clamp(22px, 5vw, 64px) clamp(14px, 4vw, 42px) 80px;
}

.share-state-card {
  display: grid;
  width: min(100%, 560px);
  min-height: 390px;
  margin: clamp(24px, 8vh, 90px) auto;
  padding: 50px 32px;
  place-content: center;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 253, 248, 0.78);
  box-shadow: var(--shadow-md);
  color: var(--ink-soft);
  text-align: center;
}

.share-state-card h1 {
  margin: 22px 0 4px;
  color: var(--ink);
  font-family: var(--reading-font);
  font-size: 2rem;
}

.share-state-card p {
  margin: 4px 0;
}

.state-symbol {
  display: grid;
  width: 64px;
  height: 64px;
  margin-bottom: 22px;
  place-items: center;
  border: 1px solid #dbb0a8;
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger);
  font-family: var(--reading-font);
  font-size: 2rem;
  font-weight: 800;
}

.error-state h1 {
  margin-top: 3px;
}

.state-actions {
  display: flex;
  gap: 8px;
  margin-top: 25px;
}

.shared-document {
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper-light);
  box-shadow: var(--shadow-md);
}

.shared-document-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  padding: clamp(28px, 5vw, 58px) clamp(24px, 7vw, 82px) 28px;
  border-bottom: 1px solid var(--line);
}

.shared-document-heading {
  min-width: 0;
}

.shared-document-heading h1 {
  margin: 0;
  font-family: var(--reading-font);
  font-size: clamp(2rem, 5.3vw, 4.25rem);
  letter-spacing: -0.045em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.shared-title-input {
  font-size: clamp(2rem, 5.3vw, 4.25rem);
}

.shared-document-meta {
  display: grid;
  flex: 0 0 auto;
  justify-items: end;
  gap: 8px;
  color: var(--ink-faint);
  font-size: 0.7rem;
  white-space: nowrap;
}

.shared-document > .notice {
  margin: 20px clamp(24px, 7vw, 82px) 0;
}

.paper-notice {
  border-color: #cbd3c5;
  background: #f1f5ee;
}

.edit-notice {
  position: relative;
  border-color: #ddc38f;
  background: #faf0d8;
}

.edit-notice .icon-btn {
  margin-left: auto;
}

.share-editor-toolbar {
  margin-top: 20px;
  border-top: 1px solid var(--line);
}

.share-image-context-toolbar {
  border-top: 1px solid #c9d2c4;
}

.share-editor-wrap {
  position: relative;
}

.shared-editor {
  width: 100%;
  min-height: 500px;
  margin: 0;
  padding: clamp(38px, 7vw, 84px) clamp(24px, 9vw, 120px);
  border: 0;
  border-radius: 0;
  background: var(--paper-light);
  box-shadow: none;
  font-size: clamp(1rem, 1.4vw, 1.12rem);
  line-height: 2.05;
}

.shared-editor[contenteditable="false"] {
  cursor: default;
}

.shared-document-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 16px clamp(24px, 7vw, 82px);
  border-top: 1px solid var(--line);
  background: #fbf6ed;
  color: var(--ink-faint);
  font-size: 0.7rem;
}

.share-origin {
  display: flex;
  align-items: center;
  gap: 10px;
}

.share-origin > span:last-child {
  display: grid;
}

.share-origin strong {
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.share-origin small {
  margin-top: 2px;
}

/* Toasts and fallback */
.toast-region {
  position: fixed;
  z-index: 200;
  inset: auto 24px 24px auto;
  display: grid;
  width: min(360px, calc(100vw - 32px));
  gap: 8px;
  pointer-events: none;
}

.toast,
.toast-region:not(:empty) {
  padding: 12px 15px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 12px;
  background: #332d27;
  color: white;
  box-shadow: var(--shadow-lg);
  font-size: 0.82rem;
  font-weight: 650;
}

.toast.is-error {
  background: #7f332d;
}

.toast.is-success {
  background: #355f46;
}

.connection-status.is-offline {
  color: var(--danger);
}

.connection-status.is-offline .status-dot {
  background: var(--danger);
}

.save-status[data-status="error"],
.save-status[data-status="pending"] {
  cursor: pointer;
}

.shared-link-item.has-download {
  grid-template-columns: 20px minmax(0, 1fr) 30px 30px;
}

.shared-link-item.is-edit-link .drag-handle {
  opacity: 0.35;
  cursor: not-allowed;
}

.dialog-list-item > div:first-child {
  display: grid;
  gap: 2px;
}

.dialog-list-item small {
  color: var(--ink-faint);
  font-size: 0.7rem;
}

.dialog-list-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.noscript-message {
  position: fixed;
  z-index: 500;
  inset: auto 16px 16px;
  padding: 13px 16px;
  border-radius: 10px;
  background: var(--danger);
  color: white;
  font-weight: 750;
  text-align: center;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  50% { opacity: 0.45; }
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Responsive */
@media (max-width: 1180px) {
  .editor-toolbar {
    padding-inline: 10px;
  }

  .toolbar-group {
    padding-inline: 4px;
  }

  .tool-label {
    display: none;
  }

  .image-field-group input {
    width: 145px;
  }
}

@media (max-width: 960px) {
  .auth-view {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-quote {
    display: none;
  }

  .app-shell,
  .app-shell.sidebar-collapsed,
  .app-shell.is-sidebar-collapsed {
    --sidebar-width: 0px;
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(88vw, 320px);
    box-shadow: 16px 0 50px rgba(46, 35, 25, 0.22);
    transform: translateX(-105%);
  }

  .sidebar.is-collapsed .brand-copy,
  .sidebar.is-collapsed .sidebar-label,
  .sidebar.is-collapsed .sidebar-shortcut,
  .sidebar.is-collapsed .sidebar-search,
  .sidebar.is-collapsed .sidebar-nav {
    display: revert;
  }

  .sidebar.is-collapsed .sidebar-header {
    flex-direction: row;
    padding: 15px 14px 14px 18px;
  }

  .sidebar.is-collapsed .sidebar-primary-action {
    padding: 14px 14px 8px;
  }

  .sidebar.is-collapsed .new-note-btn {
    justify-content: flex-start;
    padding: 0 13px;
  }

  .sidebar.is-collapsed .sidebar-footer {
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 14px 10px 18px;
  }

  .app-shell.sidebar-open .sidebar,
  .app-shell.is-sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    display: block;
    background: rgba(45, 36, 28, 0.48);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .app-shell.sidebar-open .sidebar-backdrop,
  .app-shell.is-sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sidebar-toggle {
    display: inline-flex;
  }

  .workspace-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .workspace-actions .save-status {
    display: none;
  }

  .editor-toolbar.is-floating,
  .editor-toolbar[data-toolbar-mode="floating"] {
    left: 16px;
    width: calc(100vw - 32px);
  }

  .image-editor-layout {
    grid-template-columns: 1fr;
    max-height: calc(92dvh - 146px);
    overflow: auto;
  }

  .image-editor-stage {
    min-height: 45dvh;
  }

  .image-editor-controls {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 720px) {
  .auth-view::after {
    inset: auto -46vw -10vh auto;
    width: 120vw;
  }

  .auth-card {
    width: min(100% - 28px, 440px);
    padding: 29px 24px;
    border-radius: 21px;
  }

  .auth-brand {
    margin-bottom: 32px;
  }

  .workspace-header {
    min-height: 74px;
    gap: 8px;
    padding: 10px 12px;
  }

  .workspace-kicker {
    display: none;
  }

  .note-title-input {
    font-size: 1.25rem;
  }

  .workspace-actions {
    gap: 3px;
  }

  .workspace-actions .secondary-btn {
    width: 40px;
    padding: 0;
  }

  .workspace-actions .secondary-btn span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .editor-region {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .editor-toolbar,
  .image-context-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 7px 8px;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
  }

  .editor-toolbar .toolbar-group,
  .image-context-toolbar .toolbar-group,
  .context-title {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .toolbar-spacer {
    display: none;
  }

  .toolbar-mode-controls,
  .toolbar-drag-handle {
    display: none !important;
  }

  .editor-toolbar.is-floating,
  .editor-toolbar[data-toolbar-mode="floating"] {
    position: sticky;
    top: 0;
    left: auto;
    width: auto;
    max-height: none;
    border-width: 0 0 1px;
    border-radius: 0;
    box-shadow: 0 4px 16px rgba(73, 51, 31, 0.04);
  }

  .image-field-group input {
    width: 150px;
  }

  .editor-scroll {
    padding: 0;
  }

  .paper-sheet,
  .editor {
    min-height: 100%;
    padding: 36px 24px 70px;
    border-width: 0;
    background:
      repeating-linear-gradient(0deg, transparent 0, transparent 31px, rgba(94, 75, 55, 0.04) 32px),
      var(--paper-light);
    box-shadow: none;
  }

  .empty-workspace {
    min-height: calc(100dvh - 180px);
    padding: 36px 24px;
  }

  .editor-footer {
    padding-inline: 14px;
  }

  .modal-dialog {
    width: calc(100% - 16px);
    max-height: 94dvh;
    border-radius: 16px;
  }

  .dialog-header,
  .dialog-footer {
    padding: 15px 16px;
  }

  .dialog-body {
    max-height: calc(94dvh - 140px);
    padding: 17px 16px;
  }

  .permission-card {
    grid-template-columns: 34px minmax(0, 1fr) 20px;
    gap: 9px;
    padding: 12px;
  }

  .copy-field {
    grid-template-columns: 1fr;
  }

  .share-result-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .image-editor-dialog {
    width: 100%;
    max-width: none;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .image-editor-layout {
    max-height: calc(100dvh - 134px);
  }

  .image-editor-stage {
    min-height: 42dvh;
    padding: 12px;
  }

  .image-editor-controls {
    padding: 15px;
  }

  .share-site-header {
    min-height: 62px;
    padding: 9px 13px;
  }

  .share-brand .brand-copy small {
    display: none;
  }

  .share-header-actions .secondary-btn {
    width: 40px;
    padding: 0;
  }

  .share-header-actions .secondary-btn span + * {
    display: none;
  }

  .share-main {
    padding: 12px 0 50px;
  }

  .shared-document {
    border-width: 1px 0;
    box-shadow: none;
  }

  .shared-document-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 13px;
    padding: 30px 22px 22px;
  }

  .shared-document-meta {
    justify-items: start;
  }

  .shared-document > .notice {
    margin: 14px 15px 0;
  }

  .shared-editor {
    min-height: 420px;
    padding: 40px 22px 62px;
  }

  .shared-document-footer {
    padding: 14px 18px;
  }

  .share-origin small {
    display: none;
  }

  .share-state-card {
    width: calc(100% - 28px);
    min-height: 360px;
    padding: 40px 24px;
  }

  .toast-region {
    inset: auto 16px 16px;
    width: auto;
  }
}

@media (max-width: 430px) {
  .permission-badge.large {
    display: none;
  }

  .font-select {
    width: 100px;
  }

  .dialog-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .dialog-footer > button {
    width: 100%;
  }

  .image-editor-dialog .dialog-footer {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding-inline: 10px;
  }

  .image-editor-dialog .dialog-footer > button {
    padding-inline: 5px;
    font-size: 0.74rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .brand-mark,
  .primary-btn,
  .danger-btn,
  .status-dot,
  .selection-dot {
    forced-color-adjust: none;
  }

  .editor img.is-selected,
  .editor [data-image-selected="true"] {
    outline-color: Highlight;
  }
}

.homepage-drop-target {
  transition: background-color 120ms ease, outline-color 120ms ease;
}

.homepage-drop-target.is-drop-hover {
  outline: 2px dashed var(--accent, #a85f3c);
  outline-offset: 3px;
  background: #f7e3d3;
  border-radius: 7px;
}

@media print {
  .share-site-header,
  .share-editor-toolbar,
  .share-image-context-toolbar,
  .shared-document > .notice,
  .toast-region {
    display: none !important;
  }

  .share-page,
  .share-main,
  .shared-document,
  .shared-editor {
    margin: 0;
    padding: 0;
    border: 0;
    background: white;
    box-shadow: none;
  }

  .shared-document-header {
    padding: 0 0 22px;
  }

  .shared-editor {
    padding-top: 28px;
  }
}
