:root {
  /* Follows the system unless the toggle set data-theme (see js/theme.js).
     Each colour is light-dark(light value, dark value). */
  color-scheme: light dark;
  --bg: light-dark(#e9e7e1, #161618);
  --card: light-dark(#f6f4ef, #232326);
  --field: light-dark(#fbfaf7, #232326); /* inputs, dropdowns, buttons */
  --text: light-dark(#2a2a2c, #ececef);
  --muted: light-dark(#6f6c66, #9a9aa0);
  --line: light-dark(#d6d3ca, #3a3a3f);
  --accent: light-dark(#7c3aed, #9f63ff);
  --warn: light-dark(#b3261e, #ff8a80);
  --screen: light-dark(#b5b3ad, #000000);
  --bezel: #7c3aed;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

a { color: var(--accent); }

/* Top bar */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 1.35rem; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.controls label { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.3rem 0.45rem;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button { cursor: pointer; }
#copy { background: var(--accent); border-color: var(--accent); color: #fff; }
.quiet { background: transparent; }

/* Cards */
main { padding: 1.25rem; }
#cards {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  max-width: 100%;
}
.card-head { display: flex; gap: 0.5rem; align-items: center; }
.name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 1.05rem;
  border-color: transparent;
  background: transparent;
  padding-left: 0.2rem;
}
.name::placeholder { color: var(--text); opacity: 1; text-overflow: ellipsis; }
.name { text-overflow: ellipsis; } /* a narrow card shows "Monitor 27"…" */
.name:hover { border-color: var(--line); }
.remove {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
}
.remove:hover { background: var(--bg); color: var(--text); }

/* Every stage is the same height, so screens share a bottom edge and scale. */
.stage {
  height: var(--stage-h, 150px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin: 0.75rem 0 0.35rem;
}
.screen {
  background: var(--screen);
  outline: 3px solid var(--bezel);
  display: flex;
  overflow: hidden;
}
.screen[hidden] { display: none; }
/* While something is hidden, each screen is the button that reveals it, so
   it carries a small label saying so. view.js sets data-hint from the
   screen's drawn size: full label, icon only, or nothing. */
.screen { position: relative; }
:is(.compact, .no-stats) .screen:not([data-hint=none])::after {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 1px 7px 2px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.68);
  color: #fff;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
}
.no-stats .screen::after { content: 'ⓘ Stats'; }
.compact .screen::after { content: 'ⓘ Details'; }
:is(.compact, .no-stats) .card.open .screen::after { content: '✕ Hide'; background: var(--accent); }
:is(.compact, .no-stats) .screen[data-hint=icon]::after { content: 'ⓘ'; right: 3px; bottom: 3px; padding: 0 5px 1px; }
:is(.compact, .no-stats) .card.open .screen[data-hint=icon]::after { content: '✕'; }
.stage:hover .screen::after { background: var(--accent); }
.screen[data-hint=none]::after { content: none !important; }
.screen img { width: 100%; height: 100%; object-fit: contain; }
.screen img[hidden] { display: none; }
.caption { margin: 0.4rem 0 0.6rem; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* Drag a screen to reorder: the dragged card fades, and a bar in the gap
   between cards shows where it will land. */
.stage[draggable=true] { cursor: grab; }
.card { position: relative; }
.card.dragging { opacity: 0.4; }
.card.drop-before::before, .card.drop-after::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 2px;
  background: var(--accent);
}
.card.drop-before::before { left: calc(-0.5rem - 3px); } /* middle of the 1rem gap */
.card.drop-after::after { right: calc(-0.5rem - 3px); }

.fields {
  display: grid;
  gap: 0.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
}
.fields > label {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  white-space: nowrap;
  align-items: center;
  color: var(--muted);
}
/* width 0 + min-width 100%: a dropdown fills its column but never widens the
   card to fit its longest option (the open list still shows it in full). */
.fields select { width: 0; min-width: 100%; }
.fields input:not([type=checkbox]) { width: 4.5rem; }
.fields input[data-f=an], .fields input[data-f=ad] { width: 3.5rem; }
.fields input[data-f=pw], .fields input[data-f=ph] { width: 4.25rem; }
.fields input[data-f=zones] { width: 5.5rem; }
.with-unit, .pair { display: flex; align-items: center; gap: 0.35rem; }
.pair { padding-left: 7.5rem; }
.unit { color: var(--muted); }
.check { display: flex; align-items: center; gap: 0.3rem; margin-left: 0.4rem; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.5rem;
  /* Fill the card but never widen it: a long value wraps instead. */
  width: 0;
  min-width: 100%;
  margin: 0.75rem 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; }
/* Invisible stand-ins for the Image rows while no sample image is chosen. */
.stats .ghost { visibility: hidden; }
.stats .nw { white-space: nowrap; }
.warn { color: var(--warn); margin: 0.6rem 0 0; font-size: 0.9rem; max-width: 18rem; }

.add {
  min-width: 7rem;
  min-height: 8rem;
  align-self: stretch;
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
}
.add:hover { color: var(--accent); border-color: var(--accent); }
.add[hidden] { display: none; }

/* Compact mode: too many displays to fit, so show just the screens.
   Clicking a screen opens or closes that card's details. */
.compact .card { position: relative; width: auto; min-width: 7rem; padding: 0.6rem; }
.compact .card:not(.open) .details { display: none; }
/* An open card shows its details inside itself and grows to fit them; the
   cards after it move along to make room. Any number can be open. */
.compact .card.open .details { padding-top: 0.6rem; }
.compact .card.open { outline: 2px solid var(--accent); }
.compact .card-head, .compact .caption { contain: inline-size; }
.compact .name { width: 0; font-size: 0.95rem; }
.compact .stage { cursor: pointer; margin-top: 0.4rem; }
.compact .caption { margin-bottom: 0; font-size: 0.8rem; }
.compact .add { min-width: 3rem; min-height: 0; padding: 0 0.6rem; }

/* Stats hidden: the window is too short for full cards, so cards keep their
   screens and controls and drop the stats. Clicking a screen shows or hides
   that card's stats, inside the card, exactly where a full card has them. */
.no-stats .card:not(.open) .info { display: none; }
.no-stats .stage { cursor: pointer; }
.no-stats .card.open { outline: 2px solid var(--accent); }

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
#toast.show { opacity: 1; }

footer {
  padding: 1.5rem 1.25rem 2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 480px) {
  main { padding: 0.75rem; }
  .card { min-width: 0; width: 100%; }
  .fields > label { grid-template-columns: minmax(0, 1fr); gap: 0.15rem; }
  .pair { padding-left: 0; }
}
