:root {
  --bg: #0a110d;
  --bg-deep: #070c09;
  --panel: #121b15;
  --panel-raised: #17221a;
  --panel-soft: #0e1711;
  --line: #26352b;
  --line-strong: #354c3c;
  --text: #e8ecdf;
  --muted: #94a095;
  --faint: #68766c;
  --accent: #63e0a7;
  --accent-bright: #adf7ce;
  --accent-dim: rgba(99, 224, 167, 0.11);
  --accent-line: rgba(99, 224, 167, 0.36);
  --accent-ink: #0a6b48;
  --amber: #f0c96a;
  --danger: #ff8c7a;
  --paper: #f8f3e5;
  --mono: "Cascadia Mono", "Cascadia Code", "Consolas", "SFMono-Regular", "Courier New", monospace;
  --sans: "Segoe UI Variable Text", "Segoe UI", "Aptos", system-ui, sans-serif;
  --topbar-height: 68px;
  --sidebar-width: 304px;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 0%, rgba(56, 123, 86, 0.2), transparent 34rem),
    var(--bg);
  font-family: var(--sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: radial-gradient(rgba(192, 220, 197, 0.11) 0.5px, transparent 0.5px);
  background-size: 4px 4px;
  z-index: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

h1,
h2,
h3,
p,
dl,
dd {
  margin: 0;
}

button {
  cursor: pointer;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 540px;
}

/* Header ------------------------------------------------------------------ */

.topbar {
  height: var(--topbar-height);
  flex: 0 0 var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 20, 15, 0.86);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(240, 201, 106, 0.13));
}

.brand-words {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-kicker {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.15em;
  line-height: 1.2;
  text-transform: uppercase;
}

.brand-name {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.06em;
  line-height: 1.1;
}

.title-block {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.doc-title {
  width: clamp(190px, 28vw, 430px);
  max-width: 100%;
  height: 24px;
  padding: 1px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: border-color 140ms ease;
}

.doc-title:hover {
  border-bottom-color: var(--line-strong);
}

.doc-title:focus {
  outline: 0;
  border-bottom-color: var(--accent);
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.save-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 224, 167, 0.08);
}

.save-state[data-state="saving"] .save-dot {
  background: var(--amber);
  animation: save-pulse 900ms ease-in-out infinite;
}

.save-state[data-state="error"] {
  color: var(--danger);
}

.save-state[data-state="error"] .save-dot {
  background: var(--danger);
}

@keyframes save-pulse {
  50% {
    opacity: 0.35;
  }
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141f18;
  color: var(--text);
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease,
    transform 100ms ease;
}

.btn:hover {
  border-color: var(--line-strong);
  background: #1a2820;
}

.btn:active {
  transform: translateY(1px);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  border-color: transparent;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #07130d;
  font-weight: 700;
}

.btn-primary:hover {
  border-color: var(--accent-bright);
  background: var(--accent-bright);
}

.btn-danger {
  border-color: rgba(255, 140, 122, 0.4);
  background: #50231c;
  color: #ffd9d2;
  font-weight: 650;
}

.btn-danger:hover {
  border-color: var(--danger);
  background: #642c23;
  color: #fff1ed;
}

.btn-small {
  height: 31px;
  padding: 0 10px;
  font-size: 10.5px;
}

.btn .icon {
  width: 15px;
  height: 15px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition:
    color 130ms ease,
    background 130ms ease,
    border-color 130ms ease;
}

.icon-btn:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.icon-btn.is-active,
.icon-btn[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-dim);
}

.topbar-help {
  margin-left: 3px;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

/* Sidebar ----------------------------------------------------------------- */

.sidebar {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 28, 21, 0.7), rgba(10, 17, 12, 0.35));
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar,
.palette-grid::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.sidebar::-webkit-scrollbar-thumb,
.palette-grid::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 99px;
}

.panel {
  flex: 0 0 auto;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(155deg, rgba(29, 43, 34, 0.8), rgba(17, 26, 20, 0.92)),
    var(--panel);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.025),
    0 10px 25px rgba(0, 0, 0, 0.07);
}

.page-panel {
  background:
    radial-gradient(circle at 98% 0%, rgba(240, 201, 106, 0.08), transparent 58%),
    linear-gradient(155deg, rgba(31, 44, 34, 0.86), rgba(17, 26, 20, 0.95));
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}

.eyebrow {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.panel-meta {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.size-badge {
  padding: 3px 6px;
  border: 1px solid rgba(240, 201, 106, 0.2);
  border-radius: 5px;
  background: rgba(240, 201, 106, 0.06);
  color: var(--amber);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.02em;
}

.dimension-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 13px minmax(0, 1fr);
  align-items: end;
  gap: 6px;
}

.dimension-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.dimension-field > span,
.field-label {
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 500;
}

.dimension-field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--text);
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.03em;
  padding: 0 9px;
  transition: border-color 130ms ease;
}

.dimension-field input:hover {
  border-color: #496452;
}

.dimension-field input:focus {
  border-color: var(--accent);
  outline: 0;
}

.dimension-field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.dimension-times {
  padding-bottom: 10px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
}

.page-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin-top: 9px;
}

.page-actions #page-preset {
  font-size: 9px;
}

.page-print-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.page-print-grid .field {
  gap: 5px;
}

.page-preset-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  padding: 7px 8px;
  border: 1px solid rgba(255, 255, 255, 0.055);
  border-radius: 7px;
  background: rgba(8, 14, 10, 0.38);
  font-family: var(--mono);
}

.page-preset-info strong {
  color: var(--text);
  font-size: 9.5px;
  font-weight: 600;
}

.page-preset-info span {
  color: var(--faint);
  font-size: 8px;
  line-height: 1.35;
}

.page-preset-info.is-invalid span {
  color: var(--danger);
}

.select {
  width: 100%;
  height: 31px;
  padding: 0 25px 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background-color: var(--panel-soft);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='m1 1 4 4 4-4' fill='none' stroke='%238b9a8d' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  font-size: 10px;
  appearance: none;
}

.select:hover {
  border-color: var(--line-strong);
}

.sheet-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
}

.sheet-readout > div {
  min-width: 0;
}

.sheet-readout dt {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sheet-readout dd {
  margin-top: 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9.5px;
  white-space: nowrap;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.tool-button {
  height: 61px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 1px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 8.5px;
  transition:
    color 130ms ease,
    border-color 130ms ease,
    background 130ms ease;
}

.tool-button:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: #142019;
}

.tool-button.is-active {
  border-color: var(--accent-line);
  background: var(--accent-dim);
  color: var(--accent-bright);
}

.tool-icon {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-hint {
  margin-top: 8px;
  color: var(--faint);
  font-size: 9.5px;
  line-height: 1.45;
}

.rule-row,
.glyph-size-row,
.glyph-style-row {
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
}

.rule-row .field-label,
.glyph-size-row .field-label,
.glyph-style-row .field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 9px;
}

.segmented.glyph-size-picker {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segmented.bold-picker {
  grid-template-columns: minmax(0, 1fr);
}

.bold-toggle strong {
  font-size: 12px;
  line-height: 1;
}

.bold-toggle:not(.is-active) strong {
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(8, 14, 10, 0.55);
}

.segment-button {
  min-width: 0;
  height: 27px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 3px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
}

.segment-button span {
  font-family: var(--sans);
  font-size: 8.5px;
}

.segment-button:hover {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
}

.segment-button.is-active {
  border-color: var(--accent-line);
  background: var(--accent-dim);
  color: var(--accent-bright);
}

.active-glyph {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 11px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  background: rgba(7, 13, 9, 0.5);
}

.active-glyph-tile {
  width: 35px;
  height: 49px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 5px;
  background: var(--paper);
  box-shadow: inset 0 0 0 1px rgba(23, 38, 27, 0.12);
}

.active-glyph-tile canvas {
  width: 24px;
  height: 48px;
  image-rendering: pixelated;
}

.active-glyph-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.active-glyph-info .eyebrow {
  font-size: 7.5px;
}

.active-glyph-info strong {
  color: var(--amber);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
}

.active-glyph-info > span:last-child {
  overflow: hidden;
  color: var(--faint);
  font-size: 8.5px;
  line-height: 1.3;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.panel-note {
  margin-top: -5px;
  margin-bottom: 10px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.4;
}

.palette-tabs {
  display: flex;
  gap: 3px;
  margin-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.palette-tabs::-webkit-scrollbar {
  display: none;
}

.palette-tab {
  height: 25px;
  padding: 0 7px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.015em;
  text-transform: uppercase;
}

.palette-tab:hover {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
}

.palette-tab[aria-selected="true"] {
  color: var(--accent-bright);
  border-color: var(--line-strong);
  background: #1b2a21;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 4px;
  max-height: 284px;
  overflow-y: auto;
  padding: 1px;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.glyph-chip {
  position: relative;
  height: 34px;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 1px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: rgba(6, 12, 8, 0.44);
  color: var(--muted);
  transition:
    border-color 110ms ease,
    background 110ms ease;
}

.glyph-chip:hover {
  border-color: var(--line-strong);
  background: #19261d;
}

.glyph-chip.is-selected {
  border-color: var(--accent-line);
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(99, 224, 167, 0.08);
}

.glyph-chip.is-selected::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent);
}

.glyph-chip canvas {
  width: 14px;
  height: 28px;
  image-rendering: pixelated;
  opacity: 0.92;
}

.glyph-chip.is-selected canvas {
  opacity: 1;
}

.custom-glyph {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
}

.custom-glyph > label {
  display: block;
  margin-bottom: 5px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.custom-glyph-fields {
  display: flex;
  gap: 5px;
}

.custom-glyph-fields input {
  min-width: 0;
  flex: 1;
  height: 31px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 0 8px;
}

.custom-glyph-fields input:focus {
  border-color: var(--accent);
  outline: 0;
}

.palette-footnote {
  margin-top: 8px;
  color: var(--faint);
  font-size: 8.5px;
  line-height: 1.45;
}

/* Variable fields --------------------------------------------------------- */

.variable-panel {
  position: relative;
}

.variable-add {
  width: 100%;
  margin-bottom: 9px;
}

.variable-add .icon {
  width: 14px;
  height: 14px;
}

.variable-empty {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding: 17px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(6, 12, 8, 0.24);
  text-align: center;
}

.variable-empty[hidden] {
  display: none;
}

.variable-empty-mark {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 7px;
  border: 1px dashed rgba(240, 201, 106, 0.38);
  border-radius: 5px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 9px;
}

.variable-empty-mark span {
  color: var(--faint);
}

.variable-empty p {
  max-width: 210px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.5;
}

.variable-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.variable-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 12, 8, 0.34);
  transition:
    border-color 130ms ease,
    background 130ms ease;
}

.variable-card.is-selected {
  border-color: rgba(240, 201, 106, 0.5);
  background: rgba(240, 201, 106, 0.055);
}

.variable-card-main {
  width: 100%;
  display: grid;
  grid-template-columns: 3px minmax(0, 1fr);
  gap: 9px;
  padding: 9px 9px 7px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.variable-card-swatch {
  width: 3px;
  align-self: stretch;
  border-radius: 3px;
  background: rgba(240, 201, 106, 0.44);
}

.variable-card.is-selected .variable-card-swatch {
  background: var(--amber);
}

.variable-card-copy {
  min-width: 0;
}

.variable-card-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-card-meta {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 7.5px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-card-meta.is-clipped {
  color: var(--amber);
}

.variable-card-preview {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-card-actions {
  display: flex;
  border-top: 1px solid rgba(255, 255, 255, 0.045);
}

.variable-card-action {
  flex: 1;
  height: 27px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.045);
  background: transparent;
  color: var(--faint);
  font-size: 8.5px;
}

.variable-card-action:last-child {
  border-right: 0;
}

.variable-card-action:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.variable-card-action.is-delete:hover {
  color: var(--danger);
}

.variable-card-action .icon {
  width: 12px;
  height: 12px;
}

.variable-footnote {
  margin-top: 10px;
}

.variable-outlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.variable-outline {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed rgba(139, 91, 0, 0.7);
  background: rgba(240, 201, 106, 0.035);
}

.variable-outline.is-selected {
  z-index: 2;
  border: 1.5px solid rgba(112, 70, 0, 0.96);
  background: rgba(240, 201, 106, 0.075);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.textbox-outline {
  border: 1px dashed rgba(45, 118, 163, 0.75);
}

.textbox-outline.is-selected {
  border: 1.5px solid rgba(35, 101, 146, 0.96);
  background: rgba(114, 199, 255, 0.075);
}

.textbox-outline .variable-outline-tag {
  background: #164b6b;
  color: #d9f3ff;
}

.variable-outline-tag {
  position: absolute;
  top: -18px;
  right: -1px;
  left: auto;
  max-width: 320px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  padding: 2px 3px 2px 5px;
  border-radius: 4px;
  background: #604000;
  color: #ffecb7;
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.variable-outline-tag-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline-edit-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  border: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

.outline-edit-button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.outline-edit-button .icon {
  width: 9px;
  height: 9px;
}

.variable-outline.is-selected .variable-outline-tag {
  background: #513600;
  color: #fff2c9;
}

.textbox-outline.is-selected .variable-outline-tag {
  background: #0f3e5a;
  color: #e3f7ff;
}

.table-outline {
  border: 1px dashed rgba(53, 135, 94, 0.8);
}

.table-outline.is-selected {
  border: 1.5px solid rgba(36, 111, 74, 0.96);
  background: rgba(99, 224, 167, 0.06);
}

.table-outline.is-selected .variable-outline-tag {
  background: #123f2a;
  color: #d8ffe9;
}

.resize-handle {
  position: absolute;
  z-index: 4;
  width: 8px;
  height: 8px;
  border: 1.5px solid #8b5b00;
  border-radius: 2px;
  background: #fff4d3;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  touch-action: none;
  transform: translate(-50%, -50%);
}

.resize-handle:hover {
  background: #ffe9a8;
}

.textbox-outline .resize-handle {
  border-color: #236592;
  background: #e5f7ff;
}

.textbox-outline .resize-handle:hover {
  background: #c5edff;
}

.resize-nw { left: 0; top: 0; cursor: nwse-resize; }
.resize-n { left: 50%; top: 0; cursor: ns-resize; }
.resize-ne { left: 100%; top: 0; cursor: nesw-resize; }
.resize-e { left: 100%; top: 50%; cursor: ew-resize; }
.resize-se { left: 100%; top: 100%; cursor: nwse-resize; }
.resize-s { left: 50%; top: 100%; cursor: ns-resize; }
.resize-sw { left: 0; top: 100%; cursor: nesw-resize; }
.resize-w { left: 0; top: 50%; cursor: ew-resize; }

body.is-resizing {
  user-select: none;
  -webkit-user-select: none;
}

/* Engine authentication ---------------------------------------------------- */

body.auth-locked {
  overflow: hidden;
}

body.auth-locked .app-shell {
  display: none;
}

body:not(.auth-locked) .auth-gate {
  display: none;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(99, 224, 167, 0.08), transparent 34%),
    radial-gradient(circle at 85% 80%, rgba(240, 201, 106, 0.06), transparent 30%),
    #070d09;
}

.auth-gate [hidden] {
  display: none !important;
}

.auth-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(23, 35, 27, 0.98), rgba(11, 18, 14, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.auth-brand .brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
}

.auth-brand-name {
  display: block;
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.auth-card h1 {
  margin: 0 0 8px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-lede {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 2px;
}

.auth-waiting {
  padding-top: 4px;
}

.auth-waiting-copy {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.auth-waiting-copy strong {
  color: var(--accent-bright);
}

.auth-challenge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 18px;
  border: 1px solid var(--accent-line);
  border-radius: 9px;
  background: var(--accent-dim);
}

.auth-challenge strong {
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.auth-waiting-note {
  margin: 12px 0 18px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1.6;
}

.auth-foot {
  margin: 22px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1.6;
}

@media (max-width: 520px) {
  .auth-gate {
    padding: 12px;
  }

  .auth-card {
    padding: 22px;
  }

  .auth-card h1 {
    font-size: 22px;
  }
}

/* Variable dialog --------------------------------------------------------- */

.variable-modal {
  width: min(660px, calc(100vw - 32px));
}

.variable-form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.variable-name-field input {
  font-family: var(--mono);
  font-size: 11px;
}

.variable-geometry-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 11px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 9px;
  align-items: end;
  padding-top: 2px;
}

.variable-geometry-grid .field input {
  font-family: var(--mono);
  font-size: 12px;
}

.variable-times {
  padding-bottom: 10px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  text-align: center;
}

.variable-align-row {
  display: flex;
  align-items: flex-end;
  gap: 15px;
}

.variable-align-row > .field {
  flex: 1;
}

.variable-style-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.table-columns-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.table-columns-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.table-columns-note {
  color: var(--faint);
  font-size: 8px;
  line-height: 1.4;
}

.table-columns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.table-column-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px 92px 92px;
  align-items: end;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 12, 8, 0.24);
}

.table-column-row .field {
  gap: 3px;
}

.table-column-row .field span {
  overflow: hidden;
  color: var(--faint);
  font-size: 8px;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.table-column-row .field input,
.table-column-row .field select {
  height: 34px;
}

.field input[readonly] {
  border-color: rgba(255, 255, 255, 0.055);
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  cursor: default;
}

.table-card .variable-card-swatch {
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(99, 224, 167, 0.28);
}

.textbox-card .variable-card-swatch {
  background: #72c7ff;
  box-shadow: 0 0 0 1px rgba(114, 199, 255, 0.28);
}

.textbox-card.is-selected {
  border-color: rgba(114, 199, 255, 0.5);
  background: rgba(114, 199, 255, 0.055);
}

.textbox-card.is-selected .variable-card-swatch {
  background: #a8dfff;
}

.table-card.is-selected {
  border-color: rgba(99, 224, 167, 0.5);
  background: rgba(99, 224, 167, 0.055);
}

.table-card.is-selected .variable-card-swatch {
  background: #a9f7d7;
}

.table-card-headers {
  overflow: hidden;
  color: var(--muted);
  font-size: 8.5px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.variable-style-row .variable-size-field .select {
  height: 36px;
  font-size: 10px;
}

.variable-style-row .variable-wrap-check {
  width: 100%;
  min-width: 0;
  height: 36px;
}

.align-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(6, 12, 8, 0.35);
}

.align-option {
  position: relative;
  cursor: pointer;
}

.align-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.align-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--faint);
  font-size: 9.5px;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

.align-option:hover span {
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
}

.align-option input:checked + span {
  border-color: var(--accent-line);
  background: var(--accent-dim);
  color: var(--accent-bright);
}

.align-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.variable-wrap-check {
  flex: 0 0 auto;
  min-width: 178px;
  height: 36px;
  align-items: center;
  padding: 6px 9px;
}

.variable-wrap-check > span {
  flex-direction: row;
  align-items: baseline;
  gap: 5px;
}

.variable-wrap-check strong {
  white-space: nowrap;
}

.variable-wrap-check small {
  white-space: nowrap;
}

.variable-value-field {
  margin-top: 1px;
}

.field textarea {
  width: 100%;
  min-height: 104px;
  padding: 9px 10px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
}

.field textarea:focus {
  border-color: var(--accent);
  outline: 0;
}

.field textarea::placeholder {
  color: #47584b;
}

.variable-live-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  min-height: 14px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8.5px;
}

.variable-live-summary strong {
  color: var(--amber);
  font-weight: 500;
}

.variable-live-summary .is-warning {
  color: var(--danger);
}

.variable-modal .printer-note {
  margin-top: -2px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Editor ------------------------------------------------------------------ */

.editor-region {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0a100c;
}

.editor-toolbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 23, 18, 0.96);
  flex: 0 0 auto;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  flex: 0 0 auto;
  background: var(--line);
}

.toolbar-context {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-pill {
  flex: 0 0 auto;
  padding: 4px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.context-hint {
  overflow: hidden;
  max-width: 380px;
  color: var(--faint);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-spacer {
  flex: 1;
}

.icon-btn.has-label {
  width: auto;
  padding: 0 7px;
  font-size: 9.5px;
}

.icon-btn.has-label .icon {
  width: 15px;
  height: 15px;
}

.view-toggles {
  gap: 2px;
}

.zoom-control {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0d1610;
}

.zoom-button {
  width: 27px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}

.zoom-button:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.zoom-button .icon {
  width: 13px;
  height: 13px;
}

.zoom-value {
  width: 46px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  text-align: center;
}

.zoom-value:hover {
  color: var(--text);
}

.zoom-fit {
  width: auto;
  margin-left: 1px;
  padding: 0 7px;
  gap: 4px;
  border-left: 1px solid var(--line);
  border-radius: 0 4px 4px 0;
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.02em;
}

.zoom-fit .icon {
  width: 12px;
  height: 12px;
}

.canvas-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background-color: #0a110d;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(142, 173, 151, 0.12) 1px, transparent 0),
    radial-gradient(ellipse at 50% 20%, rgba(38, 76, 53, 0.25), transparent 65%);
  background-size:
    18px 18px,
    100% 100%;
  scrollbar-color: #3b5042 #0a100c;
  scrollbar-width: thin;
}

.canvas-viewport::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.canvas-viewport::-webkit-scrollbar-track {
  background: #0a100c;
}

.canvas-viewport::-webkit-scrollbar-thumb {
  border: 3px solid #0a100c;
  border-radius: 99px;
  background: #3b5042;
}

.canvas-stage {
  position: relative;
  margin: 26px auto 40px;
  width: max-content;
  min-width: 1px;
}

.editor-canvas {
  display: block;
  touch-action: none;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}

.editor-canvas:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 6px;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.cell-hover,
.cell-cursor {
  position: absolute;
  box-sizing: border-box;
  pointer-events: none;
}

.cell-hover {
  border: 1px solid rgba(10, 107, 72, 0.38);
  background: rgba(99, 224, 167, 0.07);
}

.cell-cursor {
  z-index: 3;
  border: 1.5px solid var(--accent-ink);
  background: rgba(99, 224, 167, 0.08);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.55),
    0 1px 4px rgba(0, 0, 0, 0.16);
}

.cursor-caret {
  position: absolute;
  top: 14%;
  bottom: 14%;
  left: 3px;
  width: 2px;
  background: var(--accent-ink);
  animation: caret-blink 1.1s steps(1) infinite;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

.cell-cursor[data-tool="brush"] .cursor-caret,
.cell-cursor[data-tool="box"] .cursor-caret,
.cell-cursor[data-tool="erase"] .cursor-caret,
.cell-cursor[data-tool="variable"] .cursor-caret {
  display: none;
}

.cell-cursor[data-tool="brush"],
.cell-cursor[data-tool="box"] {
  background: rgba(99, 224, 167, 0.045);
}

.cell-cursor[data-tool="erase"] {
  border-color: rgba(157, 58, 42, 0.8);
  background: rgba(255, 140, 122, 0.1);
}

.cell-cursor[data-tool="variable"] {
  border-color: rgba(112, 70, 0, 0.85);
  background: rgba(240, 201, 106, 0.09);
}

.cell-cursor.is-invalid {
  border-color: rgba(157, 58, 42, 0.95);
  background: rgba(255, 140, 122, 0.12);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.4),
    0 0 0 3px rgba(157, 58, 42, 0.12);
}

.is-hidden {
  display: none !important;
}

.box-preview {
  position: absolute;
  z-index: 4;
  display: none;
  border: 1px dashed var(--accent-ink);
  background: rgba(99, 224, 167, 0.06);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.24),
    0 0 0 1px rgba(255, 255, 255, 0.18);
  pointer-events: none;
}

.box-preview.is-visible {
  display: block;
}

.box-preview-size {
  position: absolute;
  top: -22px;
  left: -1px;
  padding: 3px 5px;
  border-radius: 4px;
  background: #0c4b33;
  color: #d7fbe5;
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.24);
}

.preview-pill {
  display: none;
}

.preview-corner {
  display: none;
  position: absolute;
  top: 64px;
  right: 14px;
  z-index: 8;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  background: rgba(12, 45, 30, 0.92);
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
}

.editor-region.is-preview .preview-corner {
  display: flex;
}

.editor-region.is-preview .overlay-layer {
  display: none;
}

.editor-region.is-preview .editor-canvas {
  cursor: default;
}

.preview-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 224, 167, 0.1);
}

.statusbar {
  flex: 0 0 31px;
  height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  overflow: hidden;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  background: #0b130e;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.015em;
  white-space: nowrap;
}

.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.status-right {
  flex: 0 0 auto;
}

.status-left > * {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-coordinate {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-coordinate span {
  color: #46594b;
}

.status-coordinate strong {
  color: var(--accent);
  font-weight: 500;
}

.status-divider {
  width: 1px;
  height: 10px;
  background: var(--line);
}

.status-hint {
  overflow: hidden;
  max-width: 300px;
  color: #58675c;
  text-overflow: ellipsis;
}

.status-right strong {
  color: var(--muted);
  font-weight: 500;
}

/* Modals ------------------------------------------------------------------ */

.modal {
  width: min(720px, calc(100vw - 32px));
  max-height: min(860px, calc(100dvh - 40px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 15px;
  background: #111a14;
  color: var(--text);
  box-shadow:
    0 30px 100px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.modal[open] {
  animation: modal-in 160ms ease-out both;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.99);
  }
}

.modal::backdrop {
  background: rgba(3, 7, 5, 0.72);
  backdrop-filter: blur(5px);
}

.modal-small {
  width: min(470px, calc(100vw - 32px));
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at 0% 0%, rgba(99, 224, 167, 0.06), transparent 23rem),
    #121c16;
}

.modal-header h2 {
  margin-top: 5px;
  font-size: 21px;
  font-weight: 550;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

.modal-close {
  flex: 0 0 auto;
  margin: -4px -5px 0 0;
}

.modal-body {
  max-height: calc(100dvh - 230px);
  padding: 19px 22px;
  overflow-y: auto;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: #0f1812;
}

.modal-footnote {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Template API dialog ------------------------------------------------------ */

.api-modal {
  width: min(780px, calc(100vw - 32px));
}

.api-lede {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.api-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.api-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.api-section-head h3 {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.api-section-head .panel-meta {
  margin-left: 4px;
}

.api-result {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(99, 224, 167, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(99, 224, 167, 0.06), transparent 70%),
    rgba(7, 13, 9, 0.55);
}

.api-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.api-current-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.api-current-name {
  overflow: hidden;
  color: var(--text);
  font-size: 10px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-current-actions,
.api-list-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
}

.api-current-empty {
  margin-top: 3px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.5;
}

.api-id-input {
  width: 100%;
  height: 34px;
  margin-top: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(3, 8, 5, 0.55);
  color: var(--accent-bright);
  font-family: var(--mono);
  font-size: 9.5px;
}

.api-endpoint {
  display: block;
  margin-top: 8px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.api-template-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.api-template-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 11px;
  border: 1px solid rgba(255, 255, 255, 0.065);
  border-radius: 8px;
  background: rgba(7, 13, 9, 0.48);
}

.api-template-card.is-current {
  border-color: rgba(99, 224, 167, 0.34);
  background:
    linear-gradient(120deg, rgba(99, 224, 167, 0.065), transparent 70%),
    rgba(7, 13, 9, 0.55);
  box-shadow: inset 0 0 0 1px rgba(99, 224, 167, 0.06);
}

.api-template-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.api-template-name {
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
}

.api-template-id {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.api-template-meta {
  color: var(--faint);
  font-size: 8.5px;
  line-height: 1.4;
}

.api-template-params {
  overflow: hidden;
  color: var(--muted);
  font-size: 8.5px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-template-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
}

.api-template-actions .btn {
  height: 28px;
  padding: 0 8px;
  font-size: 8px;
}

.api-template-empty {
  padding: 20px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--faint);
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
}

@media (max-width: 700px) {
  .api-result-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .api-current-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .api-template-card {
    flex-direction: column;
    align-items: stretch;
  }

  .api-template-actions {
    justify-content: flex-end;
  }
}

.export-overview {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 25px;
  padding: 15px 16px;
  overflow: hidden;
  border: 1px solid rgba(99, 224, 167, 0.17);
  border-radius: 10px;
  background:
    linear-gradient(120deg, rgba(99, 224, 167, 0.075), rgba(99, 224, 167, 0.015) 55%),
    #0d1711;
}

.export-overview::after {
  content: "";
  position: absolute;
  top: -40px;
  right: -10px;
  width: 150px;
  height: 120px;
  border: 1px solid rgba(99, 224, 167, 0.12);
  transform: rotate(-17deg);
  pointer-events: none;
}

.export-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.mini-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.export-overview h3 {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 550;
  letter-spacing: -0.03em;
}

.export-overview p {
  margin-top: 3px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
}

.export-specs {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 22px;
  align-items: flex-start;
  flex: 0 0 auto;
  padding-top: 3px;
}

.export-specs dt {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 7.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.export-specs dd {
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.section-label {
  margin: 18px 0 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field > span {
  color: var(--muted);
  font-size: 9.5px;
}

.field .select {
  height: 34px;
  font-size: 10.5px;
}

.field input {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font-family: var(--mono);
  font-size: 10.5px;
}

.field input:focus {
  border-color: var(--accent);
  outline: 0;
}

.field input::placeholder {
  color: #47584b;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.check {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(6, 12, 8, 0.3);
  cursor: pointer;
}

.check:hover {
  border-color: var(--line-strong);
}

.check input {
  width: 13px;
  height: 13px;
  margin: 2px 0 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.check > span {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.check strong {
  font-size: 9.5px;
  font-weight: 550;
  line-height: 1.3;
}

.check small {
  color: var(--faint);
  font-size: 8px;
  line-height: 1.35;
}

.advanced {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(6, 12, 8, 0.25);
}

.advanced summary {
  padding: 9px 10px;
  color: var(--muted);
  font-size: 9.5px;
  cursor: pointer;
  user-select: none;
}

.advanced summary::marker {
  color: var(--faint);
}

.advanced summary span {
  margin-left: 5px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 7.5px;
  text-transform: uppercase;
}

.advanced-body {
  padding: 0 10px 11px;
}

.advanced-body > p {
  margin-bottom: 9px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.5;
}

.advanced-body code,
.printer-note code {
  padding: 1px 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.94em;
}

.inline-message {
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}

.inline-message.is-error {
  border-color: rgba(255, 140, 122, 0.35);
  background: rgba(255, 140, 122, 0.08);
  color: #ffb7aa;
}

.inline-message.is-success {
  border-color: rgba(99, 224, 167, 0.27);
  background: rgba(99, 224, 167, 0.06);
  color: var(--accent-bright);
}

.printer-note {
  margin-top: 12px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.55;
}

.export-footer {
  gap: 12px;
}

.secondary-exports {
  display: flex;
  align-items: center;
  gap: 5px;
}

.help-body {
  padding-top: 17px;
}

.help-callout {
  display: grid;
  grid-template-columns: 29px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.055);
}

.help-callout:first-child {
  padding-top: 0;
}

.help-index {
  padding-top: 1px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 8.5px;
}

.help-callout h3 {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 550;
}

.help-callout p,
.help-copy {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.6;
}

.help-section-title {
  margin: 20px 0 9px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 15px;
}

.shortcut-grid > div {
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 23px;
  color: var(--faint);
  font-size: 9.5px;
}

.shortcut-grid kbd {
  min-width: 19px;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-bottom-color: var(--line-strong);
  border-radius: 4px;
  background: var(--panel-soft);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  text-align: center;
}

.shortcut-grid span {
  margin-left: 5px;
}

.help-copy {
  margin-top: 7px;
}

.credits {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 9px;
}

.credits strong {
  color: var(--muted);
  font-weight: 550;
}

.confirm-copy {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

/* Toasts ------------------------------------------------------------------ */

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 45px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
  max-width: min(360px, calc(100vw - 30px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(18, 29, 22, 0.97);
  color: var(--text);
  font-size: 10.5px;
  line-height: 1.45;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
  animation: toast-in 150ms ease-out both;
  pointer-events: auto;
}

.toast.is-leaving {
  animation: toast-out 180ms ease-in both;
}

.toast::before {
  content: "";
  width: 5px;
  height: 5px;
  flex: 0 0 auto;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.toast.is-error {
  border-color: rgba(255, 140, 122, 0.38);
}

.toast.is-error::before {
  background: var(--danger);
}

.toast.is-warning::before {
  background: var(--amber);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(3px);
  }
}

/* Responsive -------------------------------------------------------------- */

@media (max-width: 1280px) {
  :root {
    --sidebar-width: 284px;
  }

  .topbar {
    gap: 12px;
    padding: 0 14px;
  }

  .title-block {
    padding-left: 14px;
  }

  .context-hint {
    max-width: 230px;
  }
}

@media (max-width: 1120px) {
  .top-actions .btn-label {
    display: none;
  }

  .top-actions .btn {
    width: 34px;
    padding: 0;
  }

  .title-block {
    gap: 8px;
  }

  .save-state #save-label {
    max-width: 84px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .icon-btn.has-label span {
    display: none;
  }

  .icon-btn.has-label {
    width: 31px;
    padding: 0;
  }

  .context-hint {
    max-width: 180px;
  }
}

@media (max-width: 920px) {
  :root {
    --sidebar-width: 260px;
  }

  .brand-kicker {
    display: none;
  }

  .brand-name {
    font-size: 16px;
  }

  .topbar {
    gap: 9px;
  }

  .save-state {
    display: none;
  }

  .toolbar-context {
    display: none;
  }

  .toolbar-divider:nth-of-type(2) {
    display: none;
  }

  .tool-hint {
    display: none;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
  }

  .topbar {
    height: auto;
    min-height: 62px;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .title-block {
    order: 3;
    flex-basis: 100%;
    border-left: 0;
    padding-left: 0;
    padding-bottom: 2px;
  }

  .doc-title {
    max-width: none;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .editor-region {
    order: 1;
    height: 74dvh;
    min-height: 480px;
  }

  .sidebar {
    order: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    overflow: visible;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .palette-panel,
  .variable-panel {
    grid-column: 1 / -1;
  }

  .status-hint,
  .status-right .status-divider,
  .status-right > span:nth-child(2),
  .status-right > span:nth-child(3) {
    display: none;
  }

  .modal-body {
    max-height: calc(100dvh - 190px);
  }

  .export-overview {
    flex-direction: column;
    gap: 13px;
  }

  .export-specs {
    gap: 25px;
  }

  .check-grid {
    grid-template-columns: 1fr;
  }

  .export-footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .secondary-exports {
    justify-content: stretch;
  }

  .secondary-exports .btn {
    flex: 1;
  }

  .shortcut-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .variable-geometry-grid {
    grid-template-columns: minmax(0, 1fr) 11px minmax(0, 1fr);
  }

  .variable-geometry-grid > .field:nth-of-type(3) {
    grid-column: 1 / 2;
  }

  .variable-geometry-grid > .field:nth-of-type(4) {
    grid-column: 3 / 4;
  }

  .variable-align-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .variable-style-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .table-column-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-column-row .field:first-child {
    grid-column: 1 / -1;
  }

  .variable-wrap-check {
    min-width: 0;
  }

  .variable-modal .modal-footer {
    flex-wrap: wrap;
  }

  .variable-modal .modal-actions {
    margin-left: auto;
  }
}

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