:root {
  color-scheme: dark;
  --bg: #16181A;
  --surface: #1C1F22;
  --surface-2: #202427;
  --line: #2A2E32;
  --line-strong: #3A4046;
  --fg: #E4E4E0;
  --fg-muted: #9BA1A6;
  --fg-faint: #7C8288;
  --accent: #C8A26A;
  --accent-dim: #8A6F4A;
  --err: #C86D63;
  --ok: #7E9A78;
  --tok-comment: #828E86;
  --tok-mnemonic: #A3BDCB;
  --tok-register: #B3A6C9;
  --tok-number: #C9A6A0;
  --tok-string: #9CBA8F;
  --tok-directive: #9BA1A6;
  --tok-label: #E4E4E0;
  --tok-punct: #92989D;
  --sel: rgba(200, 162, 106, 0.18);
  --ui-font: -apple-system, "Segoe UI", Inter, sans-serif;
  --code-font: "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --surface-2: #FBFBFA;
  --line: #E2E2DE;
  --line-strong: #C9C9C4;
  --fg: #1B1C1A;
  --fg-muted: #5F625E;
  --fg-faint: #6E716C;
  --accent: #8B5E34;
  --accent-dim: #6E4826;
  --err: #A03D34;
  --ok: #4F6B4A;
  --tok-comment: #6E716C;
  --tok-mnemonic: #3F5C74;
  --tok-register: #5A4870;
  --tok-number: #7A4438;
  --tok-string: #4F6B4A;
  --tok-directive: #5F625E;
  --tok-label: #1B1C1A;
  --tok-punct: #6C6F69;
  --sel: rgba(139, 94, 52, 0.16);
}

body,
.app-shell,
.topbar,
.workspace,
.pane,
.pane-head,
.editor-surface,
.line-numbers,
.splitter,
.tab,
.panel,
.terminal-output,
.code-output,
.actionbar,
.control,
.theme-toggle,
.file-tab,
.head-tools,
.run-state,
.action-note,
#source,
.syntax-layer,
.tok-comment,
.tok-mnemonic,
.tok-register,
.tok-number,
.tok-string,
.tok-directive,
.tok-label,
.tok-punct {
  transition: background-color 180ms cubic-bezier(0.2, 0, 0, 1), color 180ms cubic-bezier(0.2, 0, 0, 1), border-color 180ms cubic-bezier(0.2, 0, 0, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 400 13px/20px var(--ui-font);
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  flex: 0 0 auto;
  color: var(--fg-muted);
  font: 500 13px/20px var(--code-font);
  text-decoration: none;
}

h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  color: var(--fg);
  font: 500 15px/20px var(--ui-font);
}

.theme-toggle {
  display: inline-grid;
  flex: 0 0 28px;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg-muted);
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--fg);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 2px;
}

.theme-icon {
  display: block;
  width: 14px;
  height: 14px;
  overflow: visible;
}

.theme-sun-core,
.theme-sun-rays,
.theme-moon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 180ms cubic-bezier(0.2, 0, 0, 1), opacity 180ms cubic-bezier(0.2, 0, 0, 1);
}

.theme-sun-rays,
.theme-moon {
  opacity: 1;
}

.theme-moon {
  opacity: 0;
}

[data-theme="light"] .theme-sun-core {
  transform: scale(0.55);
}

[data-theme="light"] .theme-sun-rays {
  transform: rotate(45deg) scale(0);
  opacity: 0;
}

[data-theme="light"] .theme-moon {
  opacity: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.pane-head {
  display: flex;
  flex: 0 0 40px;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.file-tab {
  display: flex;
  align-items: center;
  height: 100%;
  color: var(--fg);
  font: 400 12px/16px var(--ui-font);
}

.head-tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  color: var(--fg-muted);
  font: 400 12px/16px var(--ui-font);
}

.control {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--fg);
  font: 400 13px/20px var(--ui-font);
  white-space: nowrap;
  cursor: pointer;
}

.control:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.control:disabled {
  color: var(--fg-faint);
  cursor: wait;
}

.control.primary {
  border-color: var(--accent);
  color: var(--accent);
}

.control.primary:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.restore-button {
  padding-right: 8px;
  padding-left: 8px;
}

.editor-wrap {
  position: relative;
  overflow: hidden;
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 52px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.active-line {
  display: none;
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  left: 0;
  height: var(--active-line-height, 20px);
  transform: translateY(var(--active-line-top, 13px));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--line) 55%, var(--surface-2));
  pointer-events: none;
}

.editor-wrap:focus-within .active-line {
  display: block;
}

.line-numbers {
  position: relative;
  z-index: 2;
  overflow: hidden;
  padding: 12px 8px 12px 0;
  border-right: 1px solid var(--line);
  color: var(--fg-faint);
  opacity: 0.8;
  font: 400 13px/20px var(--code-font);
  text-align: right;
  white-space: pre;
  user-select: none;
}

.editor-surface {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface-2);
}

.syntax-layer,
#source {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px;
  border: 1px solid transparent;
  font: 400 13px/20px var(--code-font);
  tab-size: 4;
  white-space: pre;
}

.syntax-layer {
  z-index: 2;
  overflow: hidden;
  color: var(--fg);
  pointer-events: none;
  user-select: none;
}

.syntax-layer code {
  display: block;
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  font: inherit;
}

#source {
  z-index: 3;
  overflow: auto;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--accent);
  outline: none;
  -webkit-text-fill-color: transparent;
}

#source:focus-visible {
  border-color: var(--line-strong);
  outline: 1px solid var(--accent-dim);
  outline-offset: 2px;
}

#source::selection {
  background: var(--sel);
  color: transparent;
}

.tok-comment {
  color: var(--tok-comment);
  font-style: italic;
}

.tok-mnemonic {
  color: var(--tok-mnemonic);
}

.tok-register {
  color: var(--tok-register);
}

.tok-number {
  color: var(--tok-number);
}

.tok-string {
  color: var(--tok-string);
}

.tok-directive {
  color: var(--tok-directive);
}

.tok-label {
  color: var(--tok-label);
  font-weight: 500;
}

.tok-punct {
  color: var(--tok-punct);
}

.splitter {
  position: relative;
  z-index: 2;
  width: 6px;
  min-width: 6px;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--surface);
  cursor: col-resize;
  touch-action: none;
}

.splitter:hover,
.splitter.dragging {
  background: var(--surface-2);
}

.output-head {
  padding: 0 12px;
}

.tabs {
  display: flex;
  align-self: stretch;
  gap: 12px;
  min-width: 0;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fg-muted);
  font: 400 13px/20px var(--ui-font);
  white-space: nowrap;
  cursor: pointer;
}

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

.tab.active {
  color: var(--fg);
}

.tab.active::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--accent);
  content: "";
}

.run-state {
  flex: 0 0 auto;
  color: var(--fg-muted);
  font: 400 12px/16px var(--ui-font);
}

.run-state.success {
  color: var(--ok);
}

.run-state.error {
  color: var(--err);
}

.panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.terminal-caption {
  display: flex;
  flex: 0 0 40px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  color: var(--fg-muted);
  font: 400 12px/16px var(--ui-font);
}

.terminal-output {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  margin: 0 12px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--fg);
  font: 400 13px/20px var(--code-font);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
}

.placeholder {
  color: var(--fg-muted);
}

.error-box {
  flex: 0 0 auto;
  max-height: 120px;
  margin: 0 12px 12px;
  padding: 8px 12px;
  overflow: auto;
  border: 1px solid var(--err);
  background: var(--surface-2);
  color: var(--err);
  font: 400 12px/20px var(--code-font);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code-output {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 12px 16px;
  overflow: auto;
  background: var(--surface-2);
  color: var(--fg);
  font: 400 13px/20px var(--code-font);
  white-space: pre;
}

.actionbar {
  display: flex;
  flex: 0 0 40px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.action-note {
  min-width: 0;
  overflow: hidden;
  color: var(--fg-muted);
  font: 400 12px/16px var(--ui-font);
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@media (prefers-reduced-motion: reduce) {
  body,
  .app-shell,
  .topbar,
  .workspace,
  .pane,
  .pane-head,
  .editor-surface,
  .line-numbers,
  .splitter,
  .tab,
  .panel,
  .terminal-output,
  .code-output,
  .actionbar,
  .control,
  .theme-toggle,
  .file-tab,
  .head-tools,
  .run-state,
  .action-note,
  .syntax-layer,
  .tok-comment,
  .tok-mnemonic,
  .tok-register,
  .tok-number,
  .tok-string,
  .tok-directive,
  .tok-label,
  .tok-punct,
  #source,
  .theme-sun-core,
  .theme-sun-rays,
  .theme-moon {
    transition-duration: 0ms;
  }
}

:focus-visible {
  outline: 1px solid var(--accent-dim);
  outline-offset: 2px;
  border-color: var(--line-strong);
}

.splitter:focus-visible {
  outline: none;
  border-color: var(--line);
}

.splitter:focus-visible::after {
  position: absolute;
  top: calc(50% - 12px);
  left: calc(50% - 1px);
  height: 24px;
  border-left: 1px solid var(--accent-dim);
  content: "";
  pointer-events: none;
}

@media (max-width: 700px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 6px minmax(0, 1fr);
  }

  .splitter {
    width: auto;
    min-width: 0;
    height: 6px;
    border: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    cursor: row-resize;
  }

  .splitter:focus-visible::after {
    top: calc(50% - 1px);
    left: calc(50% - 12px);
    width: 24px;
    height: 0;
    border-top: 1px solid var(--accent-dim);
    border-left: 0;
  }
}

@media (max-width: 430px) {
  .topbar {
    gap: 8px;
    padding: 0 12px;
  }

  .pane-head,
  .output-head {
    padding-right: 8px;
    padding-left: 8px;
  }

  .head-tools {
    gap: 4px;
  }

  .restore-button {
    padding-right: 4px;
    padding-left: 4px;
  }

  .tabs {
    gap: 8px;
  }

  .tab {
    padding-right: 2px;
    padding-left: 2px;
  }

  .actionbar {
    gap: 4px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .actions {
    gap: 4px;
  }

  .control {
    padding-right: 8px;
    padding-left: 8px;
  }

  .action-note {
    max-width: 94px;
  }
}
