/* SheetBound — dark parchment UI + print-perfect sheet */
:root {
  --bg: #0f0b09;
  --bg-2: #17110d;
  --panel: #1d1611;
  --panel-2: #251c15;
  --border: #3a2c20;
  --text: #f3e9dc;
  --muted: #a8977f;
  --accent: #d97706;
  --accent-2: #f59e0b;
  --danger: #ef4444;
  --paper: #faf5eb;
  --paper-ink: #241a12;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(217, 119, 6, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  background: rgba(23, 17, 13, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.tagline { margin: 0; color: var(--muted); font-size: 0.85rem; flex: 1; min-width: 0; }
.topbar-actions select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
}

/* --------------------------------------------------------------- hero */
.hero { max-width: 1100px; margin: 2.5rem auto 1.5rem; padding: 0 1.25rem; text-align: center; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.9rem); margin: 0 0 0.4rem; letter-spacing: -0.02em; }
.hero p { color: var(--muted); max-width: 46rem; margin: 0 auto 1.5rem; }

.system-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.sys-btn {
  display: flex; flex-direction: column; gap: 0.25rem; text-align: left;
  background: var(--panel); border: 2px solid var(--border); border-radius: 14px;
  padding: 0.8rem 1rem; cursor: pointer; color: var(--text);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.sys-btn small { color: var(--muted); }
.sys-btn:hover { transform: translateY(-2px); }
.sys-btn.is-active { border-color: var(--accent-2); box-shadow: 0 0 0 1px var(--accent-2) inset; }

.hero-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

/* ------------------------------------------------------------- buttons */
.btn {
  appearance: none; cursor: pointer;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  font-size: 0.92rem;
  transition: filter 0.15s ease, transform 0.05s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, #b45309, #d97706); border-color: transparent; color: #fff8ef; }
.btn-accent { background: linear-gradient(135deg, #065f46, #059669); border-color: transparent; color: #ecfdf5; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn-icon {
  appearance: none; cursor: pointer; background: transparent; border: 1px solid var(--border);
  border-radius: 8px; color: var(--muted); width: 30px; height: 30px;
}
.btn-icon:hover { color: var(--danger); border-color: var(--danger); }

/* -------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 480px) minmax(360px, 1fr);
  gap: 1.5rem;
  max-width: 1200px;
  margin: 0 auto 3rem;
  padding: 0 1.25rem;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .preview { order: -1; }
}

.editor fieldset {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.15rem 1.15rem;
  margin: 0 0 1rem;
}
.editor legend { font-weight: 700; color: var(--accent-2); padding: 0 0.4rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.grid-2 label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }
.grid-2 input, textarea {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  width: 100%;
}
.grid-2 input:focus, textarea:focus, .gear-table input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
textarea { resize: vertical; }

#fs-notes label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); margin-top: 0.5rem; }

.ability-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 0.6rem; }
.ability label { display: flex; flex-direction: column; gap: 0.25rem; align-items: center; font-size: 0.8rem; color: var(--muted); }
.ability input {
  width: 100%; text-align: center; font-weight: 700; font-size: 1.05rem;
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 0.45rem 0.2rem;
}
.ability input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }

.derived { display: flex; gap: 1.25rem; margin: 0.85rem 0 0; flex-wrap: wrap; }
.derived div { display: flex; flex-direction: column; }
.derived dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.derived dd { margin: 0; font-weight: 800; font-size: 1.1rem; color: var(--accent-2); font-variant-numeric: tabular-nums; }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 0.28rem 0.6rem; border-radius: 999px; font-size: 0.8rem;
  cursor: pointer;
}
.chip:has(input:checked) { border-color: var(--accent-2); color: var(--accent-2); }
.chip input { accent-color: var(--accent); }

.gear-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.gear-table th { text-align: left; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.3rem 0.35rem; }
.gear-table td { padding: 0.2rem 0.35rem; }
.gear-table th.num, .gear-table td.num { text-align: right; width: 5.5rem; }
.gear-table input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 0.35rem 0.5rem; font: inherit;
}
.row-between { display: flex; justify-content: space-between; align-items: center; margin-top: 0.6rem; gap: 0.5rem; }
#gear-total { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.io-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
label.btn { display: inline-flex; align-items: center; }
#status { min-height: 1.4rem; color: var(--accent-2); font-size: 0.88rem; margin: 0.5rem 0 0; }

/* system visibility (body[data-system]) */
body[data-system="osr"] .d20-only { display: none !important; }
body[data-system="freeform"] .scored { display: none !important; }
body[data-system="freeform"] .d20-only { display: none !important; }

/* -------------------------------------------------------------- sheet */
.preview { position: sticky; top: 4.2rem; }
.sheet {
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 6px;
  padding: 1.4rem 1.5rem 1rem;
  min-height: 600px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 2px 0 rgba(255, 255, 255, 0.06) inset;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.sheet-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px double #b9a48a; padding-bottom: 0.6rem; }
.sheet-head h1 { margin: 0; font-family: Georgia, 'Times New Roman', serif; font-size: 1.7rem; line-height: 1.15; overflow-wrap: anywhere; }
.sheet-head .muted { margin: 0.15rem 0 0; color: #7a6a56; font-size: 0.9rem; }
.pill-row { display: flex; gap: 0.45rem; flex-shrink: 0; }
.pill {
  background: #efe5d2; border: 1px solid #cdbb9d; border-radius: 10px;
  padding: 0.3rem 0.6rem; text-align: center; min-width: 3.2rem;
}
.pill small { display: block; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.07em; color: #8a7860; }
.pill b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.hex-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.4rem; }
.hex {
  background: #efe5d2; border: 1px solid #cdbb9d; border-radius: 12px;
  text-align: center; padding: 0.45rem 0.2rem;
  display: flex; flex-direction: column;
}
.hex b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.hex small { font-size: 0.64rem; letter-spacing: 0.08em; color: #8a7860; }
.hex .mod { font-size: 0.78rem; font-weight: 700; color: #b45309; }

.derived-print { display: none; margin: 0; }
body[data-system="d20"] .derived-print { display: flex; gap: 1.25rem; margin-top: 0.5rem; }
.derived-print div { display: flex; flex-direction: column; }
.derived-print dt { font-size: 0.62rem; text-transform: uppercase; color: #8a7860; }
.derived-print dd { margin: 0; font-weight: 800; color: #b45309; }

.sheet-saves-skills { display: grid; grid-template-columns: 1fr 1.4fr; gap: 1rem; }
.sheet h4 {
  margin: 0 0 0.3rem; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: #8a7860; border-bottom: 1px solid #dccfb8; padding-bottom: 0.15rem;
}
.tag-list { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag-list li {
  background: #f3ead9; border: 1px solid #d8c9ac; border-radius: 999px;
  padding: 0.12rem 0.55rem; font-size: 0.76rem;
}

.sheet-gear table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.sheet-gear th { text-align: left; font-size: 0.68rem; text-transform: uppercase; color: #8a7860; border-bottom: 1px solid #dccfb8; padding: 0.2rem 0.3rem; }
.sheet-gear td { padding: 0.22rem 0.3rem; border-bottom: 1px dotted #d8c9ac; }
.sheet-gear th.num, .sheet-gear td.num { text-align: right; width: 4.5rem; font-variant-numeric: tabular-nums; }

.sheet-notes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
.sheet-notes h4 { margin-bottom: 0.25rem; }
.sheet-notes p { margin: 0; font-size: 0.84rem; min-height: 2.2em; }

.sheet-foot { margin-top: auto; border-top: 1px solid #dccfb8; padding-top: 0.45rem; font-size: 0.7rem; color: #8a7860; text-align: center; }

@media (max-width: 700px) {
  .hex-row { grid-template-columns: repeat(3, 1fr); }
  .sheet-notes { grid-template-columns: 1fr; }
  .sheet-head { flex-direction: column; }
}

/* ---------------------------------------------------------- site footer */
.site-footer { text-align: center; padding: 1.5rem; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); }
.site-footer a { color: var(--accent-2); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.hidden { display: none !important; }

.muted { color: var(--muted); }

/* ------------------------------------------------------------ printing */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .no-print { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; margin: 0; }
  .preview { position: static; }
  .editor { display: none; }
  .hero-actions, .system-picker { display: none !important; }
  .hero { display: none; }
  .sheet {
    box-shadow: none; border-radius: 0; padding: 0; min-height: 0;
    background: #fff; color: #000;
  }
  .sheet-head { border-color: #999; }
  .pill, .hex, .tag-list li { background: #fff; border-color: #999; }
  .hex .mod, .derived dd { color: #000; }
  a { text-decoration: none; color: #000; }
}
