/* ============================================================
   CertForge
   ------------------------------------------------------------
   Dark, technical, cobalt on deep navy. Tokens first: almost
   everything worth changing is in the block below.
   ============================================================ */

:root {
  color-scheme: dark;

  --ink: #071523;
  --ink-deep: #04101c;
  --panel: #0c2033;
  --panel-2: #102b44;
  --rule: #1b3d57;
  --rule-soft: #143047;
  --text: #dde9f3;
  --text-dim: #a8c0d4;
  --muted: #7794ab;

  --cobalt: #2fb8ff;
  --cobalt-ink: #04121e;
  --amber: #ffb020;
  --jade: #43d9a3;
  --alarm: #ff7a6b;

  --display: "Archivo", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;

  --r: 4px;
  --r-lg: 6px;

  /* One step scale for every gap on the page. */
  --s-1: 0.5rem;
  --s-2: 0.75rem;
  --s-3: 1rem;
  --s-4: 1.5rem;
  --s-5: 2rem;
  --s-6: clamp(2rem, 1.4rem + 2.4vw, 3rem);

  /* A hairline that reads as light catching an edge, not as a border. */
  --lift: inset 0 1px 0 rgb(255 255 255 / 0.045);
}

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

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  position: relative;
  background: var(--ink);
  color: var(--text);
  font-family: var(--body);
  font-size: clamp(0.9375rem, 0.91rem + 0.14vw, 1rem);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/*
 * The grid is texture, not wallpaper: a wider cell, half the contrast it had,
 * and masked so it fades out below the masthead. It reads at the top of the
 * page and gets out of the way of the form.
 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgb(47 184 255 / 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgb(47 184 255 / 0.028) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(130% 80% at 50% -10%, #000 0%, transparent 70%);
  mask-image: radial-gradient(130% 80% at 50% -10%, #000 0%, transparent 70%);
}

::selection {
  background: color-mix(in srgb, var(--cobalt) 28%, transparent);
  color: #fff;
}

a {
  color: var(--cobalt);
  text-decoration-color: color-mix(in srgb, var(--cobalt) 40%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: text-decoration-color 0.18s ease;
}

@media (hover: hover) {
  a:hover {
    text-decoration-color: currentColor;
  }
}

p {
  text-wrap: pretty;
}

h1,
h2 {
  text-wrap: balance;
}

:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- shell ---------- */

.shell {
  width: min(100% - 2.5rem, 60rem);
  margin-inline: auto;
  padding-block: var(--s-5) 6rem;
}

.masthead {
  margin-bottom: var(--s-6);
  padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--rule);
}

/* ---------- language switcher ---------- */

.langbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 3px;
}

/*
 * Separate chips rather than one segmented control: seven language names wrap
 * to a second row on a phone, and a shared-hairline segment leaves the wrapped
 * row with an open edge.
 */
.lang {
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

@media (hover: hover) {
  .lang:hover {
    color: var(--text);
    background: var(--panel);
  }
}

.lang.on {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: var(--cobalt-ink);
  font-weight: 500;
}

/* ---------- masthead type ---------- */

.wordmark {
  margin: 0 0 var(--s-4);
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cobalt);
}

.headline {
  margin: 0 0 var(--s-3);
  max-width: 19ch;
  font-family: var(--display);
  font-size: clamp(2.25rem, 1.2rem + 4.4vw, 3.75rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.028em;
}

.headline em {
  font-style: normal;
  color: var(--cobalt);
}

.standfirst {
  margin: 0;
  max-width: 58ch;
  font-size: 1.0625rem;
  color: var(--text-dim);
}

/* ---------- panels ---------- */

.panel {
  container-type: inline-size;
  margin-bottom: var(--s-4);
  padding: clamp(1.25rem, 0.9rem + 1.6vw, 2rem);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--panel);
  box-shadow: var(--lift);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
}

.panel-title {
  margin: 0 0 var(--s-1);
  font-family: var(--display);
  font-size: clamp(1.3rem, 1.15rem + 0.7vw, 1.6rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.022em;
}

.panel-head .panel-title {
  margin-bottom: 0;
}

.panel-note {
  margin: 0 0 var(--s-4);
  max-width: 62ch;
  font-size: 0.9375rem;
  color: var(--muted);
}

/* ---------- form ---------- */

.field {
  margin-bottom: var(--s-4);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 var(--s-3);
}

/* Collapses on the panel's own width, not the viewport's — the panel is what
   actually runs out of room. */
@container (max-width: 34rem) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.label {
  display: block;
  margin-bottom: var(--s-1);
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.18s ease;
}

/* The label of whichever control has keyboard focus moves with it. */
.field:has(:focus-visible) .label {
  color: var(--cobalt);
}

textarea,
select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--ink-deep);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.6;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

textarea {
  min-height: 6rem;
  max-height: 20rem;
  line-height: 1.75;
  resize: vertical;
  field-sizing: content;
}

textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 70%, transparent);
}

/*
 * The platform select is unstyleable on the closed state in most browsers, so
 * the chevron is drawn from two gradients — no image request, and it inherits
 * the text colour.
 */
select {
  appearance: none;
  padding-inline-end: 2.4rem;
  cursor: pointer;
  /* Prose, not a token — the mono stack is too wide and clips the longer
     option labels in the narrower languages. */
  font-family: var(--body);
  font-size: 0.9rem;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  background-position: right 1.1rem top 55%, right 0.75rem top 55%;
}

[dir="rtl"] select {
  background-position: left 0.75rem top 55%, left 1.1rem top 55%;
}

@media (hover: hover) {
  textarea:hover,
  select:hover {
    border-color: var(--rule-soft);
    border-color: color-mix(in srgb, var(--cobalt) 35%, var(--rule));
  }
}

textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--cobalt);
  box-shadow: 0 0 0 3px rgb(47 184 255 / 0.18);
}

input[type="checkbox"] {
  flex: none;
  width: 1rem;
  height: 1rem;
  margin-block-start: 0.15rem;
  accent-color: var(--cobalt);
}

.hint {
  margin: var(--s-1) 0 0;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--muted);
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-3);
  margin-top: var(--s-4);
}

.actions .hint {
  margin: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 1.3rem;
  border: 1px solid var(--cobalt);
  border-radius: var(--r);
  background: var(--cobalt);
  color: var(--cobalt-ink);
  font-family: var(--display);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease,
              color 0.18s ease, transform 0.07s ease;
}

@media (hover: hover) {
  .btn:hover {
    background: color-mix(in srgb, var(--cobalt) 84%, #fff);
    border-color: color-mix(in srgb, var(--cobalt) 84%, #fff);
  }
}

.btn:active {
  transform: translateY(1px);
}

.btn-ghost {
  background: transparent;
  border-color: var(--rule);
  color: var(--text);
}

@media (hover: hover) {
  .btn-ghost:hover {
    background: var(--panel-2);
    border-color: var(--cobalt);
    color: var(--cobalt);
  }
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* ---------- challenge cards ---------- */

.task {
  margin-bottom: var(--s-3);
  padding: var(--s-4);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--panel-2);
  box-shadow: var(--lift);
}

.task-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  flex-wrap: wrap;
}

.task-name {
  font-family: var(--mono);
  font-size: 0.9375rem;
  color: var(--text);
  word-break: break-all;
}

.pill {
  padding: 0.22rem 0.55rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 10%, transparent);
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.5;
  white-space: nowrap;
}

.pill-wait {
  color: var(--muted);
}

.pill-ok {
  color: var(--jade);
}

.pill-bad {
  color: var(--alarm);
}

/* ---------- key / value ---------- */

.kv {
  display: grid;
  grid-template-columns: 7.25rem minmax(0, 1fr);
  gap: var(--s-1) var(--s-3);
  align-items: start;
  margin: var(--s-3) 0 0;
  font-size: 0.8125rem;
}

@container (max-width: 30rem) {
  .kv {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .kv dt:not(:first-child) {
    margin-top: var(--s-2);
  }
}

.kv dt {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.kv dd {
  margin: 0;
  min-width: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* The values here get copied into a DNS panel or a shell — give them an edge
   to select against rather than leaving them loose in the text. */
code {
  padding: 0.15em 0.4em;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--ink-deep);
  font-family: var(--mono);
  font-size: 0.92em;
}

/* ---------- error ---------- */

.alarm {
  display: flow-root;
  margin-bottom: var(--s-4);
  padding: var(--s-3) var(--s-4);
  border: 1px solid color-mix(in srgb, var(--alarm) 55%, transparent);
  border-inline-start-width: 3px;
  border-radius: var(--r);
  background: color-mix(in srgb, var(--alarm) 8%, var(--panel));
  font-size: 0.9375rem;
}

.alarm h4 {
  margin: 0 0 0.3rem;
  font-family: var(--mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--alarm);
}

/* ---------- fact strip ---------- */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 1px;
  margin: var(--s-4) 0;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--rule);
  overflow: hidden;
}

.fact {
  padding: var(--s-3) var(--s-3);
  background: var(--panel);
}

.fact dt {
  margin: 0 0 0.3rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.fact dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* ---------- PEM armor: the signature element ---------- */

.armor {
  margin-top: var(--s-3);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--ink-deep);
  overflow: hidden;
}

.armor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--rule);
  background: var(--panel-2);
}

.armor-name {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--cobalt);
}

/* The private key is the one file here that must never be shared, so it is the
   one block that does not look like the others. */
.armor.secret {
  border-color: color-mix(in srgb, var(--amber) 40%, transparent);
}

.armor.secret .armor-bar {
  background: color-mix(in srgb, var(--amber) 9%, var(--panel-2));
  border-bottom-color: color-mix(in srgb, var(--amber) 30%, var(--rule));
}

.armor.secret .armor-name {
  color: var(--amber);
}

.armor-body,
.snippet {
  margin: 0;
  padding: 0.9rem;
  max-height: 12rem;
  overflow: auto;
  overscroll-behavior: contain;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.snippet {
  margin-top: var(--s-4);
  max-height: none;
  padding: var(--s-3);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--ink-deep);
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ---------- footer ---------- */

.footnote {
  margin-top: var(--s-6);
  padding-top: var(--s-4);
  border-top: 1px solid var(--rule);
  max-width: 74ch;
  font-size: 0.8125rem;
  color: var(--muted);
}

.footnote p {
  margin: 0;
}

/* ============================================================
   Scripts and writing direction
   ============================================================ */

/*
 * Archivo and IBM Plex are Latin-and-Cyrillic faces. Arabic and Chinese fall
 * through to whatever the system has, so name those stacks rather than letting
 * the browser take the first default it finds — which for a mono element means
 * unjoined Arabic letterforms.
 */
:lang(ar) {
  --display: "SF Arabic", "Geeza Pro", "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  --body: "SF Arabic", "Geeza Pro", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  letter-spacing: normal;
}

:lang(ar) .headline {
  font-size: clamp(1.9rem, 1.1rem + 3.6vw, 3.1rem);
  line-height: 1.25;
  letter-spacing: 0;
}

/* Arabic is cursive: the tracking on these labels would pull the joins apart,
   and the mono stack has no Arabic at all. */
:lang(ar) .wordmark,
:lang(ar) .label,
:lang(ar) .pill,
:lang(ar) .kv dt,
:lang(ar) .fact dt,
:lang(ar) .alarm h4,
:lang(ar) .lang,
:lang(ar) .btn-sm {
  font-family: var(--body);
  letter-spacing: normal;
}

:lang(ar) .kv dd,
:lang(ar) .fact dd,
:lang(ar) .task-name {
  font-family: var(--mono);
}

:lang(zh) {
  --display: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

:lang(zh) .headline {
  font-size: clamp(1.85rem, 1.1rem + 3.2vw, 2.9rem);
  line-height: 1.28;
  letter-spacing: 0;
}

:lang(zh) .wordmark,
:lang(zh) .label,
:lang(zh) .pill,
:lang(zh) .kv dt,
:lang(zh) .fact dt,
:lang(zh) .alarm h4 {
  letter-spacing: 0.08em;
}

/*
 * Domains, tokens, PEM blocks and shell snippets are Latin whatever the page
 * language is, so they get their own direction rather than inheriting the
 * page's. Isolation alone is not enough: in an RTL line the leading neutrals
 * of "*.example.com" resolve to the paragraph direction and the asterisk ends
 * up trailing the hostname.
 */
code,
pre,
.armor-body,
.snippet,
.armor-name,
.task-name {
  direction: ltr;
  unicode-bidi: isolate;
}

[dir="rtl"] pre,
[dir="rtl"] .armor-body,
[dir="rtl"] .snippet,
[dir="rtl"] textarea {
  text-align: left;
}

[dir="rtl"] textarea {
  direction: ltr;
}

/* Notes mix a Latin hostname with translated prose; let the first strong
   character decide, so neither half is dragged to the wrong side. */
.hint,
.kv dd {
  unicode-bidi: plaintext;
}

/* ---------- motion ---------- */

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

/* ---------- indexable copy: steps and Q&A ---------- */

.prose {
  color: var(--text-dim);
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--s-4);
}

.step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s-3);
  align-items: start;
}

/* A numeral, not a bullet — the order is the instruction. */
.step-n {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--cobalt);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.step-t {
  margin: 0.15rem 0 0.3rem;
  font-family: var(--display);
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.step-b {
  margin: 0;
  max-width: 62ch;
  font-size: 0.9375rem;
}

.qa {
  border-top: 1px solid var(--hair, var(--rule));
}

.qa:last-of-type {
  border-bottom: 1px solid var(--hair, var(--rule));
}

.qa-q {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  padding: var(--s-3) 0;
  cursor: pointer;
  list-style: none;
  color: var(--text);
}

/* Safari still paints its own triangle without this. */
.qa-q::-webkit-details-marker {
  display: none;
}

.qa-q h3 {
  margin: 0;
  font-family: var(--body);
  font-size: 0.9688rem;
  font-weight: 500;
}

/* The marker is drawn rather than typed so it can rotate on open. */
.qa-q::after {
  content: "";
  flex: none;
  margin-inline-start: auto;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translate(-0.15em, -0.15em);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.qa[open] .qa-q::after {
  transform: rotate(225deg) translate(-0.05em, -0.05em);
  border-color: var(--cobalt);
}

@media (hover: hover) {
  .qa-q:hover h3 {
    color: var(--cobalt);
  }
}

.qa-a {
  margin: 0 0 var(--s-3);
  max-width: 68ch;
  font-size: 0.9063rem;
  color: var(--muted);
}

/* ---------- masthead top row ---------- */

/*
 * Byline on one edge, language chips on the other. Logical properties do the
 * mirroring, so in Arabic the byline moves to the right without a second rule.
 */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-3);
  margin-bottom: var(--s-5);
}

.byline {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.18s ease;
}

@media (hover: hover) {
  .byline:hover {
    color: var(--cobalt);
  }
}

/* On a phone the chips wrap to their own row; keep them left-aligned with the
   byline rather than stranded against the far edge. */
@media (max-width: 34rem) {
  .topbar {
    justify-content: flex-start;
  }

  .langbar {
    justify-content: flex-start;
  }
}

.footnote {
  display: flex;
}
