/* ============================ Tokens ============================ */
:root {
  --bg: #0d1421;
  --surface: #141d2e;
  --surface-2: #1b2740;
  --border: #26324c;
  --text: #e6ecf5;
  --muted: #8a97b0;
  --accent: #37d9c4;
  --accent-strong: #22bfab;
  --accent-ink: #06231f;
  --good: #46d68a;
  --warn: #f5b74e;
  --danger: #ff7a7a;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --radius: 16px;
  --radius-sm: 9px;
  --shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.8);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f6fb; --surface: #ffffff; --surface-2: #eef2f9; --border: #dde4ef;
    --text: #16202f; --muted: #5a6a85; --accent: #0fb5a0; --accent-strong: #0a8f7f;
    --accent-ink: #ffffff; --good: #14a05a; --warn: #b7791f; --danger: #d64545;
    --shadow: 0 24px 60px -34px rgba(20, 40, 80, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1421; --surface: #141d2e; --surface-2: #1b2740; --border: #26324c;
  --text: #e6ecf5; --muted: #8a97b0; --accent: #37d9c4; --accent-strong: #22bfab;
  --accent-ink: #06231f; --good: #46d68a; --warn: #f5b74e; --danger: #ff7a7a;
  --shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.8);
}
:root[data-theme="light"] {
  --bg: #f3f6fb; --surface: #ffffff; --surface-2: #eef2f9; --border: #dde4ef;
  --text: #16202f; --muted: #5a6a85; --accent: #0fb5a0; --accent-strong: #0a8f7f;
  --accent-ink: #ffffff; --good: #14a05a; --warn: #b7791f; --danger: #d64545;
  --shadow: 0 24px 60px -34px rgba(20, 40, 80, 0.4);
}

/* ============================ Base ============================ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(900px 480px at 15% -8%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 60%),
    radial-gradient(760px 420px at 100% 4%, color-mix(in srgb, #6d8cff 12%, transparent), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.55;
  min-height: 100vh;
}
code { font-family: var(--mono); font-size: 0.9em; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a { color: var(--accent-strong); }

.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.5rem) clamp(1rem, 4vw, 1.5rem) 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* ============================ Brand ============================ */
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand__mark {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--border);
}
.brand__name { font-family: var(--mono); font-weight: 600; letter-spacing: -0.02em; font-size: 1.02rem; }
.brand__dim { color: var(--muted); }

/* ============================ Hero ============================ */
.hero {
  position: relative;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, var(--accent) 4%), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.3rem, 4vw, 2rem);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero::before { /* faint global-grid texture */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(color-mix(in srgb, var(--accent) 22%, transparent) 1px, transparent 1.4px);
  background-size: 22px 22px;
  opacity: 0.10;
  mask-image: radial-gradient(120% 90% at 90% 0%, #000, transparent 70%);
}
.hero > * { position: relative; }

.hero__top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem;
}
.hero__eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.14em;
  font-size: 0.7rem; color: var(--accent-strong);
}

/* Country picker */
.country-picker { display: inline-flex; align-items: center; gap: 0.5rem; }
.country-picker__lbl {
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.1em;
  font-size: 0.62rem; color: var(--muted);
}
#countrySelect {
  font: inherit; font-size: 0.85rem; font-weight: 600;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.4rem 2rem 0.4rem 0.7rem; cursor: pointer;
  max-width: 12rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 0.85rem center, right 0.6rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
#countrySelect:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
#countrySelect:disabled { opacity: 0.6; cursor: default; }
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 70%, transparent);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.hero__body { display: flex; align-items: center; gap: 1.1rem; min-height: 72px; }
.flag {
  width: 88px; height: 66px; object-fit: cover;
  border-radius: 10px; border: 1px solid var(--border);
  box-shadow: 0 8px 22px -12px rgba(0, 0, 0, 0.6);
  background: var(--surface-2);
  flex: none;
}
.hero__id { min-width: 0; }
.hero__id h1 {
  font-size: clamp(2rem, 7vw, 3rem); line-height: 1; margin: 0 0 0.35rem;
  letter-spacing: -0.025em; text-wrap: balance;
}
.hero__place { margin: 0; color: var(--muted); font-size: 1rem; display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem; align-items: baseline; }
.hero__map { font-size: 0.82rem; text-decoration: none; border-bottom: 1px dashed currentColor; }
.hero__map:hover { color: var(--accent); }

/* Stats */
.stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
  margin-top: 1.4rem;
}
.stat {
  background: color-mix(in srgb, var(--bg) 35%, var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  min-width: 0;
}
.stat__k {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.09em;
  font-size: 0.62rem; color: var(--muted); margin-bottom: 0.35rem;
}
.stat__k b { color: var(--text); font-size: 0.78rem; letter-spacing: 0; }
.stat__v { display: block; font-weight: 600; font-size: 0.98rem; }
.stat--load { display: flex; flex-direction: column; justify-content: center; }
.meter { display: block; height: 8px; border-radius: 99px; background: var(--surface); overflow: hidden; border: 1px solid var(--border); }
.meter__fill {
  display: block; height: 100%; width: 0; border-radius: 99px;
  background: var(--good); transition: width 0.7s cubic-bezier(.2,.7,.2,1);
}
.meter__fill.is-mid { background: var(--warn); }
.meter__fill.is-high { background: var(--danger); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.chip {
  font-size: 0.76rem; font-weight: 600;
  padding: 0.28rem 0.62rem; border-radius: 99px;
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}

.hero__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.5rem; }

/* Skeleton */
.skel { background: linear-gradient(90deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 55%, var(--border)), var(--surface-2)); background-size: 200% 100%; border-radius: 8px; animation: shimmer 1.3s linear infinite; }
.skel--flag { width: 88px; height: 66px; flex: none; border-radius: 10px; }
.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 0.6rem; }
.skel--h1 { height: 34px; width: 62%; }
.skel--sub { height: 16px; width: 40%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================ Builder ============================ */
.builder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.3rem, 4vw, 1.9rem);
  box-shadow: var(--shadow);
  scroll-margin-top: 1.25rem;
}

/* Deep-link arrival (#private_key / #build_conf): a brief ring so you can see
   which step the link dropped you on. */
.builder.is-targeted { animation: target-flash 1.8s ease-out 1; }
@keyframes target-flash {
  0%, 35% {
    box-shadow: var(--shadow),
      0 0 0 2px var(--accent),
      0 0 0 7px color-mix(in srgb, var(--accent) 22%, transparent);
  }
  100% {
    box-shadow: var(--shadow),
      0 0 0 2px transparent,
      0 0 0 7px transparent;
  }
}
.builder__title { font-size: 1.35rem; margin: 0 0 0.4rem; letter-spacing: -0.01em; }
.builder__lede { color: var(--muted); margin: 0 0 1.4rem; font-size: 0.95rem; max-width: 52ch; }
.builder__lede strong { color: var(--text); }
.lbl {
  display: block; font-family: var(--mono); text-transform: uppercase;
  letter-spacing: 0.09em; font-size: 0.66rem; color: var(--muted); margin-bottom: 0.5rem;
}

/* Field */
.field { display: flex; gap: 0.5rem; }
.input {
  flex: 1; min-width: 0; font: inherit;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem; font-size: 0.92rem;
}
.input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.input:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.note { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.82rem; margin: 0.75rem 0 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
kbd {
  font-family: var(--mono); font-size: 0.72em; line-height: 1;
  padding: 0.18em 0.42em; border-radius: 5px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-width: 2px; color: var(--text);
}

/* Terminal */
.terminal {
  margin-top: 1.4rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: color-mix(in srgb, var(--bg) 55%, var(--surface-2));
}
.terminal__bar {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.75rem; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.terminal__dots { display: inline-flex; gap: 5px; }
.terminal__dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.terminal__title { font-size: 0.72rem; color: var(--muted); }
.terminal__body {
  margin: 0; padding: 1rem; font-size: 0.83rem; line-height: 1.75;
  color: var(--text); overflow-x: auto; white-space: pre; tab-size: 2; min-height: 3rem;
}
.terminal__body.is-placeholder { color: var(--muted); white-space: pre-wrap; }

.actions { display: flex; gap: 0.6rem; margin-top: 1rem; }

/* ============================ Buttons ============================ */
.btn {
  font: inherit; font-weight: 600; border-radius: var(--radius-sm);
  padding: 0.6rem 1.05rem; cursor: pointer; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 0.45rem; text-decoration: none;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:not(:disabled):hover { background: var(--accent-strong); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:not(:disabled):hover { background: var(--surface-2); }
.btn__ico { font-size: 1.05em; line-height: 1; }
.btn.is-loading { position: relative; color: transparent; }
.btn.is-loading .btn__ico { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 45%, transparent);
  border-top-color: var(--text);
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Alerts ============================ */
.alert { margin: 1.1rem 0 0; padding: 0.7rem 0.85rem; border-radius: var(--radius-sm); font-size: 0.88rem; }
.alert--error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 38%, transparent);
}
.alert--warn {
  color: var(--text);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 36%, transparent);
  margin-bottom: 1.4rem;
}
.alert--ok {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--good) 38%, transparent);
}

/* Inline text button (used inside prose) */
.linkbtn {
  font: inherit; font-size: inherit; padding: 0; cursor: pointer;
  background: none; border: 0; border-bottom: 1px dashed currentColor;
  color: var(--accent-strong);
}
.linkbtn:hover { color: var(--accent); }
.linkbtn:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 3px; }

/* Token → key section */
#curlBox { margin: -0.5rem 0 1.4rem; }
#curlBox .terminal__body { white-space: pre-wrap; word-break: break-all; }

/* ============================ Footer ============================ */
.foot { color: var(--muted); font-size: 0.8rem; text-align: center; padding: 0 0.5rem; }
.foot code { color: var(--text); }
.foot__dim { opacity: 0.7; margin-top: 0.4rem; }
.foot__by {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 0.9rem; padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: color-mix(in srgb, var(--muted) 65%, transparent);
}
.foot__by a {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); text-decoration: none;
  transition: color 0.2s ease;
}
.foot__by a:hover { color: var(--text); }
.foot__by a:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 5px; }
.foot__by svg { width: 14px; height: 14px; fill: currentColor; flex: none; }

/* ============================ Theme toggle ============================ */
.theme-toggle {
  position: fixed; top: 1rem; right: 1rem;
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); cursor: pointer;
  color: var(--accent-strong); z-index: 10;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover { background: var(--surface-2); transform: rotate(-12deg); }
.theme-toggle:focus-visible { outline: none; box-shadow: var(--ring); }
.theme-toggle > svg { grid-area: 1 / 1; }

/* Show the icon for the theme you'd switch TO: sun while dark, moon while light. */
.theme-toggle__sun { display: block; }
.theme-toggle__moon { display: none; }
@media (prefers-color-scheme: light) {
  .theme-toggle__sun { display: none; }
  .theme-toggle__moon { display: block; }
}
:root[data-theme="dark"] .theme-toggle__sun { display: block; }
:root[data-theme="dark"] .theme-toggle__moon { display: none; }
:root[data-theme="light"] .theme-toggle__sun { display: none; }
:root[data-theme="light"] .theme-toggle__moon { display: block; }

/* ============================ Responsive / motion ============================ */
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr; }
  .flag { width: 66px; height: 50px; }
  .actions, .hero__actions { flex-direction: column; }
  .actions .btn, .hero__actions .btn { width: 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
