:root {
  --bg: #fffcf7;
  --text: #2d1b06;
  --muted: #9a7b5a;
  --accent: #e86830;
  --accent-soft: #fff0e6;
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: "Inter", system-ui, sans-serif;
  max-width: 1100px;
  margin: 3rem auto;
  padding: 0 1.5rem;
  color: var(--text);
  background:
    radial-gradient(ellipse at 15% 0%, hsla(42,100%,88%,0.5), transparent 50%),
    radial-gradient(ellipse at 85% 5%, hsla(12,100%,92%,0.4), transparent 45%),
    radial-gradient(ellipse at 50% 100%, hsla(158,60%,90%,0.3), transparent 50%),
    var(--bg);
}

header { margin-bottom: 2rem; }

h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 2.4rem;
  letter-spacing: -0.025em;
  margin-bottom: 0.35rem;
}

.methodology {
  color: #7a5c3a;
  font-size: 0.88rem;
  line-height: 1.7;
  max-width: 720px;
}

.methodology code {
  font-size: 0.85em;
  background: #fff0e6;
  color: #c45a1a;
  padding: 0.12em 0.4em;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", ui-monospace, monospace;
}

.methodology a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.subtitle {
  color: #b8895a;
  font-size: 1.05rem;
  margin-bottom: 0.8rem;
}

/* ── Controls ──────────────────────────────── */

#controls { margin-bottom: 0.75rem; }

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.ctrl-label {
  font-size: 13px;
  color: #b8895a;
  font-weight: 500;
}

.count-hint {
  font-size: 12px;
  color: #c9a87a;
}

.yr-display {
  font-size: 14px;
  font-weight: 600;
  font-family: "Space Grotesk", sans-serif;
  min-width: 110px;
  color: var(--accent);
}

#countDisplay {
  min-width: 30px;
}

input[type="range"] {
  flex: 1;
  max-width: 220px;
  accent-color: var(--accent);
}

.toggle-group {
  display: inline-flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid #f0dcc6;
}

.toggle-btn {
  padding: 5px 13px;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #b8895a;
  transition: all 0.15s;
  white-space: nowrap;
}

.toggle-btn:not(:last-child) {
  border-right: 1px solid #f0dcc6;
}

.toggle-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ── Legend ─────────────────────────────────── */

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #b8895a;
  margin-bottom: 18px;
}

.github-link {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fffdf8;
  color: #b8895a;
  box-shadow: 0 2px 12px rgba(180, 120, 40, 0.08);
  transition: all 0.2s;
  z-index: 10;
  text-decoration: none;
}

.github-link svg { width: 20px; height: 20px; }
.github-link:hover { transform: translateY(-2px) scale(1.05); color: var(--accent); }
.github-link::after { display: none; }

.footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  text-align: center;
  font-size: 0.86rem;
  color: #b8895a;
}

.footer a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

#legendCanvas {
  border-radius: 7px;
  display: block;
}

/* ── Cell grid ─────────────────────────────── */

#viz.mode-cells {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cell {
  border-radius: 12px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 500;
  cursor: default;
  transition: background-color 0.3s, border-color 0.3s, transform 0.1s;
  line-height: 1.3;
  position: relative;
  white-space: nowrap;
  border: 1px solid transparent;
}

.cell:hover {
  transform: scale(1.08);
  z-index: 2;
  filter: brightness(0.96);
}

/* ── Text flow ─────────────────────────────── */

#viz.mode-text {
  line-height: 2.4;
  padding: 0.5rem 0;
}

.tname {
  display: inline;
  cursor: default;
  position: relative;
  transition: color 0.3s;
  font-weight: 600;
  letter-spacing: -0.01em;
  border-radius: 4px;
  padding: 2px 1px;
}

.tname::after {
  content: "\00a0\00a0";
  font-size: 0.5em;
}

.tname:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ── Tooltip ───────────────────────────────── */

.tip {
  position: absolute;
  background: #fffdf8;
  border: 1px solid #f0dcc6;
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 30;
  font-weight: 400;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(180, 120, 40, 0.08);
  line-height: 1.55;
}

.tip .tip-name { font-weight: 600; }
.tip .tip-delta-up { color: hsl(155, 65%, 30%); font-weight: 600; }
.tip .tip-delta-down { color: hsl(355, 75%, 45%); font-weight: 600; }

/* ── GitHub ────────────────────────────────── */

.github-link {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fffdf8;
  color: #b8895a;
  box-shadow: 0 2px 12px rgba(180, 120, 40, 0.08);
  transition: all 0.2s;
  z-index: 10;
  text-decoration: none;
}

.github-link svg { width: 20px; height: 20px; }
.github-link:hover { transform: translateY(-2px) scale(1.05); color: var(--accent); }
.github-link::after { display: none; }


/* ── Footer ────────────────────────────────── */

.footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  text-align: center;
  font-size: 0.86rem;
  color: #b8895a;
}

.footer a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}
