/* iOS-inspired theme: Apple system colors and materials, SF-style type,
   capsule tabs, switches, a segmented control, alerts and context menus. */

:root {
  color-scheme: light dark;

  --font-ui: -apple-system, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  /* Emoji fonts follow the code font so emoji render in color, as in Sublime Text. */
  --font-mono: "SF Mono", "Cascadia Mono", Consolas, "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", monospace;
  --font-emoji: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  --line-height: 22px;
  --editor-font-size: 14px;
  /* The editor's own colors; editor themes (themes.css) replace these. */
  --editor-text: var(--label);
  --editor-gutter: var(--label-3);

  --editor: #ffffff;
  --grouped: #f2f2f7;
  /* Must match TOOLBAR_COLORS in main.js. */
  --toolbar: #f6f6f8;
  --elevated: #ffffff;
  --material: rgba(246, 246, 248, 0.82);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-strong: rgba(120, 120, 128, 0.2);
  --switch-off: #e9e9eb;
  --segment-on: #ffffff;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.22);
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  --row-selected: var(--blue);
  --text-selection: rgba(0, 122, 255, 0.22);
  --current-line: rgba(120, 120, 128, 0.07);
  --selection-match: rgba(120, 120, 128, 0.18);
  --search-match: rgba(255, 204, 0, 0.32);
  --search-match-border: rgba(255, 159, 10, 0.5);
  --search-match-current: rgba(255, 159, 10, 0.55);
  --checker: #e5e5ea;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.16), 0 0 0 0.5px rgba(0, 0, 0, 0.08);

  /* Syntax colors from Xcode's default light theme. */
  --syntax-keyword: #ad3da4;
  --syntax-string: #d12f1b;
  --syntax-regexp: #c4521a;
  --syntax-number: #272ad8;
  --syntax-comment: #5d6c79;
  --syntax-type: #703daa;
  --syntax-declaration: #0b4f79;
  --syntax-function: #326d74;
  --syntax-variable: #1f7a8c;
  --syntax-attribute: #947100;
  --syntax-tag: #ad3da4;
  --syntax-preprocessor: #78492a;
  --syntax-link: #0e0eff;
  --syntax-heading: #0b4f79;
  --syntax-invalid: #ff3b30;
  --syntax-inserted: #248a3d;
  --syntax-deleted: #d70015;

  /* iOS system colors for tags. */
  --tag-red: #ff3b30;
  --tag-orange: #ff9500;
  --tag-yellow: #ffcc00;
  --tag-green: #34c759;
  --tag-mint: #00c7be;
  --tag-teal: #30b0c7;
  --tag-blue: #007aff;
  --tag-indigo: #5856d6;
  --tag-purple: #af52de;
  --tag-pink: #ff2d55;
}

/* Dark colors: with the system's dark mode, unless Settings › Appearance says Light;
   or always, when it says Dark (html[data-theme], set by the page). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --editor: #121214;
    --grouped: #1c1c1e;
    --toolbar: #1c1c1e;
    --elevated: #2c2c2e;
    --material: rgba(44, 44, 46, 0.84);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --switch-off: #39393d;
    --segment-on: #636366;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --blue: #0a84ff;
    --red: #ff453a;
    --green: #30d158;
    --orange: #ff9f0a;
    --text-selection: rgba(10, 132, 255, 0.4);
    --current-line: rgba(118, 118, 128, 0.12);
    --selection-match: rgba(118, 118, 128, 0.3);
    --search-match: rgba(255, 214, 10, 0.25);
    --search-match-border: rgba(255, 214, 10, 0.5);
    --search-match-current: rgba(255, 159, 10, 0.55);
    --checker: #2c2c2e;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.1);

    /* Syntax colors from Xcode's default dark theme. */
    --syntax-keyword: #ff7ab2;
    --syntax-string: #ff8170;
    --syntax-regexp: #ffa14f;
    --syntax-number: #d9c97c;
    --syntax-comment: #7f8c98;
    --syntax-type: #dabaff;
    --syntax-declaration: #6bdfff;
    --syntax-function: #67b7a4;
    --syntax-variable: #4eb0cc;
    --syntax-attribute: #cc9768;
    --syntax-tag: #ff7ab2;
    --syntax-preprocessor: #fd8f3f;
    --syntax-link: #6699ff;
    --syntax-heading: #6bdfff;
    --syntax-invalid: #ff453a;
    --syntax-inserted: #30d158;
    --syntax-deleted: #ff6961;

    --tag-red: #ff453a;
    --tag-orange: #ff9f0a;
    --tag-yellow: #ffd60a;
    --tag-green: #30d158;
    --tag-mint: #63e6e2;
    --tag-teal: #40c8e0;
    --tag-blue: #0a84ff;
    --tag-indigo: #5e5ce6;
    --tag-purple: #bf5af2;
    --tag-pink: #ff375f;
  }
}

:root[data-theme="dark"] {
  --editor: #121214;
  --grouped: #1c1c1e;
  --toolbar: #1c1c1e;
  --elevated: #2c2c2e;
  --material: rgba(44, 44, 46, 0.84);
  --fill: rgba(118, 118, 128, 0.24);
  --fill-strong: rgba(118, 118, 128, 0.36);
  --switch-off: #39393d;
  --segment-on: #636366;
  --label: #ffffff;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.3);
  --separator: rgba(84, 84, 88, 0.6);
  --blue: #0a84ff;
  --red: #ff453a;
  --green: #30d158;
  --orange: #ff9f0a;
  --text-selection: rgba(10, 132, 255, 0.4);
  --current-line: rgba(118, 118, 128, 0.12);
  --selection-match: rgba(118, 118, 128, 0.3);
  --search-match: rgba(255, 214, 10, 0.25);
  --search-match-border: rgba(255, 214, 10, 0.5);
  --search-match-current: rgba(255, 159, 10, 0.55);
  --checker: #2c2c2e;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.1);

  /* Syntax colors from Xcode's default dark theme. */
  --syntax-keyword: #ff7ab2;
  --syntax-string: #ff8170;
  --syntax-regexp: #ffa14f;
  --syntax-number: #d9c97c;
  --syntax-comment: #7f8c98;
  --syntax-type: #dabaff;
  --syntax-declaration: #6bdfff;
  --syntax-function: #67b7a4;
  --syntax-variable: #4eb0cc;
  --syntax-attribute: #cc9768;
  --syntax-tag: #ff7ab2;
  --syntax-preprocessor: #fd8f3f;
  --syntax-link: #6699ff;
  --syntax-heading: #6bdfff;
  --syntax-invalid: #ff453a;
  --syntax-inserted: #30d158;
  --syntax-deleted: #ff6961;

  --tag-red: #ff453a;
  --tag-orange: #ff9f0a;
  --tag-yellow: #ffd60a;
  --tag-green: #30d158;
  --tag-mint: #63e6e2;
  --tag-teal: #40c8e0;
  --tag-blue: #0a84ff;
  --tag-indigo: #5e5ce6;
  --tag-purple: #bf5af2;
  --tag-pink: #ff375f;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--editor);
  color: var(--label);
  font: 13px/1.35 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  opacity: 0;
}

body.ready {
  opacity: 1;
  transition: opacity 0.12s ease;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: default;
}

button:focus-visible,
.row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

svg { display: block; width: 100%; height: 100%; }

/* ---------- Toolbar (also the window's title bar) ---------- */

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 12px 0 16px;
  background: var(--toolbar);
  border-bottom: 0.5px solid var(--separator);
  -webkit-app-region: drag;
  user-select: none;
}

#toolbar button, #tabs { -webkit-app-region: no-drag; }

.toolbar-group {
  display: flex;
  gap: 2px;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 6px;
  border-radius: 9px;
  color: var(--blue);
  transition: background 0.15s ease, opacity 0.15s ease;
}

.icon-button:hover { background: var(--fill); }
.icon-button:active { opacity: 0.45; }

/* Tabs sit in a segmented-control track, the active one raised like a selected segment. */
#tabs {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  gap: 2px;
  margin: 0 auto;
  padding: 2px;
  overflow-x: auto;
  background: var(--fill);
  border-radius: 10px;
  scrollbar-width: none;
}

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

.tab {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 4px;
  max-width: 200px;
  height: 30px;
  padding: 0 4px 0 12px;
  border-radius: 8px;
  color: var(--label-2);
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab:hover { color: var(--label); }

.tab.active {
  background: var(--segment-on);
  color: var(--label);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

.tab.preview .title { font-style: italic; }

.tab .title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab .close {
  position: relative;
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 50%;
  color: var(--label-2);
  opacity: 0;
}

.tab:hover .close,
.tab.active .close { opacity: 1; }
.tab .close:hover { background: var(--fill-strong); color: var(--label); }

/* An unsaved tab shows a dot in place of its close button until hovered. */
.tab.dirty .close { opacity: 1; }
.tab.dirty .close svg { visibility: hidden; }
.tab.dirty .close::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--orange);
}
.tab.dirty .close:hover svg { visibility: visible; }
.tab.dirty .close:hover::after { display: none; }

/* ---------- Layout ---------- */

#layout {
  --sidebar-width: 260px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1px 1fr;
  flex: 1;
  min-height: 0;
}

#layout.sidebar-hidden { grid-template-columns: 0 0 1fr; }
#layout.sidebar-hidden #sidebar,
#layout.sidebar-hidden #splitter { visibility: hidden; }

/* ---------- Sidebar ---------- */

#sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--grouped);
  overflow: hidden;
  user-select: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px 20px;
}

.sidebar-title {
  color: var(--label);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.text-button {
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
}

.text-button:hover { opacity: 0.75; }
.text-button:active { opacity: 0.45; }

#tree {
  flex: 1;
  overflow: auto;
  padding: 4px 10px 16px;
}

.row {
  --depth: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px 0 calc(4px + var(--depth) * 16px);
  border-radius: 8px;
  color: var(--label);
  white-space: nowrap;
}

.row:hover { background: var(--fill); }

/* Last modified, at the end of each file's row. */
.row .row-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.row-date, .row-folder {
  margin-left: auto;
  padding-left: 8px;
  color: var(--label-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.row-pin { font-size: 10px; }
.row.selected .row-date, .row.selected .row-folder { color: rgba(255, 255, 255, 0.75); }

.tree-header {
  padding: 10px 10px 4px;
  color: var(--label-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Dragging a row to a new place. */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--material, var(--grouped));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  font-size: 13px;
  pointer-events: none;
}
body.dragging-row, body.dragging-row * { cursor: grabbing !important; user-select: none; }
.row.drop-before { box-shadow: inset 0 2px 0 var(--blue); }
.row.drop-after { box-shadow: inset 0 -2px 0 var(--blue); }
.menu-shortcut { margin-left: 18px; color: var(--label-2); font-size: 12px; }

.row.selected {
  background: var(--row-selected);
  color: #ffffff;
}

.row.root { font-weight: 600; }

.row .chevron {
  flex: 0 0 14px;
  height: 14px;
  color: var(--label-3);
  transition: transform 0.18s ease;
}

.row .chevron.open { transform: rotate(90deg); }
.row.selected .chevron { color: rgba(255, 255, 255, 0.75); }

.row-icon {
  flex: 0 0 18px;
  height: 18px;
}

.row-icon.folder { color: var(--blue); }
.row-icon.file { color: var(--label-2); }
.row.selected .row-icon { color: #ffffff; }

.row-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-note {
  --depth: 0;
  padding: 4px 8px 4px calc(28px + var(--depth) * 16px);
  color: var(--label-2);
  font-size: 12px;
  white-space: normal;
}

#sidebar-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: auto 0;
  padding: 24px;
  color: var(--label-2);
  text-align: center;
}

#sidebar-empty p { margin: 6px 0; }

.empty-icon {
  width: 44px;
  height: 44px;
  color: var(--label-3);
}

.empty-hint { font-size: 12px; color: var(--label-3); }

.filled-button {
  margin-top: 6px;
  padding: 8px 18px;
  border-radius: 10px;
  background: var(--blue);
  color: #ffffff;
  font-weight: 600;
}

.filled-button:hover { filter: brightness(1.08); }
.filled-button:active { opacity: 0.6; }

#splitter {
  position: relative;
  background: var(--separator);
  cursor: col-resize;
}

#splitter::after {
  content: "";
  position: absolute;
  inset: 0 -4px;
}

#splitter.dragging { background: var(--blue); }

/* ---------- Editor ---------- */

#document {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--editor);
}

#editor-host {
  height: 100%;
  font-size: var(--editor-font-size);
}

#editor-host .cm-editor { height: 100%; }
#editor-host .cm-content { tab-size: 4; }

/* #hashtags in notes, colored per tag. */
.cm-hashtag {
  padding: 1px 4px;
  margin: 0 -1px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--tag-color) 16%, transparent);
  color: color-mix(in srgb, var(--tag-color) 80%, var(--editor-text));
  font-weight: 600;
}

/* Opening a large file: a progress card, like Sublime's loading tab. */
#loading-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(360px, 80%);
  padding: 22px 24px 16px;
  border-radius: 16px;
  background: var(--grouped);
  text-align: center;
}

.loading-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}

.progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--fill-strong);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.15s linear;
}

.loading-detail {
  color: var(--label-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

#image-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  overflow: auto;
  background-color: var(--editor);
  background-image:
    linear-gradient(45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

#image {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

/* ---------- Status bar ---------- */

#status {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 30px;
  padding: 0 10px 0 16px;
  background: var(--toolbar);
  border-top: 0.5px solid var(--separator);
  color: var(--label-2);
  font-size: 12px;
  user-select: none;
}

#status-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#cursor-position { margin-right: 4px; }

.pill {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--label);
  font-size: 12px;
}

.pill:hover:not(:disabled) { background: var(--fill-strong); }
.pill:disabled { color: var(--label-2); }

/* ---------- Overlays: alerts, menus, popovers ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.backdrop.modal {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.28);
  animation: fade-in 0.15s ease;
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(1.08); } }
@keyframes drop-in { from { opacity: 0; transform: scale(0.96) translateY(-4px); } }

.alert {
  width: 280px;
  border-radius: 14px;
  background: var(--material);
  backdrop-filter: blur(40px) saturate(180%);
  box-shadow: var(--shadow);
  text-align: center;
  overflow: hidden;
  animation: pop-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.alert-title {
  padding: 20px 16px 2px;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.alert-message {
  padding: 2px 16px 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.alert-input {
  width: calc(100% - 32px);
  margin: 14px 16px 0;
  padding: 7px 8px;
  border: 0.5px solid var(--separator);
  border-radius: 8px;
  outline: none;
  background: var(--elevated);
  color: var(--label);
  font: 13px var(--font-ui);
}

.alert-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--text-selection); }

.alert-buttons {
  display: flex;
  margin-top: 18px;
  border-top: 0.5px solid var(--separator);
}

.alert-buttons.stacked { flex-direction: column; }

.alert-button {
  flex: 1;
  height: 44px;
  color: var(--blue);
  font-size: 16px;
}

.alert-button + .alert-button { border-left: 0.5px solid var(--separator); }
.alert-buttons.stacked .alert-button + .alert-button { border-left: none; border-top: 0.5px solid var(--separator); }
.alert-button:hover,
.alert-button:focus-visible { background: var(--fill); outline: none; }
.alert-button:active { background: var(--fill-strong); }
.alert-button.default { font-weight: 600; }
.alert-button.destructive { color: var(--red); font-weight: 600; }

.menu,
.popover {
  position: fixed;
  border-radius: 13px;
  background: var(--material);
  backdrop-filter: blur(40px) saturate(180%);
  box-shadow: var(--shadow);
  animation: drop-in 0.14s ease-out;
}

.menu {
  min-width: 240px;
  padding: 5px 0;
}

.menu-title {
  padding: 6px 16px 6px;
  color: var(--label-2);
  font-size: 12px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 0 14px;
  text-align: left;
  font-size: 14px;
}

.menu-item:hover,
.menu-item:focus { background: var(--fill); outline: none; }
.menu-item.destructive { color: var(--red); }

.menu-check {
  width: 14px;
  color: var(--blue);
  font-weight: 600;
}

.menu-label { flex: 1; }

.menu-icon {
  width: 18px;
  height: 18px;
}

.menu-separator {
  height: 6px;
  margin: 4px 0;
  background: var(--fill);
}

/* Settings: grouped list with switches and a segmented control. */

.settings-popover { width: 330px; max-height: calc(100vh - 80px); overflow-y: auto; padding: 4px 16px 16px; }

.list-header {
  padding: 14px 4px 6px;
  color: var(--label-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.list-group {
  border-radius: 10px;
  background: var(--elevated);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px 0 14px;
  font-size: 14px;
}

.list-row + .list-row { box-shadow: inset 14px 0.5px 0 0 var(--elevated), inset 0 0.5px 0 0 var(--separator); }

.list-footer {
  padding: 12px 4px 0;
  color: var(--label-2);
  font-size: 12px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
}

.switch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--switch-off);
  transition: background 0.2s ease;
  pointer-events: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  transition: transform 0.25s cubic-bezier(0.3, 1.3, 0.5, 1);
}

.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--blue); outline-offset: 2px; }

.segmented {
  display: flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}

.segment {
  flex: 1;
  height: 28px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s ease;
}

.segment[aria-checked="true"] {
  background: var(--segment-on);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}

/* Emoji picker */

.emoji-popover { width: 360px; overflow: hidden; }

.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 6px;
  border-bottom: 0.5px solid var(--separator);
}

.emoji-tab {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  font: 18px/32px var(--font-emoji);
}

.emoji-tab:hover { background: var(--fill); }

.emoji-scroll {
  height: 280px;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.emoji-heading {
  position: sticky;
  top: 0;
  padding: 10px 6px 4px;
  background: var(--material);
  backdrop-filter: blur(20px);
  color: var(--label-2);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
}

.emoji-cell {
  height: 40px;
  border-radius: 8px;
  font: 26px/40px var(--font-emoji);
  transition: transform 0.1s ease;
}

.emoji-cell:hover { background: var(--fill); transform: scale(1.12); }
.emoji-cell:active { transform: scale(0.94); }

.emoji-footer {
  padding: 8px 12px 10px;
  border-top: 0.5px solid var(--separator);
  color: var(--label-2);
  font-size: 11px;
  text-align: center;
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--fill-strong) padding-box;
}
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Tags ---------- */

.tag-red { --tag-color: var(--tag-red); }
.tag-orange { --tag-color: var(--tag-orange); }
.tag-yellow { --tag-color: var(--tag-yellow); }
.tag-green { --tag-color: var(--tag-green); }
.tag-mint { --tag-color: var(--tag-mint); }
.tag-teal { --tag-color: var(--tag-teal); }
.tag-blue { --tag-color: var(--tag-blue); }
.tag-indigo { --tag-color: var(--tag-indigo); }
.tag-purple { --tag-color: var(--tag-purple); }
.tag-pink { --tag-color: var(--tag-pink); }

.tag-dots {
  display: flex;
  gap: 3px;
  margin-left: auto;
  padding-left: 6px;
}

.tag-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tag-color);
}

.row.selected .tag-dot { box-shadow: 0 0 0 1.5px #ffffff; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tag-color) 18%, transparent);
  color: color-mix(in srgb, var(--tag-color) 75%, var(--label));
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tag-chip.suggestion { opacity: 0.75; }
.tag-chip.suggestion:hover { opacity: 1; }

.tag-chip-remove {
  width: 18px;
  height: 18px;
  margin-right: -6px;
  border-radius: 50%;
  color: inherit;
  font-size: 15px;
  line-height: 18px;
}

.tag-chip-remove:hover { background: color-mix(in srgb, var(--tag-color) 25%, transparent); }

.tags-filter { margin: 4px 16px 8px; }
#tags-status { padding: 0 20px 6px; color: var(--label-2); font-size: 12px; }
#tags-status:empty { display: none; }
#tags-list, #tag-detail { flex: 1; overflow: auto; padding: 0 10px 16px; }
#tags-list-view { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.tag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  text-align: left;
}

.tag-row:hover { background: var(--fill); }
.tag-name { font-weight: 600; }
.tag-count { margin-left: auto; color: var(--label-2); font-size: 12px; }

.back-button {
  margin: 2px 0 6px;
  padding: 4px 6px;
  color: var(--blue);
  font-size: 14px;
}

.back-button::before { content: "\2039\00a0"; font-size: 18px; }
.tag-detail-header { padding: 0 6px 4px; }
.tag-detail-header .tag-chip { font-size: 17px; padding: 5px 14px; }

.link-row { width: 100%; gap: 8px; text-align: left; }
.link-row:hover { background: var(--fill); }
.link-row .result-dir { margin-left: auto; }

.empty-note { padding: 14px 10px; color: var(--label-2); font-size: 12px; line-height: 1.5; }

.tag-sheet { width: 340px; padding: 0 16px 16px; }
.tag-editor { display: flex; flex-direction: column; align-items: stretch; text-align: center; }
.tag-chips, .tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
}
.tag-suggestions:empty { display: none; }
.tag-input { width: 100%; margin: 14px 0 0; }
.tag-editor .filled-button { margin-top: 16px; }

/* Settings › Sync › Set Up Google Drive Sync… */
.sync-sheet { width: 420px; max-width: calc(100vw - 32px); padding: 0 16px 16px; }
.sync-setup { display: flex; flex-direction: column; align-items: stretch; gap: 10px; text-align: center; }
.sync-setup .alert-input { width: 100%; margin: 0; box-sizing: border-box; }
.sync-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.sync-buttons button { margin: 0; padding: 8px 18px; border-radius: 10px; font-weight: 600; }
.sync-buttons .plain-button { background: var(--fill); color: var(--blue); }

/* ---------- Sidebar views ---------- */

.sidebar-switcher { margin: 12px 14px 2px; }
.sidebar-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.search-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 16px 10px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 8px;
  border-radius: 10px;
  background: var(--fill);
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--label);
  font: 14px var(--font-ui);
}

.search-box:focus-within { box-shadow: 0 0 0 2px var(--blue); }

.find-glass, .find-replace-icon {
  flex: 0 0 15px;
  height: 15px;
  opacity: 0.55;
  background: currentColor;
  -webkit-mask: no-repeat center / contain;
}

.find-glass { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5l5 5'/%3E%3C/svg%3E"); }
.find-replace-icon { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 8h13l-3-3M20 16H7l3 3'/%3E%3C/svg%3E"); }

.where-label { color: var(--label-2); font-size: 12px; }

.where-button {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  color: var(--blue);
  font-size: 18px;
  line-height: 22px;
}

.where-button:hover { background: var(--fill-strong); }

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

.search-replace { display: flex; align-items: center; gap: 8px; }
.search-replace .search-box { flex: 1; }
#search-go { margin-top: 2px; }

#search-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  padding: 0 20px 6px;
  color: var(--label-2);
  font-size: 12px;
}

#search-status.error { color: var(--red); }
.search-status-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }

#search-results {
  flex: 1;
  overflow: auto;
  padding: 0 10px 16px;
}

.result-file { margin-bottom: 6px; }

.result-header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--grouped);
  white-space: nowrap;
  z-index: 1;
}

.result-header:hover { background: color-mix(in srgb, var(--grouped) 80%, var(--label) 6%); }
.result-name { font-weight: 600; }

.result-dir {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--label-2);
  font-size: 12px;
}

.result-count {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--fill-strong);
  color: var(--label-2);
  font-size: 11px;
  font-weight: 600;
}

.result-file.collapsed .result-line { display: none; }

.result-line {
  display: flex;
  gap: 8px;
  padding: 3px 8px 3px 10px;
  border-radius: 7px;
  font: 12px/1.5 var(--font-mono);
  white-space: nowrap;
}

.result-line:hover { background: var(--fill); }
.result-line.selected { background: var(--blue); color: #ffffff; }
.result-line.selected .result-number { color: rgba(255, 255, 255, 0.75); }

.result-number {
  flex: 0 0 auto;
  min-width: 3ch;
  color: var(--label-3);
  text-align: right;
}

.result-text { overflow: hidden; text-overflow: ellipsis; }

mark {
  border-radius: 3px;
  background: var(--search-match);
  box-shadow: 0 0 0 1px var(--search-match-border);
  color: inherit;
}

.result-line.selected mark { background: rgba(255, 255, 255, 0.3); box-shadow: none; }

/* ---------- Find panel (inside the editor) ---------- */

.find-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  background: var(--toolbar);
  border-bottom: 0.5px solid var(--separator);
  font: 13px var(--font-ui);
}

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

.find-panel:not(.replace) .replace-row { display: none; }

.find-field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 140px;
  height: 30px;
  padding: 0 8px;
  border-radius: 9px;
  background: var(--fill);
}

.find-field:focus-within { box-shadow: 0 0 0 2px var(--blue); }
.find-panel.invalid .find-row:first-child .find-field { box-shadow: 0 0 0 2px var(--red); }

.find-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--label);
  font: 13px var(--font-ui);
}

.find-count {
  color: var(--label-2);
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.find-toggles { display: flex; gap: 3px; }

.find-toggle {
  height: 26px;
  padding: 0 8px;
  border-radius: 7px;
  color: var(--label-2);
  font: 600 12px var(--font-ui);
  white-space: nowrap;
}

.find-toggle:hover { background: var(--fill); color: var(--label); }
.find-toggle[aria-pressed="true"] { background: var(--blue); color: #ffffff; }

.find-nav, .find-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--blue);
  font-size: 20px;
  line-height: 26px;
}

.find-close { color: var(--label-2); }
.find-nav:hover, .find-close:hover, .find-action:hover { background: var(--fill); }

.find-action {
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--blue);
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Sheets: tag editor and Goto Anything ---------- */

.backdrop .sheet {
  border-radius: 14px;
  background: var(--material);
  backdrop-filter: blur(40px) saturate(180%);
  box-shadow: var(--shadow);
  animation: pop-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.goto-sheet {
  position: fixed;
  top: 64px;
  left: 50%;
  width: min(640px, calc(100vw - 32px));
  margin-left: calc(min(640px, calc(100vw - 32px)) / -2);
  overflow: hidden;
  animation: drop-in 0.14s ease-out;
}

.goto-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.goto-field .find-glass { flex-basis: 18px; height: 18px; }

.goto-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--label);
  font: 18px var(--font-ui);
}

.goto-list {
  max-height: min(420px, 60vh);
  overflow: auto;
  padding: 6px;
}

.goto-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 9px;
}

.goto-item.active { background: var(--blue); color: #ffffff; }
.goto-item.active .goto-detail { color: rgba(255, 255, 255, 0.75); }
.goto-item.active mark { background: rgba(255, 255, 255, 0.28); box-shadow: none; }

.goto-label {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.goto-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

.goto-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--label-2);
  font-size: 12px;
}

.goto-badge {
  margin-left: auto;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--fill-strong);
  font-size: 11px;
  font-weight: 600;
}

.goto-item.active .goto-badge { background: rgba(255, 255, 255, 0.25); }
.goto-empty { padding: 14px; color: var(--label-2); text-align: center; }

/* ---------- Misc ---------- */

.menu { max-height: calc(100vh - 16px); overflow-y: auto; }

#status-text.message { color: var(--label); }

.tab.loading .close { opacity: 1; }
.tab.loading .close svg { visibility: hidden; }
.tab.loading .close::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 2px solid var(--fill-strong);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- Boo ---------- */

.boo-logo {
  display: block;
  width: 32px;
  height: 24px;
  image-rendering: pixelated;
}

/* The Boo logo opens the Boo Guide. */
.logo-button {
  flex: 0 0 auto;
  margin-right: 2px;
  padding: 3px 4px;
  border-radius: 8px;
  transition: background 0.15s ease, transform 0.15s ease;
}

.logo-button:hover { background: var(--fill); }
.logo-button:active { transform: scale(0.92); }

/* ---------- Window buttons, as on a Mac ---------- */

.window-controls {
  display: flex;
  gap: 8px;
  margin-right: 14px;
  -webkit-app-region: no-drag;
}

.traffic {
  position: relative;
  width: 12px;
  height: 12px;
  padding: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.18);
}

.traffic.close { background: #ff5f57; }
.traffic.minimize { background: #febc2e; }
.traffic.maximize { background: #28c840; }

/* Symbols appear on all three when the pointer is over the group. */
.traffic::before,
.traffic::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  opacity: 0;
  background: rgba(0, 0, 0, 0.55);
}

.window-controls:hover .traffic::before,
.window-controls:hover .traffic::after,
.window-controls:focus-within .traffic::before,
.window-controls:focus-within .traffic::after { opacity: 1; }

.traffic.close::before,
.traffic.close::after { width: 7px; height: 1.3px; border-radius: 1px; }
.traffic.close::before { transform: rotate(45deg); }
.traffic.close::after { transform: rotate(-45deg); }

.traffic.minimize::before { width: 7px; height: 1.3px; border-radius: 1px; }
.traffic.minimize::after { display: none; }

/* Maximize: two small triangles, like the Mac zoom button; restore points them inward. */
.traffic.maximize::before,
.traffic.maximize::after {
  width: 4.5px;
  height: 4.5px;
  background: rgba(0, 0, 0, 0.55);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.traffic.maximize::before { transform: translate(-1.3px, -1.3px); }
.traffic.maximize::after { transform: translate(1.3px, 1.3px) rotate(180deg); }
.window-controls.maximized .traffic.maximize::before { transform: translate(1.3px, 1.3px); }
.window-controls.maximized .traffic.maximize::after { transform: translate(-1.3px, -1.3px) rotate(180deg); }

.traffic:active { filter: brightness(0.85); }
.traffic:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* Gray when the window isn't the active one, as on a Mac. */
.window-controls.inactive:not(:hover) .traffic {
  background: var(--fill-strong);
  box-shadow: inset 0 0 0 0.5px var(--separator);
}

/* Boo walks on top of the status bar; clicks pass through him. */
#boo-walker {
  position: fixed;
  left: 0;
  bottom: 30px;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  width: 32px;
  height: 32px;
  pointer-events: none;
  will-change: transform;
}

#boo-walker canvas {
  width: 32px;
  height: 24px;
}

/* ---------- Template form ---------- */

.template-sheet {
  display: flex;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow: hidden;
}

.template-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
}

.template-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.template-header .text-button { justify-self: start; font-size: 15px; }
.template-header .text-button.strong { justify-self: end; font-weight: 600; }
.template-header .text-button:disabled { color: var(--label-3); opacity: 1; }
.template-title { font-size: 16px; font-weight: 600; }

.template-body {
  overflow: auto;
  padding: 4px 16px 18px;
}

.template-body .list-header { display: block; text-transform: none; font-size: 13px; letter-spacing: 0; }

.template-input {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 10px;
  outline: none;
  background: var(--elevated);
  color: var(--label);
  font: 14px/1.45 var(--font-ui);
  resize: vertical;
}

.template-input.code { font: 12.5px/1.5 var(--font-mono); white-space: pre; }
.template-input:focus { box-shadow: 0 0 0 2px var(--blue); }

.template-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 10px;
  background: var(--elevated);
}

.template-tags:focus-within { box-shadow: 0 0 0 2px var(--blue); }

.template-tag-input {
  flex: 1;
  min-width: 100px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--label);
  font: 14px var(--font-ui);
}

/* ---------- Inline images in notes ---------- */

.cm-inline-image {
  padding: 6px 20px 10px 8px;
}

.cm-inline-image img {
  display: block;
  max-width: min(100%, 760px);
  max-height: 520px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px var(--separator);
  cursor: zoom-in;
}

.cm-inline-image.missing {
  color: var(--red);
  font: 12px var(--font-ui);
}

.cm-inline-image-frame {
  position: relative;
  display: inline-block;
  max-width: 100%;
  vertical-align: top;
}

.cm-inline-image-remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #ffffff;
  font-size: 17px;
  line-height: 25px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.cm-inline-image-frame:hover .cm-inline-image-remove { opacity: 1; }
.cm-inline-image-remove:hover { background: var(--red); }

/* Boo's speech bubble, for reminders that are due. */
#boo-walker.alerting canvas { animation: boo-hop 0.9s ease-in-out infinite; }
@keyframes boo-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-8px); } }

.boo-bubble {
  position: fixed;
  bottom: 74px;
  z-index: 60;
  width: min(300px, calc(100vw - 16px));
  padding: 14px 16px 12px;
  border-radius: 16px;
  background: var(--material, var(--grouped));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.22), 0 0 0 0.5px var(--separator);
  animation: boo-bubble-in 0.25s ease-out;
}
.boo-bubble::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: calc(var(--tail, 50%) - 7px);
  width: 14px;
  height: 14px;
  background: inherit;
  transform: rotate(45deg);
  box-shadow: 0.5px 0.5px 0 var(--separator);
}
@keyframes boo-bubble-in { from { opacity: 0; transform: translateY(8px) scale(0.96); } }
.boo-bubble-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--label-2);
  font-size: 18px;
  line-height: 1;
}
.boo-bubble-close:hover { background: var(--fill); }
.boo-bubble-title { padding-right: 20px; font-weight: 700; font-size: 14px; }
.boo-bubble-body { margin-top: 2px; color: var(--label-2); font-size: 12.5px; }
.boo-bubble-actions { display: flex; gap: 8px; margin-top: 12px; }
.boo-bubble-actions button { flex: 1; margin: 0; padding: 6px 8px; border-radius: 9px; font-size: 13px; font-weight: 600; }
.boo-bubble-button { background: var(--fill); color: var(--blue); }
