/*
 * Magic Apps documentation
 *
 * Same visual world as the marketing site - indigo velvet, one gilt accent - but this is a reading
 * surface, so it commits to legibility: a wide measure, quieter headings, and a sidebar that stays
 * put. The tokens mirror `website/src/assets/site.css`; keep the two in step when either changes.
 * Committed single-theme, as the site is.
 */

:root {
  --ink: #0b0918;
  --ink-raised: #100c26;
  --velvet: #16113c;
  --velvet-mid: #221d54;
  --gilt: #f5c24c;
  --conjure: #c084fc;
  --azure: #5b9bf8;
  --paper: #f4f1ea;
  --mist: #b9b2d1;
  --mist-dim: #8b84a9;

  --hairline: rgb(244 241 234 / 10%);
  --hairline-strong: rgb(244 241 234 / 18%);

  --font-ui:
    -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, 'Helvetica Neue', sans-serif;
  --font-display:
    -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, 'Helvetica Neue', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;

  --side: 17rem;
  --wrap: 54rem;
  --radius: 12px;

  /* Pagefind UI, repainted to the same palette. */
  --pagefind-ui-primary: var(--gilt);
  --pagefind-ui-text: var(--paper);
  --pagefind-ui-background: var(--ink-raised);
  --pagefind-ui-border: rgb(244 241 234 / 18%);
  --pagefind-ui-tag: var(--velvet-mid);
  --pagefind-ui-border-width: 1px;
  --pagefind-ui-border-radius: 8px;
  --pagefind-ui-font: var(--font-ui);
}

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

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

body {
  margin: 0;
  background-color: var(--ink);
  color: var(--mist);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: -20% -10% auto -10%;
  height: 70vh;
  background: radial-gradient(
    55% 50% at 50% 0%,
    rgb(99 102 241 / 16%),
    rgb(67 56 202 / 6%) 45%,
    transparent 72%
  );
  pointer-events: none;
  z-index: 0;
}

a {
  color: var(--gilt);
  text-decoration-color: rgb(245 194 76 / 35%);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: currentColor;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 1rem;
  top: 1rem;
  z-index: 10;
  background: var(--gilt);
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
}

/* ---------------------------------------------------------------- top bar */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgb(11 9 24 / 82%);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--hairline);
}

.top__inner {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  max-width: 84rem;
  margin: 0 auto;
  padding: 0.7rem clamp(1rem, 3vw, 2rem);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 600;
  text-decoration: none;
}

.brand__mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
}

.top__tag {
  margin: 0;
  color: var(--mist-dim);
  font-size: 0.9rem;
  border-left: 1px solid var(--hairline-strong);
  padding-left: 0.9rem;
}

.top__exit {
  margin-left: auto;
  font-size: 0.9rem;
}

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

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  max-width: 84rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 3vw, 2rem) 4rem;
}

.side {
  position: sticky;
  top: 4.5rem;
  align-self: start;
  max-height: calc(100vh - 5.5rem);
  overflow-y: auto;
  font-size: 0.925rem;
}

.side__home {
  display: block;
  font-weight: 600;
  color: var(--paper);
  text-decoration: none;
  padding: 0.2rem 0;
}

.search {
  margin-bottom: 1.1rem;
}

.search .pagefind-ui__search-input {
  font-size: 0.9rem;
}

.side__group {
  margin: 1.5rem 0 0.4rem;
  color: var(--mist-dim);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.side__list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--hairline);
}

.side__list a {
  display: block;
  padding: 0.22rem 0 0.22rem 0.85rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--mist);
  text-decoration: none;
}

.side__list a:hover {
  color: var(--paper);
}

.side__list a[aria-current='page'] {
  color: var(--gilt);
  border-left-color: var(--gilt);
}

/* ---------------------------------------------------------------- document */

.doc {
  max-width: var(--wrap);
  min-width: 0;
}

.doc :is(h1, h2, h3, h4) {
  font-family: var(--font-display);
  color: var(--paper);
  line-height: 1.25;
  scroll-margin-top: 5rem;
}

.doc h1 {
  margin: 0 0 1.25rem;
  font-size: clamp(1.9rem, 3.4vw, 2.6rem);
  letter-spacing: -0.02em;
}

.doc h2 {
  margin: 2.75rem 0 0.9rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hairline);
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.doc h3 {
  margin: 2rem 0 0.6rem;
  font-size: 1.15rem;
}

.doc h4 {
  margin: 1.6rem 0 0.5rem;
  font-size: 1rem;
  color: var(--mist);
}

.doc :is(h2, h3, h4) a {
  color: inherit;
  text-decoration: none;
}

.doc p,
.doc li {
  max-width: 44rem;
}

.doc ul,
.doc ol {
  padding-left: 1.3rem;
}

.doc li {
  margin: 0.3rem 0;
}

.doc strong {
  color: var(--paper);
}

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

.doc blockquote {
  margin: 1.5rem 0;
  padding: 0.2rem 1.1rem;
  border-left: 3px solid var(--hairline-strong);
  color: var(--mist-dim);
}

.doc code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--ink-raised);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 0.12em 0.38em;
}

.doc pre {
  overflow-x: auto;
  margin: 1.4rem 0;
  padding: 1rem 1.15rem;
  background: var(--ink-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  line-height: 1.55;
}

.doc pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.85rem;
}

.doc table {
  width: 100%;
  margin: 1.5rem 0;
  border-collapse: collapse;
  font-size: 0.925rem;
}

.doc :is(th, td) {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
  text-align: left;
  vertical-align: top;
}

.doc th {
  color: var(--paper);
  font-weight: 600;
}

.doc img {
  max-width: 100%;
  height: auto;
}

.doc .mermaid {
  margin: 1.5rem 0;
  padding: 1.25rem 1rem;
  overflow-x: auto;
  background: var(--ink-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  text-align: center;
}

.doc .mermaid svg {
  max-width: 100%;
  height: auto;
}

/* Mermaid's own error rendering is a red box; keep the page readable if a diagram fails. */
.doc .mermaid[data-processed='true'] {
  background: var(--ink-raised);
}

/* Anchors get a quiet marker so a deep link is findable without shouting. */
.doc :is(h2, h3, h4)::before {
  content: '#';
  color: var(--mist-dim);
  opacity: 0;
  margin-left: -1.1em;
  padding-right: 0.35em;
}

.doc :is(h2, h3, h4):hover::before {
  opacity: 0.6;
}

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

.foot {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--hairline);
}

.foot__inner {
  max-width: 84rem;
  margin: 0 auto;
  padding: 2rem clamp(1rem, 3vw, 2rem) 3rem;
  font-size: 0.9rem;
  color: var(--mist-dim);
}

.foot__inner p {
  max-width: 46rem;
}

.foot__legal {
  margin-top: 0.75rem;
}

@media (width < 60rem) {
  .shell {
    grid-template-columns: 1fr;
  }

  .side {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--hairline);
    padding-bottom: 1rem;
  }

  .doc p,
  .doc li {
    max-width: none;
  }
}
