:root {
  --bg: #0a0a0f;
  --card: #111116;
  --border: #1f1f28;
  --accent: #6366f1;
  --muted: #888;
  --text: #e5e5e7;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.5;
}

.font-display { font-family: 'Space Grotesk', 'Inter', system-ui, sans-serif; }

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

/* Header */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.header h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.5rem;
  font-weight: 600;
  letter-spacing: -1.5px;
  margin: 4px 0 0;
}
.back-link {
  color: #c7d2fe;
  text-decoration: none;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
.back-link:focus-visible, .mode-btn:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid #c7d2fe;
  outline-offset: 2px;
}
.back-link:hover { color: #fff; }
.subtitle { color: var(--muted); font-size: 1rem; margin: 0; }

/* Mode toggle */
.mode-toggle {
  display: flex;
  gap: 4px;
  background: #0f0f14;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.mode-btn {
  min-height: 44px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-btn.active {
  background: #4f46e5;
  color: #fff;
}
.mode-btn:hover:not(.active) { background: rgba(255,255,255,0.05); color: #fff; }

/* Input bar */
.input-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.expr-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.expr-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.expr-input.has-error {
  border-color: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.12);
}
.parse-btn {
  padding: 12px 24px;
  background: #4f46e5;
  border: none;
  border-radius: 12px;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
  white-space: nowrap;
}
.parse-btn:hover { background: #4338ca; }
.parse-btn:active { transform: scale(0.98); }

.parse-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  flex-wrap: wrap;
  min-height: 1.4em;
}
.status.ok { color: #34d399; }
.status.err { color: #f87171; }
.status.muted { color: var(--muted); }
.parse-error { color: #f87171; }
.ast-flat {
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 120px;
}
.node-stats {
  color: #999;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Main layout */
.main-grid {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  min-height: 540px;
}

@media (max-width: 960px) {
  .main-grid { grid-template-columns: 1fr; }
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding-right: 2px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
}
.panel-header {
  padding: 10px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #0d0d12;
}
.panel-body {
  max-height: 160px;
  overflow-y: auto;
  padding: 6px;
}
.panel-body.tall { max-height: 200px; }
.inspector-body {
  max-height: 280px;
  padding: 10px 12px;
}
.inspector-empty {
  color: #8f8f99;
  font-size: 0.78rem;
  margin: 0;
  line-height: 1.45;
}
.inspector-section { margin-bottom: 12px; }
.inspector-section:last-child { margin-bottom: 0; }
.inspector-section h4 {
  margin: 0 0 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #666;
  font-weight: 600;
}
.prop-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.prop-key { color: var(--muted); }
.prop-val {
  font-family: ui-monospace, monospace;
  color: #ccc;
  text-align: right;
  word-break: break-all;
}
.subtree-expr {
  display: block;
  font-size: 0.78rem;
  color: #c4c4ff;
  background: #0a0a12;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  word-break: break-all;
  white-space: pre-wrap;
}
.child-list {
  margin: 0;
  padding: 0 0 0 4px;
  list-style: none;
  font-size: 0.76rem;
}
.child-list li {
  padding: 4px 0;
  color: #aaa;
  line-height: 1.35;
}
.child-list strong {
  color: #ddd;
  font-weight: 600;
  font-family: ui-monospace, monospace;
}
.child-list em {
  font-style: normal;
  color: #777;
  font-size: 0.7rem;
}
.child-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.lib-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.lib-item:hover { background: rgba(99,102,241,0.12); }
.lib-name { font-size: 0.82rem; font-weight: 500; }
.lib-expr {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.lib-note {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  min-height: 36px;
}

/* Tree viewport */
.tree-area {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  min-height: 560px;
  height: min(72vh, 720px);
}
.tree-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #0d0d12;
  gap: 10px;
  flex-wrap: wrap;
}
.toolbar-hint { font-size: 0.72rem; color: var(--muted); line-height: 1.4; }
.toolbar-hint kbd {
  display: inline-block;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid #333;
  background: #1a1a22;
  font-size: 0.68rem;
  font-family: ui-monospace, monospace;
  color: #aaa;
}
.toolbar-btns { display: flex; gap: 5px; flex-wrap: wrap; }
.tool-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.12s;
}
.tool-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.tool-btn-accent {
  border-color: rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
}
.tool-btn-accent:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #fff;
}

#tree-viewport {
  flex: 1 1 auto;
  min-height: 360px;
  overflow: hidden;
  cursor: grab;
  position: relative;
  background:
    radial-gradient(ellipse at 50% 0%, #16161f 0%, transparent 55%),
    radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.04) 0%, transparent 40%),
    #0a0a0f;
}
#tree-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  touch-action: none;
}

.ast-node .node-body {
  transition: stroke 0.12s, stroke-width 0.12s;
}
.ast-node:hover .node-body {
  stroke: #ffffff;
  stroke-width: 2.25;
}

.node-detail {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  background: #0d0d12;
  flex-wrap: wrap;
}
.detail-type {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.detail-label {
  font-family: ui-monospace, monospace;
  font-weight: 600;
  font-size: 0.95rem;
}
.detail-struct { color: var(--muted); font-size: 0.75rem; }
.detail-expr {
  color: #8b8ba3;
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
  margin-left: auto;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
}
.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1.5px solid;
}

/* Proof panel */
.proof-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.proof-overlay.open { display: flex; }
.proof-modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 640px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.proof-modal h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3rem;
  margin: 0 0 6px;
}
.proof-modal p { color: var(--muted); font-size: 0.88rem; margin: 0 0 16px; }
.proof-step {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.proof-step:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}
.step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.step-label { font-weight: 600; font-size: 0.85rem; }
.step-rule {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(99,102,241,0.15);
  color: var(--accent);
}
.step-expr {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.mini-tree {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.mini-node {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: ui-monospace, monospace;
  border: 1.5px solid;
}
.mini-arrow { color: #444; font-size: 0.7rem; }
.mini-err { color: #f87171; font-size: 0.8rem; }

.close-proof {
  margin-top: 12px;
  padding: 10px 20px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  font-size: 0.85rem;
}
.close-proof:hover { background: rgba(255,255,255,0.05); }

/* Hint */
.hint {
  font-size: 0.75rem;
  color: #8a8a8a;
  margin-top: 8px;
  text-align: center;
}

/* Scrollbars */
.panel-body::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.proof-modal::-webkit-scrollbar {
  width: 6px;
}
.panel-body::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.proof-modal::-webkit-scrollbar-thumb {
  background: #2a2a36;
  border-radius: 3px;
}

/* narrow phones: let the input shrink so the button stays on screen */
.expr-input{min-width:0}
.input-bar{flex-wrap:wrap}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Reserve list space before app.js fills them (these lists always fill to their max height), so the sidebar doesn't shift on load. */
#axiom-list { min-height: 200px; }
#rule-list, #example-list { min-height: 160px; }
