:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-strong: #f0f4f7;
  --text: #18212b;
  --muted: #5e6b78;
  --line: #c8d2dc;
  --line-strong: #7f8d9a;
  --accent: #126f84;
  --accent-strong: #0c596a;
  --accent-soft: #d9f0f4;
  --warn: #8a5a00;
  --warn-bg: #fff5dc;
  --error: #9f2c2c;
  --error-bg: #fde8e8;
  --empty: #e9edf1;
  --button-fill: #e8f4f6;
  --button-line: #5ca6b5;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
.file-button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 0 12px;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

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

button.primary {
  border-color: var(--accent-strong);
  background: var(--accent);
  color: white;
}

button.primary:hover {
  background: var(--accent-strong);
}

.app-header {
  display: flex;
  align-items: center;
  min-height: 78px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.app-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.input-panel,
.output-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.input-panel {
  display: grid;
  grid-template-rows: auto auto auto;
  min-height: calc(100vh - 110px);
}

.output-panel {
  padding-bottom: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

h2,
h3 {
  margin: 0;
  font-weight: 700;
}

h2 {
  font-size: 16px;
}

.panel-help {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

h3 {
  font-size: 14px;
  padding: 12px 12px 8px;
}

.file-input {
  display: none;
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.input-source {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px 12px;
}

.source-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
}

.source-heading h3 {
  padding: 0;
  font-size: 14px;
}

.db-source {
  background: #f6f9fb;
}

.drop-zone {
  display: grid;
  gap: 4px;
  border: 2px dashed var(--line-strong);
  border-radius: 8px;
  background: #f7fbfc;
  cursor: pointer;
  padding: 16px;
  text-align: center;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-over,
.drop-zone.loaded {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.drop-zone-title {
  font-size: 15px;
  font-weight: 800;
}

.drop-zone-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.linked-upload-row {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.linked-drop-zone {
  min-height: 124px;
  align-content: center;
}

.linked-drop-zone .file-button {
  justify-self: center;
  margin-top: 8px;
}

.upload-connector {
  width: 2px;
  height: 24px;
  justify-self: center;
  background: var(--line-strong);
  position: relative;
}

.upload-connector::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--line-strong);
  border-bottom: 2px solid var(--line-strong);
  transform: translateX(-50%) rotate(45deg);
  background: transparent;
}

.input-options {
  padding: 11px 12px;
  color: var(--muted);
  font-size: 13px;
}

.input-options label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.messages {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.message {
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 13px;
  line-height: 1.4;
}

.message.note {
  border: 1px solid #d9bd72;
  background: var(--warn-bg);
  color: var(--warn);
}

.message.error {
  border: 1px solid #e2a2a2;
  background: var(--error-bg);
  color: var(--error);
}

.layout-board,
.strings-board,
.conditions-board {
  border-top: 1px solid var(--line);
}

.board-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
}

.board-heading h3 {
  padding: 0;
}

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

.modules {
  overflow-x: auto;
  padding: 0 12px 12px;
}

.layout-editor {
  display: grid;
  gap: 10px;
  min-width: 1060px;
}

.holding-tray {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  overflow: hidden;
}

.holding-title {
  display: grid;
  align-content: center;
  gap: 5px;
  border-right: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 10px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.overflow-tray .holding-title {
  background: var(--error-bg);
  color: var(--error);
}

.holding-help {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
}

.holding-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.holding-lane {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding: 8px;
}

.holding-empty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.holding-switch {
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex: 0 0 82px;
  height: 64px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--button-fill);
  cursor: grab;
  overflow: hidden;
}

.holding-switch .slot-content {
  gap: 4px;
  padding: 5px;
}

.holding-switch .slot-image {
  max-height: 34px;
  max-width: 30px;
}

.holding-switch .slot-name {
  max-height: 22px;
  overflow: hidden;
  font-size: 9px;
  line-height: 1.1;
}

.overflow-tray .holding-switch {
  flex-basis: 112px;
  height: 72px;
}

.overflow-tray .holding-switch .slot-name {
  max-height: 34px;
}

.library-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 10px;
}

.library-header {
  display: grid;
  grid-template-columns: auto auto minmax(180px, 280px);
  align-items: center;
  justify-content: start;
  gap: 8px;
}

.library-title {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.library-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.library-search {
  min-height: 32px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 9px;
  font: inherit;
}

.library-help,
.library-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.library-lane {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 70px;
  min-width: 0;
  overflow-x: auto;
}

.library-switch {
  background: #f0f7f5;
}

.dashboard-map {
  position: relative;
  min-width: 1060px;
  height: 640px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#eef2f5 1px, transparent 1px),
    linear-gradient(90deg, #eef2f5 1px, transparent 1px),
    #fbfcfd;
  background-size: 24px 24px;
  overflow: hidden;
}

.solenoid-module {
  min-width: 1060px;
  border: 2px solid #52606d;
  border-radius: 7px;
  box-shadow: 0 1px 2px rgba(24, 33, 43, 0.12);
}

.solenoid-module .module-title {
  min-height: 30px;
  padding: 6px 8px;
  background: #edf6f8;
  color: var(--accent-strong);
}

.solenoid-module .module-title span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.solenoid-slot-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  background: #fbfcfd;
}

.solenoid-slot-group {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.solenoid-slot-group:first-child {
  border-left: 0;
}

.solenoid-slot-group:last-child {
  border-right: 0;
}

.solenoid-slot {
  grid-template-rows: 24px 96px;
  min-height: 120px;
}

.solenoid-slot .slot-content {
  justify-content: space-between;
}

.solenoid-word {
  color: var(--accent-strong);
  font:
    11px/1.2 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.dashboard-map::before {
  content: "";
  position: absolute;
  inset: 16px 20px 18px 20px;
  border: 2px solid rgba(83, 95, 108, 0.55);
  border-radius: 10px 10px 4px 4px;
  clip-path: polygon(0 0, 100% 0, 97% 100%, 26% 100%, 21% 45%, 0 38%);
}

.module {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.dashboard-module {
  position: absolute;
  z-index: 1;
  border: 2px solid #52606d;
  border-radius: 7px;
  box-shadow: 0 1px 2px rgba(24, 33, 43, 0.12);
}

.dashboard-lcm {
  top: 24px;
  left: 20px;
  width: 190px;
}

.dashboard-mux1 {
  top: 146px;
  left: 288px;
  width: 360px;
}

.dashboard-mux2 {
  top: 350px;
  left: 328px;
  width: 360px;
}

.dashboard-mux3 {
  top: 232px;
  left: 704px;
  width: 340px;
}

.dashboard-mux4 {
  top: 24px;
  left: 704px;
  width: 340px;
}

.module-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
  font-size: 13px;
  font-weight: 700;
}

.dashboard-module .module-title {
  min-height: 30px;
  padding: 6px 8px;
  background: #edf6f8;
  color: var(--accent-strong);
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(var(--slot-count), minmax(0, 1fr));
}

.slot {
  display: grid;
  grid-template-rows: 24px 118px;
  min-height: 142px;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--button-fill);
}

.slot[draggable="true"] {
  cursor: grab;
}

.slot[draggable="true"]:active,
.holding-switch:active {
  cursor: grabbing;
}

.slot.dragging,
.holding-switch.dragging {
  opacity: 0.48;
}

.slot.drop-target,
.holding-tray.drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.slot.drop-target {
  background: var(--accent-soft);
}

.holding-tray.drop-target .holding-lane {
  background: var(--accent-soft);
}

.modal-backdrop {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(24, 33, 43, 0.38);
  padding: 18px;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  display: grid;
  gap: 12px;
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(24, 33, 43, 0.22);
  padding: 16px;
}

.modal h2 {
  font-size: 16px;
}

.modal p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.slot:last-child {
  border-right: 0;
}

.slot.empty {
  background: var(--empty);
}

.slot.empty.drop-target {
  background: var(--accent-soft);
}

.slot-id {
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.slot-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  padding: 6px;
}

.slot-image {
  flex: 0 0 auto;
  max-height: 58px;
  max-width: 42px;
  object-fit: contain;
}

.slot-name {
  display: block;
  max-width: 100%;
  min-width: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-align: center;
}

.slot-badge {
  max-width: 100%;
  border: 1px solid #9bb7bf;
  border-radius: 999px;
  color: var(--accent-strong);
  background: #eef8f8;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  padding: 3px 6px;
  text-transform: uppercase;
}

.slot.has-switch-image .slot-name {
  max-height: 48px;
  overflow: hidden;
  font-size: 10px;
  line-height: 1.15;
}

.slot.empty .slot-name {
  color: #7a8793;
  font-weight: 600;
}

.strings-list,
.switch-conditions-list {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.string-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.string-label {
  padding-top: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.string-value {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font:
    12px/1.45 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.switch-conditions {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  overflow: hidden;
}

.switch-condition-row {
  display: grid;
  grid-template-columns: 58px minmax(180px, 0.8fr) minmax(260px, 1.2fr);
  gap: 10px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.switch-condition-row:last-child {
  border-bottom: 0;
}

.switch-condition-header {
  background: #f6f9fb;
  color: var(--muted);
  font-weight: 800;
}

.switch-condition-priority,
.switch-condition-source {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.switch-condition-name,
.switch-condition-source {
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app-header,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions {
    flex-wrap: wrap;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .input-panel {
    min-height: 520px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 10px;
  }

  .string-row {
    grid-template-columns: 1fr;
  }

  .switch-condition-row {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .switch-condition-header {
    display: none;
  }

  .switch-condition-source {
    grid-column: 2;
  }
}

@media (max-width: 480px) {
  .linked-upload-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .upload-connector {
    justify-self: center;
    width: 2px;
    height: 28px;
  }

  .upload-connector::after {
    right: auto;
    top: auto;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%) rotate(135deg);
  }
}
