/* LED Blink Simulator — styles. No external fonts or assets.
 * Colours are tokens on :root (light) with a dark override; every pair used for
 * text or controls was checked against WCAG 2.2 AA contrast. */

/* ---------- Colour tokens ---------- */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1b1e24;
  --muted: #5b6270;
  --line: #d9dde4;
  --field-line: #767e8c;
  --accent: #0b63ce;
  --accent-ink: #ffffff;
  --field: #ffffff;
  --scope-bg: #0f1419;
  --scope-grid: #233040;
  --scope-pin: #7cc4ff;
  --scope-led: #ffd166;
  --scope-text: #9fb1c4;
  --err-bg: #fdecec; --err-line: #d93025; --err-ink: #8c1d18;
  --warn-bg: #fff6e0; --warn-line: #e3a008; --warn-ink: #6b4a00;
  --info-bg: #eaf2fd; --info-line: #6b9bd8; --info-ink: #1f3f68;
  --wire: #1b1e24;
  --bar-on: #a26a00;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1e24;
    --ink: #e7e9ee;
    --muted: #9aa3b2;
    --line: #2e3440;
    --field-line: #788396;
    --accent: #5aa2ff;
    --accent-ink: #0b0d10;
    --field: #12161b;
    --scope-bg: #0b0f13;
    --scope-grid: #1f2a36;
    --err-bg: #3a1716; --err-line: #f28b82; --err-ink: #ffd6d2;
    --warn-bg: #3a2e10; --warn-line: #fdd663; --warn-ink: #ffefc2;
    --info-bg: #15263b; --info-line: #8ab4f8; --info-ink: #d2e3fc;
    --wire: #e7e9ee;
    --bar-on: #ffb84d;
    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.1rem; }
p { margin: 0 0 .6rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }

/* ---------- Page header and footer (sources list) ---------- */
.site-head, .site-foot { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px .5rem; }
.site-head p { color: var(--muted); margin: 0; }
/* Language links: a small wrapping row above the title. Targets stay 24 px+ tall (WCAG 2.5.8). */
.langs ul { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-wrap: wrap; gap: .1rem .9rem; font-size: .9rem; }
.langs a { display: inline-block; min-height: 24px; line-height: 24px; color: var(--accent); }
.langs a[aria-current="page"] { color: var(--ink); font-weight: 600; text-decoration: none; }
.site-foot { padding-bottom: 2rem; color: var(--muted); font-size: .9rem; }
.site-foot a { color: var(--accent); }
.src-head { font-size: .95rem; margin: 1.2rem 0 .4rem; color: var(--ink); }
.sources { margin: 0 0 .8rem; padding-left: 1.4rem; font-size: .8rem; columns: 2 320px; column-gap: 2rem; }
.sources li { margin-bottom: .55rem; line-height: 1.5; break-inside: avoid; }

/* ---------- Layout: one column on phones, two columns from 900 px ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: grid; gap: 16px; }

.layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(320px, 5fr) minmax(0, 7fr);
    grid-template-areas:
      "inputs preview"
      "inputs results";
    align-items: start;
  }
  .preview { grid-area: preview; }
  .inputs  { grid-area: inputs; }
  .results { grid-area: results; }
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

/* ---------- Form ---------- */

fieldset { border: 0; padding: 0; margin: 0 0 1.1rem; min-width: 0; }
legend { font-weight: 650; padding: 0; margin-bottom: .5rem; }

label { display: block; margin-bottom: .65rem; font-size: .92rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: .2rem; }

input[type=number], input[type=text], select, textarea {
  display: block;
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 7px;
  padding: .45rem .55rem;
  min-height: 2.4rem;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; resize: vertical; }
input[type=range] { width: 100%; margin: 0 0 .3rem; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; margin: 0 .35rem 0 0; vertical-align: -2px; }

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

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.pair > label { min-width: 0; }
@media (max-width: 380px) { .pair { grid-template-columns: 1fr; } }

label.check { display: flex; align-items: center; color: var(--ink); min-height: 2.4rem; margin-bottom: .4rem; }

.seg { display: flex; border: 1px solid var(--field-line); border-radius: 8px; margin-bottom: .9rem; }
.seg label:first-child { border-radius: 7px 0 0 7px; }
.seg label:last-child { border-radius: 0 7px 7px 0; }
.seg label { flex: 1; margin: 0; text-align: center; color: var(--ink); cursor: pointer; position: relative; }
.seg label + label { border-left: 1px solid var(--field-line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label span, .seg label { padding: .5rem .3rem; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg label.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
/* Focus ring contrasts with both the selected (accent) and unselected segments. */
.seg label:has(input:focus-visible), .seg label.kb-focus { outline: 3px solid var(--ink); outline-offset: 2px; position: relative; z-index: 1; }

details.more { margin: .2rem 0 .4rem; }
details.more > summary { cursor: pointer; color: var(--accent); margin-bottom: .4rem; padding: .35rem 0; font-size: .92rem; }

.fine { font-size: .84rem; color: var(--muted); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

button {
  font: inherit;
  font-size: .92rem;
  padding: .45rem .9rem;
  min-height: 2.4rem;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
button.quiet, button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .55; cursor: not-allowed; }

.controls-row { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: .6rem 0; }
.controls-row label.check { margin: 0; }

/* ---------- Preview ---------- */

.stage { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.led-wrap { text-align: center; width: 120px; }
.led {
  width: 56px;
  height: 56px;
  margin: 18px auto 10px;
  border-radius: 50% 50% 46% 46%;
  background: #444;
  border: 1px solid rgba(127, 127, 127, .45);
}
.led.invisible { background: radial-gradient(circle at 38% 32%, rgba(255,255,255,.55), rgba(200,205,215,.25) 45%, rgba(120,125,135,.35)); }
.led.hidden-led { opacity: .25; }
.led-status { font-size: .85rem; color: var(--muted); margin: 0; min-height: 1.3em; }

/* "Start" pill over the Simple LED (LED A when there are several), shown only when the
   page opens in Still preview; see offerStart() in ui.js. Centred on the disc. */
.led-wrap, .led-cell { position: relative; }
.start-btn {
  position: absolute; left: 50%; top: 46px; transform: translate(-50%, -50%);
  min-height: 0; height: 2rem; padding: 0 .85rem 0 .7rem; border-radius: 1rem;
  display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; font-weight: 600;
}
.led-cell .start-btn { top: 30px; height: 1.75rem; padding: 0 .65rem 0 .55rem; font-size: .85rem; }
.start-btn::before { content: ""; border-style: solid; border-width: .35rem 0 .35rem .55rem; border-color: transparent transparent transparent currentColor; }
.readouts { flex: 1; min-width: 180px; }
.readouts p { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding: .25rem 0; margin: 0; }
.readouts .k { color: var(--muted); }
.readouts .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.readouts p.cap-note { display: block; border: 0; color: var(--warn-ink); font-size: .84rem; padding-top: .5rem; }

.scope-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-top: .4rem; }
.scope-head h3 { margin: 0 0 .5rem; }
.scope-head label { margin-bottom: .4rem; display: flex; align-items: center; gap: 8px; }
.scope-head select { width: auto; margin: 0; }
.scope { display: block; width: 100%; height: 170px; border-radius: 8px; background: var(--scope-bg); }

/* ---------- Results ---------- */

.calc { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: 0; }
.calc dt { color: var(--muted); }
.calc dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.calc dd small { font-weight: 400; color: var(--muted); }
.calc .big { font-size: 1.35rem; }

.warnings { list-style: none; padding: 0; margin: 0; }
.warnings li {
  border-left: 4px solid var(--info-line);
  background: var(--info-bg);
  color: var(--info-ink);
  border-radius: 6px;
  padding: .5rem .7rem;
  margin-bottom: .45rem;
  font-size: .92rem;
}
.warnings li.error { border-color: var(--err-line); background: var(--err-bg); color: var(--err-ink); }
.warnings li.warn  { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-ink); }
.warnings li b { margin-right: .3rem; }
.warnings li.ok { border-color: #34a853; }

.diagram { max-width: 420px; }
.diagram svg { display: block; width: 100%; height: auto; color: var(--wire); }
.diagram text { fill: currentColor; font: 13px system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.diagram .sub { fill: var(--muted); font-size: 12px; }
.diagram .tr-label { font-size: 10px; }

/* ---------- Several LEDs ---------- */

/* Preview: a row of smaller LEDs, each with its letter and state. */
.led-row { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: flex-start; }
/* Fixed width, so the LED never moves when its status text changes length;
   the text wraps under it instead, with room for two lines kept free. */
.led-cell { text-align: center; width: 6.5rem; flex: none; }
.led-row .led { width: 40px; height: 40px; margin: 10px auto 4px; }
.led-name { margin: 0; font-weight: 600; font-size: .85rem; }
.led-row .led-status { font-size: .78rem; line-height: 1.25; min-height: 2.5em; overflow-wrap: anywhere; }

/* Letter badge in the LED's own colour (text colour picked for contrast). */
.led-tag { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; border-radius: 50%; font-size: .78rem; font-weight: 700; flex: none; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, .55); }

/* Simple tab: one line per LED. */
.led-list { list-style: none; padding: 0; margin: .8rem 0 .4rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.led-list li { display: flex; align-items: center; gap: 8px; }
.led-list select { margin: 0; flex: 1; min-width: 0; }
.led-list .rm, .led-card .rm { padding: 0; min-width: 2.75rem; font-size: 1.2rem; line-height: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: .5rem 0; }
.chip { min-height: 2.2rem; padding: .3rem .75rem; border-radius: 999px; font-size: .88rem; }

/* Step grid: the on/off column becomes one toggle per LED (wraps when narrow). */
.mrow .togs { grid-area: state; display: flex; flex-wrap: wrap; gap: 4px; }
.tog { min-width: 28px; min-height: 28px; padding: 0 4px; border-radius: 6px; font-size: .8rem; font-weight: 700;
  background: transparent; color: var(--ink); border: 1px solid var(--line); }
.tog[aria-pressed="true"] { background: var(--c); border-color: rgba(127, 127, 127, .55); color: var(--ci); }
.srow.mrow { grid-template-columns: 1.6rem minmax(5.5rem, auto) minmax(80px, 1fr) 5.2rem 2.75rem; }

/* Bi-colour cells are small menus; RGB cells are swatches that open the palette. */
.cell-sel { width: auto; min-height: 28px; padding: 0 .3rem; margin: 0; font-size: .8rem; }
.swatch { min-width: 28px; min-height: 28px; padding: 0 4px; border-radius: 6px; font-size: .8rem; font-weight: 700;
  background: transparent; color: var(--ink); border: 1px dashed var(--line); }
.swatch.lit { background: var(--c); color: var(--ci); border: 1px solid rgba(127, 127, 127, .55); }
.swatch[aria-expanded="true"] { outline: 3px solid var(--accent); outline-offset: 1px; }
.srow.mrow.with-fade { grid-template-columns: 1.6rem minmax(5.5rem, auto) minmax(80px, 1fr) 5.2rem 6.4rem 2.75rem; grid-template-areas: "n state range num fade rm"; }
.mrow .num.fade { grid-area: fade; }

/* Palette under a grid row. */
.picker { list-style: none; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; margin: .3rem 0 .5rem; }
.picker .fine { margin: 0 0 .4rem; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: .4rem; }
.pal { width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 8px; background: var(--c); border: 1px solid rgba(127, 127, 127, .55); }
.pal.pal-off { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--line) 5px 7px); }
.pal[aria-pressed="true"] { outline: 3px solid var(--accent); outline-offset: 2px; }
.mix-row { display: grid; grid-template-columns: 4.5rem 1fr 2.5rem; align-items: center; gap: 8px; margin: 0; color: var(--ink); }
.mix-row input { margin: 0; }
.mix-val { font-variant-numeric: tabular-nums; text-align: right; }

/* LED type next to "Add another LED". */
.inline-select { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0; color: var(--ink); max-width: 100%; min-width: 0; }
.inline-select select { width: auto; max-width: 100%; min-width: 0; margin: 0; text-overflow: ellipsis; }

/* Advanced tab: a card per LED, edged in its colour. */
.led-cards { display: grid; gap: 10px; margin: .4rem 0 .6rem; }
.led-card { border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 0 8px 8px 0; padding: .55rem .7rem .2rem; }
.led-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: .4rem; }
.led-card-title { flex: 1; font-weight: 600; color: var(--ink); }
.led-card-res { margin: 0 0 .5rem; font-variant-numeric: tabular-nums; font-weight: 600; }
/* One line per die: colour dot, current (tweaked while testing), result. */
.die-row { display: grid; grid-template-columns: 14px minmax(9rem, 12rem) 1fr; gap: 4px 10px; align-items: center; }
.die-row label { margin: 0; }
.die-row .led-card-res { margin: 0; }
.die-dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, .55); }
@media (max-width: 520px) { .die-row { grid-template-columns: 14px 1fr; } .die-row .led-card-res { grid-column: 2; } }

/* ---------- Session ---------- */

.session label { color: var(--ink); }
.state-text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }
.state-msg { font-size: .9rem; min-height: 1.4em; }
.state-msg.err { color: var(--err-line); }
.state-msg ul { margin: .3rem 0 0; padding-left: 1.1rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

@media print {
  .preview, .session { display: none; }
  body { background: #fff; }
}

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--field-line); }
.tabs [role=tab] {
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  padding: .55rem 1.2rem;
  min-height: 2.75rem;
  font-weight: 600;
  margin-bottom: -2px;
}
.tabs [role=tab][aria-selected=true] {
  background: var(--panel);
  border-color: var(--field-line);
  border-bottom: 2px solid var(--panel);
  color: var(--accent);
}
.tabs [role=tab]:hover { color: var(--accent); }

/* ---------- Simple view ---------- */

.simple { max-width: 760px; width: 100%; }
.simple-side { flex: 1; min-width: 200px; }
.pattern-bar {
  display: flex;
  height: 28px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--field);
  margin: .4rem 0;
}
.pattern-bar .seg-on { background: var(--bar-on, #e8a400); }
.pattern-bar .seg-off { background: transparent; }
.pattern-bar .seg-on + .seg-on, .pattern-bar .seg-off + .seg-off, .pattern-bar .seg-on + .seg-off, .pattern-bar .seg-off + .seg-on { border-left: 1px solid var(--field-line); }

.cap-box { border-left: 4px solid var(--warn-line); background: var(--warn-bg); color: var(--warn-ink); border-radius: 6px; padding: .5rem .7rem; margin: .4rem 0 .8rem; font-size: .92rem; }
.cap-box p { margin: 0 0 .2rem; }
.cap-box label.check { color: var(--warn-ink); margin: 0; }

.simple-rows { list-style: none; padding: 0; margin: .8rem 0 .4rem; counter-reset: step; }
.srow {
  display: grid;
  grid-template-columns: 1.6rem 5.5rem minmax(80px, 1fr) 5.2rem 2.75rem;
  grid-template-areas: "n state range num rm";
  gap: 6px 10px;
  align-items: center;
  padding: .5rem 0;
  border-bottom: 1px dashed var(--line);
}
.srow .n { grid-area: n; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.srow select { grid-area: state; margin: 0; }
.srow input[type=range] { grid-area: range; margin: 0; height: 2.4rem; }
.srow .num { grid-area: num; display: flex; align-items: center; gap: 4px; }
.srow .num input { margin: 0; text-align: right; padding-right: .35rem; }
.srow .num span { color: var(--muted); font-size: .85rem; }
.srow .rm { grid-area: rm; padding: 0; min-width: 2.75rem; font-size: 1.2rem; line-height: 1; }
.srow .rm-spacer { grid-area: rm; }

@media (max-width: 520px) {
  .srow, .srow.mrow {
    grid-template-columns: 1.6rem 1fr 5.6rem 2.75rem;
    grid-template-areas: "n state num rm" "range range range range";
  }
  .srow.mrow.with-fade {
    grid-template-columns: 1.6rem 1fr 5.6rem 2.75rem;
    grid-template-areas: "n state num rm" "range range fade fade";
  }
}
