/**
 * build.marlyg.me
 *
 * The marlyg.me / portal.marlyg.me design system, verbatim. The token names
 * and values below are the ones those two sites ship, so this reads as the
 * same product rather than a tool that happens to be linked from it.
 *
 * Light only, because neither of the other two has a dark theme. One family,
 * Stack Sans Text, with weight carrying the hierarchy — mono appears in
 * exactly one place, the stream, where the content really is code.
 */

:root {
  --theme-bg: #f3f1ea;
  --theme-surface: #f3f1ea;
  --theme-surface-alt: #ece9e0;
  --theme-text: #0d0d0e;
  --theme-text-muted: #0d0d0e94;
  --theme-text-dim: #0d0d0e61;
  --theme-text-faint: #0d0d0e24;
  --theme-border: #0d0d0e29;
  --theme-border-strong: #0d0d0e66;
  --theme-accent: #0d0d0e;
  --theme-success: #2f7d4f;
  --theme-warning: #a86b1d;
  --theme-error: #b4342b;
  --theme-grid: #0d0d0e0f;
  --card-radius: 10px;
  --card-shadow: 0 1px 2px #0d0d0e0d, 0 8px 24px #0d0d0e0f;

  --sans: "Stack Sans Text", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Every flex/grid rule below would otherwise beat the UA's [hidden] display:none
   on specificity, and the stage that is meant to be hidden renders anyway. */
[hidden] { display: none !important; }

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

body {
  background: var(--theme-bg);
  color: var(--theme-text);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--theme-text); color: var(--theme-bg); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---- chrome ---------------------------------------------------------------- */

.bar {
  display: flex; align-items: center; gap: 10px;
  padding: 16px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--theme-border);
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
}
.mark { color: var(--theme-text); text-decoration: none; font-weight: 500; }
.mark:hover { color: var(--theme-text-muted); }
.bar-mid { color: var(--theme-text-dim); }
.bar-right { margin-left: auto; color: var(--theme-text-dim); font-family: var(--mono); letter-spacing: 0.04em; }

main {
  flex: 1; width: 100%;
  max-width: 62rem;
  margin: 0 auto; padding: clamp(28px, 6vw, 64px) clamp(16px, 4vw, 40px);
}

.foot {
  display: flex; gap: 14px; align-items: center;
  padding: 18px clamp(16px, 4vw, 40px);
  border-top: 1px solid var(--theme-border);
  color: var(--theme-text-dim);
}
.foot a { color: var(--theme-text-dim); }
.foot a:hover { color: var(--theme-text); }

h1 {
  font-size: clamp(2rem, 6vw, 3.25rem);
  font-weight: 500; line-height: 1.06; letter-spacing: -0.02em;
  margin-bottom: 8px;
}
h2 { font-size: 1.5rem; font-weight: 500; letter-spacing: -0.01em; }
h3 { font-size: 1.125rem; font-weight: 500; letter-spacing: -0.01em; }

.muted { color: var(--theme-text-muted); }
.fine { font-size: 12px; letter-spacing: 0.02em; color: var(--theme-text-muted); }
.bad { color: var(--theme-error); }
.spacer { flex: 1; }
.footnote { margin-top: 22px; max-width: 46ch; }

a { color: var(--theme-text); text-underline-offset: 3px; }

/* ---- controls -------------------------------------------------------------- */

button, .btn {
  font: inherit; font-size: 14px;
  padding: 9px 16px;
  color: var(--theme-text);
  background: transparent;
  border: 1px solid var(--theme-border);
  border-radius: var(--card-radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px;
  transition: border-color 0.14s ease, background 0.14s ease, color 0.14s ease;
}
button:hover, .btn:hover { border-color: var(--theme-border-strong); }
.btn.solid, button.solid {
  background: var(--theme-text); color: var(--theme-bg); border-color: var(--theme-text);
}
.btn.solid:hover, button.solid:hover { background: #000; border-color: #000; }
.ghost { border-color: transparent; color: var(--theme-text-muted); }
.ghost:hover { border-color: var(--theme-border); color: var(--theme-text); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

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

textarea, input {
  font: inherit; font-size: 15px;
  width: 100%; padding: 12px 14px;
  color: var(--theme-text);
  background: var(--theme-bg);
  border: 1px solid var(--theme-border);
  border-radius: var(--card-radius);
  resize: vertical;
}
textarea::placeholder, input::placeholder { color: var(--theme-text-dim); }
textarea:focus-visible, input:focus-visible { border-color: var(--theme-border-strong); }

/* ---- stage 0: the two doors ------------------------------------------------ */

.doors {
  display: grid; gap: 12px; margin: 30px 0 8px;
  grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
}
.door {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 22px; text-align: left;
  background: var(--theme-surface);
  box-shadow: var(--card-shadow);
}
.door:hover { border-color: var(--theme-border-strong); }
.door-k {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--theme-text-dim);
}
.door-t { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; }
.door-d { font-size: 13px; line-height: 1.55; color: var(--theme-text-muted); }

.back-link {
  border: 0; padding: 0 0 18px; background: transparent;
  color: var(--theme-text-dim); font-size: 12px; letter-spacing: 0.1em;
}
.back-link:hover { border-color: transparent; color: var(--theme-text); }
.back-link::before { content: '\2190\00a0'; }

/* ---- stage 1: quick mode --------------------------------------------------- */

#brief-form { display: flex; flex-direction: column; gap: 14px; margin-top: 26px; }
.row { display: flex; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 12.5px; padding: 7px 12px;
  color: var(--theme-text-muted); text-align: left;
  border-color: var(--theme-border);
}
.chip:hover { color: var(--theme-text); }
.actions { display: flex; align-items: center; gap: 14px; }
#fire { background: var(--theme-text); color: var(--theme-bg); border-color: var(--theme-text); }
#fire:hover { background: #000; border-color: #000; }
#count { font-family: var(--mono); font-size: 11px; color: var(--theme-text-dim); }

/* ---- stage 2: the wizard --------------------------------------------------- */

.rail {
  display: flex; flex-wrap: wrap; gap: 4px 20px; list-style: none;
  padding: 0 0 30px; counter-reset: step;
  font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--theme-text-dim);
}
.rail li { counter-increment: step; }
.rail li::before { content: counter(step) '\00a0'; opacity: 0.55; }
.rail li.is-on { color: var(--theme-text); font-weight: 500; }
.rail li.is-done { color: var(--theme-text-muted); }
.rail li.is-done::before { content: '\2713\00a0'; opacity: 1; }

.wstep { display: flex; flex-direction: column; gap: 18px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-l {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--theme-text-dim);
}

.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(232px, 1fr)); }
.card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 16px; text-align: left; background: var(--theme-surface);
}
.card.is-on { border-color: var(--theme-text); box-shadow: var(--card-shadow); }
.card-t { font-size: 15.5px; font-weight: 500; }
.card-d { font-size: 12.5px; line-height: 1.5; color: var(--theme-text-muted); }
.card-p {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--theme-text-dim);
}

.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 13px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
}
.toggle:has(input:checked) { border-color: var(--theme-text); }
.toggle:has(input:disabled) { opacity: 0.55; cursor: default; }
.toggle input { accent-color: var(--theme-text); }

.custom {
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
  padding: 14px 16px;
}
.custom summary { cursor: pointer; font-size: 13px; color: var(--theme-text-muted); }
.custom summary:hover { color: var(--theme-text); }
.custom-row { display: flex; gap: 8px; margin: 14px 0 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { padding: 7px 13px; font-size: 12px; color: var(--theme-text-muted); }
.tab.is-on { border-color: var(--theme-text); color: var(--theme-text); }
.tabpane { display: flex; flex-direction: column; gap: 9px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
input[type="file"] { font-size: 13px; color: var(--theme-text-muted); border: 0; padding: 0; }

.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { display: flex; flex-direction: column; gap: 6px; width: 96px; cursor: pointer; }
.swatch input[type="color"] {
  width: 96px; height: 60px; padding: 0; cursor: pointer;
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
  background: transparent;
}
.swatch-r {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--theme-text-dim);
}
.swatch-h { font-family: var(--mono); font-size: 11.5px; color: var(--theme-text-muted); }

.pairs { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(248px, 1fr)); }
.pair {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 18px; text-align: left; background: var(--theme-surface);
}
.pair.is-on { border-color: var(--theme-text); box-shadow: var(--card-shadow); }
.pair-d { font-size: 29px; line-height: 1.04; letter-spacing: -0.01em; }
.pair-t { font-size: 13px; line-height: 1.5; color: var(--theme-text-muted); }
.pair-n {
  font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--theme-text-dim);
}

.reflist { display: flex; flex-direction: column; gap: 9px; }

.summary {
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
  padding: 18px; background: var(--theme-surface-alt);
}
.summary dl { display: grid; grid-template-columns: 104px 1fr; gap: 10px 16px; }
.summary dt {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--theme-text-dim); padding-top: 3px;
}
.summary dd { font-size: 14px; }
.sw {
  display: inline-block; width: 22px; height: 22px; border-radius: 4px;
  border: 1px solid var(--theme-border); margin-right: 5px; vertical-align: middle;
}

.wnav {
  display: flex; align-items: center; gap: 14px;
  margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--theme-border);
}

/* ---- stage 3: the build ---------------------------------------------------- */

.build-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
  font-size: 13px; letter-spacing: 0.04em;
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--theme-text); animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.22 } }
#build-bytes { margin-left: auto; font-family: var(--mono); }

.progress {
  display: flex; flex-direction: column;
  margin-bottom: 16px;
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
  overflow: hidden;
}
.prog {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; font-size: 12.5px;
  border-bottom: 1px solid var(--theme-border);
}
.prog:last-child { border-bottom: 0; }
.prog-l { min-width: 96px; }
.prog-b { min-width: 76px; font-family: var(--mono); font-size: 11.5px; color: var(--theme-text-dim); }
.prog-s {
  margin-left: auto; font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--theme-text-dim);
}
.prog.is-done .prog-s { color: var(--theme-success); }
.prog.is-failed .prog-s { color: var(--theme-error); }

#stream {
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  max-height: 54vh; overflow: auto; padding: 18px;
  background: var(--theme-text); color: #d8d6cf;
  border-radius: var(--card-radius);
  white-space: pre-wrap; word-break: break-word;
}

/* ---- stage 4: the result --------------------------------------------------- */

.done-head {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
  justify-content: space-between; margin-bottom: 18px;
}
.done-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#done-note, #gh-result { margin-bottom: 14px; }
#gh-result a { color: var(--theme-text); }

.viewport {
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
  overflow: hidden; box-shadow: var(--card-shadow);
}
.viewport-bar {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  padding: 9px 13px;
  background: var(--theme-surface-alt);
  border-bottom: 1px solid var(--theme-border);
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--theme-text-faint);
}
#frame-label {
  margin-left: 7px; font-family: var(--mono); font-size: 11px;
  color: var(--theme-text-dim);
}
.seg {
  padding: 4px 10px; font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; border-color: transparent; color: var(--theme-text-dim);
}
.seg.is-on { border-color: var(--theme-border); color: var(--theme-text); background: var(--theme-bg); }

.pagetabs { display: flex; flex-wrap: wrap; gap: 4px; margin-left: 12px; }
.ptab {
  padding: 4px 10px; font-size: 11px; letter-spacing: 0.06em;
  border-color: transparent; color: var(--theme-text-dim);
}
.ptab.is-on { border-color: var(--theme-border); color: var(--theme-text); background: var(--theme-bg); }

#preview {
  display: block; width: 100%; height: min(70vh, 780px);
  border: 0; background: #fff; margin: 0 auto;
}

/* ---- the hand-it-over dialog ----------------------------------------------- */

dialog {
  border: 1px solid var(--theme-border); border-radius: var(--card-radius);
  background: var(--theme-bg); color: var(--theme-text);
  padding: 26px; max-width: 30rem; width: calc(100% - 32px);
  box-shadow: var(--card-shadow);
}
dialog::backdrop { background: #0d0d0e5c; }
#claim-form { display: flex; flex-direction: column; gap: 12px; }
.claim-actions { display: flex; gap: 8px; justify-content: flex-end; }
#claim-status.bad { color: var(--theme-error); }

/* ---- narrow ---------------------------------------------------------------- */

@media (max-width: 700px) {
  .summary dl { grid-template-columns: 1fr; gap: 3px; }
  .summary dt { padding-top: 10px; }
  .custom-row { flex-direction: column; }
  .pair-d { font-size: 24px; }
  .done-head { align-items: flex-start; }
  .done-actions { width: 100%; }
  #preview { height: 62vh; }
}

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