:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-alt: #eef2ee;
  --ink: #1d2524;
  --muted: #65706c;
  --line: #d8ded9;
  --accent: #16836f;
  --accent-strong: #0c6656;
  --amber: #bf7814;
  --danger: #b03b3b;
  --shadow: 0 10px 30px rgba(35, 47, 42, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover:not(:disabled),
.file-button:hover {
  border-color: #9eb3aa;
  background: #f8faf8;
}

button:disabled {
  cursor: not-allowed;
  color: #9aa39f;
  background: #eef1ef;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

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

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 76px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  position: sticky;
  top: 0;
  z-index: 5;
}

.browser-warning {
  margin: 14px 18px 0;
  padding: 12px 14px;
  border: 1px solid rgba(176, 59, 59, 0.35);
  border-left: 5px solid var(--danger);
  border-radius: 8px;
  background: #fff1f1;
  color: var(--ink);
  box-shadow: 0 4px 16px rgba(176, 59, 59, 0.1);
}

.browser-warning strong {
  display: block;
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 4px;
}

.browser-warning span {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 230px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  object-fit: contain;
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.15;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.baud-field,
.select-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.select-field select {
  width: auto;
  min-width: 118px;
}

.language-field {
  margin-left: 8px;
}

.pushbox-type-field {
  align-items: stretch;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px 10px;
  border: 1px solid rgba(22, 131, 111, 0.28);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #eef8f4;
  color: var(--accent-strong);
  font-weight: 800;
}

.pushbox-type-field span {
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
}

.pushbox-type-field select {
  min-width: 160px;
  min-height: 42px;
  border-color: rgba(22, 131, 111, 0.38);
  color: var(--ink);
  font-weight: 800;
}

.baud-field input {
  width: 96px;
}

.workspace {
  display: grid;
  grid-template-columns: 250px minmax(320px, 1fr) 10px minmax(320px, var(--device-panel-width, 430px));
  gap: 14px;
  padding: 18px;
  flex: 1;
}

.production-workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(320px, 420px);
  gap: 18px;
  padding: 18px;
  flex: 1;
}

.production-form {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.nav-link {
  min-height: 38px;
  display: grid;
  place-items: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
}

.production-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.production-list-item {
  display: grid;
  gap: 4px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.production-list-item strong {
  color: var(--ink);
}

.production-list-edit {
  grid-template-columns: 1fr;
  display: grid;
  gap: 7px;
}

.production-list-edit label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.production-list-edit input {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 13px;
  text-transform: none;
}

.production-list-edit button {
  min-height: 32px;
  padding: 6px 10px;
}

.production-list-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-column,
.editor,
.device-panel {
  min-width: 0;
}

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

.column-heading,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.column-heading {
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.column-heading button {
  min-height: 32px;
  padding: 0 10px;
}

.button-list {
  display: grid;
  gap: 8px;
}

.help-button {
  width: 100%;
  margin-top: auto;
}

.button-card {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(37, 51, 46, 0.04);
  cursor: pointer;
  min-height: 66px;
}

.button-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(22, 131, 111, 0.14);
}

.button-number {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--surface-alt);
  font-weight: 800;
}

.button-meta {
  min-width: 0;
}

.button-meta strong {
  display: block;
  font-size: 14px;
}

.button-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swatches {
  display: flex;
  gap: 4px;
  margin-top: 7px;
}

.swatch {
  width: 22px;
  height: 8px;
  border-radius: 99px;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

.editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.section-title {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: block;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.section-title h2 {
  margin-top: 3px;
  font-size: 22px;
}

.selected-preview {
  width: 96px;
  height: 58px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #d8d9d4;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.18);
}

.selected-preview::before {
  content: "";
  position: absolute;
  width: 40px;
  height: 40px;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: var(--preview-color, #fff);
  opacity: var(--preview-opacity, 1);
  box-shadow:
    0 0 22px var(--preview-color, #fff),
    inset 0 -6px 10px rgba(0, 0, 0, 0.16);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.2fr);
  gap: 14px;
  margin-top: 16px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

legend {
  padding: 0 6px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-alt);
  margin-bottom: 12px;
}

.segmented button {
  border-color: transparent;
  min-height: 34px;
  padding: 0 8px;
  background: transparent;
}

.segmented button.active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

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

textarea {
  min-height: 78px;
  resize: vertical;
  line-height: 1.35;
}

.action-panel {
  display: none;
}

.action-panel.active {
  display: grid;
  gap: 12px;
}

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

.modifier-row label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
}

.modifier-row input {
  width: auto;
  min-height: auto;
}

.key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.state-editor {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.state-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.state-tabs button.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: #eef8f4;
}

.state-grid {
  display: grid;
  grid-template-columns: 130px minmax(150px, 1fr) minmax(150px, 1fr) 70px minmax(150px, 1fr) 70px;
  align-items: end;
  gap: 12px;
}

input[type="color"] {
  padding: 3px;
}

input[type="range"] {
  padding-left: 0;
  padding-right: 0;
}

#brightnessOutput,
#periodOutput {
  color: var(--muted);
  font-weight: 800;
  min-height: 38px;
  display: grid;
  align-items: center;
}

.preview-strip {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(var(--button-count, 6), minmax(0, 1fr));
  gap: 8px;
}

.preview-button {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #d3d4d0;
  position: relative;
  overflow: hidden;
  display: block;
  color: #202423;
  font-weight: 800;
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.preview-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--led-color);
  opacity: var(--led-opacity);
  box-shadow:
    0 0 22px var(--led-color),
    inset 0 -6px 10px rgba(0, 0, 0, 0.16);
}

.preview-number {
  position: absolute;
  right: 12px;
  bottom: 9px;
  line-height: 1;
  font-size: 16px;
}

.preview-button.signature-preview .preview-dot {
  animation-duration: var(--led-period, 1000ms);
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

.preview-button.signature-preview[data-mode="0"] .preview-dot,
.preview-button.signature-preview[data-mode="1"] .preview-dot {
  opacity: var(--led-opacity);
}

.preview-button.signature-preview[data-mode="2"] .preview-dot {
  animation-name: preview-blink;
}

.preview-button.signature-preview[data-mode="3"] .preview-dot {
  animation-name: preview-pulse;
}

.preview-button.signature-preview[data-mode="4"] .preview-dot {
  animation-name: preview-double-flash;
}

.preview-button.signature-preview[data-mode="5"] .preview-dot {
  animation-name: preview-rainbow;
}

@keyframes preview-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.08;
  }
}

@keyframes preview-pulse {
  0%,
  100% {
    opacity: 0.18;
    filter: brightness(0.45);
  }
  50% {
    opacity: 1;
    filter: brightness(1.2);
  }
}

@keyframes preview-double-flash {
  0%,
  12%,
  28%,
  40% {
    opacity: 1;
  }
  13%,
  27%,
  41%,
  100% {
    opacity: 0.08;
  }
}

@keyframes preview-rainbow {
  from {
    filter: hue-rotate(0deg) brightness(1.15);
  }
  to {
    filter: hue-rotate(360deg) brightness(1.15);
  }
}

.device-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.splitter {
  width: 10px;
  min-height: 100%;
  border-radius: 8px;
  cursor: col-resize;
  position: relative;
  touch-action: none;
}

.splitter::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 4px;
  width: 2px;
  border-radius: 99px;
  background: var(--line);
}

.splitter:hover::before,
.splitter.active::before {
  background: var(--accent);
}

body.resizing-split {
  cursor: col-resize;
  user-select: none;
}

.panel-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  display: grid;
  gap: 8px;
}

.panel-block h2 {
  font-size: 15px;
  margin-bottom: 2px;
}

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

.device-info {
  display: grid;
  gap: 7px;
  margin: 0 0 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.device-info div {
  display: grid;
  grid-template-columns: minmax(105px, 0.85fr) minmax(0, 1.15fr);
  gap: 8px;
}

.device-info dt,
.device-info dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.25;
}

.device-info dt {
  color: var(--muted);
  font-weight: 800;
}

.device-info dd {
  color: var(--ink);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.hint-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.hint-list li + li {
  margin-top: 6px;
}

.help-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgba(18, 25, 22, 0.42);
}

.help-dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.help-dialog-head h2 {
  font-size: 18px;
}

.manual-content {
  padding: 16px;
  overflow: auto;
}

.manual-content section + section {
  margin-top: 18px;
}

.manual-content h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.manual-content p,
.manual-content ol {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.manual-content p + p {
  margin-top: 7px;
}

.manual-content ol {
  padding-left: 20px;
}

.manual-content li + li {
  margin-top: 4px;
}

.file-button {
  border: 1px solid var(--line);
  border-radius: 7px;
  min-height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: var(--surface);
}

.file-button input {
  display: none;
}

#log {
  height: 230px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: 7px;
  background: #17211e;
  color: #dbf1e7;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.ok {
  color: var(--accent-strong);
}

.warn {
  color: var(--amber);
}

.error {
  color: var(--danger);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 220px minmax(360px, 1fr);
  }

  .splitter {
    display: none;
  }

  .device-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #log {
    height: 160px;
  }
}

@media (max-width: 780px) {
  .topbar,
  .workspace {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .top-actions button,
  .baud-field,
  .select-field {
    width: 100%;
  }

  .select-field select {
    flex: 1;
  }

  .pushbox-type-field {
    flex-direction: row;
    align-items: center;
  }

  .language-field {
    margin-left: 0;
  }

  .workspace,
  .production-workspace,
  .form-grid,
  .state-grid,
  .device-panel {
    grid-template-columns: 1fr;
  }

  .button-list,
  .preview-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
