:root {
  --paper: #f5f4ef;
  --surface: #ffffff;
  --ink: #18181b;
  --muted: #52525b;
  --tertiary: #a1a1aa;
  --line: #e2e0d8;
  --line-strong: #d5d2c8;
  --run-hover: #27272a;
  --comment: #7a7a7a;
  --underline: #c8c8cc;
  --error: #991b1b;
  --error-bg: #fef2f2;
  --warning: #92400e;
  --warning-bg: #fffbeb;
  --success: #15803d;
  --neutral: #71717a;
  --serif: "Liberation Serif", "EB Garamond", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "Liberation Mono", ui-monospace, SFMono-Regular, monospace;
  --editor-size: 18px;
  --editor-leading: 1.72;
  --editor-pad-y: 24px;
  --editor-pad-x: 28px;
  --editor-line: calc(var(--editor-size) * var(--editor-leading));
  --italic-skew: skewX(-7deg);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Header ------------------------------------------------------------------ */

.topbar {
  min-height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  margin-right: auto;
  white-space: nowrap;
}

.brand-name {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.003em;
  text-decoration: none;
}

.brand-name:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.brand-version {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.01em;
}

.brand-by {
  color: var(--muted);
  font-size: 11.5px;
}

.brand-by a {
  color: var(--muted);
  text-underline-offset: 2px;
}

.brand-by a:hover {
  color: var(--ink);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.picker {
  display: flex;
  align-items: center;
  min-width: 0;
}

.picker select {
  width: 250px;
  max-width: 250px;
  height: 32px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
}

.button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
}

.button:hover:not(:disabled) {
  background: #f0efe9;
}

.button:disabled {
  color: var(--tertiary);
  cursor: default;
}

.button-primary {
  border-color: var(--ink);
  background: var(--ink);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  background: var(--run-hover);
}

.button-primary:disabled {
  border-color: var(--neutral);
  background: var(--neutral);
  color: #ffffff;
}

.button kbd {
  margin-left: 8px;
  color: inherit;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 400;
  opacity: 0.6;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 15px;
  white-space: nowrap;
}

.topnav a {
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: none;
}

.topnav a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Workbench --------------------------------------------------------------- */

.workbench {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  background: var(--surface);
}

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

.editor-pane {
  border-right: 1px solid var(--line);
}

.pane-head {
  height: 34px;
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px 0 24px;
  border-bottom: 1px solid var(--line);
}

.file-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.file-name {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: nowrap;
}

.legend {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 12px;
  white-space: nowrap;
}

.legend-sep {
  color: var(--tertiary);
}

.legend-action {
  color: var(--ink);
  text-shadow: 0.35px 0 0 currentColor, -0.35px 0 0 currentColor;
}

.legend-variable {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.legend-italic {
  display: inline-block;
  color: var(--ink);
  transform: var(--italic-skew);
  transform-origin: left bottom;
}

.legend-comment {
  display: inline-block;
  color: var(--comment);
  transform: var(--italic-skew);
  transform-origin: left bottom;
}

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

.text-button {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
}

.text-button:hover {
  color: var(--ink);
}

.text-button:disabled {
  color: var(--tertiary);
  cursor: default;
}

.editor-caption {
  min-height: 28px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  padding: 6px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.editor-caption span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  background: var(--surface);
}

.gutter {
  width: 58px;
  flex: 0 0 58px;
  overflow: hidden;
  padding: var(--editor-pad-y) 10px var(--editor-pad-y) 0;
  border-right: 1px solid var(--line);
  color: var(--tertiary);
  font-family: var(--mono);
  font-size: 12px;
  line-height: var(--editor-line);
  text-align: right;
  user-select: none;
}

.gutter-line {
  position: relative;
  min-height: var(--editor-line);
}

.gutter-line.has-error::before,
.gutter-line.has-warning::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 13px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
}

.gutter-line.has-error::before {
  background: var(--error);
}

.gutter-line.has-warning::before {
  background: var(--warning);
}

.editor-canvas {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.editor-highlight,
.editor-input {
  position: absolute;
  inset: 0;
  margin: 0;
  border: 0;
  padding: var(--editor-pad-y) var(--editor-pad-x);
  font-family: var(--serif);
  font-size: var(--editor-size);
  line-height: var(--editor-leading);
  letter-spacing: 0.005em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  tab-size: 2;
}

.editor-highlight {
  z-index: 1;
  overflow: hidden;
  background: var(--surface);
  color: var(--ink);
  pointer-events: none;
}

.editor-input {
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  resize: none;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--ink);
  scrollbar-width: none;
  overscroll-behavior: contain;
}

.editor-input::-webkit-scrollbar {
  display: none;
}

.editor-input:focus-visible {
  outline: none;
}

.editor-input::selection {
  background: rgba(24, 24, 27, 0.16);
}

.highlight-line {
  min-height: var(--editor-line);
}

/* Compiler-driven monochrome typography. Bold uses text-shadow so glyph
   advance widths never change; italic uses a synthetic skew for the same
   reason. The overlay therefore stays exactly aligned with the transparent
   textarea and its caret. */
.token-verb,
.token-keyword {
  text-shadow: 0.35px 0 0 currentColor, -0.35px 0 0 currentColor;
}

.token-variable {
  text-decoration: underline;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.token-anaphor,
.token-string,
.token-comment {
  display: inline-block;
  max-width: 100%;
  vertical-align: baseline;
  line-height: inherit;
  transform: var(--italic-skew);
  transform-origin: left bottom;
}

.token-comment {
  color: var(--comment);
  white-space: pre-wrap;
}

/* Inspector --------------------------------------------------------------- */

.inspector-head {
  height: 36px;
  flex: 0 0 36px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px 0 24px;
  border-bottom: 1px solid var(--line);
}

.tablist {
  display: flex;
  align-items: stretch;
  gap: 22px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tablist::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

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

.tab[aria-selected="true"] {
  color: var(--ink);
}

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--ink);
}

.tab-copy {
  align-self: center;
  flex: 0 0 auto;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11.5px;
}

.tab-copy:hover:not(:disabled) {
  color: var(--ink);
  background: #f0efe9;
}

.tab-copy:disabled {
  color: var(--tertiary);
  cursor: default;
}

.panels {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.panel {
  padding: 22px 24px 48px;
}

.mono {
  margin: 0;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

.mono.is-empty {
  color: var(--muted);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.6;
}

.stdout {
  min-height: 22px;
}

.placeholder {
  max-width: 48ch;
  margin: 0;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.6;
}

.diagnostics {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.diagnostics:empty {
  display: none;
}

.diagnostic {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-left: 3px solid var(--error);
  border-radius: 2px;
  background: var(--error-bg);
  color: var(--error);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
}

.diagnostic:hover {
  background: #fde9e9;
}

.diagnostic.warning {
  border-left-color: var(--warning);
  background: var(--warning-bg);
  color: var(--warning);
}

.diagnostic.warning:hover {
  background: #fdf4dd;
}

.diagnostic-location {
  align-self: start;
  padding: 1px 5px;
  border: 1px solid currentColor;
  border-radius: 2px;
  font-size: 10.5px;
  font-weight: 600;
  white-space: nowrap;
}

.diagnostic-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.diagnostic-category {
  margin-left: 8px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.trace {
  display: flex;
  flex-direction: column;
}

.trace-entry {
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.trace-entry:first-child {
  padding-top: 0;
}

.trace-entry:last-child {
  border-bottom: 0;
}

.trace-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.trace-location {
  flex: 0 0 auto;
  color: var(--tertiary);
  font-family: var(--mono);
  font-size: 11px;
}

.trace-badge {
  flex: 0 0 auto;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.07em;
}

.trace-badge.exec {
  border-color: var(--line-strong);
  color: var(--ink);
}

.trace-badge.omitted {
  color: var(--tertiary);
}

.trace-badge.unsupported {
  border-color: #fecaca;
  color: var(--error);
}

.trace-text {
  margin: 7px 0 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.trace-entry.omitted .trace-text {
  color: var(--comment);
  font-style: italic;
}

.trace-entry.omitted .trace-meta,
.trace-entry.omitted .trace-reason {
  color: var(--tertiary);
}

.trace-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.trace-reason {
  margin: 6px 0 0;
  color: var(--error);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

/* Footer ------------------------------------------------------------------ */

.statusbar {
  min-height: 34px;
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: 11.5px;
}

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

.dot {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--neutral);
}

.dot.ok {
  background: var(--success);
}

.dot.error {
  background: var(--error);
}

.status-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  color: var(--tertiary);
  font-size: 10.5px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-right a {
  color: var(--tertiary);
  text-decoration: none;
}

.status-right a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.status-sep {
  color: var(--line-strong);
}

/* Responsive -------------------------------------------------------------- */

@media (max-width: 1080px) {
  .brand-version {
    display: none;
  }
}

@media (max-width: 940px) {
  .brand-by {
    display: none;
  }
}

@media (max-width: 860px) {
  :root {
    --editor-size: 16px;
    --editor-leading: 1.7;
    --editor-pad-y: 18px;
    --editor-pad-x: 18px;
  }

  body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .topbar {
    min-height: 0;
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand nav"
      "controls controls";
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
  }

  .brand {
    grid-area: brand;
    gap: 0;
    margin: 0;
  }

  .brand-name {
    font-size: 17px;
  }

  .brand-version,
  .brand-by {
    display: none;
  }

  .topnav {
    grid-area: nav;
    gap: 14px;
  }

  .topnav a {
    display: flex;
    align-items: center;
    min-height: 36px;
    font-size: 12.5px;
  }

  .controls {
    grid-area: controls;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    width: 100%;
    gap: 8px;
  }

  .picker select {
    width: 100%;
    max-width: none;
    height: 36px;
    padding: 0 26px 0 9px;
    font-size: 12.5px;
  }

  .button {
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  .button kbd {
    display: none;
  }

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

  .editor-pane {
    flex: 1.8 1 0;
    min-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .inspector-pane {
    flex: 1 1 0;
    min-height: 140px;
  }

  .pane-head {
    height: 34px;
    flex-basis: 34px;
    padding: 0 12px 0 18px;
  }

  .text-button {
    min-height: 34px;
    padding: 0 2px;
  }

  .legend {
    display: none;
  }

  .editor-caption {
    min-height: 26px;
    padding: 5px 12px;
  }

  .gutter {
    width: 48px;
    flex-basis: 48px;
    font-size: 11px;
  }

  .gutter-line.has-error::before,
  .gutter-line.has-warning::before {
    top: 10px;
  }

  .inspector-head {
    height: 36px;
    flex-basis: 36px;
    padding: 0 12px 0 18px;
  }

  .tablist {
    gap: 16px;
  }

  .tab-copy {
    height: 36px;
    border: 0;
    background: none;
  }

  .tab {
    font-size: 12px;
  }

  .panel {
    padding: 18px 18px 32px;
  }

  .statusbar {
    min-height: 0;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 3px 12px;
    padding: 7px 14px;
    font-size: 11px;
  }

  .status-right {
    flex-basis: 100%;
    flex-wrap: wrap;
    gap: 2px 6px;
    overflow: visible;
    font-size: 10px;
    text-align: left;
    white-space: normal;
  }
}

@media (max-width: 480px) {
  .brand-name {
    font-size: 16px;
  }

  .topnav {
    gap: 12px;
  }

  .controls {
    gap: 8px;
  }

  .picker select {
    padding-left: 8px;
    font-size: 12.5px;
  }

  .button {
    padding: 0 9px;
    font-size: 12px;
  }

  .tablist {
    gap: 14px;
  }

  .tab {
    font-size: 11.5px;
  }

  .tab-copy {
    padding: 0 7px;
  }

  .statusbar {
    padding: 6px 12px;
  }

  .status-right {
    font-size: 9.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
