/* Base: reset + element defaults. Replaces what Pico.css used to provide.
   Styles bare elements and the generic classes emitted by the web components
   (`secondary`, `outline`, `close`, dialog > article). Tokens only. */

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color_bg_page);
  color: var(--color_fg_default);
  font-family: var(--font-primary);
  font-size: var(--text-md);
  line-height: 1.6;
  font-feature-settings: 'zero';
  -webkit-font-smoothing: antialiased;
}

main {
  flex: 1;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 var(--space-3);
  color: var(--color_fg_bold);
  font-family: var(--font-secondary);
  font-weight: 500;
  line-height: 1.2;
  overflow-wrap: break-word;   /* a long word in a heading breaks instead of widening the page when text is enlarged */
}

h1 { font-size: var(--text-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); margin-top: var(--space-6); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-md); }

p,
ul,
ol,
pre,
table,
figure {
  margin: 0 0 var(--space-4);
}

hgroup {
  margin-bottom: var(--space-5);
}

hgroup > * {
  margin-bottom: var(--space-2);
}

hgroup > :last-child {
  margin-bottom: 0;
  color: var(--color_fg_muted);
  font-size: var(--text-lg);
  font-weight: 400;
  font-family: var(--font-primary);
}

a {
  color: var(--color_fg_link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

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

small {
  font-size: var(--text-sm);
}

hr {
  border: 0;
  border-top: 1px solid var(--color_border_default);
  margin: var(--space-5) 0;
}

/* Code */

code,
pre,
kbd {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--color_bg_layer_alternate-bold);
  color: var(--color_fg_bold);
}

pre {
  padding: var(--space-4);
  overflow-x: auto;
  border: 1px solid var(--color_border_default);
  border-radius: var(--radius-md);
  background: var(--color_bg_layer_alternate);
}

pre code {
  padding: 0;
  background: none;
  font-size: 1em;   /* the <pre> sets the size; 0.875em on top of it would compound (14px -> 12.25px) */
}

/* Tables (diagram Markdown) */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

th,
td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color_border_default);
  text-align: left;
}

th {
  color: var(--color_fg_bold);
  font-weight: 500;
}

blockquote {
  margin: 0 0 var(--space-4);
  padding: var(--space-1) var(--space-4);
  border-left: 3px solid var(--color_border_bold);
  color: var(--color_fg_muted);
}

/* Forms */

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

input[type='search'],
input[type='text'] {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color_border_input);
  border-radius: var(--radius-md);
  background: var(--color_bg_input);
  color: var(--color_fg_bold);
  transition: border-color var(--duration-fast);
}

input::placeholder {
  color: var(--color_fg_input_placeholder);
}

input:hover {
  border-color: var(--color_border_input_hover);
}

input:focus {
  border-color: var(--color_border_focus);
}

/* Buttons: default is the neutral token button; `secondary`/`outline`
   are the class names emitted by interactive-diagram.js. */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color_border_button);
  border-radius: var(--radius-md);
  background: var(--color_bg_button);
  color: var(--color_fg_on_button);
  font-weight: 500;
  line-height: 1.5;
  cursor: pointer;
  transition: background-color var(--duration-fast), border-color var(--duration-fast);
}

button:hover {
  background: var(--color_bg_button_hover);
}

button:active {
  background: var(--color_bg_button_pressed);
}

button:disabled,
button[aria-disabled='true'] {
  color: var(--color_fg_disabled);
  cursor: not-allowed;
}

button.secondary.outline,
button.outline {
  background: transparent;
}

button.outline:hover {
  background: var(--color_bg_button_hover);
}

button[aria-pressed='true'] {
  background: var(--color_bg_primary);
  border-color: var(--color_bg_primary);
  color: var(--color_fg_on_primary);
}

button[aria-pressed='true']:hover {
  background: var(--color_bg_primary_hover);
}

button.close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
  font-size: var(--text-lg);
}

button.close::before {
  content: '\00d7';
  line-height: 1;
}

/* Dialog (message details) */

dialog {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  max-width: 100vw;
}

/* Frosted modal (as on openidconnect.net): the page behind is heavily blurred and only lightly dimmed, so it
   reads as soft colour; the panel is a translucent surface over that. Fallback values keep it usable in
   browsers where ::backdrop does not inherit the theme tokens. */
dialog::backdrop {
  background: var(--color_bg_scrim, rgba(10, 10, 10, 0.38));
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
  backdrop-filter: blur(16px) saturate(1.15);
}

dialog > article {
  margin: 0 auto;
  padding: var(--space-4);
  border: 1px solid var(--color_border_default);
  border-radius: var(--radius-lg);
  background: var(--color_bg_modal);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
  box-shadow: var(--shadow_card_hover);
}

/* No blur available, or blur not wanted: opaque scrim and panel so nothing relies on seeing through. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
  dialog > article { background: var(--color_bg_layer_elevated); }
}

@media (prefers-reduced-transparency: reduce) {
  dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  dialog > article {
    background: var(--color_bg_layer_elevated);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

/* Open: the backdrop fades in and the panel rises slightly. */
@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-rise { from { opacity: 0; transform: translateY(8px) scale(0.985); } }

dialog[open]::backdrop { animation: modal-fade var(--duration-base) ease-out; }
dialog[open] > article { animation: modal-rise 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }

@media (prefers-reduced-motion: reduce) {
  dialog[open]::backdrop,
  dialog[open] > article { animation: none; }
}

dialog > article > header {
  margin-bottom: var(--space-3);
}

/* Set by theme-toggle.js for the frame in which the theme changes, so colours switch together instead of
   fading element by element (the fade shows up as a flash on cards and buttons). */
html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition: none !important;
}

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

  * {
    transition: none !important;
  }
}
