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

html {
  min-width: 20rem;
  background: var(--canvas);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
}

button,
select,
summary,
input[type="checkbox"] {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

a {
  color: var(--accent-strong);
  text-underline-offset: 0.2em;
  text-decoration-thickness: 0.08em;
}

a:hover {
  text-decoration-thickness: 0.14em;
}

:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.2rem;
  box-shadow: 0 0 0 0.08rem var(--focus-halo);
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

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

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.75rem 1rem;
  transform: translateY(-180%);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 4.75rem;
  display: grid;
  grid-template-columns: minmax(12rem, 15rem) minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.5rem;
  padding: 0.7rem clamp(1rem, 2.2vw, 2rem);
  border-bottom: 1px solid var(--rule);
  background: var(--header-bg);
  color: var(--header-text);
}

.brand {
  display: inline-flex;
  flex-direction: column;
  width: fit-content;
  color: var(--header-text);
  text-decoration: none;
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.brand-line {
  color: var(--header-muted);
  font-size: 0.72rem;
  letter-spacing: 0.045em;
}

.header-context {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--header-muted);
  font-size: 0.8rem;
}

.mode-badge {
  flex: 0 0 auto;
  padding: 0.28rem 0.5rem;
  border: 1px solid currentColor;
  color: var(--header-text);
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.identity-copy {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-control label {
  color: var(--header-muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.theme-control select {
  min-height: 2.75rem;
  max-width: 14rem;
  padding: 0.4rem 2rem 0.4rem 0.65rem;
  border: 1px solid var(--header-muted);
  border-radius: 0;
  background: var(--header-bg);
  color: var(--header-text);
}

.custom-theme-open,
.custom-theme-close {
  min-height: 2.75rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--header-muted);
  border-radius: 0;
  background: var(--header-bg);
  color: var(--header-text);
  font-size: 0.78rem;
  font-weight: 800;
}

.custom-theme-dialog {
  width: min(46rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.custom-theme-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.custom-theme-form {
  padding: clamp(1rem, 3vw, 1.75rem);
}

.custom-theme-form > header,
.custom-theme-form > footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.custom-theme-form h2 {
  margin: 0.2rem 0 0;
  font-family: var(--font-serif);
  font-size: clamp(1.55rem, 4vw, 2.25rem);
  line-height: 1.05;
}

.custom-theme-help {
  margin: 1rem 0 1.25rem;
  color: var(--text-muted);
}

.custom-theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem 1rem;
}

.custom-colour-field {
  display: grid;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.custom-colour-inputs {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
}

.custom-colour-inputs input {
  min-height: 2.75rem;
  border: 1px solid var(--input-border);
  border-radius: 0;
  background: var(--input-bg);
  color: var(--text);
}

.custom-colour-inputs input[type="color"] {
  width: 3rem;
  padding: 0.2rem;
  border-right: 0;
}

.custom-colour-inputs input[type="text"] {
  min-width: 0;
  padding: 0.45rem 0.65rem;
  font-family: var(--font-mono);
  text-transform: lowercase;
}

.custom-colour-inputs input[aria-invalid="true"] {
  border-color: var(--danger);
}

.custom-theme-form > footer {
  align-items: center;
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

@media (max-width: 40rem) {
  .custom-theme-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .custom-theme-open {
    min-height: 2.6rem;
    padding-inline: 0.45rem;
    font-size: 0.7rem;
  }

  .theme-control:has(.custom-theme-open:not([hidden])) select {
    max-width: 6.5rem;
  }
}

.site-shell {
  min-height: calc(100vh - 4.75rem);
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr);
}

.primary-nav {
  position: sticky;
  top: 4.75rem;
  height: calc(100vh - 4.75rem);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--rule);
  background: var(--nav-bg);
  color: var(--nav-text);
}

.nav-group + .nav-group {
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid color-mix(in srgb, var(--nav-text) 22%, transparent);
}

.nav-label {
  margin: 0 0 0.45rem 0.75rem;
  color: var(--nav-muted);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.primary-nav a {
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  margin: 0.1rem 0;
  padding: 0.55rem 0.75rem;
  border-left: 0.2rem solid transparent;
  color: var(--nav-text);
  font-size: 0.9rem;
  text-decoration: none;
}

.primary-nav a:hover {
  background: color-mix(in srgb, var(--nav-text) 9%, transparent);
}

.primary-nav a[aria-current="page"] {
  border-left-color: var(--nav-active-bg);
  background: var(--nav-active-bg);
  color: var(--nav-active-text);
  font-weight: 800;
}

.nav-foot {
  display: grid;
  gap: 0.15rem;
  margin-top: auto;
  padding: 1rem 0.75rem 0;
  border-top: 1px solid color-mix(in srgb, var(--nav-text) 22%, transparent);
  color: var(--nav-muted);
  font-size: 0.7rem;
}

.main-content {
  min-width: 0;
  padding: clamp(1.25rem, 3vw, 3.25rem);
  background: var(--surface);
}

.fixture-banner {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin: 0 auto clamp(1.5rem, 3vw, 2.5rem);
  padding: 0.7rem 0.85rem;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.fixture-banner strong {
  flex: 0 0 auto;
  color: var(--accent-strong);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mobile-nav {
  display: none;
}

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

@media print {
  .site-header,
  .primary-nav,
  .mobile-nav,
  .fixture-banner,
  .theme-control,
  .demo-states,
  .post-answer-action {
    display: none !important;
  }

  body,
  .main-content {
    background: #fff !important;
    color: #111 !important;
  }

  .site-shell {
    display: block;
  }

  .main-content {
    padding: 0;
  }

  a {
    color: #111 !important;
  }
}
