/* zsgr.org — shared stylesheet for every page. */

:root {
  color-scheme: dark;

  --bg: #120f1a;
  --bg-raised: #1c1728;
  --bg-sunken: #0d0b13;
  --border: #2e2540;
  --border-strong: #453a5e;

  --text: #eae7f0;
  --text-muted: #a89fba;
  --text-faint: #786d90;

  --accent: #b794f6;
  --accent-quiet: #6d4fa0;
  --accent-contrast: #1c0f30;

  --danger: #f2846b;
  --warn: #e8c069;

  --dot-online: #b794f6;
  --dot-offline: #f2846b;
  --dot-unknown: #786d90;

  --focus: #c9b3ff;

  --radius: 10px;
  --radius-sm: 6px;
  --measure: 700px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

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

  --bg: #ffffff;
  --bg-raised: #ffffff;
  --bg-sunken: #f6f3fb;
  --border: #e4defa;
  --border-strong: #cab8ef;

  --text: #201a2e;
  --text-muted: #675d7d;
  --text-faint: #8b8098;

  --accent: #7c3aed;
  --accent-quiet: #ece2fc;
  --accent-contrast: #ffffff;

  --danger: #b3401f;
  --warn: #8a6410;

  --dot-online: #7c3aed;
  --dot-offline: #b3401f;
  --dot-unknown: #8b8098;

  --focus: #6d28d9;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */

.wrap {
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.25rem;
}

main {
  padding: 1.5rem 0 4rem;
}

section {
  margin: 0 0 3rem;
}

section:last-child {
  margin-bottom: 0;
}

/* ---------- Skip link ---------- */

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 0 0 var(--radius-sm) 0;
  font-weight: 600;
}

.skip-link:focus {
  left: 0;
}

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--text);
}

.brand:hover {
  color: var(--accent);
}

.site-header nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.94rem;
}

.site-header nav a:hover,
.site-header nav a[aria-current="page"] {
  color: var(--text);
}

.site-header nav a[aria-current="page"] {
  font-weight: 600;
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  flex: none;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

/* ---------- Typography ---------- */

h1,
h2,
h3 {
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
  text-wrap: balance;
}

h1 {
  font-size: 1.9rem;
}

h2 {
  font-size: 1.35rem;
  margin-top: 0;
}

h3 {
  font-size: 1.05rem;
}

p {
  margin: 0 0 1rem;
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

.lede {
  font-size: 1.08rem;
  color: var(--text-muted);
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.88rem;
}

code,
kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ---------- Focus ---------- */

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

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

.hero {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 2rem 0 1rem;
  flex-wrap: wrap;
}

.avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  object-fit: cover;
  flex: none;
  display: block;
}

.hero h1 {
  margin: 0;
  font-size: 2.1rem;
}

.hero .tagline {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
}

/* ---------- Link list ---------- */

.links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.link-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.link-row .label {
  font-weight: 600;
  min-width: 5.25rem;
  flex: none;
}

.link-row .value {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--text-muted);
  word-break: break-all;
  flex: 1 1 auto;
}

.link-row a.value {
  color: var(--accent);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  flex: none;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn:disabled:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

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

.btn-primary:hover {
  background: var(--accent);
  color: var(--accent-contrast);
  filter: brightness(1.08);
}

.btn-lg {
  font-size: 1rem;
  padding: 0.75rem 1.4rem;
}

.btn-copied {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Status widget ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.94rem;
}

.status-dot {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: var(--dot-unknown);
  flex: none;
}

.status[data-state="online"] .status-dot {
  background: var(--dot-online);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot-online) 22%, transparent);
}

.status[data-state="offline"] .status-dot {
  background: var(--dot-offline);
}

.status[data-state="loading"] .status-dot {
  animation: pulse 1.3s ease-in-out infinite;
}

.status-text {
  color: var(--text);
}

.status[data-state="unavailable"] .status-text,
.status[data-state="loading"] .status-text {
  color: var(--text-muted);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

/* ---------- Cards ---------- */

.cards {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: 1fr;
}

.card {
  display: block;
  padding: 1.1rem 1.25rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}

.card:hover {
  border-color: var(--accent);
}

.card h3 {
  margin: 0 0 0.25rem;
  color: var(--accent);
}

.card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.94rem;
}

/* ---------- Callouts / TODO ---------- */

.callout {
  padding: 1rem 1.15rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

.todo {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-weight: 700;
  padding: 0.1em 0.45em;
  border-radius: 4px;
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  border: 1px dashed var(--warn);
  color: var(--warn);
}

/* ---------- Steps ---------- */

.steps {
  margin: 0;
  padding: 0 0 0 1.4rem;
  display: grid;
  gap: 0.5rem;
}

.steps li {
  padding-left: 0.25rem;
}

.steps strong {
  display: block;
}

.steps .step-note {
  color: var(--text-muted);
  font-size: 0.94rem;
}

/* ---------- Rules ---------- */

.rules-group {
  margin: 0 0 2.25rem;
}

.rules-list {
  margin: 0;
  padding: 0 0 0 1.6rem;
  display: grid;
  gap: 0.7rem;
}

.rules-list li {
  padding: 0.15rem 0.35rem 0.15rem 0.25rem;
  border-radius: var(--radius-sm);
  scroll-margin-top: 5rem;
}

.rule-body {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.rule-body > span {
  flex: 1 1 auto;
}

.anchor-btn {
  flex: none;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.2rem 0.3rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.rules-list li:hover .anchor-btn,
.anchor-btn:focus-visible,
.anchor-btn.is-copied {
  opacity: 1;
}

.anchor-btn:hover {
  color: var(--accent);
  border-color: var(--border);
}

.anchor-btn.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

.rules-list li.rule-target {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  animation: ruleflash 2.4s ease-out forwards;
}

@keyframes ruleflash {
  0%,
  55% {
    background: color-mix(in srgb, var(--accent) 20%, transparent);
  }
  100% {
    background: transparent;
  }
}

/* ---------- Tables ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 22rem;
  font-size: 0.95rem;
}

caption {
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

th,
td {
  text-align: left;
  padding: 0.65rem 1rem;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

thead th {
  background: var(--bg-sunken);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: 0;
}

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

.field {
  margin: 0 0 1.4rem;
}

.field label,
.legend-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.field .hint {
  display: block;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 0.4rem;
}

input[type="text"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.98rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
}

textarea {
  min-height: 6.5rem;
  resize: vertical;
}

input[type="text"]:hover,
select:hover,
textarea:hover {
  border-color: var(--text-faint);
}

.field.has-error input[type="text"],
.field.has-error select,
.field.has-error textarea {
  border-color: var(--danger);
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.88rem;
  margin-top: 0.35rem;
}

.field.has-error .error-msg {
  display: block;
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.9rem 1rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.checkbox-field input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0.25rem 0 0;
  accent-color: var(--accent);
  flex: none;
}

.checkbox-field label {
  margin: 0;
  font-weight: 400;
}

.field.has-error .checkbox-field {
  border-color: var(--danger);
}

.char-count {
  display: block;
  text-align: right;
  color: var(--text-faint);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.75rem;
}

.success-panel {
  padding: 1.5rem;
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

.success-panel h2 {
  color: var(--accent);
}

/* ---------- Redirect page ---------- */

.redirect-page {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0 2.5rem;
  color: var(--text-faint);
  font-size: 0.88rem;
}

.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
}

/* ---------- Utilities ---------- */

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Wider screens ---------- */

@media (min-width: 34rem) {
  h1 {
    font-size: 2.2rem;
  }

  .cards {
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  }
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .rules-list li.rule-target {
    background: color-mix(in srgb, var(--accent) 15%, transparent);
  }
}
