@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;700&display=swap");

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #fafaf9;
  --fg: #1c1917;
  --muted: #78716c;
  --faint: #a8a29e;
  --border: #e7e5e4;
  --surface: #f5f5f4;
  --paper: #ffffff;
  --error: #b91c1c;
  --ok: #0d9488;

  --mono: "JetBrains Mono", "Fira Code", ui-monospace, "SF Mono", monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

html.dark {
  --bg: #1a1a1a;
  --fg: #e0ddd9;
  --muted: #9a9590;
  --faint: #6b6560;
  --border: #2e2c2a;
  --surface: #242220;
  --paper: #f5f3ef;
  --error: #fca5a5;
  --ok: #5eead4;
}

.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--faint);
  padding: 0.25rem 0.4rem;
  transition: color .15s;
  line-height: 1;
}
.theme-toggle:hover { color: var(--fg); }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

body.editor-page {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* nav */
.editor-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.brand .sub {
  color: var(--faint);
  font-weight: 400;
  font-size: 0.7rem;
  letter-spacing: 0;
}
.brand .sh { color: var(--faint); font-weight: 400; }

.nav-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--fg); color: var(--fg); }
.btn:disabled { opacity: 0.4; cursor: default; }

select.btn {
  appearance: none;
  padding-right: 1.5rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 0.75rem) 55%, calc(100% - 0.5rem) 55%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}

/* main split */
.editor-main {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
}
.editor-main.editor-hidden .editor-pane,
.editor-main.editor-hidden .splitter { display: none; }

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

.splitter {
  flex: 0 0 4px;
  background: transparent;
  cursor: col-resize;
  transition: background .15s;
  touch-action: none;
  border-left: 1px solid var(--border);
  margin-left: -1px;
}
.splitter:hover, .splitter.dragging { background: var(--faint); }
.pane-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  padding: 0.55rem 1.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.pane-label .hint { color: var(--faint); font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 0.7rem; }
.pane-label .hint a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
  transition: color .15s, text-decoration-color .15s;
}
.pane-label .hint a:hover { color: var(--fg); text-decoration-color: var(--fg); }

.editor-pane textarea {
  flex: 1;
  min-height: 0;
  width: 100%;
  background: transparent;
  color: var(--fg);
  border: none;
  outline: none;
  padding: 1rem 1.25rem;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  resize: none;
  tab-size: 2;
}
.editor-pane textarea:read-only { color: var(--muted); cursor: default; }

.preview-pane {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}
.preview-viewport {
  flex: 1;
  overflow: hidden;
  display: flex;
  padding: 1.5rem;
  min-height: 0;
  min-width: 0;
}
.preview-paper {
  flex: 1;
  align-self: stretch;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  cursor: zoom-in;
}
.preview-paper svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Zoomed: SVG at natural size, viewport scrolls from top-left. */
.preview-pane.zoomed .preview-viewport {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}
.preview-pane.zoomed .preview-paper {
  flex: 0 0 auto;
  align-self: auto;
  cursor: zoom-out;
  margin: auto;
}
.preview-pane.zoomed .preview-paper svg {
  width: auto;
  height: auto;
}

.preview-viewport pre.error {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--error);
  white-space: pre-wrap;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  max-width: 100%;
  overflow: auto;
}

/* footer */
.editor-footer {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--faint);
  padding: 0.5rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.status.ok { color: var(--ok); }
.status.bad { color: var(--error); }
.prompt { letter-spacing: 0.05em; }

/* trace player extras */
.trace-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.trace-info {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.trace-info .label { font-weight: 600; color: var(--fg); }
.trace-info .desc { color: var(--muted); margin-left: 0.5rem; }
.trace-info .counter { color: var(--faint); margin-right: 0.6rem; }

/* narrow screens */
@media (max-width: 720px) {
  .editor-main { flex-direction: column; }
  .editor-pane {
    flex: 0 0 45%;
    min-width: 0;
    min-height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .splitter { display: none; }
  .editor-nav { padding: 0.5rem 0.9rem; }
  .brand .sub { display: none; }
}
