:root {
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --fg: #1c1917;
  --muted: #6b6560;
  --faint: #a8a29e;
  --border: #e7e3de;
  --accent: #d30001;
  --accent-soft: #fde8e8;
  --accent-fg: #ffffff;
  --ok: #15803d;
  --code-bg: #1c1917;
  --code-fg: #f5f0eb;
  --shadow: 0 1px 2px rgb(28 25 23 / .04), 0 4px 16px rgb(28 25 23 / .05);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e0d;
    --surface: #181614;
    --surface-2: #1e1c1a;
    --fg: #f2efeb;
    --muted: #a39e98;
    --faint: #6b6560;
    --border: #2c2926;
    --accent: #ff4d4d;
    --accent-soft: #3a1414;
    --ok: #4ade80;
    --code-bg: #0a0908;
    --code-fg: #ede7e1;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

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

html { scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); border: 1px solid var(--border); padding: .05em .35em; border-radius: 5px; }

/* Hero ------------------------------------------------------------------ */

.hero {
  background:
    radial-gradient(1200px 400px at 85% -10%, rgb(255 255 255 / .14), transparent 60%),
    linear-gradient(135deg, #b30000 0%, #d30001 45%, #e8331f 100%);
  color: #fff;
  padding: 2.5rem 1.25rem 3.25rem;
}

.hero__inner { max-width: 1160px; margin: 0 auto; }

.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; letter-spacing: .01em; }
.brand__mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: rgb(255 255 255 / .16); border: 1px solid rgb(255 255 255 / .25);
}

.hero h1 {
  max-width: 22ch;
  margin: 1.75rem 0 .75rem;
  font-size: clamp(1.8rem, 4vw, 2.75rem);
  line-height: 1.12;
  letter-spacing: -.02em;
  text-wrap: balance;
}

.hero__lede { max-width: 60ch; margin: 0; color: rgb(255 255 255 / .85); font-size: 1.05rem; }
.hero code { background: rgb(0 0 0 / .2); border-color: rgb(255 255 255 / .2); color: #fff; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .6rem;
  margin: 2rem 0 0;
}
.stat {
  padding: .7rem .9rem;
  border-radius: 10px;
  background: rgb(0 0 0 / .14);
  border: 1px solid rgb(255 255 255 / .16);
  backdrop-filter: blur(4px);
}
.stat dt { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: rgb(255 255 255 / .7); }
.stat dd { margin: .15rem 0 0; font-family: var(--mono); font-size: .95rem; font-weight: 600; }
.stat dd.on::before, .stat dd.off::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: .4rem; vertical-align: middle; background: #86efac;
}
.stat dd.off::before { background: rgb(255 255 255 / .4); }

/* Section nav ----------------------------------------------------------- */

.toc {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: .25rem; justify-content: center; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.toc a {
  padding: .35rem .8rem; border-radius: 999px;
  color: var(--muted); text-decoration: none; font-size: .88rem; font-weight: 500;
}
.toc a:hover { background: var(--surface); color: var(--fg); }

/* Content --------------------------------------------------------------- */

.content { max-width: 1160px; margin: 0 auto; padding: 1rem 1.25rem 2rem; }

.group { padding-top: 2.25rem; }
.group__head { display: flex; align-items: baseline; gap: .75rem 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.group__head h2 { margin: 0; font-size: 1.3rem; letter-spacing: -.01em; }
.group__head p { margin: 0; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1rem; }

.card {
  display: flex; flex-direction: column;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }

.card__head { display: flex; align-items: flex-start; gap: .85rem; }
.card__num {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--mono); font-weight: 700; font-size: .85rem;
}
.card__title { margin: 0; font-size: 1.05rem; font-family: var(--mono); letter-spacing: -.01em; }
.card__kicker { margin: .1rem 0 0; color: var(--muted); font-size: .85rem; }
.card__desc { margin: .9rem 0; color: var(--muted); font-size: .92rem; }

.badge {
  margin-left: auto; flex: none;
  padding: .2em .65em; border-radius: 999px;
  background: var(--accent); color: var(--accent-fg);
  font-size: .72rem; font-weight: 700; letter-spacing: .02em;
}

.code {
  margin: 0 0 1rem;
  padding: .9rem 1rem;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 10px;
  font: .8rem/1.6 var(--mono);
  overflow-x: auto;
}
.code code { background: none; border: 0; padding: 0; font-size: inherit; }

.card__controls { margin-top: auto; padding-top: 1rem; border-top: 1px dashed var(--border); }

/* Forms ----------------------------------------------------------------- */

.form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.input {
  min-width: 0;
  height: 38px;
  padding: 0 .75rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--fg);
  font: inherit; font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
}
.input--grow { flex: 1 1 160px; }
select.input { padding-right: 2rem; cursor: pointer; }
input[type=number].input { width: 110px; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

.check { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .88rem; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.btn {
  height: 38px;
  padding: 0 1.1rem;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--fg);
  color: var(--bg);
  font: inherit; font-size: .9rem; font-weight: 600;
  cursor: pointer;
  transition: transform .08s, opacity .15s;
}
.btn:hover { opacity: .88; }
.btn:active { transform: translateY(1px); }
.btn--danger { background: var(--accent); color: var(--accent-fg); }
.btn--ghost { background: transparent; color: var(--fg); border-color: var(--border); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); opacity: 1; }

/* Stress tiles ---------------------------------------------------------- */

.grid--stress { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }

.tile {
  display: flex; flex-direction: column; gap: .2rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.tile__title { font-weight: 650; }
.tile__desc { color: var(--muted); font-size: .85rem; }
.tile__row { display: flex; gap: .5rem; margin-top: auto; padding-top: .75rem; }
.tile__row .btn { flex: 1; }

/* Footer + toast -------------------------------------------------------- */

.footer { max-width: 1160px; margin: 1rem auto 0; padding: 1.5rem 1.25rem 6rem; color: var(--muted); font-size: .88rem; border-top: 1px solid var(--border); }
.footer p { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 1.25rem; z-index: 20;
  translate: -50% 0;
  display: flex; align-items: center; gap: .85rem;
  width: max-content; max-width: calc(100vw - 2rem);
  padding: .8rem .8rem .8rem 1rem;
  background: var(--fg); color: var(--bg);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgb(0 0 0 / .25);
  animation: toast-in .25s ease-out;
}
.toast--leaving { animation: toast-out .2s ease-in forwards; }
.toast__dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 4px rgb(74 222 128 / .2); }
.toast__body { display: flex; flex-direction: column; min-width: 0; font-size: .9rem; }
.toast__meta { opacity: .7; font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast__meta code { background: none; border: 0; padding: 0; color: inherit; }
.toast__btn {
  flex: none; padding: .35rem .75rem; border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--bg) 30%, transparent);
  background: transparent; color: inherit; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.toast__close { flex: none; border: 0; background: none; color: inherit; opacity: .6; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 .25rem; }

@keyframes toast-in { from { opacity: 0; translate: -50% 12px; } }
@keyframes toast-out { to { opacity: 0; translate: -50% 12px; } }

@media (max-width: 520px) {
  .hero { padding: 1.75rem 1rem 2.5rem; }
  .content { padding-inline: 1rem; }
  .toc { justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; }
  .toc a { white-space: nowrap; }
}
