:root {
  --bg: #f0ead9;
  --panel: #e6dfc8;
  --panel-border: #a8a077;
  --text: #2e2b1f;
  --text-dim: #6b6650;
  --accent: #6b5a3f;
  --gold: #a9843f;
}
* { 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;
  min-height: 100vh;
}
.site-header {
  text-align: center;
  padding: 36px 20px 20px;
  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); }
.site-header h1 {
  font-family: 'Spectral', Georgia, serif;
  font-weight: 700;
  font-size: 2.1rem;
  margin: 0 0 6px;
}
.site-header p {
  color: var(--text-dim);
  font-size: 0.92rem;
  font-style: italic;
  margin: 0;
}

main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.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;
}
.deck-panel h2 {
  font-family: 'Spectral', Georgia, serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gold);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 8px;
  margin: 0 0 10px;
}
#deck-list { list-style: none; margin: 0 0 14px; padding: 0; }
.deck-item {
  padding: 9px 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  border-radius: 3px;
}
.deck-item.active { background: rgba(169, 132, 63, 0.22); border-color: var(--gold); }
.deck-panel button {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  border-radius: 3px;
}
.deck-panel button:hover { border-color: var(--gold); }
.deck-panel input[type="file"] { font-size: 0.75rem; width: 100%; }

.form-panel, .preview-panel { flex: 1 1 420px; min-width: 320px; }

fieldset {
  border: none;
  border-top: 2px solid var(--gold);
  padding: 16px 0 4px;
  margin: 0 0 20px;
}
legend {
  font-family: 'Spectral', Georgia, serif;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--gold);
  padding: 0 2px;
}
label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 14px;
}
select, input[type="text"] {
  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', sans-serif;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.checkbox-row input { width: 16px; height: 16px; }
.checkbox-row label { margin: 0; }

.reroll-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.reroll-row button {
  flex: 1;
  min-width: 140px;
  padding: 9px 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  border-radius: 3px;
}
.reroll-row button:hover { border-color: var(--gold); color: var(--gold); }

.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; }
.randomize-bar .hint { margin: 8px 0 0; text-align: left; font-size: 0.78rem; color: var(--text-dim); }

/* ---- Card ---- */
#card-wrapper { display: flex; justify-content: center; }
#settlement-card {
  width: 560px;
  background: #f3ecd8;
  color: #2a2216;
  border: 1px solid #2a2216;
  outline: 1px solid #2a2216;
  outline-offset: -4px;
  padding: 28px 32px 20px;
  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;
}
.settlement-name {
  font-size: 1.9rem;
  font-weight: 700;
  margin: 0 0 4px;
}
.settlement-tier-tag {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  border: 1px solid #a9843f;
  color: #a9843f;
  padding: 2px 8px;
  border-radius: 2px;
  margin-bottom: 10px;
}
.settlement-vibe {
  font-style: italic;
  font-size: 0.98rem;
  margin: 0 0 16px;
  color: #4a4230;
}

.card-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid #a9843f;
  margin-bottom: 16px;
}
.card-tab-btn {
  padding: 8px 16px;
  background: rgba(169,132,63,0.12);
  border: none;
  font-family: 'Work Sans', sans-serif;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b5a3f;
  cursor: pointer;
  border-radius: 3px 3px 0 0;
}
.card-tab-btn.active { background: #a9843f; color: #f3ecd8; }
.card-tab-panel { display: none; }
.card-tab-panel.active { display: block; }
/* When exporting to PNG, every panel needs to be visible at once
   regardless of which tab is active on screen. */
#settlement-card.export-all .card-tab-panel { display: block !important; margin-bottom: 18px; }
#settlement-card.export-all .card-tabs { display: none; }

.card-line { margin: 0 0 10px; line-height: 1.5; font-size: 0.95rem; }
.card-line b { color: #7a2020; }
.gov-figure { margin-bottom: 12px; }
.gov-figure-name { font-weight: 700; font-size: 1.05rem; }
.gov-figure-title { font-style: italic; color: #6b5a3f; font-size: 0.85rem; }
.gov-figure-desc { font-size: 0.9rem; margin-top: 2px; }

.tavern-name { font-size: 1.3rem; font-weight: 700; margin: 0 0 2px; }
.tavern-meta { font-size: 0.85rem; color: #6b5a3f; margin-bottom: 10px; }
.menu-list { margin: 10px 0 0; padding: 0; list-style: none; }
.menu-list li { margin-bottom: 8px; font-size: 0.9rem; }
.menu-list .menu-item-name { font-weight: 700; }

.card-footer {
  margin-top: 18px;
  padding-top: 10px;
  border-top: 1px dotted #a8a077;
  font-size: 0.7rem;
  color: #8a8264;
  text-align: center;
}

.export-controls { text-align: center; margin-top: 18px; }
.export-controls button {
  padding: 10px 22px;
  background: var(--panel);
  border: 1px solid var(--gold);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 3px;
}
.export-controls button:hover { background: var(--gold); color: #f3ead8; }

.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;
}

#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); }

@media (max-width: 760px) {
  .deck-panel { position: static; max-height: none; flex: 1 1 100%; order: -1; }
  #settlement-card { width: 100%; }
}
