/*
 * Design tokens and base element styles. Components each live in their own file in this folder,
 * and the layout links all of them.
 */

:root {
  color-scheme: light; /* Scrollbars and the browser's own controls */

  --content-max-width: 720px;
  --sidebar-width: 15rem;
  --tab-bar-height: 3.5rem;
  --focus-glow-size: 10px;

  /* How far things floating at the bottom of the screen keep from its edge. The nav raises it on phones (nav.css) */
  --bottom-inset: env(safe-area-inset-bottom);

  /* Bars that stay on screen as the page scrolls under them */
  --bar-backdrop-filter: blur(20px) saturate(1.8);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --radius-s: 0.5rem;
  --radius-m: 1rem;

  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-h1: 2rem;
  --fs-h2: 1.5rem;
  --fs-body: 1rem;
  --fs-small: 0.875rem;

  --bg-color: rgb(250, 248, 246);
  --text-color: #1c1a19;
  --meta-text-color: #6b6461;
  --border-color: #ddd6d2;
  --button-color: hsl(16, 85%, 74%);
  --button-hover-color: hsl(16, 85%, 68%);
  --button-text-color: #1c1a19;
  --link-color: hsl(16, 70%, 45%);
  --link-hover-color: hsl(16, 70%, 38%);
  --card-bg-color: #f0ebe8;
  --card-bg-hover-color: #e9e2de;
  --drop-shadow-color: rgba(0, 0, 0, 0.1);
  --focus-color: hsl(197, 59%, 50%);
  --focus-shadow-color: rgba(52, 160, 203, 0.65);
  --form-error-color: rgb(255, 120, 120);
  --notice-bg-color: #d4edda;
  --notice-text-color: #155724;
  --alert-bg-color: #f8d7da;
  --alert-text-color: #721c24;
  --badge-contributor-bg-color: #b8d3eb;
  --badge-viewer-bg-color: #e3ded9;
  --required-asterisk-color: rgb(228, 59, 59);
  --danger-color: hsl(0, 65%, 45%);
  --keep-color: hsl(140, 55%, 32%);
  --star-color: hsl(40, 90%, 48%);
  --bar-bg-color: color-mix(in srgb, var(--bg-color) 80%, transparent);

  /* Chevron for <select>. The stroke color is repeated per theme since CSS vars can't be used inside a url() string */
  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%231c1a19' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='1 1 6 7 11 1'/></svg>");
}

/* [data-theme="dark"] is set on <html> by an inline script in the layout head before first paint. Parts of a page
   that are dark in either theme, such as the viewer, have .always-dark */
:root[data-theme="dark"], .always-dark {
  color-scheme: dark;

  --bg-color: #141211;
  --text-color: #ebe6e3;
  --meta-text-color: #9a928e;
  --border-color: #46403d;
  --button-color: hsl(16, 50%, 45%);
  --button-hover-color: hsl(16, 50%, 50%);
  --button-text-color: #ebe6e3;
  --link-color: hsl(16, 75%, 65%);
  --link-hover-color: hsl(16, 75%, 72%);
  --card-bg-color: #262220;
  --card-bg-hover-color: #312c29;
  --drop-shadow-color: rgba(255, 255, 255, 0.08);
  --focus-color: rgb(115, 215, 255);
  --focus-shadow-color: rgba(115, 215, 255, 0.65);
  --form-error-color: rgb(163, 67, 67);
  --notice-bg-color: #234d2c;
  --notice-text-color: #d4edda;
  --alert-bg-color: #5c2329;
  --alert-text-color: #f8d7da;
  --badge-contributor-bg-color: #4c6a85;
  --badge-viewer-bg-color: #4a4441;
  --required-asterisk-color: rgb(207, 52, 52);
  --danger-color: hsl(0, 80%, 70%);
  --keep-color: hsl(140, 55%, 62%);
  --star-color: hsl(42, 95%, 60%);

  --select-arrow: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23ebe6e3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='1 1 6 7 11 1'/></svg>");
}

html {
  box-sizing: border-box;
  background-color: var(--bg-color);
  scrollbar-gutter: stable; /* Reserve the scrollbar gutter so layout doesn't shift between short and long pages */
}

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

/* Thin, faint scrollbars on the page and anything inside it that scrolls, such as dialogs. Set on every element
   rather than inherited so each one picks up its own theme's text color (e.g. .always-dark) */
:where(*) {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-color) 25%, transparent) transparent;
}

/* A <details> holds its content in a slot that * doesn't match, so the content wouldn't inherit border-box from it */
:where(details) > * {
  box-sizing: border-box;
}

body {
  min-height: 100svh;
  margin: 0;
  display: flex;
  flex-direction: column;

  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--font-family);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* :where() keeps specificity at 0 so components can override these without fighting them */
:where(h1, h2) {
  margin: var(--space-4) 0;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

:where(h1) {
  font-size: var(--fs-h1);
  font-weight: 700;
}

:where(h2) {
  font-size: var(--fs-h2);
  font-weight: 500;
}

:where(p) {
  margin: var(--space-4) 0;
}

:where(ul) {
  margin: 0;
  padding: 0;
  list-style: none;
}

:where(img) {
  max-width: 100%;
}

:where(a) {
  color: var(--link-color);
  text-decoration: none;
  transition: color 0.4s ease-out;

  &:hover {
    color: var(--link-hover-color);
    text-decoration: underline currentColor solid 2px;
  }
}

:where(button, input[type="submit"]) {
  appearance: none;
  border: none;
  font: inherit;
  line-height: 1.5;
}

:where(a, button, input, select, textarea):focus {
  outline: none;
}

:where(a, button, input, select):focus-visible,
:where(textarea):focus {
  box-shadow: 0 0 var(--focus-glow-size) var(--focus-shadow-color);
}

[hidden] {
  display: none !important;
}

/* Hidden on screen but still read by screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Text cut short where it doesn't fit its line (truncated_text). Shrinks to fit inside a flex row */
.truncated {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.icon svg {
  display: block;
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Something loading, such as the pull-to-refresh indicator or a button sending its form */
@keyframes spin {
  to {
    rotate: 360deg;
  }
}
