:root {
  --bg: #0b0e14; --surface: #11161f; --surface-2: #1a212e; --border: #232c3b;
  --text: #e6edf3; --muted: #8a97a8; --accent: #f472b6; --accent-2: #818cf8;
  --ok: #34d399; --err: #f87171;
  --radius: 12px; --shadow: 0 10px 40px rgba(0,0,0,.4);
  --code-font: ui-monospace, "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
}
[data-theme="light"] {
  --bg: #eef1f6; --surface: #ffffff; --surface-2: #f0f3f8; --border: #dce2ec;
  --text: #131a26; --muted: #5b6675; --shadow: 0 10px 40px rgba(30,50,90,.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; transition: background .25s, color .25s; }
button, input, select, textarea { font-family: inherit; color: inherit; }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 12px; top: 12px; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 99; }

/* topbar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px clamp(16px,3vw,28px); border-bottom: 1px solid var(--border); }
.brand { font-weight: 900; font-size: 20px; }
.accent { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.priv { font-size: 12.5px; color: var(--accent-2); font-weight: 600; }
.nav-link { color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.nav-link:hover { color: var(--text); }
.icon-btn { background: var(--surface-2); border: 1px solid var(--border); width: 38px; height: 38px; border-radius: 9px; cursor: pointer; font-size: 15px; display: inline-grid; place-items: center; }
.icon-btn:hover { border-color: var(--accent); }

/* layout */
.layout { display: grid; grid-template-columns: 300px 1fr; flex: 1; min-height: 0; }
.controls { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; }
.ctl { display: flex; flex-direction: column; gap: 9px; }
.ctl-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.select, .input { background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; font-size: 14px; }
.select:focus, .input:focus { outline: none; border-color: var(--accent); }
.select.sm { padding: 6px 8px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }

/* swatches */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch { height: 38px; border-radius: 9px; border: 2px solid var(--border); cursor: pointer; font-weight: 800; font-size: 13px; display: grid; place-items: center; overflow: hidden; }
.swatch:hover { transform: translateY(-1px); }
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent); }
.mini { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 11px; font-size: 12.5px; font-weight: 600; cursor: pointer; color: var(--muted); }
.mini.on { border-color: var(--accent); color: var(--text); }
.col-pick { width: 42px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; }

/* sliders */
.slider-label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.slider-label span { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.toggles { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); }

/* buttons */
.btn { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 11px 16px; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.export { gap: 10px; }
.msg { font-size: 13px; color: var(--muted); min-height: 1.2em; }
.msg.ok { color: var(--ok); } .msg.err { color: var(--err); }

/* stage */
.stage-wrap { overflow: auto; display: grid; }
.stage { min-height: 100%; min-width: 100%; display: grid; place-items: center; padding: 64px; }
.stage.transparent {
  background-color: #2a2a2a;
  background-image: linear-gradient(45deg, #3a3a3a 25%, transparent 25%), linear-gradient(-45deg, #3a3a3a 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #3a3a3a 75%), linear-gradient(-45deg, transparent 75%, #3a3a3a 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

/* card (the rendered window) */
.card {
  --fs: 14px; --c-bg: #1e1e2e; --c-text: #cdd6f4;
  background: var(--c-bg); border-radius: 14px; box-shadow: 0 24px 60px rgba(0,0,0,.45);
  width: fit-content; max-width: min(760px, 100%); min-width: 340px; overflow: hidden;
}
.card.no-shadow { box-shadow: none; }
.win-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px 4px; }
.dots { display: flex; gap: 7px; width: 52px; }
.dots.ghost { opacity: 0; }
.d { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.d.r { background: #ff5f56; } .d.y { background: #ffbd2e; } .d.g { background: #27c93f; }
.win-title { flex: 1; text-align: center; font-family: -apple-system, "Segoe UI", system-ui, sans-serif; font-size: 13px; color: color-mix(in srgb, var(--c-text) 60%, transparent); }
.win-body { display: flex; padding: 12px 18px 20px; }

/* editor: pre + textarea must share identical metrics */
.gutter { font-family: var(--code-font); font-size: var(--fs); line-height: 1.6; color: color-mix(in srgb, var(--c-text) 38%, transparent); text-align: right; padding-right: 14px; user-select: none; min-width: 1.6em; }
.editor { position: relative; flex: 1; min-width: 0; }
.hl, .code-input {
  font-family: var(--code-font); font-size: var(--fs); line-height: 1.6; letter-spacing: 0;
  white-space: pre-wrap; word-break: break-word; tab-size: 2; margin: 0; padding: 0; border: 0;
}
.hl { color: var(--c-text); min-height: 1.6em; }
.hl code { display: block; }
.code-input { position: absolute; inset: 0; width: 100%; height: 100%; background: transparent; color: transparent; caret-color: var(--c-text); resize: none; outline: none; overflow: hidden; }

/* tokens */
.tok-comment { color: var(--c-comment); font-style: italic; }
.tok-string { color: var(--c-string); }
.tok-keyword { color: var(--c-keyword); }
.tok-number { color: var(--c-number); }
.tok-function { color: var(--c-function); }
.tok-literal { color: var(--c-literal); }
.tok-punct { color: var(--c-punct); }

/* footer */
.footer { border-top: 1px solid var(--border); }
.footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px clamp(16px,3vw,28px); color: var(--muted); font-size: 13px; }
.footer-links a { color: var(--muted); text-decoration: none; margin: 0 3px; }
.footer-links a:hover { color: var(--accent); }
.footer-bottom { border-top: 1px solid var(--border); text-align: center; padding: 11px; color: var(--muted); font-size: 12px; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .controls { border-right: none; border-bottom: 1px solid var(--border); max-height: 46vh; }
  .stage { padding: 32px; }
}
