:root {
  --ink: #1c1712;
  --ink-raised: #241d16;
  --parchment: #eae0c8;
  --parchment-dim: #a89b7d;
  --gold: #b98a3d;
  --gold-bright: #d4a752;
  --verdigris: #4c7a6f;
  --rose: #8c4a42;
  --line: #3a3126;

  --display: "Fraunces", Georgia, serif;
  --body: "Source Serif 4", Georgia, serif;
  --mono: "IBM Plex Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ink);
  background-image:
    radial-gradient(ellipse at top left, rgba(185, 138, 61, 0.05), transparent 55%),
    radial-gradient(ellipse at bottom right, rgba(76, 122, 111, 0.05), transparent 55%);
  color: var(--parchment);
  font-family: var(--body);
  line-height: 1.6;
}

a { color: var(--gold-bright); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

/* ── Header ─────────────────────────────────────────── */

.site-header {
  max-width: 780px;
  margin: 0 auto;
  padding: 64px 24px 24px;
  border-bottom: 1px solid var(--line);
}

.site-header h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}

.subtitle {
  font-family: var(--display);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--parchment-dim);
  margin: 0 0 28px;
}

.subtitle strong {
  font-style: normal;
  color: var(--gold-bright);
}

.header-meta p {
  margin: 0 0 12px;
  color: var(--parchment);
  font-size: 1rem;
}

.header-meta .instructions {
  color: var(--parchment-dim);
  font-size: 0.92rem;
}

/* ── Layout ─────────────────────────────────────────── */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

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

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px 24px;
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 24px;
  margin-bottom: 32px;
}

.control-group label {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}

select {
  width: 100%;
  background: var(--ink);
  color: var(--parchment);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 9px 10px;
  font-family: var(--body);
  font-size: 0.92rem;
}

.radio-row {
  display: flex;
  gap: 14px;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding-top: 4px;
}

.radio-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--parchment-dim);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  margin: 0;
  cursor: pointer;
}

.radio-row input[type="radio"] {
  accent-color: var(--gold);
}

.slider-readout {
  color: var(--parchment-dim);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.72rem;
}

.dual-slider {
  position: relative;
  height: 32px;
}

.dual-slider-track {
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}

.dual-slider-range {
  position: absolute;
  top: 14px;
  height: 3px;
  background: var(--gold);
  border-radius: 2px;
}

.dual-slider input[type="range"] {
  position: absolute;
  top: 6px;
  left: 0;
  width: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}

.dual-slider input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid var(--ink);
  cursor: pointer;
  margin-top: 0;
}

.dual-slider input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid var(--ink);
  cursor: pointer;
}

.dual-slider input[type="range"]::-webkit-slider-runnable-track,
.dual-slider input[type="range"]::-moz-range-track {
  background: transparent;
}

.reset-btn {
  align-self: end;
  background: transparent;
  color: var(--gold-bright);
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.reset-btn:hover {
  background: var(--gold);
  color: var(--ink);
}

/* ── Chart ──────────────────────────────────────────── */

.chart-section {
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 32px;
}

#chart {
  width: 100%;
  height: 520px;
}

.chart-hint {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--parchment-dim);
  margin: 4px 0 0;
}

/* ── Detail / manuscript panel ─────────────────────────── */

.detail-panel {
  position: relative;
  background: var(--ink-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 40px clamp(24px, 5vw, 64px);
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.6);
}

.detail-empty {
  color: var(--parchment-dim);
  font-family: var(--mono);
  font-size: 0.85rem;
  text-align: center;
  margin: 20px 0;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 24px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.detail-title {
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 600;
  margin: 0;
}

.detail-byline {
  font-family: var(--display);
  font-style: italic;
  color: var(--gold-bright);
  font-size: 1rem;
}

.detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--parchment-dim);
  margin-bottom: 28px;
}

.detail-stats span strong {
  color: var(--verdigris);
  font-weight: 500;
}

.detail-stats .level-tag {
  color: var(--ink);
  background: var(--gold);
  padding: 2px 8px;
  border-radius: 2px;
  font-weight: 500;
}

.poem-text {
  font-family: var(--body);
  font-size: 1.08rem;
  line-height: 1.9;
  white-space: pre-wrap;
  columns: 1;
}

.poem-text::first-letter {
  font-family: var(--display);
  font-size: 3.4rem;
  font-weight: 600;
  color: var(--gold-bright);
  float: left;
  line-height: 0.8;
  padding-right: 8px;
  padding-top: 6px;
}

.poem-loading, .poem-error {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--parchment-dim);
}

.poem-error { color: var(--rose); }

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

.site-footer {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  color: var(--parchment-dim);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-align: center;
}

.dev-line {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--parchment-dim);
  text-align: center;
  margin: 16px 0 0;
}

.dev-line a,
.site-footer a {
  color: var(--gold-bright);
}

.dev-line .divider,
.site-footer .divider {
  color: var(--line);
  margin: 0 10px;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 640px) {
  .controls { grid-template-columns: 1fr; }
  #chart { height: 420px; }
  .detail-panel { padding: 28px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reset-btn { transition: none; }
}
