@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=IM+Fell+English&family=Source+Sans+3:wght@300;400;600&display=swap');

:root {
  --ink: #1a1209;
  --faded-ink: #4a3c28;
  --rule: #8b7355;
  --rule-light: #c9b99a;
  --parchment: #f5edd8;
  --parchment-dark: #e8d9bb;
  --parchment-deeper: #d9c99a;
  --panel: #2c2015;
  --panel-text: #f0e6cc;
  --accent: #7a3b1e;
  --accent-glow: #a0522d;
}

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

body {
  background: #2a1f0e;
  background-image: repeating-linear-gradient(0deg, transparent, transparent 28px, rgba(255,255,255,0.015) 28px, rgba(255,255,255,0.015) 29px);
  font-family: 'Source Sans 3', sans-serif;
  color: var(--ink);
  min-height: 100vh;
  padding: 24px 16px 48px;
}

.sheet-wrapper {
  max-width: none;
  margin: 0 auto;
  background: var(--parchment);
  border: 2px solid var(--rule);
  box-shadow: 0 0 0 6px #2a1f0e, 0 0 0 8px var(--rule), 0 8px 40px rgba(0,0,0,0.7);
  border-radius: 2px;
}

/* Title bar */
.sheet-title {
  background: var(--panel);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 3px solid var(--rule);
}
.sheet-title h1 {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--panel-text);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  flex: 1;
  text-align: center;
}
.title-ornament { color: var(--parchment-deeper); font-size: 1.1rem; opacity: 0.7; }

/* ── Character nameplate ──
   Three-column grid: note | name | balance spacer.
   The 1fr/auto/1fr split keeps the name centered on the sheet regardless of
   how long the note is, and lets the note wrap without shifting it. */
.nameplate {
  border-bottom: 1.5px solid var(--rule-light);
  padding: 8px 20px 7px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  row-gap: 6px;
  column-gap: 16px;
  background: var(--parchment-dark);
}
/* The selector bar is appended into #nameplate by character_state.js, so it
   arrives as a 4th grid item. Span the full row and center it, matching the
   old flex-column behaviour. */
.nameplate > #char-selector-bar {
  grid-column: 1 / -1;
  justify-self: center;
}
.nameplate-note {
  font-family: 'IM Fell English', serif;
  font-size: 0.72rem;
  font-style: italic;
  line-height: 1.4;
  color: var(--faded-ink);
  max-width: 220px;
}
.nameplate-note em { font-style: normal; font-weight: 600; color: var(--ink); }
.nameplate-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.nameplate-name {
  font-family: 'IM Fell English', serif;
  font-size: 1.4rem;
  font-style: italic;
  color: var(--ink);
  letter-spacing: 0.03em;
  line-height: 1.2;
  text-align: center;
}
.nameplate-name.empty {
  color: var(--rule);
  font-size: 0.85rem;
}
.nameplate-rule {
  width: 240px;
  max-width: 100%;
  height: 1px;
  background: var(--rule-light);
}
/* Narrow screens: stack, note beneath the name, spacer collapses. */
@media (max-width: 900px) {
  .nameplate { grid-template-columns: 1fr; row-gap: 6px; justify-items: center; }
  .nameplate-center { order: 1; }
  .nameplate-note { order: 2; max-width: none; text-align: center; }
  .nameplate > #char-selector-bar { order: 3; grid-column: 1; }
  .nameplate-spacer { display: none; }
  .nameplate-note:empty { display: none; }
}

/* Fluid multi-column body: as many ~440px columns as the screen fits */
.two-col {
  display: block;
  columns: 440px;
  column-gap: 1.5px;
  column-rule: 1.5px solid var(--rule-light);
  column-fill: balance;
}
.two-col > div { display: contents; }
.col-left { border-right: none; }

/* Section block */
.section-block {
  border-bottom: 1.5px solid var(--rule-light);
  padding: 12px 16px 14px;
  break-inside: avoid;
}
.section-block:last-child { border-bottom: none; }

.section-header {
  display: inline-flex;
  align-items: center;
  background: var(--panel);
  color: var(--panel-text);
  font-family: 'Cinzel', serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 4px 10px;
  margin-bottom: 10px;
  border-radius: 1px;
}
.section-notes {
  float: right;
  font-family: 'Cinzel', serif;
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faded-ink);
  margin-top: 4px;
  clear: none;
}
.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

/* Sub-stat row: label + slider */
.sub-stat {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}
/* Column wrapping a slider and its Low/High ticks, so the ticks inherit
   the slider's exact width regardless of label or notes-field widths. */
.slider-col {
  flex: 1;
  min-width: 80px;
  display: flex;
  flex-direction: column;
}
/* Re-center the fixed-width side elements against the slider track. */
.sub-stat > .sub-stat-label,
.sub-stat > .stat-num,
.sub-stat > .notes-field,
.sub-stat > .blank-label { margin-top: 2px; }
.sub-stat-label {
  font-family: 'IM Fell English', serif;
  font-size: 0.82rem;
  color: var(--faded-ink);
  min-width: 110px;
  text-align: right;
  flex-shrink: 0;
}
.sub-stat-label.wide { min-width: 130px; }
.sub-stat-label.narrow { min-width: 80px; }
.sub-stat input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: linear-gradient(to right, var(--rule-light), var(--rule));
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.sub-stat input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--parchment);
  box-shadow: 0 0 3px rgba(0,0,0,0.4);
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.52rem;
  color: var(--rule);
  font-family: 'Cinzel', serif;
  letter-spacing: 0.06em;
  margin-top: 1px;
}

/* Blank sub-stat row (user-fillable) */
.sub-stat-blank input[type="text"].blank-label {
  border: none;
  border-bottom: 1px solid var(--rule-light);
  background: transparent;
  font-family: 'IM Fell English', serif;
  font-size: 0.82rem;
  color: var(--ink);
  min-width: 80px;
  max-width: 110px;
  outline: none;
  text-align: right;
  flex-shrink: 0;
}
.sub-stat-blank input[type="text"].blank-label:focus { border-bottom-color: var(--accent); }

/* Blank-row labels must occupy exactly the same track width as the named
   .sub-stat-label spans beside them, or the slider-col starts at a different
   x-offset and the whole blank row drifts left. field-sizing:content (inherited
   from textarea.ae) would otherwise collapse them to the placeholder width. */
.sub-stat-blank .blank-label {
  flex: 0 0 110px;
  width: 110px;
  min-width: 110px;
  max-width: 110px;
  field-sizing: fixed;
  /* Match .sub-stat-label's single-line box exactly. Two things bloat the
     textarea otherwise: (1) with field-sizing:fixed + height:auto it falls back
     to rows=2 (~2 lines tall); (2) textarea.ae's border + padding add to the
     outer box. Fix: pin height to one line (1.2em, same as the span) and draw
     the underline as a box-shadow, which sits outside the box model and so
     adds zero height and never clips the text. */
  font-size: 0.82rem;
  line-height: 1.2;
  height: 1.2em;
  min-height: 0;
  padding: 0 3px 0 0;
  border-bottom: none;
  box-shadow: 0 1px 0 var(--rule-light);
  box-sizing: border-box;
  color: var(--ink);
}
.sub-stat-blank .blank-label:focus { box-shadow: 0 1px 0 var(--accent); }
.sub-stat-blank .blank-label.wide {
  flex: 0 0 130px; width: 130px; min-width: 130px; max-width: 130px;
}
.sub-stat-blank .blank-label.narrow {
  flex: 0 0 80px; width: 80px; min-width: 80px; max-width: 80px;
}

/* Bipolar slider row */
.bipolar-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.bipolar-label-left {
  font-family: 'IM Fell English', serif;
  font-size: 0.75rem;
  color: var(--faded-ink);
  min-width: 90px;
  text-align: right;
  flex-shrink: 0;
}
.bipolar-label-right {
  font-family: 'IM Fell English', serif;
  font-size: 0.75rem;
  color: var(--faded-ink);
  min-width: 80px;
  flex-shrink: 0;
}
.bipolar-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: linear-gradient(to right, var(--accent), var(--rule-light), var(--accent));
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  min-width: 70px;
}
.bipolar-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--rule);
  box-shadow: 0 0 3px rgba(0,0,0,0.4);
}
.bipolar-notes {
  border: none;
  border-bottom: 1px solid var(--rule-light);
  background: transparent;
  font-family: 'IM Fell English', serif;
  font-size: 0.75rem;
  color: var(--ink);
  width: 60px;
  outline: none;
  flex-shrink: 0;
}
.bipolar-notes:focus { border-bottom-color: var(--accent); }

/* Notes field next to slider */
.notes-field {
  border: none;
  border-bottom: 1px solid var(--rule-light);
  background: transparent;
  font-family: 'IM Fell English', serif;
  font-size: 0.78rem;
  color: var(--ink);
  outline: none;
  flex-shrink: 0;
}
.notes-field:focus { border-bottom-color: var(--accent); }
.notes-field.short { width: 70px; }
.notes-field.medium { width: 100px; }
.notes-field.long { width: 140px; }

/* Text input line */
.text-line {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 6px;
}
.text-line label {
  font-family: 'IM Fell English', serif;
  font-size: 0.85rem;
  color: var(--faded-ink);
  white-space: nowrap;
}
.text-line input[type="text"] {
  flex: 1;
  border: none;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  font-family: 'IM Fell English', serif;
  font-size: 0.85rem;
  color: var(--ink);
  padding: 1px 3px;
  outline: none;
}
.text-line input[type="text"]:focus { border-bottom-color: var(--accent); }

/* Textarea */
textarea.notes-area {
  width: 100%;
  border: 1px solid var(--rule-light);
  border-radius: 2px;
  background: rgba(0,0,0,0.02);
  font-family: 'IM Fell English', serif;
  font-size: 0.82rem;
  color: var(--ink);
  padding: 4px 6px;
  resize: vertical;
  outline: none;
  min-height: 50px;
}
textarea.notes-area:focus { border-color: var(--accent); }

/* ── Per-section Notes box ─────────────────────────────────────────────────────
   One big write-in box at the foot of each section, replacing the old thin
   note lines that sat to the right of every slider. The extra .section-notes-block
   qualifier outranks the per-page `textarea.ae.notes-area` rules in each page's
   own <style>, so the box looks the same on all ten sheets. */
.section-notes-block { margin-top: 12px; }
.section-notes-block .notes-label {
  font-family: 'Cinzel', serif;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faded-ink);
  margin-bottom: 3px;
}
.section-notes-block textarea.ae.notes-area,
.section-notes-block textarea.notes-area {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--rule-light);
  border-radius: 2px;
  background: rgba(0,0,0,0.02);
  font-family: 'IM Fell English', serif;
  font-size: 0.82rem;
  color: var(--ink);
  padding: 6px 8px;
  min-height: 90px;
  outline: none;
}
.section-notes-block textarea.ae.notes-area:focus,
.section-notes-block textarea.notes-area:focus { border-color: var(--accent); }

/* Item card */
.item-card {
  border: 1.5px solid var(--rule);
  border-radius: 2px;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: rgba(0,0,0,0.02);
  break-inside: avoid;
}
.item-card .text-line label { min-width: 70px; }

/* Footer bar (decorative; matches header height) */
.action-bar {
  background: var(--panel);
  height: 55px;
  border-top: 3px solid var(--rule);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  color: var(--panel-text);
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  padding: 10px 24px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Section desc text */
.section-desc {
  font-family: 'IM Fell English', serif;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--faded-ink);
  margin-bottom: 8px;
  line-height: 1.4;
}
.section-desc strong { font-style: normal; font-weight: 600; color: var(--ink); }

/* Full-width header bar */
.full-header {
  background: var(--panel);
  color: var(--panel-text);
  font-family: 'Cinzel', serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 6px 16px;
  text-align: center;
  margin: -12px -16px 10px;
}

/* Sub-section label */
.subsec-label {
  font-family: 'Cinzel', serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faded-ink);
  border-bottom: 1px solid var(--rule-light);
  margin: 8px 0 4px;
  padding-bottom: 2px;
}
.subsec-desc {
  font-family: 'IM Fell English', serif;
  font-size: 0.72rem;
  font-style: italic;
  color: var(--rule);
  margin-bottom: 4px;
}


/* ── Navigation strip ── */
.nav-strip {
  background: var(--panel);
  border-bottom: 2px solid var(--rule);
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nav-strip::-webkit-scrollbar { display: none; }
.nav-strip a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  text-decoration: none;
  font-family: 'Cinzel', serif;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--rule-light);
  white-space: nowrap;
  border-right: 1px solid rgba(139,115,85,0.3);
  transition: background 0.12s, color 0.12s;
  flex: 1;
  min-width: 72px;
}
.nav-strip a:last-child { border-right: none; }
.nav-strip a:hover { background: rgba(255,255,255,0.06); color: var(--panel-text); }
.nav-strip a.active {
  background: var(--parchment);
  color: var(--panel);
  font-weight: 700;
  position: relative;
}
.nav-strip a.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}


/* ── Option A: auto-expanding textarea inputs ── */
textarea.ae {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule);
  font-family: 'IM Fell English', serif;
  font-size: 0.92rem;
  color: var(--ink);
  padding: 2px 3px;
  outline: none;
  width: 100%;
  resize: none;
  overflow: hidden;
  line-height: 1.45;
  min-height: 1.5em;
  display: block;
  box-sizing: border-box;
  field-sizing: content;
}
textarea.ae:focus { border-bottom-color: var(--accent, #7a3b1e); }
textarea.ae.notes-field { font-size: 0.78rem; }
textarea.ae.notes-area { border: 1px solid var(--rule-light); border-radius: 2px; background: rgba(0,0,0,0.02); padding: 4px 6px; min-height: 50px; }
textarea.ae.slider-val { width: 60px; flex-shrink: 0; font-size: 0.85rem; }
textarea.ae.blank-label { text-align: right; flex-shrink: 0; field-sizing: fixed; }
textarea.ae.bipolar-notes { width: 60px; flex-shrink: 0; font-size: 0.75rem; }
