:root {
  color-scheme: light dark;
  --background: #f5f3ee;
  --surface: #fffdf8;
  --surface-raised: #ffffff;
  --surface-muted: #ece9e1;
  --text: #25231f;
  --muted: #6d6960;
  --border: #d9d4c9;
  --accent: #315c4b;
  --accent-hover: #244739;
  --accent-text: #ffffff;
  --danger: #a13d32;
  --danger-soft: #f8e7e4;
  --warning: #8a5a16;
  --warning-soft: #fff2cf;
  --focus: #397fca;
  --shadow: 0 14px 40px rgb(35 31 24 / 10%);
  --radius: 12px;
  --header-height: 60px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #171916;
    --surface: #1e211d;
    --surface-raised: #252923;
    --surface-muted: #2b3029;
    --text: #eeece6;
    --muted: #aaa99f;
    --border: #3c4139;
    --accent: #74b599;
    --accent-hover: #90c8af;
    --accent-text: #10241b;
    --danger: #ee8e81;
    --danger-soft: #442824;
    --warning: #edc170;
    --warning-soft: #41351f;
    --focus: #78b7f5;
    --shadow: 0 14px 40px rgb(0 0 0 / 35%);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.clipboard-fallback {
  position: fixed;
  width: 1px;
  height: 1px;
  left: -10000px;
  opacity: 0;
  pointer-events: none;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  line-height: 1.5;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  padding: 0.65rem 0.75rem;
}

textarea {
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 62%, transparent);
  outline-offset: 2px;
}

code {
  border-radius: 5px;
  background: var(--surface-muted);
  padding: 0.12rem 0.32rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  line-height: 1.18;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  transform: translateY(-180%);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0.6rem 0.9rem;
}

.skip-link:focus {
  transform: none;
}

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: var(--header-height);
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  padding: 0.55rem clamp(1rem, 3vw, 2rem);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 720;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-family: Georgia, serif;
}

.account-controls,
.button-row,
.section-heading-row,
.editor-topline,
.editor-actions,
.move-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.section-heading-row,
.editor-actions {
  justify-content: space-between;
}

.button,
.icon-button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  padding: 0.58rem 0.82rem;
  font-weight: 650;
}

.button:hover,
.icon-button:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: var(--surface-muted);
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.button.primary:hover {
  background: var(--accent-hover);
}

.button.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--danger);
}

.button.subtle {
  border-color: transparent;
  background: transparent;
}

.icon-button {
  display: inline-grid;
  min-width: 2.25rem;
  min-height: 2.25rem;
  place-items: center;
  padding: 0.25rem;
  font-size: 1.2rem;
}

.global-status,
.global-alert {
  position: fixed;
  z-index: 50;
  right: 1rem;
  bottom: 1rem;
  max-width: min(28rem, calc(100vw - 2rem));
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
}

.global-status:empty {
  display: none;
}

.global-status {
  background: var(--surface-raised);
}

.global-alert {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.centered-card {
  width: min(29rem, calc(100% - 2rem));
  margin: clamp(2rem, 9vh, 7rem) auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: clamp(1.35rem, 4vw, 2.4rem);
}

.wide-card {
  width: min(38rem, calc(100% - 2rem));
}

.eyebrow {
  margin-bottom: 0.35rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 1rem;
}

.compact-stack {
  gap: 0.7rem;
}

.field {
  display: grid;
  gap: 0.32rem;
}

.field label {
  font-size: 0.9rem;
  font-weight: 680;
}

.field-help,
.muted,
.empty-copy,
.save-status {
  color: var(--muted);
}

.field-help,
.empty-copy,
.save-status {
  margin: 0;
  font-size: 0.82rem;
}

.app-shell {
  display: grid;
  min-height: calc(100vh - var(--header-height));
  grid-template-columns: minmax(15rem, 20rem) minmax(0, 1fr);
}

.app-shell.devices-open {
  grid-template-columns: minmax(15rem, 19rem) minmax(24rem, 1fr) minmax(18rem, 23rem);
}

.sidebar,
.device-panel {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
}

.sidebar {
  display: flex;
  max-height: calc(100vh - var(--header-height));
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}

.sidebar-section {
  min-width: 0;
}

.sidebar-section.grow {
  min-height: 8rem;
  flex: 1;
}

.sidebar-heading {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.025em;
}

.note-tree,
.result-list,
.trash-list,
.token-list {
  display: grid;
  margin: 0.6rem 0 0;
  padding: 0;
  gap: 0.25rem;
  list-style: none;
}

.note-item {
  min-width: 0;
}

.note-item.depth-1 {
  padding-left: 0.82rem;
}

.note-item.depth-2 {
  padding-left: 1.64rem;
}

.note-item.depth-3 {
  padding-left: 2.46rem;
}

.note-item.depth-4 {
  padding-left: 3.28rem;
}

.note-item.depth-5 {
  padding-left: 4.1rem;
}

.note-item.depth-6 {
  padding-left: 4.92rem;
}

.note-button,
.result-button {
  width: 100%;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  padding: 0.48rem 0.55rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-button:hover,
.result-button:hover {
  background: var(--surface-muted);
}

.note-button[aria-current="true"] {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
  background: color-mix(in srgb, var(--accent) 13%, var(--surface));
  color: var(--accent);
  font-weight: 700;
}

.result-list {
  max-height: 17rem;
  overflow-y: auto;
}

.result-item {
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

.result-title,
.result-snippet {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-title {
  font-weight: 680;
}

.result-snippet {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.sidebar-details {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.sidebar-details summary {
  border-radius: 5px;
  font-weight: 700;
}

.sidebar-details[open] summary {
  margin-bottom: 0.8rem;
}

.count-badge {
  display: inline-block;
  min-width: 1.35rem;
  border-radius: 99px;
  background: var(--surface-muted);
  padding: 0.05rem 0.35rem;
  text-align: center;
  font-size: 0.75rem;
}

.trash-item,
.token-item {
  display: grid;
  gap: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  padding: 0.65rem;
}

.item-title {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.item-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.item-actions .button {
  padding: 0.34rem 0.52rem;
  font-size: 0.78rem;
}

.workspace {
  min-width: 0;
  background: var(--background);
}

.editor-empty {
  display: grid;
  min-height: calc(100vh - var(--header-height));
  place-content: center;
  padding: 2rem;
  text-align: center;
}

.editor {
  display: flex;
  min-height: calc(100vh - var(--header-height));
  flex-direction: column;
  gap: 0.8rem;
  padding: clamp(1rem, 3vw, 2.2rem);
}

.title-input {
  min-width: 0;
  flex: 1;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  padding: 0.35rem 0;
  font-size: clamp(1.45rem, 4vw, 2.25rem);
  font-weight: 760;
}

.title-input:focus {
  border-bottom-color: var(--border);
}

.save-status {
  flex: none;
}

.body-editor {
  min-height: 22rem;
  flex: 1;
  border-color: transparent;
  background: var(--surface);
  padding: clamp(0.9rem, 2vw, 1.4rem);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
  line-height: 1.65;
  resize: none;
}

.conflict-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid color-mix(in srgb, var(--warning) 50%, var(--border));
  border-radius: 9px;
  background: var(--warning-soft);
  color: var(--warning);
  padding: 0.8rem 1rem;
}

.conflict-panel p {
  margin: 0.2rem 0 0;
  font-size: 0.87rem;
}

.editor-actions {
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
}

.move-controls {
  flex-wrap: wrap;
}

.inline-field {
  min-width: 11rem;
  grid-template-columns: auto minmax(8rem, 1fr);
  align-items: center;
}

.device-panel {
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  border-right: 0;
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgb(0 0 0 / 7%);
}

.device-panel h2 {
  margin-bottom: 0;
}

.token-result {
  margin: 1rem 0;
  border: 1px solid color-mix(in srgb, var(--warning) 50%, var(--border));
  border-radius: 9px;
  background: var(--warning-soft);
  padding: 0.85rem;
}

.token-result h3,
.token-result p {
  margin-bottom: 0.45rem;
}

.token-result textarea {
  margin-bottom: 0.55rem;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.noscript {
  margin: 1rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  padding: 1rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .app-shell.devices-open {
    grid-template-columns: minmax(14rem, 18rem) minmax(0, 1fr);
  }

  .device-panel {
    position: fixed;
    z-index: 30;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: min(24rem, 92vw);
  }
}

@media (max-width: 720px) {
  :root {
    --header-height: 56px;
  }

  .account-controls .muted {
    display: none;
  }

  .app-shell,
  .app-shell.devices-open {
    display: block;
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .workspace,
  .editor,
  .editor-empty {
    min-height: 65vh;
  }

  .editor-topline,
  .conflict-panel,
  .editor-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .move-controls,
  .move-controls > * {
    width: 100%;
  }

  .inline-field {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .button,
  .icon-button,
  .note-button,
  .result-button {
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  }
}
