/**
 * KISCSS content styles.
 */
html {
  font-size: var(--base-size);
}

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

body {
  margin: 0;
  background: var(--background-color);
  color: var(--text-color);
  font-family: var(--font);
  font-size: var(--text-size);
  font-weight: var(--text-weight);
  line-height: var(--line-height);
  overflow-wrap: anywhere;
}

/**
 * Headings and prose keep spacing proportional to their own text.
 */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin-block: 1.5em 0.5em;
  font-family: var(--heading-font);
  font-weight: var(--heading-weight);
  line-height: var(--heading-line-height);
  text-wrap: pretty;
}

h1 {
  font-size: 2rem;
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.25rem;
}

h4 {
  font-size: 1.12em;
}

h5,
h6 {
  font-size: 1em;
}

h6 {
  color: var(--muted-color);
}

:is(h1, h2, h3, h4, h5, h6):first-child {
  margin-top: 0;
}

p,
ul,
ol,
dl,
blockquote,
address {
  margin-block: 0 1em;
}

ul,
ol {
  padding-inline-start: 1.5em;
}

li+li {
  margin-top: 0.5em;
}

li> :is(ul, ol) {
  margin-block: 0.5em;
}

dt {
  font-weight: 600;
}

dd {
  margin-inline-start: 1.5em;
}

dd+dt {
  margin-top: 1em;
}

strong {
  font-weight: 700;
}

small {
  font-size: 0.88em;
}

address {
  font-style: normal;
}

abbr[title] {
  text-decoration: underline dotted;
  text-underline-offset: 0.15em;
}

sub,
sup {
  position: relative;
  font-size: 0.75em;
  line-height: 0;
  vertical-align: baseline;
}

sub {
  bottom: -0.25em;
}

sup {
  top: -0.5em;
}

a {
  color: var(--link-color);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--link-hover-color);
  text-decoration-thickness: 2px;
}

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

blockquote {
  margin-inline: 0;
  border-inline-start: 3px solid var(--border-color);
  padding-inline-start: 1em;
}

blockquote> :last-child {
  margin-bottom: 0;
}

/**
 * Code stays literal; wide examples scroll within the page.
 */
code,
kbd,
samp {
  font-family: var(--code-font);
  font-size: 0.88em;
}

:not(pre)>code {
  border-radius: var(--radius);
  padding: 0.15em 0.35em;
  background: var(--surface-color);
}

pre {
  border-radius: var(--radius);
  max-width: 100%;
  margin-block: 1em;
  padding: var(--panel-padding);
  overflow-x: auto;
  border: 1px solid var(--border-color);
  background: var(--surface-color);
  color: var(--text-color);
  font-family: var(--code-font);
  font-size: 1em;
  line-height: 1.6;
  tab-size: 2;
  overflow-wrap: normal;
}

pre code {
  padding: 0;
  background: transparent;
  white-space: pre;
}

kbd {
  border-radius: var(--radius);
  display: inline-block;
  padding: 0.1em 0.35em;
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  background: var(--surface-color);
}

/**
 * Plain tables scroll without requiring a renderer-specific wrapper.
 */
table {
  border-radius: var(--radius);
  display: block;
  width: 100%;
  max-width: 100%;
  margin-block: 1em;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9em;
}

th,
td {
  min-width: 8rem;
  padding: 0.6em 0.9em;
  border-bottom: 1px solid var(--border-color);
  text-align: start;
  vertical-align: top;
}

th {
  background: var(--surface-color);
  font-weight: 600;
  white-space: nowrap;
}

tbody:last-child tr:last-child > :is(th, td) {
  border-bottom: 0;
}

caption {
  padding: 0.5em;
  text-align: start;
}

/* Keep corner cell backgrounds inside the rounded table border. */
table > :nth-child(1 of thead, tbody, tfoot) > tr:first-child > :first-child {
  border-start-start-radius: var(--radius);
}
table > :nth-child(1 of thead, tbody, tfoot) > tr:first-child > :last-child {
  border-start-end-radius: var(--radius);
}
table > :is(tbody, tfoot):last-child > tr:last-child > :first-child {
  border-end-start-radius: var(--radius);
}
table > :is(tbody, tfoot):last-child > tr:last-child > :last-child {
  border-end-end-radius: var(--radius);
}

/**
 * Optional focusable wrapper for wide tables.
 */
.markdown-table {
  max-width: 100%;
  margin-block: 1em;
  overflow-x: auto;
}

.markdown-table table {
  display: table;
  margin: 0;
}

/**
 * Media and panels use layout spacing independent of their text size.
 */
figure {
  max-width: 100%;
  margin: var(--section-gap) 0;
}

img,
video {
  border-radius: var(--radius);
  display: block;
  max-width: 100%;
  height: auto;
}

figcaption {
  margin-top: 0.75em;
  color: var(--muted-color);
  font-size: 0.88em;
}

hr {
  margin-block: var(--section-gap);
  border: 0;
  border-top: 1px solid var(--border-color);
}

mark {
  border-radius: var(--radius);
  padding: 0.1em 0.2em;
  background: var(--mark-color);
  color: var(--mark-text-color);
}

details {
  border-radius: var(--radius);
  margin-block: var(--section-gap);
  padding: var(--panel-padding);
  border: 1px solid var(--border-color);
}

summary {
  cursor: pointer;
  font-weight: 600;
}

details[open]>summary {
  margin-bottom: 0.75em;
}

details> :last-child {
  margin-bottom: 0;
}

/**
 * Forms keep native control behaviour and use ordinary labels and groups.
 */
fieldset {
  border-radius: var(--radius);
  min-inline-size: 0;
  margin: 0 0 1em;
  padding: var(--panel-padding);
  border: 1px solid var(--border-color);
}

legend {
  padding-inline: 0.35em;
  font-weight: 600;
}

label {
  display: block;
  margin-bottom: 0.35em;
}

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

input:not([type='checkbox'], [type='radio'], [type='range'], [type='color'], [type='hidden'], [type='submit'], [type='reset'], [type='button'], [type='image']),
select,
textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 0.6em 0.75em;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--background-color);
  color: var(--text-color);
}

textarea {
  min-height: 8em;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-color);
  opacity: 1;
}

input[type='checkbox'],
input[type='radio'],
input[type='range'] {
  accent-color: var(--primary-color);
}

input[type='range'] {
  width: 100%;
}

input[type='color'] {
  min-width: 44px;
  min-height: 44px;
}

input[type='file'] {
  max-width: 100%;
}

/**
 * Native indicators retain the browser's states and high-contrast support.
 */
progress,
meter {
  display: block;
  width: 100%;
  height: 1em;
  margin-block: 0.35em 1em;
}

progress,
meter {
  appearance: none;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-color);
  color: var(--status-color, var(--primary-color));
  accent-color: var(--status-color, var(--primary-color));
}

progress::-webkit-progress-bar {
  border-radius: var(--radius);
  background: var(--surface-color);
}

progress::-webkit-progress-value {
  border-radius: var(--radius);
  background: var(--status-color, var(--primary-color));
}

progress::-moz-progress-bar {
  border-radius: var(--radius);
  background: var(--status-color, var(--primary-color));
}

meter::-webkit-meter-bar {
  height: 100%;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-color);
  box-shadow: none;
}

meter::-webkit-meter-optimum-value,
meter::-webkit-meter-suboptimum-value,
meter::-webkit-meter-even-less-good-value {
  border-radius: var(--radius);
  background: var(--status-color, var(--primary-color));
}

meter::-moz-meter-bar {
  border-radius: var(--radius);
  background: var(--status-color, var(--primary-color));
}

:is(input, select, textarea):disabled {
  background: var(--surface-color);
  color: var(--muted-color);
  cursor: not-allowed;
  opacity: 1;
}

input[readonly],
textarea[readonly] {
  background: var(--surface-color);
}

:is(input, select, textarea)[aria-invalid='true'] {
  border: 2px solid var(--danger-color);
}

/**
 * Status colours always accompany a written label or explanation.
 */
.is-danger {
  --status-color: var(--danger-color);
  --status-hover-color: var(--danger-hover-color);
  --status-text-color: var(--danger-text-color);
}

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

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

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

.notice {
  border-radius: var(--radius);
  margin-block: 0 1em;
  padding: var(--panel-padding);
  background: var(--status-color, var(--surface-color));
  color: var(--status-text-color, var(--text-color));
}

.notice a {
  color: inherit;
}

.notice> :last-child {
  margin-bottom: 0;
}

.form-field {
  margin-bottom: 1em;
}

.form-field>small {
  display: block;
  margin-top: 0.35em;
}

.form-choice {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  min-height: 44px;
  margin: 0;
  padding-block: 0.4em;
}

.form-choice:has(> .toggle) {
  align-items: center;
}

.form-choice>input {
  flex: none;
  margin: 0;
}

/**
 * A native checkbox styled as an on/off switch; pair with role="switch".
 */
input[type='checkbox'].toggle {
  appearance: none;
  position: relative;
  inline-size: 2.75em;
  block-size: 1.5em;
  border: 2px solid var(--border-color);
  border-radius: 2em;
  background: var(--surface-color);
  vertical-align: middle;
  cursor: pointer;
}

input[type='checkbox'].toggle::before {
  content: '';
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 0.15em;
  inline-size: 1em;
  block-size: 1em;
  border-radius: 50%;
  background: var(--text-color);
  transform: translateY(-50%);
}

input[type='checkbox'].toggle:checked {
  border-color: var(--primary-color);
  background: var(--primary-color);
}

input[type='checkbox'].toggle:checked::before {
  inset-inline-start: auto;
  inset-inline-end: 0.15em;
  background: var(--primary-text-color);
}

input[type='checkbox'].toggle:disabled {
  border-style: dashed;
  cursor: not-allowed;
}

/**
 * Calls to action: links navigate; native buttons perform actions.
 */
button,
input:is([type='submit'], [type='reset'], [type='button']),
.button {
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 44px;
  max-width: 100%;
  padding: 0.65em 1.25em;
  border: 0;
  background: var(--status-color, var(--primary-color));
  color: var(--status-text-color, var(--primary-text-color));
  font: inherit;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
  cursor: pointer;
}

button:not(:disabled):hover,
input:is([type='submit'], [type='reset'], [type='button']):not(:disabled):hover,
.button:not(:disabled):hover {
  background: var(--status-hover-color, var(--primary-hover-color));
  color: var(--status-text-color, var(--primary-text-color));
  text-decoration: none;
}

/* Outlined actions use the same palette as filled buttons. */
:is(button, input[type='submit'], input[type='reset'], input[type='button'], .button).is-outlined {
  border: 2px solid var(--status-color, var(--primary-color));
  padding: calc(0.65em - 2px) calc(1.25em - 2px);
  background: transparent;
  color: var(--status-color, var(--primary-color));
}

:is(button, input[type='submit'], input[type='reset'], input[type='button'], .button).is-outlined.is-warning {
  color: var(--text-color);
}

:is(button, input[type='submit'], input[type='reset'], input[type='button'], .button).is-outlined:not(:disabled):hover {
  border-color: var(--status-hover-color, var(--primary-hover-color));
  background: var(--status-hover-color, var(--primary-hover-color));
  color: var(--status-text-color, var(--primary-text-color));
}

button:disabled,
input:is([type='submit'], [type='reset'], [type='button']):disabled,
.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/**
 * A few opt-in helpers; content remains ordinary semantic HTML.
 */
.container {
  max-width: var(--container-max-width);
  margin: auto;
}

.section {
  padding-block: var(--section-gap);
}

.text-center {
  text-align: center;
}

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

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

.no-radius {
  --radius: 0;
  border-radius: 0;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-block: 1em;
}

.text-center .button-group {
  justify-content: center;
}

.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.125em;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-to-content {
  border-radius: var(--radius);
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 10;
  padding: 0.5em 1em;
  background: var(--background-color);
  transform: translateY(-200%);
}

.skip-to-content:focus {
  transform: none;
}