* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  letter-spacing: 0;
}

button,
textarea,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
.intersection-list:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

svg {
  display: block;
}

.app-shell {
  width: 100%;
  height: 100dvh;
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(292px, var(--rail)) minmax(0, 1fr);
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 28%),
    var(--bg);
}

.control-rail,
.canvas-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(27, 28, 29, 0.96);
  box-shadow: var(--shadow);
}

.control-rail {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.brand-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.brand-mark path,
.brand-mark circle {
  fill: none;
  stroke: var(--coral);
  stroke-width: 4;
  stroke-linecap: round;
}

.brand-mark circle {
  fill: var(--coral);
}

h1 {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.05;
}

.brand-row p,
.stage-title small,
.input-row,
.metric-grid small {
  margin: 0;
  color: var(--muted);
}

.brand-row p {
  margin-top: 5px;
  font-size: 0.84rem;
}

.view-nav {
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  border-bottom: 1px solid var(--line-soft);
}

.view-button {
  min-width: 0;
  min-height: 58px;
  padding: 8px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: #151718;
  text-align: left;
}

.view-button svg {
  grid-row: 1 / 3;
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--coral);
}

.view-button span,
.view-button small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-button span {
  font-weight: 760;
  font-size: 0.9rem;
}

.view-button small {
  color: var(--muted);
  font-size: 0.72rem;
}

.view-button:hover,
.view-button.is-active {
  border-color: #5a6062;
  background: var(--panel-3);
}

.view-button.is-active svg,
.view-button.is-active span {
  color: var(--coral);
}

.rail-scroll {
  min-height: 0;
  overflow: auto;
  padding: 14px 18px 18px;
  scrollbar-color: var(--line) transparent;
}

.view-panel {
  display: none;
}

.view-panel.is-active {
  display: block;
}

.rail-section {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.rail-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.section-title {
  margin-bottom: 11px;
  color: var(--coral);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.field-label {
  display: block;
  margin: 11px 0 7px;
  color: var(--muted);
  font-size: 0.84rem;
}

.field-label:first-of-type {
  margin-top: 0;
}

textarea,
.text-input {
  width: 100%;
  color: var(--text);
  background: #121314;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

textarea {
  min-height: 92px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
  text-transform: uppercase;
}

.text-input {
  height: 40px;
  padding: 0 12px;
  text-transform: uppercase;
}

.input-row {
  min-height: 36px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.86rem;
}

.segmented,
.choice-grid,
.palette-grid {
  display: grid;
  gap: 7px;
}

.segmented,
.palette-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choice-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.palette-grid {
  margin-bottom: 15px;
}

.choice-button,
.palette-button,
.ghost-button,
.primary-button,
.secondary-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: #161819;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.choice-button,
.palette-button {
  min-width: 0;
  padding: 0 8px;
  font-size: 0.82rem;
}

.choice-button.is-active,
.palette-button.is-active,
.primary-button {
  color: #171111;
  border-color: transparent;
  background: linear-gradient(180deg, var(--coral-2), var(--coral));
  font-weight: 800;
}

.palette-button span {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border-radius: 4px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.ghost-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
}

.ghost-button.full {
  width: 100%;
  margin-top: 11px;
}

.primary-button,
.secondary-button {
  padding: 0 13px;
}

.secondary-button {
  color: var(--text);
  background: var(--panel-2);
}

.secondary-button:hover,
.choice-button:hover,
.palette-button:hover,
.ghost-button:hover {
  border-color: #5a6062;
  background: var(--panel-3);
}

.primary-button svg,
.secondary-button svg,
.ghost-button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toggle-row,
.range-row {
  min-height: 38px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  color: var(--text);
  font-size: 0.88rem;
}

.toggle-row input {
  width: 42px;
  height: 24px;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #121314;
  position: relative;
}

.toggle-row input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}

.toggle-row input:checked {
  border-color: transparent;
  background: var(--coral);
}

.toggle-row input:checked::after {
  transform: translateX(18px);
  background: white;
}

.range-row {
  grid-template-columns: 64px minmax(90px, 1fr) 42px;
}

.range-row input {
  accent-color: var(--coral);
  min-width: 0;
}

.range-row output {
  color: var(--muted);
  text-align: right;
  font-family: var(--font-mono);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.metric-grid div {
  padding: 10px;
  min-height: 68px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: #151718;
}

.metric-grid span {
  display: block;
  font-size: 1.24rem;
  font-family: var(--font-mono);
  color: var(--text);
}

.metric-grid small {
  display: block;
  margin-top: 4px;
  font-size: 0.76rem;
}

.intersection-list {
  min-height: 92px;
  max-height: 210px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: #131415;
  padding: 8px;
  scrollbar-color: var(--line) transparent;
}

.detail-item,
.empty-state {
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-item {
  color: var(--text);
  background: rgba(255, 200, 87, 0.08);
}

.detail-item + .detail-item {
  margin-top: 6px;
}

.detail-item strong {
  color: var(--gold);
  font-family: var(--font-mono);
}

.export-bar {
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line-soft);
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.icon-only {
  width: 42px;
  padding: 0;
}

.canvas-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.stage-toolbar {
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stage-title span {
  color: var(--coral);
  font-weight: 840;
  text-transform: uppercase;
}

.stage-title small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.compact {
  min-height: 36px;
}

.stage-frame {
  min-height: 0;
  padding: 10px;
  display: grid;
  place-items: center;
  background: #101111;
}

#artSvg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #111111;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  max-width: min(520px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: #1d2021;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(260px, 44dvh) minmax(0, 1fr);
  }

  .control-rail {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .brand-row {
    padding: 12px 14px;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  h1 {
    font-size: 1.1rem;
  }

  .view-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 8px 10px;
  }

  .view-button {
    min-height: 46px;
  }

  .view-button small {
    display: none;
  }

  .rail-scroll {
    padding: 12px 14px;
  }

  .export-bar {
    padding: 10px 14px 12px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 6px;
    gap: 6px;
    grid-template-rows: minmax(270px, 46dvh) minmax(0, 1fr);
  }

  .brand-row p,
  .stage-title small,
  .compact span {
    display: none;
  }

  .view-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view-button {
    grid-template-columns: 22px minmax(0, 1fr);
    min-height: 40px;
    padding: 7px;
  }

  .view-button svg {
    width: 22px;
    height: 22px;
  }

  .view-button span {
    font-size: 0.82rem;
  }

  .segmented,
  .palette-grid,
  .choice-grid.two {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric-grid div {
    min-height: 56px;
    padding: 7px;
  }

  .metric-grid span {
    font-size: 0.96rem;
  }

  .metric-grid small {
    font-size: 0.66rem;
  }

  .export-bar {
    grid-template-columns: 1fr 1fr;
  }

  #copySvgButton {
    display: none;
  }

  .stage-toolbar {
    padding: 8px;
  }

  .stage-frame {
    padding: 6px;
  }
}
