/* Smitten editor
 *
 * Design rules: contrast comes from surfaces, not outlines. The editor is a
 * dark (or light) frame holding rounded cards: panels, the stage, windows.
 * Controls sit on their card as slightly lighter or darker fills; hairlines
 * are rare, and outlines come back only in high-contrast mode. One blue
 * accent for focus, selection and "on" states, pink only in the logo. Motion
 * is quick and small: things respond to the pointer, appear from where they
 * come from, and never make you wait. Sentence-case labels, 13px UI text.
 */

:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --gap: 6px;
  --topbar-h: 46px;
  --header-h: 36px;
  --editor-font-size: 13px;
  --brand: #e5487a;
  /* Motion */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
  --fast: 110ms;
  --medium: 180ms;
  --slow: 260ms;
  /* Piece colors, by what the piece is for. */
  --node-visual: #6aa6ff;
  --node-physics: #f2a65a;
  --node-ui: #61d394;
  --node-sound: #c792ea;
  --node-basic: #b9bec8;
}

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --frame: #0d0e10;
  --bg: #0d0e10;
  --panel: #18191c;
  --panel-2: #232428;
  --panel-3: #2c2e33;
  --panel-elev: #1f2024;
  --editor-bg: #131416;
  --input-bg: #0f1012;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.11);
  --line: transparent;
  --line-strong: transparent;
  --fg: #ececee;
  --fg-muted: #a2a5ad;
  --fg-subtle: #6b6f78;
  --hover: rgba(255, 255, 255, 0.05);
  --active: rgba(255, 255, 255, 0.085);
  --accent: #4b8bff;
  --accent-fg: #ffffff;
  --accent-soft: rgba(75, 139, 255, 0.16);
  --accent-text: #85b1ff;
  --primary-bg: #ececee;
  --primary-hover: #ffffff;
  --primary-fg: #121315;
  --danger: #ff7b7b;
  --danger-solid: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.14);
  --success: #46c37b;
  --warning: #f5b84d;
  --info: #4b8bff;
  --error-fg: #ff9a9a;
  --error-line-bg: rgba(229, 72, 77, 0.14);
  --error-widget-bg: rgba(229, 72, 77, 0.1);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 6px 18px rgba(0, 0, 0, 0.4);
  --backdrop: rgba(0, 0, 0, 0.5);
  --focus: 0 0 0 2px var(--accent-soft), 0 0 0 1px var(--accent);
  --cm-selection: rgba(75, 139, 255, 0.28);
  --cm-active-line: rgba(255, 255, 255, 0.035);
  --cm-bracket: rgba(255, 255, 255, 0.08);
  --cm-bracket-outline: rgba(255, 255, 255, 0.3);
  --cm-search: rgba(245, 184, 77, 0.2);
  --cm-search-outline: rgba(245, 184, 77, 0.55);
  --cm-search-selected: rgba(245, 184, 77, 0.4);
  --cm-selection-match: rgba(255, 255, 255, 0.08);
  --cm-whitespace: rgba(255, 255, 255, 0.16);
  --syn-keyword: #c792ea;
  --syn-string: #a5d6a7;
  --syn-number: #f7c97e;
  --syn-comment: #6f737c;
  --syn-builtin: #7eacff;
  --syn-special: #ff8fa3;
  --syn-property: #c2c6ce;
  --syn-function: #82d2f5;
  --syn-type: #61d394;
  --syn-operator: #a0a4ad;
  --syn-variable: #e6e7ea;
  --game-bg: #000000;
}

:root[data-theme="light"] {
  color-scheme: light;
  --frame: #e4e6ea;
  --bg: #e4e6ea;
  --panel: #ffffff;
  --panel-2: #f0f1f4;
  --panel-3: #e5e7eb;
  --panel-elev: #ffffff;
  --editor-bg: #f7f8fa;
  --input-bg: #f1f2f5;
  --border: rgba(16, 18, 24, 0.07);
  --border-strong: rgba(16, 18, 24, 0.13);
  --line: transparent;
  --line-strong: transparent;
  --fg: #1b1d21;
  --fg-muted: #555a64;
  --fg-subtle: #8a8f98;
  --hover: rgba(16, 18, 24, 0.045);
  --active: rgba(16, 18, 24, 0.08);
  --accent: #2f6fed;
  --accent-fg: #ffffff;
  --accent-soft: rgba(47, 111, 237, 0.12);
  --accent-text: #2459c9;
  --primary-bg: #1b1d21;
  --primary-hover: #33363c;
  --primary-fg: #ffffff;
  --danger: #d23b40;
  --danger-solid: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.09);
  --success: #1e9e57;
  --warning: #b7791f;
  --info: #2f6fed;
  --error-fg: #c42f34;
  --error-line-bg: rgba(229, 72, 77, 0.09);
  --error-widget-bg: rgba(229, 72, 77, 0.06);
  --shadow: 0 18px 48px rgba(20, 22, 28, 0.16), 0 2px 6px rgba(20, 22, 28, 0.08);
  --shadow-sm: 0 6px 18px rgba(20, 22, 28, 0.1);
  --backdrop: rgba(20, 22, 28, 0.28);
  --cm-selection: rgba(47, 111, 237, 0.18);
  --cm-active-line: rgba(0, 0, 0, 0.03);
  --cm-bracket: rgba(0, 0, 0, 0.06);
  --cm-bracket-outline: rgba(0, 0, 0, 0.3);
  --cm-search: rgba(245, 184, 77, 0.35);
  --cm-search-outline: rgba(183, 121, 31, 0.6);
  --cm-search-selected: rgba(245, 184, 77, 0.55);
  --cm-selection-match: rgba(0, 0, 0, 0.06);
  --cm-whitespace: rgba(0, 0, 0, 0.18);
  --syn-keyword: #8a3fd1;
  --syn-string: #2e7d32;
  --syn-number: #b45309;
  --syn-comment: #858a94;
  --syn-builtin: #2459c9;
  --syn-special: #c2185b;
  --syn-property: #3f444d;
  --syn-function: #0b7285;
  --syn-type: #1e9e57;
  --syn-operator: #555a64;
  --syn-variable: #1d1f23;
  --game-bg: #000000;
  --node-visual: #2f6fed;
  --node-physics: #c4620e;
  --node-ui: #1e9e57;
  --node-sound: #8a3fd1;
  --node-basic: #6b7079;
}

/* High contrast (Settings › Appearance › Contrast): outlines on every surface
 * and control, stronger text, bolder focus. */
:root[data-contrast="more"][data-theme="dark"] {
  --frame: #000000;
  --bg: #000000;
  --panel: #0a0a0b;
  --panel-2: #1a1b1e;
  --panel-3: #26282c;
  --panel-elev: #0a0a0b;
  --editor-bg: #000000;
  --input-bg: #000000;
  --border: #6e737c;
  --border-strong: #b9bdc5;
  --line: #6e737c;
  --line-strong: #c9ccd3;
  --fg: #ffffff;
  --fg-muted: #dcdee3;
  --fg-subtle: #b3b7bf;
  --hover: rgba(255, 255, 255, 0.12);
  --active: rgba(255, 255, 255, 0.2);
  --accent: #6ea4ff;
  --accent-soft: rgba(110, 164, 255, 0.3);
  --accent-text: #a8c8ff;
  --focus: 0 0 0 3px var(--accent);
}
:root[data-contrast="more"][data-theme="light"] {
  --frame: #ffffff;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #eceef1;
  --panel-3: #dfe2e6;
  --editor-bg: #ffffff;
  --input-bg: #ffffff;
  --border: #50545c;
  --border-strong: #1b1d21;
  --line: #50545c;
  --line-strong: #1b1d21;
  --fg: #000000;
  --fg-muted: #24262b;
  --fg-subtle: #42464e;
  --hover: rgba(0, 0, 0, 0.08);
  --active: rgba(0, 0, 0, 0.14);
  --accent: #1d5ad6;
  --accent-soft: rgba(29, 90, 214, 0.2);
  --accent-text: #1546a8;
  --focus: 0 0 0 3px var(--accent);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--frame);
  color: var(--fg);
  font: 13px/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }

/* Icons: a box the size of the glyph, centred on whatever holds it. */
.icon { display: inline-flex; align-items: center; justify-content: center; flex: none; line-height: 0; vertical-align: middle; }
.icon svg { display: block; }

:focus-visible { outline: none; box-shadow: var(--focus); }

/* Thin, unobtrusive scrollbars on the app's own panes. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--panel-3) transparent;
}

/* ----------------------------------------------------------------------- */
/* Buttons & inputs */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--fg);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--fast), color var(--fast), transform var(--fast) var(--ease), box-shadow var(--fast);
}
.btn:hover:not(:disabled) { background: var(--panel-3); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, white); }
.btn.danger { background: var(--danger-solid); border-color: var(--danger-solid); color: #ffffff; }
.btn.danger:hover:not(:disabled) { background: #c93a3f; border-color: #c93a3f; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
.btn svg { flex: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  flex: none;
  transition: background-color var(--fast), color var(--fast), transform var(--fast) var(--ease);
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
.icon-btn:active:not(:disabled) { background: var(--active); transform: scale(0.92); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn[aria-pressed="true"] { color: var(--fg); background: var(--active); }

.input, .select {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--fg);
  font: inherit;
  outline: none;
  transition: background-color var(--fast), box-shadow var(--fast);
}
.input:hover:not(:focus), .select:hover:not(:focus) { background: color-mix(in srgb, var(--input-bg) 70%, var(--panel-3)); }
.input::placeholder { color: var(--fg-subtle); }
.input:focus, .select:focus { box-shadow: var(--focus); }
.input.small, .select.small { height: 26px; font-size: 12px; padding: 0 8px; }
.select { padding-right: 6px; cursor: pointer; }
select.input { cursor: pointer; }

/* On/off switch: <button role="switch" aria-checked> */
.switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-3);
  cursor: pointer;
  transition: background-color var(--medium) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform var(--medium) var(--ease-spring), width var(--fast) var(--ease);
}
.switch:active::after { width: 20px; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(14px); }
.switch[aria-checked="true"]:active::after { transform: translateX(10px); }

/* Segmented control: a row of mutually exclusive options. */
.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  border: 1px solid var(--line);
}
.segmented button {
  height: 24px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background-color var(--fast), color var(--fast);
}
.segmented button:hover { color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--panel-3); color: var(--fg); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  background: var(--panel-3);
  color: var(--fg-muted);
}
.badge.danger { background: var(--danger-solid); color: #ffffff; }
kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); color: var(--fg-muted);
  font: 11px var(--font-ui);
}

/* ----------------------------------------------------------------------- */
/* File tree */

#file-tree {
  flex: 1;
  overflow: auto;
  padding: 4px 6px 12px;
  outline: none;
}
#file-tree.drop-target { box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.tree-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 2px 0 calc(6px + var(--depth) * 14px);
  border-radius: 5px;
  color: var(--fg-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  outline: none;
}
.tree-row { transition: background-color var(--fast), color var(--fast); }
.tree-row:hover { background: var(--hover); color: var(--fg); }
.tree-row:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.tree-row.active { background: var(--active); color: var(--fg); }
.tree-row.drop-target { background: var(--accent-soft); color: var(--fg); }
.tree-row.dragging { opacity: .45; }
.tree-row .twisty { width: 14px; display: inline-flex; color: var(--fg-subtle); }
.tree-row > .icon:not(.twisty) { color: var(--fg-subtle); }
.tree-row.active > .icon:not(.twisty) { color: var(--fg-muted); }
.tree-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tree-row > .thumb { width: 15px; height: 15px; flex: none; object-fit: contain; image-rendering: pixelated; }
.tree-row .dirty-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-muted); flex: none; margin-right: 6px; }
.tree-row .row-menu { width: 22px; height: 22px; opacity: 0; }
.tree-row:hover .row-menu, .tree-row:focus-within .row-menu { opacity: 1; }
.tree-empty { padding: 20px 16px; text-align: center; color: var(--fg-muted); }
.tree-empty .btn { margin: 4px auto; }
.tree-empty .hint { font-size: 12px; color: var(--fg-subtle); }

.sidebar-footer {
  flex: none;
  padding: 7px 12px;
  font-size: 11.5px;
  color: var(--fg-subtle);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}


/* Built-in tools (pixel, map, sound and music editors) fill the editor area. */
#tool-host { position: absolute; inset: 0; background: var(--editor-bg); }
#tool-host > .tool-root { position: absolute; inset: 0; overflow: hidden; }
#tool-host > [hidden] { display: none; }
.tool-placeholder { display: grid; place-items: center; height: 100%; color: var(--fg-muted); padding: 24px; text-align: center; }
.preview-checker {
  max-width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background-color: var(--panel);
  /* transparency checkerboard */
  background-image:
    linear-gradient(45deg, var(--panel-2) 25%, transparent 25%), linear-gradient(-45deg, var(--panel-2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--panel-2) 75%), linear-gradient(-45deg, transparent 75%, var(--panel-2) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.preview-checker img { display: block; max-width: 100%; max-height: 60vh; image-rendering: auto; }
.preview-checker.pixelated img { image-rendering: pixelated; }
.preview-meta { color: var(--fg-muted); font-size: 12px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; }
.preview-meta strong { color: var(--fg); font-weight: 600; }
.preview-font { width: min(640px, 100%); display: flex; flex-direction: column; gap: 12px; }
.preview-font .sample { color: var(--fg); line-height: 1.25; word-break: break-word; }
.preview-font input { width: 100%; }
.preview-audio audio { width: min(420px, 80vw); }
.preview-icon { color: var(--fg-subtle); }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  color: var(--fg-muted);
  background: var(--editor-bg);
}
.empty-state h2 { margin: 0; font-size: 15px; color: var(--fg); font-weight: 600; }
.empty-state p { margin: 0; }
.empty-icon { color: var(--fg-subtle); margin-bottom: 6px; }
.shortcut-list { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 8px; min-width: 260px; }
.shortcut-list li { display: flex; justify-content: space-between; align-items: center; gap: 24px; font-size: 12.5px; }
.shortcut-list kbd + kbd { margin-left: 3px; }

.loading-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--fg-muted); background: inherit; z-index: 3;
}
#app:not(.booting) #editor-loading { display: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--fg-muted);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#statusbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
  flex: none;
  padding: 0 6px;
  font-size: 11.5px;
  color: var(--fg-subtle);
  background: var(--panel);
  border-top: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
}
#statusbar .spacer { flex: 1; }
#status-left { overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }
.status-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: inherit;
  cursor: pointer;
}
.status-item:hover { background: var(--hover); color: var(--fg); }
.status-item.static { cursor: default; }
.status-item.static:hover { background: transparent; color: inherit; }
.status-item.has-errors { color: var(--danger); }
.status-item.has-warnings { color: var(--warning); }


/* ----------------------------------------------------------------------- */
/* Console */

#console-output {
  flex: 1;
  overflow: auto;
  padding: 6px 0;
  font: 12px/1.6 var(--font-mono);
  background: var(--editor-bg);
  outline: none;
}
#console-output .line { padding: 0 12px; white-space: pre-wrap; word-break: break-word; }
#console-output.nowrap .line { white-space: pre; word-break: normal; }
#console-output .line .ts { color: var(--fg-subtle); margin-right: 8px; user-select: none; }
#console-output .line.out { color: var(--fg); }
#console-output .line.err { color: var(--warning); }
#console-output .line.meta { color: var(--fg-subtle); }
#console-output .line.meta.success { color: var(--success); }
#console-output .line.meta.danger { color: var(--danger); }
#console-output .line.meta.warning { color: var(--warning); }
#console-output .line.separator { display: flex; align-items: center; gap: 10px; color: var(--fg-subtle); margin: 6px 0 4px; font: 11px var(--font-ui); }
#console-output .line.separator::before, #console-output .line.separator::after { content: ""; height: 1px; background: var(--border); flex: 1; }
#console-output .error-block { margin: 4px 8px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--danger-soft); border: 1px solid var(--line); animation: menu-in var(--medium) var(--ease); }
#console-output .error-title { display: flex; gap: 8px; align-items: flex-start; color: var(--danger); font-weight: 600; }
#console-output .error-title .icon { margin-top: 2px; }
#console-output .error-trace { margin: 6px 0 0 22px; color: var(--fg-muted); font: inherit; white-space: pre-wrap; }
#console-output .loc-link { color: inherit; text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 2px; cursor: pointer; }
#console-output .error-block .loc-link { color: var(--danger); }
#console-output .loc-link:hover { color: var(--accent-text); text-decoration-color: currentColor; }
.console-empty { height: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--fg-subtle); font-family: var(--font-ui); font-size: 12.5px; padding: 12px; text-align: center; }

/* ----------------------------------------------------------------------- */
/* Menus, dialogs, toasts */

.menu {
  position: fixed;
  z-index: 1000;
  min-width: 220px;
  padding: 4px;
  background: var(--panel-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform-origin: var(--menu-origin, top left);
  animation: menu-in var(--medium) var(--ease);
}
.menu.closing { animation: menu-out var(--fast) ease-in forwards; pointer-events: none; }
@keyframes menu-in { from { opacity: 0; transform: scale(0.96) translateY(-4px); } }
@keyframes menu-out { to { opacity: 0; transform: scale(0.98); } }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
  outline: none;
  transition: background-color 60ms;
}
.menu-item .icon { width: 16px; color: var(--fg-muted); }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--active); box-shadow: none; }
.menu-item .check { margin-left: auto; color: var(--accent-text); }
.menu-item:disabled { opacity: .45; cursor: default; }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }
.menu-label { flex: 1; }
.menu-item kbd { font-size: 11px; padding: 0; min-width: 0; color: var(--fg-subtle); background: transparent; border: 0; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 8px; }
.menu-heading { padding: 6px 8px 4px; font-size: 11.5px; font-weight: 500; color: var(--fg-subtle); }

.dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--panel-elev);
  color: var(--fg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.dialog.wide { width: min(820px, calc(100vw - 32px)); }
.dialog[open] { animation: dialog-in var(--medium) var(--ease); display: flex; flex-direction: column; }
.dialog.closing { animation: dialog-out var(--fast) ease-in forwards; }
.dialog.closing::backdrop { animation: backdrop-out var(--fast) ease-in forwards; }
.dialog form { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 48px); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(4px) scale(0.98); } }
@keyframes backdrop-in { from { opacity: 0; } }
@keyframes backdrop-out { to { opacity: 0; } }
.dialog::backdrop { background: var(--backdrop); animation: backdrop-in var(--medium) var(--ease); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px 6px 20px; flex: none; }
.dialog-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.dialog-body { padding: 10px 20px 18px; overflow: auto; min-height: 0; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; flex: none; }
.dialog-footer .left { margin-right: auto; }
.dialog-message { margin: 0; color: var(--fg-muted); line-height: 1.55; white-space: pre-wrap; }
.dialog-list { margin: 8px 0 12px; padding-left: 20px; font: 12px/1.6 var(--font-mono); color: var(--fg-muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--fg-muted); }
.field .input { width: 100%; height: 34px; }
.field .input:focus { background: var(--input-bg); }
.field-error { min-height: 1.2em; font-size: 12px; color: var(--danger); }

/* Projects dialog */
.projects-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 24px; }
.section-title { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.project-list { display: flex; flex-direction: column; gap: 2px; max-height: 420px; overflow: auto; margin: 0 -6px; padding: 0 6px; }
.project-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 6px 7px 10px; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid transparent; transition: background-color var(--fast);
}
.project-item:hover { background: var(--hover); }
.project-item.current { background: var(--active); }
.project-item .project-info { flex: 1; min-width: 0; }
.project-item .project-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item .project-meta { font-size: 11.5px; color: var(--fg-subtle); }
.project-item .project-actions { display: flex; gap: 0; opacity: 0; }
.project-item:hover .project-actions, .project-item:focus-within .project-actions, .project-item.current .project-actions { opacity: 1; }
.project-item .heart { color: var(--fg-subtle); }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.template-card {
  display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 10px 12px; min-height: 80px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
  cursor: pointer; transition: background-color var(--fast), transform var(--fast) var(--ease);
}
.template-card:hover { background: var(--panel-3); }
.template-card:active { transform: scale(0.98); }
.template-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--panel); }
.template-card strong { font-size: 13px; font-weight: 600; }
.template-card span { font-size: 11.5px; color: var(--fg-muted); line-height: 1.4; }
.new-project-row { display: flex; gap: 8px; margin-top: 12px; }
.new-project-row .input { flex: 1; height: 34px; }
.new-project-row .btn { height: 34px; }
.projects-footer-note { font-size: 12px; color: var(--fg-subtle); }

/* Shortcuts list (settings dialog) */
.shortcuts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.shortcuts h3 { margin: 18px 0 6px; font-size: 12px; font-weight: 600; color: var(--fg-muted); }
.shortcuts h3:first-child { margin-top: 0; }
.shortcut { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 8px; margin: 0 -8px; border-radius: var(--radius-sm); }
.shortcut:hover { background: var(--hover); }
.shortcut:last-child { border-bottom: 0; }
.shortcut kbd { margin-left: 3px; }

/* Share dialog */
.share-box { display: flex; gap: 8px; }
.share-box .input { flex: 1; height: 34px; font-family: var(--font-mono); font-size: 12px; }

/* Quick open and command palette */
.quick-open { width: min(600px, calc(100vw - 32px)); margin-top: 12vh; }
.quick-open .dialog-header { display: none; }
.quick-open .dialog-body { padding: 0; }
.quick-open .input { width: 100%; height: 46px; font-size: 14px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0 16px; background: transparent; box-shadow: none; }
.quick-list { padding: 4px; max-height: 360px; overflow: auto; }
.quick-item { display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 4px 10px; border-radius: 5px; cursor: pointer; }
.quick-item .icon { color: var(--fg-subtle); }
.quick-item .label { flex: 1 0 auto; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-item .hint { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--fg-subtle); font-size: 12px; white-space: nowrap; text-align: right; }
.quick-item .dir { color: var(--fg-subtle); font-size: 12px; margin-left: auto; }
.quick-item kbd + kbd { margin-left: 3px; }
.quick-item[aria-selected="true"] { background: var(--active); }
.quick-item mark { background: none; color: var(--accent-text); font-weight: 600; }
.quick-empty { padding: 14px 12px; color: var(--fg-subtle); }

/* Settings dialog */
.settings-dialog { width: min(760px, calc(100vw - 32px)); height: min(600px, calc(100vh - 48px)); }
.settings-dialog form { height: 100%; }
.settings-dialog .dialog-header { padding-bottom: 12px; }
.settings-dialog .dialog-body { padding: 0; flex: 1; display: flex; overflow: hidden; }
.settings-dialog .dialog-footer { padding-top: 10px; }
.settings-layout { display: grid; grid-template-columns: 180px minmax(0, 1fr); flex: 1; min-height: 0; }
.settings-dialog form > .dialog-body:last-child .settings-content { margin-bottom: 12px; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px 10px 12px; overflow: auto; }
.settings-nav button {
  display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; border: 0; border-radius: 5px;
  background: transparent; color: var(--fg-muted); font: inherit; text-align: left; cursor: pointer;
  transition: background-color var(--fast), color var(--fast);
}
.settings-nav button:hover { background: var(--hover); color: var(--fg); }
.settings-nav button[aria-current="true"] { background: var(--active); color: var(--fg); }
.settings-nav .nav-spacer { flex: 1; }
.settings-content { margin: 0 12px 0 0; padding: 0 16px 24px; overflow: auto; background: var(--panel); border-radius: var(--radius); }
.settings-search { position: relative; margin: 14px 0 4px; }
.settings-search + .settings-section h3:first-child { margin-top: 18px; }
.settings-search .input { width: 100%; padding-left: 32px; }
.settings-search .icon { position: absolute; left: 10px; top: 0; bottom: 0; color: var(--fg-subtle); pointer-events: none; }
.settings-section h3 { margin: 22px 0 2px; font-size: 13px; font-weight: 600; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 8px 24px; padding: 11px 0; flex-wrap: wrap; }
.setting-row .setting-text { flex: 1 1 240px; }
.setting-row .setting-control { flex-wrap: wrap; justify-content: flex-end; margin-left: auto; max-width: 100%; min-width: 0; }
.setting-row + .setting-row { box-shadow: 0 -1px 0 var(--border); }
.setting-text { min-width: 0; }
.setting-label { font-weight: 500; }
.setting-desc { margin-top: 2px; font-size: 12px; color: var(--fg-subtle); line-height: 1.45; }
.setting-control { flex: none; display: flex; align-items: center; gap: 8px; }
.setting-control .select { min-width: 140px; }
.number-stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--input-bg); border-radius: var(--radius-sm); overflow: hidden; }
.number-stepper button { width: 28px; height: 28px; border: 0; background: transparent; color: var(--fg-muted); cursor: pointer; }
.number-stepper button:hover { background: var(--hover); color: var(--fg); }
.number-stepper output { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
.settings-empty { padding: 32px 0; color: var(--fg-subtle); text-align: center; }

#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; z-index: 2000; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px;
  border-radius: var(--radius); background: var(--panel-elev); color: var(--fg); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow); opacity: 0; transform: translateY(10px) scale(0.97);
  transition: opacity var(--medium) var(--ease), transform var(--slow) var(--ease-spring); pointer-events: auto;
}
.toast.show { opacity: 1; transform: none; }
.toast.success .icon { color: var(--success); }
.toast.error .icon { color: var(--danger); }
.toast.info .icon { color: var(--fg-muted); }

#drop-overlay {
  position: fixed; inset: 0; z-index: 1500; display: flex; align-items: center; justify-content: center;
  background: var(--backdrop); pointer-events: none;
}
#drop-overlay .drop-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 40px;
  border: 2px dashed var(--accent); border-radius: var(--radius-lg); background: var(--panel-elev); color: var(--fg-muted); box-shadow: var(--shadow);
  animation: dialog-in var(--medium) var(--ease);
}
#drop-overlay .drop-card strong { color: var(--fg); font-size: 14px; font-weight: 600; }
#drop-overlay .drop-card .icon { color: var(--fg-muted); }


/* ----------------------------------------------------------------------- */
/* Motion: small, quick and interruptible. Off when the system asks. */

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

/* Narrow screens: settings dialogs in one column, sections as a row of chips. */
@media (max-width: 640px) {
  .settings-dialog { height: calc(100vh - 32px); }
  .settings-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .settings-nav { flex-direction: row; overflow-x: auto; padding: 0 12px 8px; gap: 4px; }
  .settings-nav button { flex: none; height: 28px; }
  .settings-nav .nav-spacer { display: none; }
  .settings-content { margin: 0 12px 12px; }
}
