@charset "UTF-8";

:root {
  color-scheme: light;
  --paper: #faf9f5;
  --surface: #f3f2ec;
  --surface-raised: #fffefa;
  --surface-hover: #eeede6;
  --ink: #30362f;
  --muted: #6c7468;
  --faint: #8b9285;
  --line: #e3e4da;
  --accent: #3d6650;
  --accent-strong: #2f513e;
  --accent-soft: #e5ece1;
  --accent-line: #c8d6c4;
  --selection: #d5e5d3;
  --code-paper: #eff2e9;
  --error: #a34535;
  --error-soft: #f8e9e3;
  --shadow: 0 16px 64px #28332320, 0 2px 8px #2833230a;
  --ui: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --prose: Georgia, "Times New Roman", serif;
  font: 13px/1.5 var(--ui);
  background: var(--paper);
  color: var(--ink);
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #20251f;
  --surface: #1b201b;
  --surface-raised: #292f27;
  --surface-hover: #30372d;
  --ink: #dde2d6;
  --muted: #a1ac99;
  --faint: #74806c;
  --line: #363e32;
  --accent: #adc79d;
  --accent-strong: #c2d9b5;
  --accent-soft: #303e2e;
  --accent-line: #4e6545;
  --selection: #465a3d;
  --code-paper: #252e23;
  --error: #f1a18e;
  --error-soft: #402b25;
  --shadow: 0 16px 64px #0006, 0 2px 8px #0003;
}

* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button { border: 0; background: none; }
button:disabled { opacity: .45; cursor: default; }
a { color: inherit; }
svg { width: 18px; height: 18px; flex-shrink: 0; }
button svg, .command-search svg, .document-tab svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
button { border-radius: 5px; }
button:hover { background: var(--surface-hover); }
::selection { background: var(--selection); }
[hidden] { display: none !important; }
kbd {
  font: 10px/1.5 var(--ui);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  white-space: nowrap;
}

.app-shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.app-header {
  height: 64px;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 25px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font: 600 23px/1 var(--ui); letter-spacing: -1.2px; }
.brand > svg { width: 27px; height: 27px; stroke: var(--accent); stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-x { color: var(--accent); font-weight: 450; }
.header-divider { width: 1px; height: 19px; background: var(--line); }
.header-label { color: var(--muted); font: italic 15px var(--prose); }
.header-actions { display: flex; align-items: center; gap: 13px; margin-left: auto; }
.saved-indicator { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; margin-right: 11px; white-space: nowrap; }
.saved-indicator > span, .runtime-indicator > span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: .7; flex-shrink: 0; }
.saved-indicator.is-saving > span { background: #b68d44; }
.icon-button { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); padding: 6px; flex-shrink: 0; }
.icon-button:hover { color: var(--ink); }
.command-button { display: flex; align-items: center; gap: 8px; height: 31px; padding: 0 8px; color: var(--muted); }
.command-button svg { width: 15px; height: 15px; }
.command-button kbd { margin-left: 8px; }
.workspace { display: flex; flex: 1; min-width: 0; min-height: 0; }
.main-panel { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.document-bar { height: 44px; min-height: 44px; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 21px; gap: 7px; }
.document-tab { height: 44px; max-width: min(70%, 460px); display: flex; align-items: center; gap: 8px; border-bottom: 2px solid var(--accent); padding: 2px 11px 0; color: var(--ink); font-size: 11px; }
.document-tab svg { width: 14px; height: 14px; color: var(--muted); }
#document-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-dot { width: 4px; height: 4px; background: var(--muted); opacity: .6; border-radius: 50%; margin: 0 1px 0 5px; flex-shrink: 0; }
.document-actions { display: flex; gap: 7px; align-items: center; margin-left: auto; }
.text-button { display: inline-flex; gap: 8px; align-items: center; justify-content: center; min-height: 29px; padding: 4px 9px; font-size: 11px; color: var(--muted); }
.text-button svg { width: 13px; height: 13px; }
.document-actions .icon-button { width: 28px; height: 28px; margin-left: 3px; }
.editor-toolbar { min-height: 44px; height: 44px; display: flex; align-items: center; gap: 15px; padding: 0 29px; border-bottom: 1px solid var(--line); }
.view-switch { display: inline-flex; gap: 2px; align-items: center; }
.view-switch button { color: var(--muted); padding: 4px 9px; font-size: 10px; border-radius: 4px; line-height: 1.6; }
.view-switch button[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); font-weight: 600; }
.toolbar-divider { height: 17px; width: 1px; background: var(--line); }
.format-actions { display: flex; gap: 5px; align-items: center; }
.format-button { display: inline-flex; align-items: center; justify-content: center; gap: 3px; color: var(--muted); min-width: 25px; height: 27px; padding: 2px 5px; font-size: 14px; }
.format-button small { font-size: 9px; }
.bold-button { font-weight: 750; }
.italic-button { font: italic 17px var(--prose); }
.code-button { font: 12px var(--mono); }
.run-actions { display: flex; align-items: center; gap: 19px; margin-left: auto; }
.runtime-indicator { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.runtime-indicator.is-error { color: var(--error); }
.runtime-indicator.is-error > span { background: var(--error); }

.editor-body { flex: 1; display: flex; min-height: 0; position: relative; overflow: hidden; background: var(--paper); }
.editor-instance { height: 100%; min-height: 0; }
.cm-editor { height: 100%; background: var(--paper); color: var(--ink); }
.cm-editor.cm-focused { outline: none; }
.cm-editor .cm-scroller {
  font: var(--editor-font-size, 15px)/1.25 var(--mono);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  padding-inline: 0;
}
.cm-editor .cm-content { min-width: 0; padding: 8px 16px 100px; caret-color: var(--accent); }
.cm-editor .cm-line { padding: 0; }
.cm-editor .cm-gutters { background: transparent; color: var(--faint); border: 0; padding: 0; user-select: none; }
.cm-editor .cm-lineNumbers .cm-gutterElement { display: flex; align-items: flex-start; justify-content: flex-end; min-width: 38px; padding: 0 8px 0 12px; font: 10px/1.25 var(--mono); line-height: calc(var(--editor-font-size, 15px) * 1.25); }
.cm-editor .cm-activeLineGutter { color: var(--accent); background: transparent; }
.cm-editor .cm-activeLine { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.cm-editor .cm-selectionBackground, .cm-editor.cm-focused .cm-selectionBackground { background: var(--selection); }
.cm-editor .cm-cursor, .cm-editor .cm-dropCursor { border-left-color: var(--accent); }
.cm-editor .cm-foldGutter .cm-gutterElement { padding: 0 2px; color: var(--faint); font-size: 10px; }
.cm-editor .cm-foldPlaceholder { border: 0; background: var(--accent-soft); color: var(--muted); border-radius: 3px; padding: 1px 5px; }
.cm-editor .cm-panels { background: var(--surface); color: var(--ink); border-color: var(--line); }
.cm-editor .cm-search { padding: 8px 15px; font: 11px var(--ui); }
.cm-editor .cm-textfield { color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 5px 7px; }
.cm-editor .cm-button { font: 11px var(--ui); color: var(--ink); background: var(--surface-raised); border: 1px solid var(--line); border-radius: 4px; }
.cm-editor .cm-searchMatch { background: #c4ab5d38; outline: 1px solid #b8954938; }
.cm-editor .cm-searchMatch-selected { background: #c4ab5d70; }
.cm-sxript-gutter { min-width: 16px; }
.cm-sxript-gutter .cm-gutterElement { display: flex; align-items: center; justify-content: center; }
.sx-run-marker { display: inline-flex; justify-content: center; align-items: center; width: 17px; height: 100%; margin: 0; padding: 0; color: var(--accent); font-size: 10px; line-height: 1; border-radius: 3px; opacity: .8; }
.sx-run-marker:hover { color: var(--accent-strong); opacity: 1; background: var(--accent-soft); }
.cm-tooltip { border: 1px solid var(--line) !important; background: var(--surface-raised) !important; color: var(--ink); border-radius: 5px; box-shadow: var(--shadow); font: 12px var(--ui); }
.cm-tooltip-autocomplete ul li[aria-selected] { background: var(--accent-soft) !important; color: var(--accent-strong) !important; }

.reading-view { width: 100%; height: 100%; min-width: 0; overflow: auto; overscroll-behavior: contain; padding: 8px 16px 100px; scrollbar-width: thin; }
.reading-content { width: 100%; max-width: none; margin: 0; font: 17px/1.3 var(--prose); overflow-wrap: anywhere; }
.reading-content > :first-child { margin-top: 0; }
.reading-content h1, .reading-content h2, .reading-content h3, .reading-content h4 { font-family: var(--ui); line-height: 1.2; font-weight: 600; }
.reading-content h1 { font-size: 33px; letter-spacing: -1.2px; margin: 0 0 18px; }
.reading-content h2 { font-size: 23px; letter-spacing: -.5px; margin: 28px 0 12px; }
.reading-content h3 { font-size: 18px; margin: 22px 0 10px; }
.reading-content p { margin: 0 0 12px; }
.reading-content a { color: var(--accent-strong); text-underline-offset: 3px; }
.reading-content hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
.reading-content blockquote { color: var(--muted); border-left: 2px solid var(--accent-line); padding-left: 23px; margin: 16px 0; }
.reading-content ul, .reading-content ol { padding-left: 27px; margin: 12px 0 15px; }
.reading-content li { padding-left: 4px; margin: 3px 0; }
.reading-content code { font: .8em/1.25 var(--mono); background: var(--code-paper); border-radius: 3px; padding: 2px 4px; }
.reading-content pre { background: var(--code-paper); padding: 12px 16px; border-radius: 4px; overflow: auto; margin: 14px 0; font: 12px/1.25 var(--mono); }
.reading-content pre code { padding: 0; background: none; font: inherit; white-space: pre; }
.reading-content .katex-display { overflow-x: auto; overflow-y: hidden; padding: 6px 0; margin: 14px 0; }
.reading-content img { max-width: 100%; height: auto; }
.reading-content table { border-collapse: collapse; font: 13px/1.3 var(--ui); width: 100%; margin: 16px 0; }
.reading-content th, .reading-content td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.reading-content th { font-weight: 600; background: var(--surface); }
.math-display { display: block; }
.sxript-reading-block { margin: 18px 0; }
.sxript-reading-label { color: var(--accent); font: 600 9px/1.3 var(--ui); letter-spacing: 1.1px; text-transform: uppercase; margin-bottom: 5px; }
.sxript-reading-block > pre { margin-top: 0; }
.sxript-result { border-left: 2px solid var(--accent-line); background: var(--code-paper); padding: 8px 14px; margin: -6px 0 16px; font: 12px/1.25 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.sxript-result pre { margin: 0; padding: 0; background: none; border-radius: 0; font: inherit; white-space: pre-wrap; }
.result-label { display: flex; align-items: center; gap: 7px; color: var(--accent); font: 600 9px/1.3 var(--ui); letter-spacing: 1.1px; text-transform: uppercase; margin-bottom: 5px; }
.sxript-result .result-label { justify-content: space-between; }
.result-time { color: var(--muted); font-weight: 400; letter-spacing: 0; text-transform: none; }
.sxript-result[data-error="true"], .sxript-result.is-error { background: var(--error-soft); color: var(--error); border-color: var(--error); }
.sxript-result.is-error .result-label { color: var(--error); }
.sxript-result[data-stale="true"], .sxript-result.is-stale { opacity: .65; border-left-style: dashed; }
.drop-overlay { position: absolute; z-index: 20; inset: 12px; display: flex; align-items: center; justify-content: center; flex-direction: column; border: 2px dashed var(--accent-line); border-radius: 6px; background: color-mix(in srgb, var(--paper) 94%, transparent); pointer-events: none; color: var(--accent-strong); }
.drop-overlay > span { font: 25px var(--prose); }
.drop-overlay p { font: 11px var(--mono); color: var(--muted); }
.status-bar { height: 28px; min-height: 28px; display: flex; justify-content: space-between; gap: 15px; align-items: center; padding: 0 19px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; background: var(--paper); }
.status-left, .status-right { display: flex; align-items: center; gap: 18px; min-width: 0; white-space: nowrap; }
.status-bar button { font-size: 10px; padding: 1px 3px; color: var(--muted); }
.status-bar .status-brand { font: 600 11px var(--ui); color: var(--accent); margin-right: 2px; }
.status-bar .help-button { border: 1px solid var(--line); border-radius: 50%; width: 14px; height: 14px; font-size: 9px; line-height: 1; padding: 0; }

.popover { z-index: 50; position: fixed; background: var(--surface-raised); border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow); padding: 5px; }
.file-menu { min-width: 230px; max-width: calc(100vw - 20px); }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 22px; width: 100%; padding: 8px 10px; font-size: 11px; text-align: left; }
.menu-item:hover { background: var(--accent-soft); }
.menu-item kbd { border: 0; padding: 0; font-size: 10px; }
.menu-divider { height: 1px; background: var(--line); margin: 5px 6px; }
dialog { color: var(--ink); background: var(--surface-raised); border: 1px solid var(--line); border-radius: 9px; padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: #1f291b4d; backdrop-filter: blur(2px); }
.command-dialog { width: min(560px, calc(100vw - 36px)); max-height: min(560px, calc(100dvh - 100px)); margin: min(20vh, 150px) auto auto; overflow: hidden; }
.command-search { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); color: var(--muted); }
.command-search input { width: 100%; min-width: 0; border: 0; background: none; outline: 0; color: var(--ink); font-size: 14px; padding: 0; }
.command-search input::placeholder { color: var(--faint); }
.command-search input:focus-visible { outline: 0; }
.command-search:focus-within { box-shadow: inset 0 -2px var(--accent-line); }
.command-search .command-close { flex-shrink: 0; min-width: 30px; height: 28px; padding: 0 4px; border: 1px solid var(--line); border-radius: 0; color: var(--muted); font: 11px/1 var(--mono); }
.command-search .command-close:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-strong); }
.command-list { padding: 6px; max-height: min(380px, calc(100dvh - 230px)); overflow: auto; scrollbar-width: thin; }
.command-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border-radius: 5px; padding: 10px 12px; font-size: 12px; }
.command-item.selected { background: var(--accent-soft); color: var(--accent-strong); }
.command-name { flex: 1; }
.command-hint { font-size: 10px; color: var(--muted); white-space: nowrap; }
.command-group { padding: 10px 12px 5px; color: var(--faint); font-size: 9px; letter-spacing: 1px; text-transform: uppercase; }
.empty-commands { padding: 24px 12px 28px; text-align: center; font-size: 12px; color: var(--muted); }
.command-footer { display: flex; justify-content: space-between; gap: 10px; padding: 10px 17px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.command-footer kbd { margin-right: 3px; }
.help-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 64px); padding: 27px 32px 26px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.help-dialog h2 { font: 28px/1.3 var(--prose); letter-spacing: -.5px; margin: 20px 0 14px; }
.help-dialog p { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 0 0 22px; }
.help-dialog code { font: 10px var(--mono); color: var(--ink); padding: 2px 4px; background: var(--code-paper); border-radius: 3px; }
#shortcut-list { margin: 0 0 21px; }
.shortcut-row { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.help-dialog p.help-footnote { font-size: 10px; margin: 0; }
.confirm-dialog { width: min(420px, calc(100vw - 32px)); padding: 26px; }
.confirm-dialog h2 { font: 24px var(--prose); margin: 0 0 13px; }
.confirm-dialog p { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 0 0 24px; }
.confirm-dialog > div { display: flex; justify-content: flex-end; gap: 10px; }
.toast { position: fixed; z-index: 100; bottom: 44px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 10px 16px; background: var(--surface-raised); border: 1px solid var(--line); color: var(--ink); box-shadow: 0 4px 24px #00000012; border-radius: 6px; font-size: 12px; animation: toast-in .16s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 5px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 1000px) {
  .editor-toolbar { padding-inline: 20px; gap: 10px; }
  .run-actions { gap: 10px; }
  .runtime-indicator { display: none; }
}
@media (max-width: 760px) {
  .app-header { padding: 0 17px; gap: 15px; height: 56px; min-height: 56px; }
  .brand { font-size: 21px; }
  .brand > svg { width: 24px; height: 24px; }
  .header-actions { gap: 5px; }
  .saved-indicator { margin-right: 5px; font-size: 10px; }
  .command-button { padding-inline: 6px; }
  .command-button kbd { display: none; }
  .header-label { font-size: 13px; }
  .document-bar { padding-inline: 14px; }
  .document-tab { padding-inline: 8px; max-width: 58%; }
  .document-actions { gap: 1px; }
  .editor-toolbar { padding-inline: 16px; gap: 9px; }
  .format-actions { gap: 1px; }
  .run-actions { gap: 0; }
  .cm-editor .cm-scroller { font-size: var(--editor-font-size, 13px); }
  .cm-editor .cm-content { padding: 8px 16px 90px; }
  .cm-editor .cm-lineNumbers .cm-gutterElement { min-width: 31px; padding-left: 7px; padding-right: 6px; }
  .reading-view { padding: 8px 16px 80px; }
  .reading-content { font-size: 16px; }
  .status-bar { padding-inline: 14px; }
  .status-left, .status-right { gap: 12px; }
}
@media (max-width: 540px) {
  .header-divider, .header-label, .saved-indicator, .command-button > span:not(:first-child) { display: none; }
  .command-button { width: 30px; justify-content: center; }
  .document-actions .text-button { padding-inline: 7px; }
  .document-tab { font-size: 10px; gap: 5px; max-width: 54%; }
  .tab-dot { display: none; }
  .editor-toolbar { gap: 8px; padding-inline: 12px; }
  .view-switch button { font-size: 10px; padding: 4px 7px; }
  .toolbar-divider, .format-actions { display: none; }
  .status-bar { font-size: 9px; padding-inline: 10px; }
  .status-left, .status-right { gap: 10px; }
  .status-right > span, #selection-status { display: none; }
  .status-bar button { font-size: 9px; }
  .reading-content h1 { font-size: 28px; }
  .reading-content h2 { font-size: 21px; }
  .help-dialog { padding: 23px; }
  .help-dialog h2 { font-size: 25px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print {
  :root, [data-theme="dark"] { color-scheme: light; --paper: #fff; --ink: #111; --muted: #555; --code-paper: #f4f4f0; --line: #ddd; --accent: #35553e; --accent-strong: #284531; --accent-line: #c4cfc1; }
  body { overflow: visible; background: white; }
  .app-shell, .workspace, .main-panel, .editor-body { display: block; height: auto; overflow: visible; }
  .app-header, .document-bar, .editor-toolbar, .status-bar, .popover, dialog, .toast, .drop-overlay, .focus-exit { display: none !important; }
  .reading-content { max-width: none; font-size: 11pt; line-height: 1.3; }
  .reading-content h1 { font-size: 25pt; }
  .reading-content h2 { font-size: 17pt; }
  .reading-content h3 { font-size: 13pt; }
  .reading-content h1, .reading-content h2, .reading-content h3 { break-after: avoid; }
  .reading-content pre, .reading-content blockquote, .reading-content .katex-display, .sxript-result { break-inside: avoid; }
  .reading-content pre { white-space: pre-wrap; }
  .reading-content a { color: inherit; }
  @page { margin: 20mm 22mm; }
}
