/*
 * Devshop UI baseline (runtime/guidelines/ui.md). A project copies this file and owns it: change the
 * colours, add components. Token names are shadcn/ui's, so a React app adopting shadcn/ui keeps
 * them. Light is :root; dark is :root[data-theme="dark"] (the toggle) and, with the same values,
 * the system-dark rule below (no toggle choice). Only these three rules declare custom properties;
 * tokens-check.mjs holds that, and that every var() used here and in pages is defined.
 */

:root {
  color-scheme: light;

  --background: #EEF0EA;
  --foreground: #17191C;
  --card: #F7F8F4;
  --card-foreground: #17191C;
  --popover: #F7F8F4;
  --popover-foreground: #17191C;
  --primary: #1E6B4A;
  --primary-foreground: #F7F8F4;
  --secondary: #E2E6DE;
  --secondary-foreground: #17191C;
  --muted: #E2E6DE;
  --muted-foreground: #4A524C;
  --accent: #DCE9E1;
  --accent-foreground: #14523A;
  --destructive: oklch(0.52 0.2 27);
  --destructive-foreground: oklch(0.985 0.005 250);
  --border: #C3C9BF;
  --input: #6F776D;
  --ring: #2B44C9;
  --link: #2B44C9;
  --shadow:
    0 1px 2px oklch(0.2 0.02 260 / 6%), 0 1px 3px oklch(0.2 0.02 260 / 8%);

  --radius: 0.75rem;
  --font-sans:
    system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  --font-display:
    'Bricolage Grotesque', 'Arial Narrow', system-ui, -apple-system, sans-serif;
  --font-mono:
    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --tap: 44px; /* minimum control size (L-72, WCAG 2.5.5) */
  --measure: 68ch; /* longest comfortable line of text */
  --page-max: 72rem;
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --background: #15171A;
  --foreground: #E4E6E0;
  --card: #1C1F22;
  --card-foreground: #E4E6E0;
  --popover: #1C1F22;
  --popover-foreground: #E4E6E0;
  --primary: #6FD3A0;
  --primary-foreground: #10140F;
  --secondary: #262A2D;
  --secondary-foreground: #E4E6E0;
  --muted: #262A2D;
  --muted-foreground: #A6ADA5;
  --accent: #1F3A2D;
  --accent-foreground: #CDEBDB;
  --destructive: oklch(0.66 0.19 25);
  --destructive-foreground: oklch(0.17 0.02 25);
  --border: #3A4043;
  --input: #7A8285;
  --ring: #8EA2FF;
  --link: #8EA2FF;
  --shadow: 0 1px 2px oklch(0 0 0 / 30%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --background: #15171A;
    --foreground: #E4E6E0;
    --card: #1C1F22;
    --card-foreground: #E4E6E0;
    --popover: #1C1F22;
    --popover-foreground: #E4E6E0;
    --primary: #6FD3A0;
    --primary-foreground: #10140F;
    --secondary: #262A2D;
    --secondary-foreground: #E4E6E0;
    --muted: #262A2D;
    --muted-foreground: #A6ADA5;
    --accent: #1F3A2D;
    --accent-foreground: #CDEBDB;
    --destructive: oklch(0.66 0.19 25);
    --destructive-foreground: oklch(0.17 0.02 25);
    --border: #3A4043;
    --input: #7A8285;
    --ring: #8EA2FF;
    --link: #8EA2FF;
    --shadow: 0 1px 2px oklch(0 0 0 / 30%);
  }
}

/* ---- Base ---- */

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

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

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

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

h1,
h2,
h3 {
  margin: 0 0 var(--space-2);
  line-height: 1.2;
  text-wrap: balance;
}

h1 {
  font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2.25rem);
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.125rem;
}

p {
  max-width: var(--measure);
  margin: 0 0 var(--space-4);
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

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

/* ---- Layout: one column on a phone, wider from 768 px, a 3-column grid from 1280 px ---- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.site-header > .inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--space-2) var(--space-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  font-weight: 650;
  font-size: 1.0625rem;
  color: var(--foreground);
  text-decoration: none;
}

.page {
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}

.stack > * + * {
  margin-top: var(--space-6);
}

.site-footer {
  max-width: var(--page-max);
  margin-inline: auto;
  padding: var(--space-6) var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 768px) {
  .site-header > .inner,
  .page,
  .site-footer {
    padding-inline: var(--space-8);
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ---- Components ---- */

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

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

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.list > li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--tap);
  padding: var(--space-2) var(--space-4);
}

.list > li + li {
  border-top: 1px solid var(--border);
}

.badge {
  display: inline-block;
  padding: 0.125rem var(--space-2);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-foreground);
  font-size: 0.8125rem;
  font-weight: 550;
  white-space: nowrap;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ---- Controls: the L-72 contract, set once here ---- */

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

/* Tappable at once, no double-tap zoom delay. */
a,
button,
input,
select,
textarea,
summary,
label,
[role='button'] {
  touch-action: manipulation;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 0.25rem);
  background: var(--secondary);
  color: var(--secondary-foreground);
  font-weight: 550;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    filter 0.15s,
    transform 0.08s;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: transparent;
}

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.btn-destructive {
  background: var(--destructive);
  color: var(--destructive-foreground);
  border-color: transparent;
}

.btn-outline {
  background: transparent;
  color: var(--foreground);
  border-color: var(--input);
}

/*
 * The theme switch (specs/theme-toggle.md): a sun and a moon on an outline track, and a flat lens of a
 * knob over the theme that's on. The knob's side follows <html> like the theme rules above, so it is
 * right at the first paint; only the knob moves, so the button keeps the baseline's press. Hidden
 * until theme.js marks <html> with `js` (with JavaScript off it couldn't work).
 */
:root:not(.js) [data-theme-toggle] {
  display: none;
}

.theme-switch {
  position: relative;
  width: 80px;
  padding: 0;
}

.theme-icon {
  position: absolute;
  top: 11px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-sun {
  left: 11px;
}

.theme-moon {
  left: 47px;
}

.theme-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 36px;
  height: 36px;
  border: 2px solid var(--foreground);
  border-radius: calc(var(--radius) - 0.375rem);
  background: color-mix(in srgb, var(--primary) 30%, transparent);
  pointer-events: none;
  transition: transform 200ms ease-in-out;
}

:root[data-theme='dark'] .theme-knob {
  transform: translateX(36px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-knob {
    transform: translateX(36px);
  }
}

@media (hover: hover) {
  :where(button, .btn, [role='button']):hover:not(
      :disabled,
      [aria-disabled='true']
    ) {
    filter: brightness(0.95);
  }
}

/* The pressed state: one low-specificity rule every control inherits. */
:where(button, .btn, [role='button'], summary):active:not(
    :disabled,
    [aria-disabled='true']
  ) {
  transform: scale(0.97);
  filter: brightness(0.9);
}

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

:where(button, .btn):disabled,
:where(button, .btn)[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Busy: disabled at once; the spinner shows only after a delay, so fast actions don't flicker. */
[aria-busy='true'] {
  cursor: progress;
}

:where(button, .btn)[aria-busy='true'] {
  opacity: 0.85;
}

:where(button, .btn)[aria-busy='true']::before {
  content: '';
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0;
  animation:
    busy-show 0s 250ms forwards,
    busy-spin 0.7s linear infinite;
}

@keyframes busy-show {
  to {
    opacity: 1;
  }
}

@keyframes busy-spin {
  to {
    transform: rotate(1turn);
  }
}

/* Forms */

.field {
  display: grid;
  gap: var(--space-1);
}

.field > label {
  font-weight: 550;
}

input:not([type='checkbox'], [type='radio'], [type='hidden']),
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 0.25rem);
  background: var(--background);
  color: var(--foreground);
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

.check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap);
  cursor: pointer;
}

input[type='checkbox'],
input[type='radio'] {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--primary);
}

.form {
  display: grid;
  gap: var(--space-4);
  max-width: 40rem;
}

/* ---- Fonts: served from /fonts (OFL, see fonts/OFL.txt) ---- */

@font-face {
  font-family: 'Bricolage Grotesque';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/bricolage-grotesque-700.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-500.woff2') format('woff2');
}

.mono {
  font-family: var(--font-mono);
  font-weight: 500;
}

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

/* ---- Home: the systems map (DESIGN.md). One column on a phone, two from 768 px ---- */

.home {
  display: grid;
  gap: var(--space-8);
  grid-template-columns: minmax(0, 1fr);
}

.home h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: var(--space-3);
}

.name {
  font-family: var(--font-display);
  font-size: clamp(2.25rem, 1.6rem + 3vw, 3.5rem);
  line-height: 1.02;
  margin-bottom: var(--space-2);
}

.tagline {
  color: var(--muted-foreground);
  margin: 0;
}

.map,
.projects,
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
}

.map {
  display: grid;
  gap: var(--space-4);
}

.node,
.project {
  position: relative;
  display: grid;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border-radius: calc(var(--radius) - 0.5rem);
}

.node {
  background: var(--card);
  color: var(--card-foreground);
  border: 2px solid var(--foreground);
}

/* The edge between two steps of the map. */
.node + .node::before {
  content: '';
  position: absolute;
  top: calc(-1 * var(--space-4) - 2px);
  left: var(--space-6);
  width: 2px;
  height: var(--space-4);
  background: var(--foreground);
}

.node b,
.project b {
  font-family: var(--font-display);
  font-size: 1.0625rem;
}

.node span,
.project .status {
  color: var(--muted-foreground);
  font-size: 0.9375rem;
}

.loop {
  margin: var(--space-3) 0 0;
  color: var(--primary);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin-bottom: var(--space-3);
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.legend li,
.project .status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.projects {
  display: grid;
  gap: var(--space-3);
  padding-left: var(--space-4);
  border-left: 2px solid var(--foreground);
}

.project {
  border: 2px dashed var(--border);
}

.project.live {
  background: var(--accent);
  border: 2px solid var(--primary);
}

.project.live .status {
  color: var(--accent-foreground);
}

/* Status marks, drawn so they never depend on a font having the glyph. */
.mark {
  flex: none;
  width: 0.8em;
  height: 0.8em;
  border: 2px solid var(--primary);
  border-radius: 50%;
}

.mark.progress {
  background: linear-gradient(90deg, var(--primary) 50%, transparent 50%);
}

.mark.shipped {
  background: var(--primary);
}

@media (min-width: 768px) {
  .home {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--space-8);
  }

  .intro {
    grid-column: 1 / -1;
  }

  .how {
    grid-row: span 2;
  }
}

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