:root {
  --bg: #fafaf7;
  --fg: #1a1a1a;
  --muted: #6b6b66;
  --accent: #b8860b;
  --border: #e5e5e0;
  --card: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f;
    --fg: #ededed;
    --muted: #989893;
    --accent: #d4af37;
    --border: #2a2a25;
    --card: #1d1d19;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--fg);
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
}

header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

header h1 a {
  color: var(--fg);
  text-decoration: none;
}

header .tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

h2 { font-size: 1.4rem; margin: 2rem 0 0.5rem; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; margin: 1.75rem 0 0.5rem; }

p { margin: 0.5rem 0; }

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

.muted { color: var(--muted); font-size: 0.9rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin: 1rem 0;
}

form { display: grid; gap: 1rem; }

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

input, select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 6px;
  width: 100%;
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* value + unit pair on one row: input flexes, unit select sizes to content */
.inline { display: flex; gap: 0.5rem; }
.inline input { flex: 1 1 auto; }
.inline select { flex: 0 0 auto; width: auto; }

button {
  font: inherit;
  font-weight: 500;
  padding: 0.65rem 1.1rem;
  border: 0;
  background: var(--fg);
  color: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  justify-self: start;
}
button:disabled { opacity: 0.55; cursor: progress; }
button.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}

/* Row of small preset buttons (e.g. tip-percentage shortcuts). */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: -0.5rem;
}
.chip {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip:hover { border-color: var(--accent); }

/* Slim progress bar (e.g. days-until year-progress). */
.progress-track {
  height: 0.6rem;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.result {
  font-size: 2.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.result .label {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}

.formula {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

th, td {
  text-align: right;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

th:first-child, td:first-child { text-align: left; }
th { font-weight: 500; color: var(--muted); }

/* Home page: widen the shell and flow the category blocks into columns.
   CSS multi-column (not grid) lets short categories pack tightly under tall
   ones — masonry-style — so a long list like Maths doesn't leave big gaps
   beside it. column-width keeps it responsive: 3 columns on desktop collapse
   to 2, then 1, as the viewport narrows, with no fixed breakpoints. */
.home .container { max-width: 1100px; }

.home main {
  column-width: 300px;
  column-gap: 2.5rem;
}

/* Keep each category whole — never split a list across a column break.
   Kill the first-child top margin so every column starts level. */
.home .category {
  margin: 0 0 0.5rem;
  break-inside: avoid;
}
.home .category h2 { margin-top: 1.25rem; }

.tool-list { list-style: none; padding: 0; margin: 0; }
.tool-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}
.tool-list li:last-child { border-bottom: 0; }
.tool-list a {
  font-size: 1.1rem;
  font-weight: 500;
  text-decoration: none;
}
.tool-list a:hover { text-decoration: underline; }
.tool-list .desc {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

footer {
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
footer a { color: var(--muted); }

.related {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  margin-bottom: 1.1rem;
  font-size: 0.85rem;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.25rem 0 1.25rem;
}

.kw {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  letter-spacing: 0.01em;
  user-select: text;
}

/* ---- Fractal explorers (Mandelbrot, Julia, …) -------------------------- */
.fractal-stage {
  position: relative;
  width: 100%;
  margin: 0.25rem 0 0.75rem;
  cursor: crosshair;
  touch-action: none;          /* we handle pan/zoom ourselves */
}
.fractal-stage.grabbing { cursor: grabbing; }
.fractal-stage canvas {
  display: block;
  width: 100%;
  border-radius: 8px;
}
.fractal-stage .base {
  border: 1px solid var(--border);
  background: #000;
}
.fractal-stage .overlay {       /* marker + orbit, drawn on top */
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fractal-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  align-items: baseline;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.5rem;
}
.fractal-bar b { color: var(--fg); font-weight: 600; }
.fractal-bar .busy { color: var(--accent); }

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 520px) { .controls-grid { grid-template-columns: 1fr; } }

/* Responsive grid of compact stat cards (label / big value / sub-note). */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}
.stat-grid .card { margin: 0; }
.stat .label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.stat .big { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }
.unit { font-weight: 400; color: var(--muted); font-size: 0.62em; }
.small { display: block; margin-top: 0.25rem; font-size: 0.8rem; }

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

/* Editable affine-map table (Barnsley fern): compact numeric cells. */
.coeff-table { font-variant-numeric: tabular-nums; }
.coeff-table th, .coeff-table td { padding: 0.3rem 0.35rem; text-align: center; }
.coeff-table th:first-child, .coeff-table td:first-child { text-align: center; }
input.coeff-input {
  width: 4.2rem;
  padding: 0.3rem 0.35rem;
  text-align: right;
  border-radius: 4px;
  font-size: 0.85rem;
}
