:root {
  color-scheme: dark;
  --bg: #101316;
  --panel: #191f24;
  --panel-soft: #20272d;
  --line: #35414b;
  --text: #e9f0f4;
  --muted: #9cabaf;
  --green: #54d66f;
  --blue: #43a8ff;
  --off: #343a40;
  --accent: #f0b84d;
  --danger: #e56767;
  --designer-cell-size: 58px;
  --component-preview-cell-size: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Segoe UI, Roboto, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: #14191d;
}

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

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

h3 {
  margin-top: 18px;
  font-size: 15px;
  color: var(--muted);
}

.topbar p,
.hint {
  margin-top: 6px;
  color: var(--muted);
}

.designer-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.designer-stats {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #12171b;
  color: var(--accent);
  font-size: 13px;
}

.tabs,
.button-row,
.section-title,
.stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tabs {
  flex-wrap: wrap;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: #71808a;
}

button.active,
button.primary {
  border-color: var(--accent);
  background: #3a3020;
  color: #fff1cf;
}

button.danger {
  border-color: #854444;
  color: #ffd6d6;
}

main {
  padding: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.planner-layout {
  display: grid;
  grid-template-columns: minmax(420px, 620px) 1fr;
  gap: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 14px;
}

.select-stack {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.reactor-previews {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: -4px 0 16px;
}

.reactor-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #12171b;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #11161a;
  color: var(--text);
}

.grid {
  display: grid;
  gap: 4px;
}

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

.large {
  width: min(100%, 520px);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid #11161a;
  border-radius: 5px;
  background: var(--off);
  color: #0d1114;
  font-size: 11px;
  font-weight: 700;
  overflow: hidden;
}

.cell.green {
  background: var(--green);
}

.cell.blue {
  background: var(--blue);
}

.cell.off {
  background: var(--off);
}

.cell.component {
  z-index: 1;
  border-color: var(--component-dark);
  background:
    linear-gradient(145deg, var(--component-light), var(--component-color) 48%, var(--component-dark));
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.32),
    inset -3px -3px 0 rgba(0, 0, 0, 0.28),
    0 5px 10px rgba(0, 0, 0, 0.28);
  color: rgba(17, 22, 26, 0.8);
}

.cell.component:hover {
  z-index: 12;
}

.cell.component::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--component-color);
  font-size: clamp(18px, 3vw, 30px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow:
    -2px -2px 0 #11161a,
    2px -2px 0 #11161a,
    -2px 2px 0 #11161a,
    2px 2px 0 #11161a,
    0 3px 0 rgba(0, 0, 0, 0.65);
  -webkit-text-stroke: 2px #11161a;
}

.cell.component::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  pointer-events: none;
}

.cell-tooltip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 20;
  max-width: 180px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 5px 8px;
  background: rgba(13, 17, 20, 0.96);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, 4px);
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.cell-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  border: 5px solid transparent;
  border-top-color: rgba(13, 17, 20, 0.96);
  transform: translateX(-50%);
}

.cell.component:hover .cell-tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.cell.component.edge-top {
  border-top-width: 4px;
}

.cell.component.edge-right {
  border-right-width: 4px;
}

.cell.component.edge-bottom {
  border-bottom-width: 4px;
}

.cell.component.edge-left {
  border-left-width: 4px;
}

.stats {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
}

.message {
  min-height: 24px;
  margin-top: 10px;
  color: var(--accent);
}

.component-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 12px;
}

.component-chip,
.selected-chip {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
  cursor: pointer;
}

.component-chip:hover {
  border-color: var(--accent);
}

.component-chip.is-selected {
  border-color: rgba(255, 255, 255, 0.78);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

.selection-count {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10;
  min-width: 28px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(17, 22, 26, 0.88);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}

.mini-grid {
  display: grid;
  gap: 3px;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
}

.component-mini-grid {
  gap: 3px;
}

.mini-cell {
  width: 16px;
  aspect-ratio: 1;
  border-radius: 3px;
  background: #47515a;
}

.component-mini-grid .mini-cell {
  width: var(--component-preview-cell-size);
}

.mini-cell.on {
  background: var(--accent);
}

.mini-cell.component-mini-cell {
  position: relative;
  border: 1px solid var(--component-dark);
  background:
    linear-gradient(145deg, var(--component-light), var(--component-color) 48%, var(--component-dark));
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.32),
    inset -2px -2px 0 rgba(0, 0, 0, 0.25);
}

.mini-cell.component-mini-cell[data-label]:not([data-label=""])::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--component-color);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  text-shadow:
    -1px -1px 0 #11161a,
    1px -1px 0 #11161a,
    -1px 1px 0 #11161a,
    1px 1px 0 #11161a,
    0 2px 0 rgba(0, 0, 0, 0.65);
  -webkit-text-stroke: 1px #11161a;
}

.mini-cell.green {
  background: var(--green);
}

.mini-cell.blue {
  background: var(--blue);
}

.mini-name {
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.field-badge {
  width: fit-content;
  max-width: 100%;
  margin: 7px auto 0;
  border: 1px solid rgba(240, 184, 77, 0.36);
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(240, 184, 77, 0.1);
  color: #ffd98b;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
}

.selected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 42px;
  margin-top: 8px;
}

.selected-chip {
  width: 128px;
  cursor: default;
}

.selected-chip button {
  display: block;
  width: 100%;
  min-height: 28px;
  margin-top: 8px;
  padding: 0 8px;
}

.editor-panel {
  max-width: 880px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.checkbox {
  grid-auto-flow: column;
  align-items: center;
  justify-content: start;
}

.checkbox input {
  width: auto;
  min-height: auto;
}

.editor-grid {
  width: min(100%, 560px);
}

#componentEditorGrid {
  max-width: 100%;
  overflow-x: auto;
}

#componentEditorGrid .cell {
  width: var(--designer-cell-size);
}

.editor-grid .cell {
  cursor: pointer;
}

@media (max-width: 920px) {
  .topbar,
  .planner-layout {
    display: block;
  }

  .tabs,
  .right-panel {
    margin-top: 16px;
  }

  .select-stack,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
