:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --panel: #ffffff;
  --panel-alt: #f0f6f4;
  --ink: #202124;
  --muted: #6b716f;
  --line: #d9ded9;
  --accent: #0f766e;
  --accent-dark: #0b4f4a;
  --warm: #a84f2a;
  --code-bg: #272822;
  --code-gutter: #20211c;
  --code-line: #3e3d32;
  --code-ink: #f8f8f2;
  --code-muted: #75715e;
  --code-keyword: #f92672;
  --code-type: #66d9ef;
  --code-string: #e6db74;
  --code-number: #ae81ff;
  --code-preprocessor: #a6e22e;
  --focus: #d77a32;
  --gutter-width: 52px;
  --code-font-size: 13px;
  --code-line-height: 1.55;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
  max-width: 1680px;
  min-height: calc(100vh - 32px);
  margin: 0 auto;
}

.source-pane,
.output-pane {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.source-pane,
.output-pane {
  flex-direction: column;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.pane-header h1,
.pane-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  letter-spacing: 0;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
}

.pane-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.commit-link {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--panel-alt);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace,
    monospace;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.commit-link:hover {
  border-color: var(--accent);
  text-decoration: underline;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-link {
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.header-link:hover {
  text-decoration: underline;
}

.file-button,
.mode-button,
.tab-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.tab-list {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.source-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 55px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.mode-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.mode-button,
.tab-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
}

.file-button:hover,
.mode-button:hover,
.tab-button:hover {
  border-color: var(--accent);
}

.source-label {
  display: flex;
  align-items: center;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.source-editor-shell {
  position: relative;
  flex: 1;
  min-height: 360px;
  width: 100%;
  overflow: hidden;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace,
    monospace;
  font-size: var(--code-font-size);
  line-height: var(--code-line-height);
  tab-size: 2;
}

#source-editor {
  position: absolute;
  inset: 0 0 0 var(--gutter-width);
  z-index: 2;
  width: calc(100% - var(--gutter-width));
  height: 100%;
  resize: none;
  padding: 14px 16px 18px;
  border: 0;
  outline: 0;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: var(--code-ink);
  -webkit-text-fill-color: transparent;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  tab-size: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#source-editor::selection {
  background: rgb(73 72 62 / 82%);
  color: transparent;
}

.source-mirror {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  will-change: transform;
}

.output-header {
  background: #fff;
}

.mode-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.run-badge {
  min-width: 72px;
  padding: 0;
  border: 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.run-badge.running {
  color: var(--warm);
}

.run-badge.ok {
  color: var(--accent-dark);
}

.run-badge.error {
  color: var(--warm);
}

.tab-list {
  min-height: 55px;
  background: var(--panel-alt);
}

.tab-button {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-button.active {
  border-color: var(--accent);
  background: #dff1ec;
  color: var(--accent-dark);
}

.output-view,
.code-lines {
  flex: 1;
  min-height: 360px;
  overflow: auto;
  background: var(--code-bg);
  color: var(--code-ink);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace,
    monospace;
  font-size: var(--code-font-size);
  line-height: var(--code-line-height);
  tab-size: 2;
}

.code-lines {
  padding: 14px 0 18px;
  overflow: visible;
}

.code-line {
  display: grid;
  grid-template-columns: var(--gutter-width) minmax(0, 1fr);
  min-width: 0;
}

.line-number {
  min-height: calc(var(--code-font-size) * var(--code-line-height));
  padding: 0 10px 0 8px;
  border-right: 1px solid var(--code-line);
  background: var(--code-gutter);
  color: var(--code-muted);
  text-align: right;
  user-select: none;
}

.line-code {
  min-width: 0;
  min-height: calc(var(--code-font-size) * var(--code-line-height));
  padding: 0 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.tok-keyword {
  color: var(--code-keyword);
}

.tok-type {
  color: var(--code-type);
}

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

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

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

.tok-preprocessor {
  color: var(--code-preprocessor);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 8px;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .source-pane,
  .output-pane {
    min-height: 640px;
  }

  .pane-header {
    align-items: flex-start;
    flex-direction: column;
  }
}
