@font-face {
  font-family: "Inter";
  src: url("fonts/Inter.ttf") format("truetype-variations"),
       url("fonts/Inter.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Montserrat";
  src: url("fonts/Montserrat.ttf") format("truetype-variations"),
       url("fonts/Montserrat.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: block;
}

:root {
  --bg: #0b0d12;
  --surface: #12151d;
  --surface-2: #171b25;
  --line: #242a37;
  --text: #e9edf5;
  --muted: #8b93a7;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --radius: 14px;
  --bar-h: 62px;
  --side-w: 440px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ------------------------------------------------------------- app bar */

.appbar {
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; color: inherit; text-decoration: none; }
.brand:hover .brand-title { color: #fff; }

.brand-mark {
  width: 34px; height: 34px;
  display: block; flex: none;
  border-radius: 10px;
  filter: drop-shadow(0 3px 10px rgba(99, 102, 241, .35));
  transition: transform .18s ease;
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.06); }

.brand-title { font-weight: 600; line-height: 1.15; }
.brand-sub { font-size: 11.5px; color: var(--muted); line-height: 1.3; }

.appbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
}

/* -------------------------------------------------------------- buttons */

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { border-color: #3a4256; background: #1d2230; }

.btn-accent, .btn-soft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: .15s;
  white-space: nowrap;
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 18px -6px rgba(99, 102, 241, .8);
}
.btn-accent:hover { filter: brightness(1.08); }

.btn-soft {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
}
.btn-soft:hover { border-color: #3a4256; background: #1d2230; }

button:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.w-100 { width: 100%; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.ms-auto { margin-left: auto; }

/* ---------------------------------------------------------------- shell */

.shell {
  display: flex;
  height: calc(100% - var(--bar-h));
  position: relative;
}

.sidebar {
  width: var(--side-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition: margin-left .22s ease;
  z-index: 20;
}
.shell.collapsed .sidebar { margin-left: calc(var(--side-w) * -1); }

.sidebar-scroll {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar-scroll::-webkit-scrollbar { width: 10px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #2f3646; border-radius: 8px; border: 3px solid var(--surface); }
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: #3c4557; }

.scrim { display: none; }

/* --------------------------------------------------------------- groups */

.group {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  flex: none;
}

.group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.group-head .num {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 11px;
  letter-spacing: 0;
}

.group-body { padding: 14px; }

/* --------------------------------------------------------------- inputs */

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 11.5px; color: var(--muted); }

input[type=number], input[type=text], select {
  width: 100%;
  background: #0e1118;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: .15s;
}
input[type=number]:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.18); }

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b93a7' stroke-width='2' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 15px;
  padding-right: 28px;
}

input[type=color] {
  width: 100%;
  height: 34px;
  padding: 3px;
  background: #0e1118;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}

.grid-2, .grid-3, .grid-4 { display: grid; gap: 8px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.note { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ----------------------------------------------------------- drop zone */

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
  padding: 20px 14px;
  border: 1.5px dashed #303748;
  border-radius: 12px;
  cursor: pointer;
  transition: .15s;
  background: #0e1118;
}
.drop:hover { border-color: var(--accent); background: #12162150; }
.drop svg { width: 22px; height: 22px; color: var(--accent); }
.drop b { font-size: 13.5px; font-weight: 600; }
.drop small { font-size: 11.5px; color: var(--muted); }

/* ------------------------------------------------------ segmented ctrl */

.seg {
  display: flex;
  background: #0e1118;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg > button, .seg > label {
  flex: 1;
  text-align: center;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: .15s;
  margin: 0;
}
.seg > button:hover, .seg > label:hover { color: var(--text); }
.seg > button.active,
.seg input:checked + label {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.seg-sm > label { padding: 6px 8px; font-size: 12px; }

.tab { display: none; margin-top: 12px; }
.tab.active { display: block; }

/* -------------------------------------------------------------- switch */

.switches { display: flex; flex-wrap: wrap; gap: 16px; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  margin: 0;
}
.switch input { display: none; }
.switch > span {
  width: 34px; height: 19px;
  border-radius: 999px;
  background: #2a3040;
  position: relative;
  transition: .18s;
  flex: none;
}
.switch > span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #8b93a7;
  transition: .18s;
}
.switch input:checked + span { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.switch input:checked + span::after { left: 17px; background: #fff; }
.switch input:checked ~ * { color: var(--text); }

/* --------------------------------------------------------- data table */

.data-table {
  max-height: 46vh;
  min-height: 120px;
  overflow: auto;
  overscroll-behavior: contain;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  resize: vertical;
}
.data-table::-webkit-scrollbar { width: 10px; height: 10px; }
.data-table::-webkit-scrollbar-track { background: #0e1118; }
.data-table::-webkit-scrollbar-thumb { background: #2f3646; border-radius: 8px; border: 2px solid #0e1118; }
.data-table::-webkit-scrollbar-thumb:hover { background: #3c4557; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12px; }
th, td {
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
th { position: sticky; top: 0; background: #0e1118; color: var(--muted); font-weight: 500; z-index: 1; }
tbody tr:hover td { background: #1b2130; }

td.rownum { color: var(--muted); cursor: pointer; text-align: right; width: 1%; }

td.editable { cursor: text; outline: none; transition: background .12s; }
td.editable:hover { background: #1d2331; }
td.editable:focus {
  background: #0e1118;
  box-shadow: inset 0 0 0 2px var(--accent);
  border-radius: 4px;
}

/* -------------------------------------------------------------- output */

.output {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1000px 500px at 60% -10%, #1a1f2e 0%, transparent 70%),
    var(--bg);
}

.output-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
}
.stepper #rowLabel { font-size: 12.5px; color: var(--muted); padding: 0 8px; min-width: 110px; text-align: center; }
.stepper .icon-btn { width: 28px; height: 28px; border-color: transparent; background: transparent; }
.stepper .icon-btn:hover { background: var(--surface-2); }

.canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 54px 40px;
  border: 1.5px dashed #2c3346;
  border-radius: 16px;
  background: rgba(18, 21, 29, .6);
  max-width: 420px;
}
.empty[hidden] { display: none; }
.empty svg { width: 36px; height: 36px; color: var(--accent); stroke-width: 1.4; }
.empty b { font-size: 15px; font-weight: 600; }
.empty span { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .85);
}
.stage canvas { display: block; max-width: 100%; height: auto; }
.stage[hidden] { display: none; }

.guide {
  position: absolute;
  border: 2px dashed rgba(99, 102, 241, .95);
  background: rgba(99, 102, 241, .12);
  border-radius: 4px;
  cursor: move;
  line-height: 1;
  touch-action: none;
}
.guide span {
  position: absolute;
  top: -19px; left: -2px;
  font-size: 10px;
  letter-spacing: .08em;
  background: var(--accent);
  color: #fff;
  padding: 2px 7px;
  border-radius: 4px 4px 0 0;
  white-space: nowrap;
}
.guide .handle {
  position: absolute;
  right: -7px; bottom: -7px;
  width: 14px; height: 14px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 4px;
  cursor: nwse-resize;
}
.stage.hide-guides .guide { display: none; }

.output-foot {
  padding: 10px 20px 16px;
  border-top: 1px solid var(--line);
}

/* --------------------------------------------------------- credit line */

.credit {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  font-size: 13px;
  letter-spacing: .06em;
  color: var(--muted);
  user-select: none;
  white-space: pre;
}

.credit .strong {
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.credit .caret {
  display: inline-block;
  width: 2px;
  height: 14px;
  margin-left: 3px;
  border-radius: 1px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  animation: caret-blink 1s steps(1) infinite;
}

@keyframes caret-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .credit .caret { display: none; }
}

.bar {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.bar > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .12s linear;
}

/* --------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .brand-sub { display: none; }
}

@media (max-width: 900px) {
  .sidebar {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    box-shadow: 0 0 60px rgba(0, 0, 0, .6);
  }
  .shell:not(.collapsed) .scrim {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 15;
  }
  .appbar-right .btn-soft { display: none; }
}
