:root {
  --bg:        #fafaf7;
  --fg:        #1c1c1a;
  --muted:     #6b6b66;
  --accent:    #a8521b;
  --bar:       #d8a55c;
  --bar-bg:    #ece5d4;
  --border:    #d6d2c3;
  --output-bg: #fff8e8;
  --code:      ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --serif:     ui-serif, Georgia, "Iowan Old Style", Palatino, serif;
  --sans:      -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #16161a;
    --fg:        #ebe6d6;
    --muted:     #8a857a;
    --accent:    #e6a35a;
    --bar:       #c47a2c;
    --bar-bg:    #2c2a25;
    --border:    #2c2a25;
    --output-bg: #1f1d18;
  }
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  padding: 2rem 1.25rem 4rem;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.55;
}
header, main, footer {
  max-width: 780px;
  margin: 0 auto;
}
header { margin-bottom: 2rem; }
h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2.2rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.4rem;
}
h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.25rem;
  letter-spacing: -0.005em;
  margin: 2.2rem 0 0.6rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.lead {
  font-size: 1.02rem;
  margin: 0 0 0.6rem;
  max-width: 60ch;
}
.meta { color: var(--muted); font-size: 0.9rem; margin: 0; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.7rem; }
.muted { color: var(--muted); font-size: 0.85rem; }
em { font-style: italic; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

textarea, .output, button, select, input[type=range] {
  font: inherit;
  border-radius: 6px;
}
textarea {
  width: 100%;
  font-family: var(--code);
  font-size: 0.85rem;
  background: var(--output-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.6rem 0.7rem;
  resize: vertical;
}
.output {
  background: var(--output-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 1rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--code);
  font-size: 0.9rem;
  min-height: 8rem;
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem 1.4rem;
  margin: 0.6rem 0 1rem;
}
.grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
}
.grid label span { color: var(--muted); }
.grid label output {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
input[type=range] {
  width: 100%;
  accent-color: var(--accent);
}
select {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 0.4rem 0.5rem;
}

.row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.5rem 0 0;
}
button {
  font-family: var(--sans);
  font-weight: 500;
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.55rem 1.2rem;
  cursor: pointer;
  letter-spacing: 0.01em;
}
button:hover  { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.viz {
  font-family: var(--code);
  font-size: 0.82rem;
  display: grid;
  gap: 1rem;
}
.viz-prefix {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  background: var(--output-bg);
}
.viz-prefix-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.45rem;
}
.viz-prefix-head .label {
  font-weight: 600;
  letter-spacing: 0.02em;
}
.viz-prefix-head .total {
  color: var(--muted);
  font-size: 0.78rem;
}
.viz-row {
  display: grid;
  grid-template-columns: 4ch 4.5ch 1fr;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
}
.viz-row .glyph {
  text-align: center;
  background: var(--bar-bg);
  border-radius: 3px;
  padding: 0.05rem 0;
}
.viz-row .pct {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.viz-bar {
  height: 0.6em;
  background: var(--bar);
  border-radius: 2px;
}

footer {
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
