:root {
  --ink: #10231d;
  --muted: #60736c;
  --line: #dce8e3;
  --surface: #ffffff;
  --surface-soft: #f5faf7;
  --green: #087f5b;
  --green-dark: #056044;
  --green-soft: #e9f8f1;
  --orange: #f47a2a;
  --blue: #2878d0;
  --code: #071a15;
  --code-muted: #86a79b;
  --shadow: 0 24px 65px -38px rgba(14, 54, 40, .42);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #edf5f1;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 9% 0%, rgba(46, 160, 118, .12), transparent 28rem),
    linear-gradient(180deg, #f8fbf9 0, #edf5f1 44rem, #f7faf8 100%);
}
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(8, 127, 91, .22);
  outline-offset: 2px;
}

.tikz-page {
  width: min(1680px, calc(100% - 44px));
  margin: 0 auto;
  padding: 38px 0 72px;
}

.hero {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 36px;
  margin-bottom: 26px;
  padding: 36px 40px;
  overflow: hidden;
  border: 1px solid rgba(8, 127, 91, .18);
  border-radius: 26px;
  background:
    linear-gradient(112deg, rgba(255, 255, 255, .98), rgba(239, 250, 245, .93)),
    var(--surface);
  box-shadow: var(--shadow);
}
.hero::after {
  content: "";
  position: absolute;
  right: -86px;
  top: -156px;
  width: 420px;
  height: 420px;
  border: 62px solid rgba(8, 127, 91, .055);
  border-radius: 50%;
  pointer-events: none;
}
.hero-copy, .hero-actions { position: relative; z-index: 1; }
.eyebrow, .panel-kicker {
  margin: 0;
  color: var(--green);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .115em;
  text-transform: uppercase;
}
.eyebrow { display: flex; align-items: center; gap: 9px; }
.eyebrow span { width: 22px; height: 2px; background: var(--orange); }
.hero h1 {
  margin: 9px 0 0;
  font-size: clamp(34px, 5vw, 59px);
  line-height: .98;
  letter-spacing: -.055em;
}
.hero h1 b { color: var(--orange); font-weight: 760; }
.hero-lead {
  max-width: 760px;
  margin: 16px 0 0;
  color: #52665e;
  font-size: clamp(15px, 1.5vw, 18px);
  line-height: 1.65;
}
.hero-badges { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 20px; }
.hero-badges span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid #d7e8e0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .78);
  color: #3e574d;
  font-size: 12px;
  font-weight: 720;
}
.hero-badges svg { width: 14px; color: var(--green); }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; min-width: 330px; }

.button, .icon-button, .tab-button {
  border: 0;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
}
.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 780;
}
.button svg { width: 17px; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--green), #09956a);
  box-shadow: 0 13px 25px -17px rgba(8, 127, 91, .9);
}
.button-primary:hover { background: linear-gradient(135deg, var(--green-dark), var(--green)); }
.button-ghost {
  border: 1px solid #d7e4df;
  color: #365249;
  background: rgba(255, 255, 255, .86);
}
.button-ghost:hover { border-color: #accdc0; background: #fff; }
.button.compact { min-height: 39px; padding: 0 13px; font-size: 12px; }

.workflow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 17px;
  margin: 0 auto 18px;
  color: #62776f;
  font-size: 12px;
  font-weight: 700;
}
.workflow span { display: inline-flex; align-items: center; gap: 7px; }
.workflow b {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--green);
  background: var(--green-soft);
  font-size: 11px;
}
.workflow > svg { width: 14px; color: #9eb0a9; }

.studio {
  display: grid;
  grid-template-columns: minmax(620px, 1.45fr) minmax(430px, .85fr);
  gap: 18px;
  align-items: stretch;
}
.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(150, 177, 166, .42);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-header {
  min-height: 71px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
}
.panel-header h2 {
  margin: 4px 0 0;
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: -.018em;
}
.panel-actions { display: flex; align-items: center; gap: 8px; }
.live-pill, .quality-pill {
  min-height: 29px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 760;
}
.live-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22b47e;
  box-shadow: 0 0 0 4px rgba(34, 180, 126, .12);
}
.live-pill.is-error { color: #a53b2b; background: #fff0ec; }
.live-pill.is-error i { background: #e1533f; box-shadow: 0 0 0 4px rgba(225, 83, 63, .12); }
.quality-pill { background: #eef5ff; color: #2464a9; }
.quality-pill svg { width: 14px; }
.icon-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #dce6e2;
  border-radius: 9px;
  color: #566b63;
  background: #f8fbf9;
}
.icon-button svg { width: 16px; }

.ggb-host {
  position: relative;
  width: 100%;
  min-height: 720px;
  height: calc(100vh - 255px);
  max-height: 930px;
  overflow: hidden;
  background: #fff;
}
.ggb-status {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  padding: 30px;
  color: #456057;
  background: linear-gradient(145deg, #fff, #f0f8f4);
  text-align: center;
}
.ggb-status strong { font-size: 15px; }
.ggb-status small { color: var(--muted); }
.ggb-status .button { margin-top: 7px; }
.loader-ring {
  width: 30px;
  height: 30px;
  margin-bottom: 4px;
  border: 3px solid #dcebe4;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.export-panel { display: flex; flex-direction: column; min-height: 792px; }
.export-settings { padding: 14px 16px 13px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.setting-row-main { margin-bottom: 10px; }
.switch-label {
  min-height: 52px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 9px 11px;
  border: 1px solid #d8e6e0;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}
.switch-label strong, .switch-label small, .select-row strong, .select-row small { display: block; }
.switch-label strong, .select-row strong { color: #2b453b; font-size: 12px; }
.switch-label small, .select-row small { margin-top: 3px; color: #7b8d86; font-size: 10px; }
.switch-label input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 39px;
  height: 23px;
  border-radius: 999px;
  background: #c9d6d1;
  transition: background .16s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(15, 23, 42, .2);
  transition: transform .16s ease;
}
.switch-label input:checked + .switch { background: var(--green); }
.switch-label input:checked + .switch::after { transform: translateX(16px); }
.setting-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.check-card {
  min-width: 0;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  padding: 6px 4px;
  border: 1px solid #dce7e2;
  border-radius: 10px;
  background: #fff;
  color: #71827b;
  cursor: pointer;
  text-align: center;
  transition: border-color .16s ease, background .16s ease, color .16s ease;
}
.check-card input { position: absolute; opacity: 0; pointer-events: none; }
.check-card svg { width: 15px; }
.check-card span { overflow: hidden; font-size: 9.5px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.check-card:has(input:checked) { border-color: #9fcfbd; color: var(--green-dark); background: var(--green-soft); }
.select-row {
  min-height: 49px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
  padding: 7px 10px;
  border: 1px solid #dce7e2;
  border-radius: 10px;
  background: #fff;
}
.select-row select {
  max-width: 115px;
  height: 32px;
  border: 1px solid #d6e1dc;
  border-radius: 8px;
  padding: 0 8px;
  color: #365349;
  background: #f8fbf9;
  font-size: 11px;
  font-weight: 700;
}

.output-tabs {
  min-height: 44px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px 12px 0;
  border-bottom: 1px solid #15372c;
  background: #0b221b;
}

.tab-button {
  position: relative;
  min-height: 37px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-radius: 8px 8px 0 0;
  color: #88a49a;
  background: transparent;
  font-size: 11px;
  font-weight: 760;
}
.tab-button svg { width: 14px; }
.tab-button.is-active { color: #dbf5eb; background: #071a15; }
.tab-button.is-active::after {
  content: "";
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 0;
  height: 2px;
  background: #37c58e;
}
.object-count { margin: 0 4px 12px auto; color: #769188; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.tab-pane { min-height: 0; flex: 1; background: var(--code); }
.code-pane { display: none; }
.code-pane.is-active { display: flex; }
#codeOutput {
  width: 100%;
  min-height: 380px;
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  padding: 18px;
  color: #bcebd9;
  background:
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px) 0 0 / 36px 100%,
    var(--code);
  font: 12px/1.7 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  tab-size: 2;
  white-space: pre;
}
.preview-pane { position: relative; display: none; background: #fff; }
.preview-pane.is-active { display: flex; }
.preview-empty {
  min-height: 380px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  flex-direction: column;
  gap: 7px;
  padding: 20px;
  color: #768a82;
  text-align: center;
}
.preview-empty svg { width: 34px; color: #9ab6aa; }
.preview-empty strong { color: #3f5c51; font-size: 13px; }
.preview-empty span { font-size: 11px; }
.preview-empty[hidden], #previewFrame[hidden], [hidden] { display: none !important; }
#previewFrame { width: 100%; min-height: 380px; flex: 1; border: 0; background: #fff; }
.export-footer {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.export-footer p {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: #698078;
  font-size: 10px;
}
.export-footer p svg { width: 14px; color: var(--green); }
.export-footer > div { display: flex; gap: 7px; }

.support-grid {
  display: grid;
  grid-template-columns: 1.25fr .75fr .75fr;
  gap: 14px;
  margin-top: 18px;
}
.support-card {
  display: flex;
  gap: 15px;
  min-width: 0;
  padding: 22px;
  border: 1px solid #dbe7e2;
  border-radius: 16px;
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 18px 45px -38px rgba(14, 54, 40, .35);
}
.support-card h2 { margin: 5px 0 0; font-size: 14px; line-height: 1.45; }
.support-card p:not(.panel-kicker) { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.support-card code {
  display: block;
  margin-top: 9px;
  color: var(--green-dark);
  font: 10.5px/1.65 "SFMono-Regular", Consolas, monospace;
}
.support-icon {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: var(--green);
  background: var(--green-soft);
}
.support-icon svg { width: 19px; }
.support-icon.amber { color: #af581d; background: #fff1e6; }
.support-icon.blue { color: #2766ad; background: #eaf3ff; }
.feature-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.feature-list span {
  padding: 5px 8px;
  border-radius: 7px;
  color: #4e665d;
  background: #f0f6f3;
  font-size: 9.5px;
  font-weight: 700;
}
.technical-notes {
  margin-top: 14px;
  border: 1px solid #dce7e2;
  border-radius: 14px;
  background: rgba(255,255,255,.68);
}
.technical-notes summary {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 17px;
  color: #4f665e;
  cursor: pointer;
  font-size: 11px;
  font-weight: 760;
  list-style: none;
}
.technical-notes summary span { display: flex; align-items: center; gap: 7px; }
.technical-notes summary svg { width: 15px; }
.technical-notes summary > svg { transition: transform .16s ease; }
.technical-notes[open] summary > svg { transform: rotate(180deg); }
.technical-notes > div { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 0 17px 16px; }
.technical-notes p { margin: 0; color: #657970; font-size: 11px; line-height: 1.65; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10020;
  max-width: min(360px, calc(100vw - 30px));
  display: none;
  padding: 12px 15px;
  border-radius: 12px;
  color: #fff;
  background: #0c2b21;
  box-shadow: 0 20px 44px -22px rgba(0,0,0,.6);
  font-size: 12px;
  font-weight: 700;
}
.toast.is-visible { display: block; animation: toastIn .18s ease-out; }
.toast.is-error { background: #8b2d22; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1220px) {
  .tikz-page { width: min(100% - 28px, 1680px); }
  .studio { grid-template-columns: minmax(520px, 1.25fr) minmax(390px, .85fr); }
  .hero { padding: 31px; }
  .hero-actions { min-width: 260px; }
  .support-grid { grid-template-columns: 1fr 1fr; }
  .support-card-wide { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .hero { align-items: flex-start; flex-direction: column; }
  .hero-actions { min-width: 0; justify-content: flex-start; }
  .studio { grid-template-columns: 1fr; }
  .ggb-host { min-height: 650px; height: 70vh; }
  .export-panel { min-height: 730px; }
}
@media (max-width: 680px) {
  .tikz-page { width: min(100% - 20px, 1680px); padding: 18px 0 45px; }
  .hero { gap: 24px; margin-bottom: 16px; padding: 25px 20px; border-radius: 19px; }
  .hero-actions, .hero-actions .button { width: 100%; }
  .hero-actions { flex-direction: column; }
  .hero h1 { font-size: 37px; }
  .hero-lead { font-size: 14px; }
  .workflow { justify-content: flex-start; gap: 7px; overflow-x: auto; padding: 0 3px 3px; }
  .workflow > svg { display: none; }
  .workflow span { flex: 0 0 auto; padding-right: 10px; }
  .panel-header { min-height: 65px; padding: 12px 13px; }
  .ggb-host { min-height: 560px; height: 72vh; }
  .quality-pill { display: none; }
  .setting-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .check-card { min-height: 52px; }
  .export-footer { align-items: stretch; flex-direction: column; padding: 11px; }
  .export-footer > div, .export-footer .button { width: 100%; }
  .export-footer > div { display: grid; grid-template-columns: 1fr 1fr; }
  .support-grid { grid-template-columns: 1fr; }
  .support-card-wide { grid-column: auto; }
  .technical-notes > div { grid-template-columns: 1fr; }
  .live-pill { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
