/*
  Shared by every page and every theme: the reset, small helpers, buttons, the
  story page's notice and the theme-preview bar. The Manage page adds
  manage.css on top.

  Colours and typefaces come from the theme: each theme file
  (theme-street.css, theme-syllabus.css, theme-fall.css) sets the variables
  these rules and manage.css read, and styles the public pages itself under
  its own [data-theme='...'] selector. The one exception is the theme-preview
  bar, which looks the same whatever theme is showing.
*/

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

/* Elements shown and hidden from script stay hidden whatever their display is. */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header) + 1rem);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--body-bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

main {
  display: block;
  min-height: 60vh;
  background: var(--page);
}

/* The story page fills in after it loads. A full-height page keeps the footer from jumping when it does. */
main[data-portfolio-page='story'] {
  min-height: 100vh;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-stretch: var(--display-stretch);
  font-weight: var(--display-weight);
  line-height: 1.05;
  letter-spacing: var(--display-tracking);
  text-wrap: balance;
}

p {
  margin: 0;
}

:focus-visible {
  outline: var(--paint) solid var(--accent);
  outline-offset: 3px;
}

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

.skip {
  position: absolute;
  top: 0;
  left: -999px;
  z-index: 20;
  padding: 0.6rem 0.9rem;
  background: var(--skip-bg);
  color: var(--skip-ink);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
}

.skip:focus {
  top: 0.5rem;
  left: 0.5rem;
}

/* Arrows are drawn, not typed, so they keep one weight in every font. */
.arrow {
  display: inline-block;
  flex: none;
  width: 0.72em;
  height: 0.72em;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3'%3E%3Cpath d='M2 12h19M13 4l8 8-8 8'/%3E%3C/svg%3E")
    center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3'%3E%3Cpath d='M2 12h19M13 4l8 8-8 8'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

.arrow-left {
  transform: rotate(180deg);
}

.arrow-down {
  transform: rotate(90deg);
}

.arrow-out {
  transform: rotate(-45deg);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.6rem;
  padding: 0 1.05rem;
  border: 0;
  border-radius: var(--btn-radius);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 0.12s,
    color 0.12s;
}

.btn:hover {
  background: var(--btn-hover-bg);
  color: var(--btn-hover-ink);
}

.btn-solid {
  background: var(--btn-solid-bg);
  color: var(--btn-solid-ink);
}

/* The story page's "Loading story…" notice. It turns red when the story cannot be shown. */
.status-banner {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--box-radius);
  background: var(--notice-bg);
  font-size: 0.92rem;
  font-weight: 500;
}

.status-banner.is-error {
  background: var(--stop);
  color: #fff;
}

/* The holder keeps the notice's margins inside it, and takes no room once the notice is hidden. */
.story-status {
  display: flow-root;
}

.story-status .status-banner {
  margin-block: 0.5rem clamp(2rem, 5vw, 4rem);
}

/* Shown while one browser tab is trying a theme out. Its colours never change with the theme. */
.preview-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1rem;
  padding: 0.6rem 1rem;
  background: #131416;
  color: #fff;
  font-family: system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.3;
}

.preview-bar button {
  padding: 0.4rem 0.75rem;
  border: 0;
  border-radius: 3px;
  background: #fff;
  color: #131416;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.preview-bar button:focus-visible {
  outline: 3px solid #ffe566;
  outline-offset: 2px;
}

/* theme.js measures the bar, which is taller on a phone, so the page can leave exactly that much room. */
.is-previewing body {
  padding-bottom: var(--preview-bar-height);
}

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

  .btn {
    transition: none;
  }
}

/* Windows high-contrast mode replaces backgrounds, so arrows and buttons need shapes it keeps. */
@media (forced-colors: active) {
  .arrow {
    forced-color-adjust: none;
    background: CanvasText;
  }

  .btn {
    border: 1px solid ButtonText;
  }
}
