/* ===================================================================
   The front door — stylesheet.

   Two halves, in this order:

     1. A standalone copy of the product's design tokens and shared
        primitives (upstream packages/ui/tokens.css). This page cannot
        import them — it has no build step — so it carries the same
        variable NAMES with the same defaults. Those defaults are only
        ever seen in the fraction of a second before GET /api/brand
        answers, or if the gateway is unreachable.

     2. The layout that is this page's own.

   Every colour below is a var() off that token set, so the brand pack
   the gateway returns re-skins the whole page by replacing variables —
   exactly as it does for the console and the chat. Nothing is hard-coded.
   =================================================================== */

/* ============================ 1. tokens ============================ */

:root {
  --font-sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-display: var(--font-sans);

  --radius-control: 8px;
  --radius-card: 12px;
  --radius-dialog: 14px;
  --radius-pill: 999px;

  --btn-height: 38px;
  --btn-height-dialog: 40px;
}

:root,
[data-theme="dark"] {
  --bg: #0b0b0d;
  --surface: #151519;
  --surface-2: #1d1d22;
  --border: #27272d;
  --text: #f7f7f8;
  --dim: #a2a2ac;
  --faint: #71717b;
  --nav-bg: #101014;
  --accent: #6366f1;
  --accent-strong: #a5b4fc;
  --accent-soft: rgba(99, 102, 241, 0.14);
  --on-accent: #ffffff;
  --pos: #34d399;
  --pos-bg: rgba(52, 211, 153, 0.13);
  --pos-btn: #059669;
  --on-pos: #ffffff;
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.13);
  --neg: #f87171;
  --neg-bg: rgba(248, 113, 113, 0.13);
  --learn: #10b981;
  --learn-bg: rgba(16, 185, 129, 0.13);
  --on-learn: #04211a;
  --seg-on: #2b2b32;
  --track: #27272d;
  --backdrop: rgba(0, 0, 0, 0.62);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #ececee;
  --border: #e2e2e6;
  --text: #1b1b1f;
  --dim: #5a5a64;
  --faint: #8a8a93;
  --nav-bg: #fafafa;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.09);
  --on-accent: #ffffff;
  --pos: #047857;
  --pos-bg: rgba(4, 120, 87, 0.1);
  --pos-btn: #047857;
  --on-pos: #ffffff;
  --warn: #b45309;
  --warn-bg: rgba(180, 83, 9, 0.1);
  --neg: #b91c1c;
  --neg-bg: rgba(185, 28, 28, 0.08);
  --learn: #047857;
  --learn-bg: rgba(4, 120, 87, 0.1);
  --on-learn: #ffffff;
  --seg-on: #ffffff;
  --track: #e2e2e6;
  --backdrop: rgba(24, 24, 27, 0.35);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.14);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f4f5;
    --surface: #ffffff;
    --surface-2: #ececee;
    --border: #e2e2e6;
    --text: #1b1b1f;
    --dim: #5a5a64;
    --faint: #8a8a93;
    --nav-bg: #fafafa;
    --accent: #4f46e5;
    --accent-strong: #4338ca;
    --accent-soft: rgba(79, 70, 229, 0.09);
    --on-accent: #ffffff;
    --pos: #047857;
    --pos-bg: rgba(4, 120, 87, 0.1);
    --pos-btn: #047857;
    --on-pos: #ffffff;
    --warn: #b45309;
    --warn-bg: rgba(180, 83, 9, 0.1);
    --neg: #b91c1c;
    --neg-bg: rgba(185, 28, 28, 0.08);
    --learn: #047857;
    --learn-bg: rgba(4, 120, 87, 0.1);
    --on-learn: #ffffff;
    --seg-on: #ffffff;
    --track: #e2e2e6;
    --backdrop: rgba(24, 24, 27, 0.35);
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.14);
  }
}

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

[data-theme="dark"] {
  color-scheme: dark;
}
[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

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

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

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

button {
  font-family: var(--font-sans);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--btn-height);
  padding: 0 18px;
  border: none;
  border-radius: var(--radius-control);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-positive {
  background: var(--pos-btn);
  color: var(--on-pos);
}

.btn-primary:hover:not(:disabled),
.btn-positive:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 4px;
}

.btn-text:hover:not(:disabled) {
  text-decoration: underline;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--dim);
  white-space: nowrap;
}

.pill-pos {
  background: var(--pos-bg);
  color: var(--pos);
}
.pill-warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.pill-accent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.banner {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  padding: 10px 14px;
  font-size: 13px;
}

.banner.error {
  background: var(--neg-bg);
  color: var(--neg);
  border-color: var(--neg);
}

.banner.good {
  background: var(--pos-bg);
  color: var(--pos);
  border-color: var(--pos);
}

.theme-switch {
  display: inline-flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
}

.theme-switch button {
  border: none;
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--dim);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--seg-on);
  color: var(--text);
}

/* ========================== 2. the page =========================== */

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---- top bar: the mark, and the two ways out ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 26px;
  border-bottom: 1px solid var(--border);
  background: var(--nav-bg);
}

.brandmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

/* The pack's logo, as a background image off --brand-mark (a data: URI the
   gateway's pack already encodes). Never innerHTML'd — markup from the network
   does not become markup on the page. */
.brandmark .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background-image: var(--brand-mark);
  background-size: cover;
  background-color: var(--surface-2);
  flex: none;
}

.topbar-spacer {
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.who {
  font-size: 12.5px;
  color: var(--dim);
  max-width: 30ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- stage ---- */

.stage {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 44px 24px 64px;
}

.loading {
  color: var(--dim);
  font-size: 13px;
}

/* ---- the auth panel ---- */

.panel {
  width: 100%;
  max-width: 420px;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 30px;
  box-shadow: var(--shadow);
}

.panel-wide {
  max-width: 560px;
}

.panel-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.panel-sub {
  margin: 0 0 22px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--dim);
}

.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 3px;
  margin-bottom: 22px;
}

.tabs button {
  flex: 1;
  border: none;
  border-radius: var(--radius-pill);
  padding: 8px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--dim);
}

.tabs button[aria-pressed="true"] {
  background: var(--seg-on);
  color: var(--text);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--dim);
}

.form input {
  height: var(--btn-height-dialog);
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
}

.form input.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}

.form select {
  height: var(--btn-height-dialog);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
}

.form .btn {
  height: var(--btn-height-dialog);
  margin-top: 4px;
}

.hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--faint);
  margin: 0;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--faint);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.social {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.social .btn {
  width: 100%;
  height: var(--btn-height-dialog);
}

/* ---- the flow ---- */

.flow {
  width: 100%;
  max-width: 720px;
}

.flow-head {
  margin-bottom: 30px;
}

.flow-head h1 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.flow-head p {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: var(--dim);
}

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.progress-track {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--track);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--pos);
  border-radius: var(--radius-pill);
  transition: width 0.35s ease;
}

.progress-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.steps {
  display: flex;
  flex-direction: column;
}

.step {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 16px;
}

.step-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.step-dot {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  color: var(--dim);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.step[data-state="done"] .step-dot {
  background: var(--pos);
  border-color: var(--pos);
  color: var(--on-pos);
}

.step[data-state="active"] .step-dot {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.step-line {
  flex: 1;
  width: 1.5px;
  background: var(--border);
  margin: 6px 0;
  min-height: 12px;
}

.step:last-child .step-line {
  display: none;
}

.step-body {
  padding-bottom: 22px;
  min-width: 0;
}

.step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 26px;
}

.step-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.step[data-state="todo"] .step-head h2 {
  color: var(--dim);
}

.step-why {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--dim);
}

.step-detail {
  margin-top: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.step-detail > * + * {
  margin-top: 14px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row > label {
  flex: 1;
  min-width: 180px;
}

/* ---- code blocks ---- */

.code {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  overflow: hidden;
}

.code pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre;
}

.code .copy {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--dim);
  border-radius: var(--radius-control);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
}

.code .copy:hover {
  color: var(--text);
  border-color: var(--accent);
}

.code-caption {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--faint);
}

/* the once-only secret */
.secret {
  border-color: var(--pos);
  background: var(--pos-bg);
}

.secret pre {
  color: var(--pos);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- the waiting state ---- */

.waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--dim);
}

.spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--track);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  flex: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
  .progress-fill {
    transition: none;
  }
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.actions .spacer {
  flex: 1;
}

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

.footer {
  padding: 18px 26px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--faint);
}

.footer .spacer {
  flex: 1;
}

@media (max-width: 560px) {
  .topbar {
    padding: 14px 16px;
    gap: 10px;
  }
  /* The controls total ~460px, which a phone does not have. The signed-in
     address and the three-way theme switch are the two that can go: the
     theme still follows the OS, and the console carries the picker. What
     stays is the way out and the way forward. */
  .who,
  .topbar .theme-switch {
    display: none;
  }
  .topbar-right {
    gap: 8px;
  }
  .topbar-right .btn {
    padding: 0 12px;
  }
  .stage {
    padding: 28px 16px 48px;
  }
  .panel {
    padding: 22px;
  }
  .step-detail {
    padding: 16px;
  }
  .step {
    grid-template-columns: 26px 1fr;
    gap: 12px;
  }
  /* Five client tabs do not fit on a phone. They become a scrollable strip
     rather than squeezing the labels — `.step-body` already has min-width:0,
     so the strip scrolls inside itself and the page does not. */
  .step-detail .tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }
  .step-detail .tabs::-webkit-scrollbar {
    display: none;
  }
  .step-detail .tabs button {
    flex: 0 0 auto;
  }
  /* Desktop has slack at the end of each line for a floating Copy button;
     a phone does not, and the first line ends up underneath it. */
  .code {
    display: flex;
    flex-direction: column;
  }
  .code .copy {
    position: static;
    align-self: flex-end;
    margin: 0 8px 8px;
  }
}
