:root {
  color-scheme: dark;

  --bg: #0a0b0f;
  --surface: #12141b;
  --surface-2: #171a23;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #e7e9f0;
  --muted: #8a92a6;
  --accent: #a3e635;
  --danger: #ff6b6b;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-right: auto;
}

.brand h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
}

.brand .back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
}

.brand .back:hover {
  color: var(--text);
}

.presets {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

button {
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    color 0.15s ease;
}

button:hover {
  border-color: var(--line-strong);
}

button.active {
  color: var(--accent);
  border-color: var(--accent);
}

.actions {
  display: flex;
  gap: 0.35rem;
}

/* ---------- layout ---------- */

main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane + .pane {
  border-left: 1px solid var(--line);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

/* ---------- editor ---------- */

.editor-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  background: var(--surface);
}

#gutter {
  padding: 1rem 0.55rem 1rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  text-align: right;
  color: rgba(255, 255, 255, 0.22);
  user-select: none;
  overflow: hidden;
  white-space: pre;
}

#editor {
  flex: 1;
  min-width: 0;
  padding: 1rem 1rem 1rem 0.35rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

#error {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.7rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--danger);
  background: rgba(40, 12, 14, 0.96);
  border-top: 1px solid rgba(255, 107, 107, 0.4);
  white-space: pre-wrap;
}

#error[hidden] {
  display: none;
}

/* ---------- canvas ---------- */

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 1.1rem;
  background:
    radial-gradient(
      circle at 50% 40%,
      rgba(163, 230, 53, 0.06),
      transparent 60%
    ),
    var(--bg);
}

.canvas-box {
  width: 100%;
  max-width: min(100%, 68vh);
  aspect-ratio: 1 / 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #0b0c10;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#status {
  font-variant-numeric: tabular-nums;
}

/* ---------- docs ---------- */

details.docs {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

details.docs > summary {
  padding: 0.5rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

details.docs > summary:hover {
  color: var(--text);
}

.docs-body {
  padding: 0 0.9rem 1rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.75;
  color: var(--muted);
  max-height: 34vh;
  overflow: auto;
}

.docs-body code {
  color: var(--accent);
}

.docs-body dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.15rem 1rem;
  margin: 0.4rem 0 0;
}

.docs-body dt {
  white-space: nowrap;
}

@media (max-width: 860px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 1fr) minmax(280px, auto);
  }

  .pane + .pane {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .canvas-box {
    max-width: min(100%, 46vh);
  }
}
