/* Rosé Pine palette — see https://rosepinetheme.com.
   Default = Dawn (light); :root[data-theme="dark"] = Rosé Pine. */
:root {
  --base:    #faf4ed;
  --surface: #fffaf3;
  --overlay: #f2e9e1;
  --text:    #575279;
  --subtle:  #797593;
  --muted:   #9893a5;
  --pine:    #286983;
  --foam:    #56949f;
  --iris:    #907aa9;
  --love:    #b4637a;
  --gold:    #ea9d34;
  --rose:    #d7827e;
  --hl-low:  #f4ede8;
  --hl-med:  #dfdad9;
  --hl-high: #cecacd;

  /* Semantic */
  --bg:          var(--base);
  --bg-pane:     var(--surface);
  --bg-elevated: var(--overlay);
  --fg:          var(--text);
  --fg-muted:    var(--subtle);
  --fg-faint:    var(--muted);
  --accent:      var(--pine);
  --accent-2:    var(--foam);
  --border:      var(--hl-med);
  --code-bg:     var(--overlay);
  --error:       var(--love);
  --warn:        var(--gold);
  --link:        var(--foam);
  /* Shadow rgb tuple kept literal — alpha varies per use. */
  --shadow-rgb:  0, 0, 0;
}

:root[data-theme="dark"] {
  --base:    #191724;
  --surface: #1f1d2e;
  --overlay: #26233a;
  --text:    #e0def4;
  --subtle:  #908caa;
  --muted:   #6e6a86;
  --pine:    #31748f;
  --foam:    #9ccfd8;
  --iris:    #c4a7e7;
  --love:    #eb6f92;
  --gold:    #f6c177;
  --rose:    #ebbcba;
  --hl-low:  #21202e;
  --hl-med:  #403d52;
  --hl-high: #524f67;

  --link: var(--foam);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
}

header {
  display: flex; align-items: baseline; gap: 0.75rem;
  padding: 0.5rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--bg-pane);
}
header h1 { margin: 0; font-size: 1.1rem; font-weight: 600; }
header .tag { font-size: 0.75rem; color: var(--fg-faint); }

#cheatsheet-toggle, #theme-toggle {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  width: 1.6rem; height: 1.6rem; line-height: 1;
  border: 1px solid var(--border); background: var(--bg-pane); color: var(--fg);
  border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
#cheatsheet-toggle { margin-left: auto; }
#theme-toggle { margin-left: 0.4rem; }
#cheatsheet-toggle:hover, #theme-toggle:hover { background: var(--bg-elevated); }

main {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  min-height: 0;
}
.pane { display: flex; flex-direction: column; min-width: 0; }
.pane h2 {
  margin: 0; padding: 0.4rem 1rem; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-muted);
  background: var(--bg-elevated); border-bottom: 1px solid var(--border);
}
.pane.src { border-right: 1px solid var(--border); }

#dot, #err {
  padding: 1rem; margin: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px; line-height: 1.5;
  border: 0; outline: 0; background: var(--bg-pane); color: var(--fg);
  overflow: auto;
}

#editor { flex: 1; min-height: 0; background: var(--bg-pane); overflow: auto; }
#editor .cm-editor { height: 100%; }
#editor .cm-scroller {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px; line-height: 1.5;
}
#editor .cm-content { padding: 1rem 0; }

#out {
  flex: 1; min-height: 0; padding: 1rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-pane); overflow: auto;
}
#out svg { max-width: 100%; max-height: 100%; }
#err { color: var(--error); flex: 0 0 auto; background: var(--bg-elevated); }
#err:empty { display: none; }
.raw { border-top: 1px solid var(--border); background: var(--bg); }
.raw summary {
  padding: 0.4rem 1rem; cursor: pointer; font-size: 0.75rem;
  color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.raw[open] summary { border-bottom: 1px solid var(--border); }
.raw #dot { max-height: 200px; }

/* cheatsheet overlay */
#cheatsheet {
  position: fixed; inset: 0; background: rgba(var(--shadow-rgb), 0.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 4rem 1rem 1rem; z-index: 100;
}
#cheatsheet.open { display: flex; }
.cheatsheet-panel {
  width: 100%; max-width: 720px; max-height: calc(100vh - 5rem);
  display: flex; flex-direction: column;
  background: var(--bg-pane); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 12px 32px rgba(var(--shadow-rgb), 0.28);
  overflow: hidden;
}
.cheatsheet-panel > header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border); background: var(--bg-elevated);
}
.cheatsheet-panel > header h2 {
  margin: 0; font-size: 0.95rem; font-weight: 600;
}
.cheatsheet-panel nav.tabs { display: flex; gap: 0.25rem; margin-left: 0.5rem; }
.cheatsheet-panel .tab {
  font: inherit; font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  background: transparent; border: 1px solid var(--border); border-radius: 999px;
  color: var(--fg-muted); cursor: pointer;
}
.cheatsheet-panel .tab:hover { background: var(--bg-elevated); }
.cheatsheet-panel .tab.active {
  background: var(--accent); color: var(--bg-pane); border-color: var(--accent);
}
#cheatsheet-close {
  margin-left: auto;
  font: inherit; font-size: 1.4rem; line-height: 1;
  width: 1.8rem; height: 1.8rem;
  background: transparent; border: 0; cursor: pointer; color: var(--fg-muted);
}
#cheatsheet-close:hover { color: var(--fg); }

.tab-panel { display: none; padding: 0.5rem 1rem 1rem; overflow: auto; }
.tab-panel.active { display: block; }
.tab-panel section { margin-top: 0.75rem; }
.tab-panel h3 {
  margin: 0 0 0.4rem; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--fg-muted);
  border-bottom: 1px solid var(--border); padding-bottom: 0.25rem;
}
.tab-panel dl {
  margin: 0; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 0.25rem 1rem; align-items: baseline; font-size: 0.85rem;
}
.tab-panel dt { color: var(--fg); }
.tab-panel dd { margin: 0; color: var(--fg-muted); }
.tab-panel kbd {
  display: inline-block; padding: 1px 6px; min-width: 1.2rem; text-align: center;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.75rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 3px; color: var(--fg);
}
.tab-panel code {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.8rem;
  background: var(--code-bg); padding: 1px 4px; border-radius: 3px;
}
.tab-panel pre {
  margin: 0.25rem 0; padding: 0.5rem 0.75rem;
  background: var(--code-bg); border-radius: 4px;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.78rem;
  line-height: 1.5; overflow: auto;
}
.tab-panel pre code { background: transparent; padding: 0; }
.tab-panel p { margin: 0.4rem 0; font-size: 0.82rem; color: var(--fg-muted); }
.tab-panel .hint { font-size: 0.78rem; color: var(--fg-faint); margin-top: 0.75rem; }
.tab-panel .hint a { color: var(--link); text-decoration: none; }
.tab-panel .hint a:hover { text-decoration: underline; }
