/* Element foundation: what a bare HTML tag looks like before any class is
   involved. Hand-written instead of a normalising library (project rule 2) --
   browsers agree on far more than they did when those libraries were written,
   and the parts that matter here fit on two screens.
 *
 * Rule for everything that follows: element selectors live in this file only.
 * Later packages style with classes, so a new page never fights this one. */

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

html {
  /* Anchors and in-page jumps must not hide behind the sticky header. */
  scroll-padding-top: var(--space-8);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  /* Capture happens on a phone in a classroom: no rubber-band sideways drift. */
  overflow-wrap: break-word;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 var(--space-3);
  line-height: var(--leading-tight);
  font-weight: 600;
  text-wrap: balance;
}

h1 {
  font-size: var(--text-3xl);
  letter-spacing: -0.01em;
}
h2 {
  font-size: var(--text-2xl);
}
h3 {
  font-size: var(--text-xl);
}
h4 {
  font-size: var(--text-lg);
}

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

:is(h1, h2, h3, h4) + :is(p, ul, ol, dl, table) {
  margin-top: 0;
}

ul,
ol {
  padding-left: var(--space-5);
}

li + li {
  margin-top: var(--space-1);
}

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

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

/* One visible focus ring for the whole application. Keyboard users get it,
   mouse users do not, and it never disappears without a replacement. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

hr {
  height: 1px;
  margin: var(--space-6) 0;
  border: 0;
  background: var(--border);
}

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

strong {
  font-weight: 600;
}

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

code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

pre {
  padding: var(--space-3);
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  line-height: 1.45;
}

pre code {
  padding: 0;
  background: none;
}

blockquote {
  margin-left: 0;
  padding-left: var(--space-4);
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

img,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

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(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--text-muted);
  font-weight: 600;
}

/* --- forms ---------------------------------------------------------------
   Styled here rather than as components: a form field is a field whether it
   sits in the login form (package 5) or the note editor (package 11). */

label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

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

input:not([type='checkbox'], [type='radio'], [type='file']),
textarea,
select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

textarea {
  min-height: 8rem;
  resize: vertical;
  line-height: var(--leading-normal);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: var(--surface-sunken);
  color: var(--text-faint);
  cursor: not-allowed;
}

::placeholder {
  color: var(--text-faint);
}

fieldset {
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

legend {
  padding: 0 var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* --- page frame ---------------------------------------------------------- */

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: var(--space-3);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--text-on-accent);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
}

.site-header__inner,
.site-main,
.site-footer__inner {
  width: 100%;
  max-width: var(--width-wide);
  margin: 0 auto;
  padding: var(--space-4);
}

/* Reading pages opt out of the wide measure by adding this to <main>. */
.site-main--narrow {
  max-width: var(--width-text);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-5);
  padding-block: var(--space-3);
}

.site-title {
  color: inherit;
  font-size: var(--text-lg);
  font-weight: 600;
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-right: auto;
}

.site-nav a {
  /* inline-flex plus min-height: a thumb on a phone needs the full target,
     not just the two lines of text. */
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  color: var(--text-muted);
  text-decoration: none;
}

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

/* Who is signed in, and the way out. A form, not a link -- logging out
   changes something, so it is a POST with a token like every other change. */
.site-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0;
}

.site-user__name {
  color: var(--text-muted);
  font-size: var(--text-sm);
  /* A long display name must not push the buttons off a narrow screen. */
  overflow: hidden;
  max-width: 12rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* On a phone the name costs a whole wrapped row -- measured: 162px of sticky
   header instead of 118px, a fifth of the screen gone before the first entry.
   The button says enough; there is one person holding the phone anyway. */
@media (width < 30rem) {
  .site-user__name {
    display: none;
  }
}

.site-main {
  padding-block: var(--space-6) var(--space-8);
}

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.site-footer p {
  margin: 0;
}

/* --- prose ---------------------------------------------------------------
   The wrapper for rendered markdown (package 11) and any longer German text.
   Serif, narrower measure, larger line height -- reading, not scanning. */

.prose {
  max-width: var(--width-text);
  font-family: var(--font-reading);
  font-size: var(--text-lg);
  line-height: 1.7;
}

/* --- respect the system setting ------------------------------------------ */

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