/* LED Art — a quiet light workbench; the sign is the only dark, heavy object. */

:root {
  --paper: #eceeea;
  --surface: #f6f7f4;
  --ink: #1c2220;
  --muted: #5d6762;
  --line: #d2d7d1;
  --line-strong: #b9c0b8;
  --amber: #f2a900;
  --amber-deep: #c98a00;
  --live: #1e8e5a;
  --error: #b3261e;
  --housing: #17191a;

  --wide: "wdth" 125;
  --radius-s: 6px;
  --radius-m: 10px;

  color-scheme: light;
  -webkit-tap-highlight-color: rgba(242, 169, 0, 0.25);
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  font-family: "Archivo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  touch-action: manipulation;
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.2; font-variation-settings: var(--wide); }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.skip {
  position: absolute; left: 12px; top: -60px; padding: 8px 12px; background: var(--ink); color: var(--paper);
  border-radius: var(--radius-s); z-index: 10;
}
.skip:focus { top: 12px; }

.wordmark {
  font-size: 20px;
  font-weight: 800;
  font-variation-settings: var(--wide);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.hint { color: var(--muted); font-size: 13px; }
.field-error { color: var(--error); font-size: 13px; min-height: 1.5em; }

/* ─── Controls ─────────────────────────────────────────────────────────── */

label, .field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); min-width: 0; }
.label { font-size: 13px; font-weight: 500; color: var(--muted); }

input, select, textarea, button { font: inherit; color: var(--ink); }

input:not([type="checkbox"]):not([type="range"]):not([type="color"]):not([type="file"]), select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 15px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
}
textarea { resize: vertical; line-height: 1.4; }
select { background-color: #fff; color: var(--ink); }
input::placeholder, textarea::placeholder { color: #8a938e; }

input[type="color"] {
  width: 48px; height: 40px; padding: 3px; background: #fff;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s); cursor: pointer;
}
input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }
input[type="file"] { font-size: 14px; color: var(--muted); }
input[type="file"]::file-selector-button {
  font: inherit; margin-right: 10px; padding: 8px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-s); background: #fff; color: var(--ink); cursor: pointer;
}

.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; font-weight: 400; min-height: 40px; cursor: pointer; }

button {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) { background: var(--surface); border-color: var(--ink); }
button:disabled { cursor: default; opacity: 0.55; }
button[aria-busy="true"] { cursor: progress; }
button[aria-busy="true"]::after {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 8px; vertical-align: -1px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

button.primary { background: var(--amber); border-color: var(--amber-deep); color: var(--ink); }
button.primary:hover:not(:disabled) { background: #ffb81a; border-color: var(--ink); }
button.large { min-height: 48px; padding: 10px 24px; font-size: 16px; font-variation-settings: var(--wide); }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
button.quiet:hover:not(:disabled) { background: transparent; border-color: var(--line-strong); color: var(--ink); }
button.danger { color: var(--error); }
button.danger:hover:not(:disabled) { border-color: var(--error); background: #fff; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--ink); }

/* ─── Login ────────────────────────────────────────────────────────────── */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 8px; }
.login-form .wordmark { font-size: 32px; margin-bottom: 24px; }
.login-form button { margin-top: 4px; }

/* ─── Shell ────────────────────────────────────────────────────────────── */

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "rail main";
}

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 24px;
  padding: 14px max(24px, env(safe-area-inset-right)) 14px max(24px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
}
.topbar .wordmark { margin-right: auto; }
.topbar button { white-space: nowrap; flex: none; }

.status { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-width: 0; }
.status span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: none; }
.status.live { color: var(--ink); }
.status.live .dot { background: var(--live); box-shadow: 0 0 0 3px rgba(30, 142, 90, 0.18); }
.status.lost .dot { background: var(--error); }
.status.lost { color: var(--error); }

.rail {
  grid-area: rail;
  padding: 24px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0;
}

.main {
  grid-area: main;
  padding: 28px 32px 48px;
  display: flex; flex-direction: column; gap: 32px;
  max-width: 1120px;
  min-width: 0;
  outline: none;
}

.workspace { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 40px; }
.workspace:disabled .controls, .workspace:disabled .compose { opacity: 0.5; }

/* ─── Screen list ──────────────────────────────────────────────────────── */

.screens, .found, .rows { list-style: none; margin: 0; padding: 0; }
.screens { display: flex; flex-direction: column; gap: 4px; }
.screens .empty { color: var(--muted); font-size: 14px; }

.screen {
  display: grid; grid-template-columns: 1fr auto; align-items: center;
  border-radius: var(--radius-s);
}
.screen-select {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  min-height: 52px; padding: 7px 10px; text-align: left;
  background: transparent; border: 1px solid transparent; font-weight: 600; min-width: 0;
}
.screen-select small { font-weight: 400; color: var(--muted); font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen[aria-current="true"] .screen-select { background: #fff; border-color: var(--ink); }
.screen .remove { min-height: 36px; padding: 4px 10px; color: var(--muted); background: transparent; border-color: transparent; font-weight: 500; }
.screen .remove:hover { color: var(--error); border-color: transparent; background: transparent; }
.screen.lost small { color: var(--error); }

.connect { display: flex; flex-direction: column; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }
.connect-fields { display: grid; grid-template-columns: 1fr 88px; gap: 8px; }

.found { display: flex; flex-direction: column; gap: 6px; }
.found li { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.found .what { display: flex; flex-direction: column; min-width: 0; }
.found .what small { color: var(--muted); font-size: 12.5px; }

/* ─── The sign ─────────────────────────────────────────────────────────── */

.stage { display: flex; flex-direction: column; gap: 12px; }

.sign {
  margin: 0;
  padding: clamp(12px, 2vw, 22px);
  background: var(--housing);
  border-radius: var(--radius-m);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 1px 2px rgba(28, 34, 32, 0.25), 0 18px 40px -18px rgba(28, 34, 32, 0.55);
  max-width: 100%;
  width: fit-content;
}
#preview { display: block; max-width: 100%; height: auto; image-rendering: pixelated; background: #0b0c0c; border-radius: 2px; }

.stage-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; }
.device-line { font-weight: 600; }
.device-line span + span::before { content: ""; display: inline-block; width: 1px; height: 0.9em; margin: 0 10px; vertical-align: -1px; background: var(--line-strong); }

/* ─── Controls row ─────────────────────────────────────────────────────── */

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.segmented { display: inline-flex; }
.segmented button:first-child { border-radius: var(--radius-s) 0 0 var(--radius-s); }
.segmented button:last-child { border-radius: 0 var(--radius-s) var(--radius-s) 0; margin-left: -1px; }
.brightness { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-size: 14px; font-weight: 600; }
.brightness input { width: 170px; accent-color: var(--ink); }
.brightness output { min-width: 3.5ch; font-weight: 500; color: var(--muted); }
.controls .danger { margin-left: auto; }

/* ─── Composer ─────────────────────────────────────────────────────────── */

.compose { display: flex; flex-direction: column; gap: 18px; }
.compose-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }

.tabs { display: inline-flex; gap: 2px; padding: 3px; background: #e1e4df; border-radius: 8px; }
.tabs button { min-height: 36px; border: 0; background: transparent; color: var(--muted); padding: 6px 14px; }
.tabs button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.6); color: var(--ink); }
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(28, 34, 32, 0.15); }

.size-row { display: flex; align-items: flex-end; gap: 8px; }
.size-row label { width: 96px; }
.size-row > span { padding-bottom: 9px; color: var(--muted); }

.panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 16px; max-width: 760px; }
.panel .wide { grid-column: 1 / -1; }
.checks { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 22px; }
.inline { display: flex; align-items: center; gap: 12px; }
.clock-row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 48px; gap: 10px; align-items: center; }

.send-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding-top: 6px; }
progress { width: 220px; height: 8px; accent-color: var(--ink); }

/* ─── Files, advanced, activity ────────────────────────────────────────── */

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.rows li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.rows li:last-child { border-bottom: 1px solid var(--line); }
.rows .name { font-weight: 600; overflow-wrap: anywhere; }
.rows .size { color: var(--muted); font-size: 13px; }
.rows .empty { display: block; color: var(--muted); font-size: 14px; }

details > summary {
  cursor: pointer; list-style: none; font-weight: 700; font-variation-settings: var(--wide);
  display: flex; align-items: center; gap: 8px; min-height: 40px; width: fit-content;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s;
}
details[open] > summary::before { transform: rotate(45deg); }

.raw { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; margin-top: 12px; max-width: 760px; }
.raw .wide { grid-column: 1 / -1; }
pre {
  margin: 0; padding: 12px; max-height: 300px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-s);
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
pre:empty { display: none; }

.activity { border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); }
.log { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 3px; max-height: 240px; overflow: auto; }
.log time { color: var(--muted); margin-right: 10px; }
.log .ok { color: var(--ink); }
.log .err { color: var(--error); }

/* ─── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 16px; border-radius: 8px;
  background: var(--ink); color: var(--paper); font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(28, 34, 32, 0.6);
  animation: toast-in 0.18s ease-out;
}
.toast.err { background: var(--error); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ─── Protocol variants ────────────────────────────────────────────────── */

body.gen6 .sdk2-only, body.remote .local-only { display: none !important; }
body:not(.gen6) .gen6-only { display: none !important; }

/* ─── Small screens ────────────────────────────────────────────────────── */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "rail" "main"; grid-template-rows: auto auto 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
  .main { padding: 20px 16px 32px; }
  .topbar { padding: 12px 16px; gap: 12px; }
  .topbar .status span:last-child { max-width: 46vw; }
  .controls .danger { margin-left: 0; }
  .clock-row { grid-template-columns: 110px minmax(0, 1fr) 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
