/* Flat and calm: one muted accent, quiet surfaces. The keypad plate stays dark in
   both themes because it depicts the real board, where lit keys glow. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e7;
  --text: #1c222a;
  --muted: #5c6776;
  --accent: #3a5fcf;
  --accent-soft: #e6ecfb;
  --accent-text: #ffffff;
  --danger: #c23b3b;
  --danger-soft: #fbeaea;
  --warn: #9a6200;
  --warn-soft: #fdf3e1;
  --ok: #1e7f55;
  --ok-soft: #e5f4ec;
  --plate: #14171c;
  --plate-edge: #262b33;
  --key-off: #262b33;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #161a20;
    --surface-2: #1d222a;
    --border: #2a3039;
    --text: #e5e8ed;
    --muted: #98a2b0;
    --accent: #7d9bff;
    --accent-soft: #1f2840;
    --accent-text: #0c1222;
    --danger: #ff7b7b;
    --danger-soft: #3a1f22;
    --warn: #f0b84c;
    --warn-soft: #362a14;
    --ok: #5fd39c;
    --ok-soft: #15301f;
    --plate: #0b0d10;
    --plate-edge: #22272f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea { font: inherit; color: inherit; }
kbd, code { font-family: var(--mono); font-size: 0.92em; }
a { color: var(--accent); }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
h3 { font-size: 12px; margin: 18px 0 8px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--plate);
  background-image:
    radial-gradient(circle at 30% 30%, #7c9cff 0 3px, transparent 3.5px),
    radial-gradient(circle at 70% 30%, #ff9d00 0 3px, transparent 3.5px),
    radial-gradient(circle at 30% 70%, #00b39b 0 3px, transparent 3.5px),
    radial-gradient(circle at 70% 70%, #ff3d6e 0 3px, transparent 3.5px);
}
.conn { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 7px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.status[data-state="on"]::before { background: var(--ok); }
.status[data-state="busy"]::before { background: var(--warn); }
.status[data-state="bad"]::before { background: var(--danger); }

/* Buttons and fields */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn.icon { padding: 3px 8px; min-width: 30px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn.recording { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="text"], input[type="number"], select, textarea {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 9px;
  min-width: 0;
}
textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 13px; }
input[type="color"] { width: 42px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .label { font-weight: 600; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: 12.5px; }
.error-text { color: var(--danger); font-size: 12.5px; }

/* Banners and toasts */

.banners { display: grid; gap: 8px; padding: 0 20px; max-width: 1240px; width: 100%; margin: 12px auto 0; }
.banners:empty { display: none; }
.banner {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--surface);
  display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.banner.warn { background: var(--warn-soft); border-color: transparent; }
.banner.danger { background: var(--danger-soft); border-color: transparent; }
.banner.info { background: var(--accent-soft); border-color: transparent; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--text); color: var(--bg);
  border-radius: 8px; padding: 9px 13px; font-size: 13px;
  animation: toast-in 0.15s ease-out;
}
.toast.bad { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 440px) minmax(0, 1fr);
  gap: 20px;
  padding: 16px 20px 24px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 20px; }
  .topbar { padding: 10px 16px; }
  .banners { padding: 0 16px; }
}

.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 16px 18px; }

/* Layer tabs */

.layer-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.layer-tab {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.layer-tab[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.layer-tab .live { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.layer-tab.add { color: var(--muted); }

/* Keypad */

.pad {
  background: var(--plate);
  border: 1px solid var(--plate-edge);
  border-radius: 18px;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.key {
  --led: #000000;
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--key-off);
  color: #f4f6f9;
  cursor: pointer;
  padding: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-align: center;
  overflow: hidden;
  transition: transform 0.08s ease, filter 0.08s ease;
}
.key.lit {
  background: radial-gradient(circle at 50% 46%,
    color-mix(in srgb, var(--led) 92%, #fff) 0%,
    color-mix(in srgb, var(--led) 72%, var(--key-off)) 46%,
    color-mix(in srgb, var(--led) 30%, var(--key-off)) 100%);
}
.key-label { font-weight: 650; font-size: 12.5px; line-height: 1.15; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55); overflow-wrap: anywhere; }
.key-desc { font-size: 11px; opacity: 0.85; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-num { position: absolute; top: 5px; left: 7px; font-size: 11px; font-weight: 600; opacity: 0.7; font-family: var(--mono); }
.key.selected { outline: 3px solid var(--accent); outline-offset: 3px; }
.key.down { transform: scale(0.95); filter: brightness(1.45); }
.key.down:not(.lit) { background: #4a525e; }
.key.invalid::after { content: "!"; position: absolute; top: 4px; right: 6px; width: 16px; height: 16px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; }
@media (max-width: 420px) {
  .pad { padding: 10px; gap: 7px; }
  .key-desc { display: none; }
  .key-label { font-size: 11px; }
}

.pick { display: flex; gap: 8px; align-items: center; margin: 12px 2px 0; color: var(--muted); font-size: 13px; cursor: pointer; }
.pick input { accent-color: var(--accent); }
.pick.disabled { opacity: 0.5; cursor: not-allowed; }

.savebar { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.save-state { flex: 1; color: var(--muted); font-size: 13px; }
.save-state.dirty { color: var(--warn); font-weight: 600; }
.validation { margin: 10px 0 0; padding: 9px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* Editor panel */

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; min-width: 0; }
.tabs { display: flex; gap: 2px; padding: 6px 6px 0; border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.panel-body { padding: 18px; }
@media (max-width: 420px) { .panel-body { padding: 14px; } }

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

.segmented { display: flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; width: fit-content; max-width: 100%; }
.segmented button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; padding: 0; }
.swatch.off { background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, var(--surface) 4px 8px); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }

.editor { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; background: var(--surface-2); margin-top: 10px; }
.editor .field:last-child { margin-bottom: 0; }

.combo { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 2px 4px 2px 8px; font-size: 13px;
}
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 14px; line-height: 1; }
.combo-preview { font-family: var(--mono); font-size: 16px; padding: 4px 10px; border-radius: 7px; background: var(--surface); border: 1px solid var(--border); min-width: 44px; text-align: center; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.step { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 8px; align-items: start; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 8px; }
.step-num { color: var(--muted); font-size: 12px; padding-top: 7px; text-align: right; }
.step-body { display: grid; gap: 6px; min-width: 0; }
.step-tools { display: flex; gap: 2px; }
.step-tools .btn { padding: 2px 7px; }
.step.invalid { border-color: var(--danger); }

.info-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.info-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 5px 12px 5px 0; width: 42%; vertical-align: top; }
.info-table td { padding: 5px 0; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.1s; }

.actions-list { display: grid; gap: 10px; }
.action-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; align-items: start; }
.action-row .btn { min-width: 170px; }
@media (max-width: 520px) { .action-row { grid-template-columns: minmax(0, 1fr); } }

details { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-top: 16px; }
details summary { cursor: pointer; font-weight: 600; }
details ol { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 6px; }

.empty { color: var(--muted); padding: 20px 0; text-align: center; }
