:root {
  --bg: #f0ead9;
  --panel: #e6dfc8;
  --panel-border: #a8a077;
  --text: #2e2b1f;
  --text-dim: #6b6650;
  --accent: #8a2727;
  --gold: #a9843f;
  --mono: 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #f6f1e0 0%, #e9e0c4 70%);
  color: var(--text);
  font-family: 'Work Sans', -apple-system, sans-serif;
}

.site-header {
  padding: 20px 20px 18px;
  text-align: center;
  border-bottom: 1px solid var(--panel-border);
}

.back-link {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-decoration: none;
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.back-link:hover { color: var(--gold); }

.cross-link {
  display: block;
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--gold);
  text-decoration: none;
}

.cross-link:hover { text-decoration: underline; }

.site-header h1 {
  margin: 0;
  font-family: 'Spectral', Georgia, serif;
  font-weight: 700;
  font-size: 2.1rem;
  letter-spacing: 1.5px;
}

.tagline {
  color: var(--text-dim);
  margin: 6px 0 0;
  font-size: 0.95rem;
  font-style: italic;
}

.layout {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 24px 20px 60px;
  max-width: 1300px;
  margin: 0 auto;
}

.deck-panel { flex: 0 1 220px; min-width: 200px; position: sticky; top: 16px; align-self: flex-start; max-height: calc(100vh - 32px); overflow-y: auto; }
.form-panel, .preview-panel { flex: 1 1 420px; min-width: 320px; }

.deck-panel h2 {
  font-family: 'Spectral', Georgia, serif;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--gold);
  margin: 0 0 10px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 8px;
}

#deck-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  max-height: 260px;
  overflow-y: auto;
}

.deck-item {
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--panel-border);
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 0.15s ease;
}

.deck-item.active { border-left-color: var(--accent); background: rgba(169, 132, 63, 0.22); }

.deck-panel button, .file-btn {
  display: block;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 8px;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.deck-panel button:hover, .file-btn:hover { border-color: var(--accent); color: var(--text); }
.file-btn { box-sizing: border-box; }

.deck-io { border-top: 1px solid var(--panel-border); padding-top: 12px; margin-top: 8px; }
.convert-io { border-top: 1px solid var(--panel-border); padding-top: 12px; margin-top: 8px; }
.convert-io button { border-color: var(--gold); }
#deck-status a { color: var(--gold); }

#deck-status {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  min-height: 1.2em;
  font-style: italic;
}

.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.type-btn {
  flex: 1;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.type-btn:hover { border-color: var(--accent); }

.type-btn.active {
  background: var(--accent);
  color: #f3ead8;
  border-color: var(--accent);
}

fieldset {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-top: 2px solid var(--accent);
  margin-bottom: 18px;
  padding: 16px 18px 18px;
}

legend {
  padding: 0 8px;
  color: var(--gold);
  font-family: 'Spectral', Georgia, serif;
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  background: #f7f2e2;
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 0.95rem;
  font-family: 'Work Sans', -apple-system, sans-serif;
}
.combobox-wrapper { position: relative; }

.combobox-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  margin: 2px 0 0;
  padding: 4px 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.combobox-dropdown li {
  padding: 7px 12px;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text);
}

.combobox-dropdown li:hover { background: var(--gold); color: var(--panel); }

#back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  padding: 10px 18px;
  background: var(--gold);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  transition: background 0.15s ease, transform 0.1s ease;
}

#back-to-top:hover { background: var(--accent); color: #f3ead8; transform: translateY(-1px); }

.randomize-bar {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 14px 16px;
  margin-bottom: 14px;
  text-align: center;
}

.randomize-bar button {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #f3ead8;
  border: none;
  border-radius: 3px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.randomize-bar button:hover { opacity: 0.9; }

.stats-randomize-row { display: flex; gap: 8px; }
.stats-randomize-row button { width: auto; flex: 1; }

/* The 5E SRD's own alignment values (lawful good, unaligned, etc.) are
   lowercase by convention, and that's genuinely correct for how the 2014
   card format writes them inline ("Large beast, unaligned"). This is
   purely cosmetic — capitalizes how it LOOKS in the form/dropdown without
   touching the actual stored value or the correctly-lowercase card text. */
.capitalize-display,
.combobox-wrapper:has(.capitalize-display) .combobox-dropdown li {
  text-transform: capitalize;
}
#reset-stats { background: transparent; border: 1px solid var(--panel-border); color: var(--text-dim); }
#reset-stats:hover { border-color: var(--gold); color: var(--gold); opacity: 1; }
.randomize-bar.stats-disabled { opacity: 0.5; pointer-events: none; }

.randomize-bar .hint { margin: 8px 0 0; text-align: left; }

.field-highlighted {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  background: rgba(169, 132, 63, 0.12);
  border-radius: 2px;
  transition: background 0.15s ease, outline-color 0.15s ease;
}

@media (max-width: 760px) {
  #back-to-top { bottom: 16px; right: 16px; padding: 9px 14px; font-size: 0.78rem; }
}


input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="color"] { padding: 2px; height: 38px; }
textarea { resize: vertical; }

.ability-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 12px;
}

.ability-grid label { margin-bottom: 12px; }

.feature-row {
  border: 1px solid var(--panel-border);
  margin-top: 8px;
}

.feature-row:first-child { margin-top: 0; }

.feature-row summary {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.feature-row summary::-webkit-details-marker { display: none; }

.feature-row summary::before {
  content: '\25B8';
  color: var(--gold);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}

.feature-row[open] summary::before { transform: rotate(90deg); }

.feature-row summary .summary-type {
  color: var(--text-dim);
  font-size: 0.78rem;
}

.feature-row-body {
  padding: 0 12px 12px;
  border-top: 1px solid var(--panel-border);
}

.feature-row-body label:first-of-type { margin-top: 12px; }

.quick-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.quick-add {
  flex: 1;
  min-width: 90px;
  padding: 9px 8px;
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.quick-add:hover { border-color: var(--accent); color: var(--text); }

.fieldset-details {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-top: 2px solid var(--accent);
  margin-bottom: 18px;
}

.fieldset-details summary {
  padding: 12px 18px;
  cursor: pointer;
  color: var(--gold);
  font-family: 'Spectral', Georgia, serif;
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fieldset-details summary::-webkit-details-marker { display: none; }

.fieldset-details summary::before {
  content: '\25B8';
  transition: transform 0.15s ease;
}

.fieldset-details[open] summary::before { transform: rotate(90deg); }

.fieldset-details > *:not(summary) { padding-left: 18px; padding-right: 18px; }
.fieldset-details > *:last-child { padding-bottom: 18px; }
.fieldset-details .hint { margin-top: 0; }

.feature-row-header {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.feat-cat-label { flex: 0 0 140px; }
.feature-row-header label:not(.feat-cat-label) { flex: 1; min-width: 140px; }

.remove-feature {
  background: transparent;
  border: 1px solid #a85a4a;
  color: #8a4a2a;
  padding: 8px 10px;
  cursor: pointer;
  height: 38px;
  margin-top: 5px;
}

.remove-feature:hover { border-color: var(--accent); color: var(--text); }

#add-feature {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px dashed var(--panel-border);
  color: var(--text-dim);
  cursor: pointer;
  margin-top: 6px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.78rem;
}

#add-feature:hover { border-color: var(--accent); color: var(--text); }

.hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
  margin: -4px 0 12px;
  line-height: 1.45;
}

.hint code {
  background: rgba(169, 132, 63, 0.15);
  border: 1px solid var(--panel-border);
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 0.82em;
  font-style: normal;
  color: var(--gold);
}

.field-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 3px;
  font-style: italic;
  min-height: 1.1em;
}

.field-hint.warn { color: #a85a2a; }

.guidance-box {
  font-size: 0.78rem;
  color: var(--text-dim);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--gold);
  background: rgba(169, 132, 63, 0.08);
  padding: 8px 10px;
  margin-bottom: 10px;
  line-height: 1.45;
}

.variable-row {
  display: grid;
  grid-template-columns: 1fr 1.6fr auto;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}

.variable-key { text-transform: uppercase; letter-spacing: 0.5px; font-family: var(--mono); font-size: 0.85rem; }

#add-variable {
  width: 100%;
  padding: 10px;
  background: transparent;
  border: 1px dashed var(--panel-border);
  color: var(--text-dim);
  cursor: pointer;
  margin-top: 2px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.78rem;
}

#add-variable:hover { border-color: var(--accent); color: var(--text); }

#randomize-item {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #f3ead8;
  cursor: pointer;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  transition: opacity 0.15s ease;
}

#randomize-item:hover { opacity: 0.85; }

.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -4px 0 12px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  background: #e6dfc8;
}

.image-preview img {
  max-width: 70px;
  max-height: 70px;
  width: auto;
  margin: 0;
  border: 1px solid var(--panel-border);
  background:
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%) 0 0/10px 10px,
    linear-gradient(45deg, #333 25%, transparent 25%, transparent 75%, #333 75%) 5px 5px/10px 10px,
    #222;
}

#remove-image {
  padding: 7px 12px;
  background: transparent;
  border: 1px solid #a85a4a;
  color: #8a4a2a;
  cursor: pointer;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: 'Work Sans', -apple-system, sans-serif;
}

#remove-image:hover { border-color: var(--accent); color: var(--text); }

.preview-panel { position: sticky; top: 16px; align-self: flex-start; }

#card-wrapper {
  display: flex;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
}

/* ===== The card itself ===== */

#statblock-card {
  width: 700px;
  padding: 28px 34px 22px;
  font-family: 'Alegreya', Georgia, serif;
  position: relative;
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
  overflow-wrap: break-word;
  word-break: break-word;
}

#statblock-card.format-2014 { width: 460px; padding: 30px 28px 22px; }

#statblock-card.theme-parchment { background: #f3ecd8; color: #2a2216; border: 1px solid #2a2216; outline: 1px solid #2a2216; outline-offset: -4px; }
#statblock-card.theme-dark { background: #17161a; color: #ece7d9; border: 1px solid #4a4640; outline: 1px solid #4a4640; outline-offset: -4px; }
#statblock-card.theme-verdant { background: #10201a; color: #e3ecdf; border: 1px solid #3c5347; outline: 1px solid #3c5347; outline-offset: -4px; }
#statblock-card.theme-arcane { background: #14101f; color: #e6e1f2; border: 1px solid #4a3f63; outline: 1px solid #4a3f63; outline-offset: -4px; }

.corner-tag { position: absolute; top: 0; padding: 6px 12px 5px; text-align: center; background: rgba(0,0,0,0.03); max-width: 45%; overflow-wrap: break-word; word-break: break-word; }
.corner-tag.corner-right { right: 0; border: 1px solid var(--card-accent, #8a2727); border-top: none; border-right: none; }
.corner-tag.corner-left { left: 0; border: 1px solid var(--card-accent, #8a2727); border-top: none; border-left: none; }
.theme-dark .corner-tag, .theme-verdant .corner-tag, .theme-arcane .corner-tag { background: rgba(255,255,255,0.04); }

.corner-tier { font-family: 'Alegreya', Georgia, serif; font-weight: 700; font-size: 1.05rem; letter-spacing: 1px; color: var(--card-accent, #8a2727); line-height: 1.1; }
.corner-type { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.85; margin-top: 2px; }
.corner-icon { width: 11px; height: 11px; flex: 0 0 11px; color: var(--card-accent, #8a2727); }
.corner-icon svg { width: 100%; height: 100%; display: block; }

.card-illustration { display: block; height: auto; margin: 4px 0 14px; }
.card-illustration.align-left { margin-right: auto; margin-left: 0; }
.card-illustration.align-right { margin-left: auto; margin-right: 0; }

.stat-image-row { clear: both; display: flex; align-items: center; gap: 18px; margin: 8px 0 4px; }
.stat-col { flex: 1; min-width: 0; }
.stat-image-row .card-illustration { flex: 0 0 auto; margin: 0; }

.card-illustration-bottom {
  width: 100%;
  height: auto;
  margin: 14px 0 10px;
}

.card-name { font-family: 'Alegreya', Georgia, serif; font-weight: 700; font-size: 1.9rem; letter-spacing: 0.5px; margin: 0 0 6px; line-height: 1.1; }
.card-kind { clear: both; font-size: 0.82rem; font-style: italic; opacity: 0.75; border-bottom: 1.5px solid var(--card-accent, #8a2727); padding-bottom: 8px; margin-bottom: 10px; }

.trait-chip-row { clear: both; display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.trait-chip {
  border: 1px solid var(--card-accent, #8a2727);
  padding: 2px 9px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.85;
}

.card-desc { font-size: 0.88rem; font-style: italic; opacity: 0.85; margin-bottom: 10px; line-height: 1.4; }

.core-stat-row {
  clear: both;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
  border-top: 1.5px solid var(--card-accent, #8a2727);
  border-bottom: 1.5px solid var(--card-accent, #8a2727);
  padding: 8px 0;
  margin-bottom: 4px;
}

.core-stat { font-size: 0.85rem; }
.core-stat b { font-family: 'Alegreya', Georgia, serif; font-weight: 700; color: var(--card-accent, #8a2727); }

.section-divider {
  clear: both;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: center;
  margin: 16px 0 10px;
  font-size: 0.68rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0.6;
}

.section-divider::before, .section-divider::after { content: ""; flex: 1; border-top: 1.5px dotted currentColor; opacity: 0.6; }

.card-line { font-size: 0.85rem; margin: 5px 0; line-height: 1.4; }
.card-line b { font-family: 'Alegreya', Georgia, serif; font-weight: 700; color: var(--card-accent, #8a2727); }

.ability-row {
  clear: both;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 12px 0 16px;
}

.statblock-columns {
  clear: both;
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0 26px;
  align-items: start;
}

.col-right {
  border-left: 1px solid var(--card-accent, #8a2727);
  padding-left: 24px;
}

.col-right .col-divider:first-child { margin-top: 0; }

.ability-box {
  border: 1px solid var(--card-accent, #8a2727);
  padding: 5px 2px;
  text-align: center;
}

.ability-lbl { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 1px; opacity: 0.75; }
.ability-val { font-family: 'Alegreya', Georgia, serif; font-weight: 700; font-size: 1.05rem; margin-top: 1px; }
.ability-mod { font-size: 0.7rem; opacity: 0.8; }

.card-feature { margin: 10px 0; font-size: 0.83rem; line-height: 1.42; }
.feat-head { display: flex; align-items: center; gap: 6px; }
.card-feature .feat-name { font-family: 'Alegreya', Georgia, serif; font-weight: 700; font-style: italic; font-size: 0.95rem; color: var(--card-accent, #8a2727); }
.feat-icon { width: 10px; height: 10px; flex: 0 0 10px; color: var(--card-accent, #8a2727); opacity: 0.8; }
.feat-icon svg { width: 100%; height: 100%; display: block; }
.feat-text { margin-top: 2px; display: inline; }

.card-footer {
  clear: both;
  margin-top: 16px;
  padding-top: 8px;
  border-top: 1px dotted currentColor;
  opacity: 0.5;
  font-size: 0.6rem;
  text-align: center;
  letter-spacing: 0.3px;
}

.export-controls { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 16px; }

#export-png {
  padding: 11px 26px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-family: 'Work Sans', -apple-system, sans-serif;
  transition: background 0.15s ease, color 0.15s ease;
}

#export-png:hover { background: var(--accent); color: #f3ead8; }
#export-status { color: var(--text-dim); font-size: 0.85rem; font-style: italic; }

.compliance-note { font-size: 0.72rem; color: var(--text-dim); text-align: center; margin-top: 16px; line-height: 1.4; }

.site-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 20px;
  border-top: 1px solid var(--panel-border);
  font-style: italic;
}

.kofi-footer-link { margin-top: 10px; font-style: normal; }
.kofi-footer-link a { color: var(--gold); text-decoration: none; font-size: 0.78rem; }
.kofi-footer-link a:hover { text-decoration: underline; }

.print-cell { break-inside: avoid; }

@media (max-width: 760px) {
  .preview-panel { position: static; }
  #statblock-card { width: 100%; }
  .deck-panel { flex: 1 1 100%; order: -1; position: static; max-height: none; }
  #deck-list { max-height: 160px; }
  .ability-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .statblock-columns { grid-template-columns: 1fr; }
  .col-right { border-left: none; padding-left: 0; border-top: 1px solid var(--card-accent, #8a2727); padding-top: 10px; margin-top: 6px; }
  .ability-row { grid-template-columns: repeat(3, 1fr); }
}
