:root {
  --bg-void: #1b120c;
  --bg-panel: #2a1c12;
  --bg-panel-raised: #332316;
  --wood-trim: #4a311f;
  --wood-trim-light: #5f402a;
  --ember: #c9540c;
  --ember-dim: #8a3d0c;
  --flame-gold: #e8a33d;
  --parchment: #e8d9bf;
  --parchment-dim: #b8a583;
  --danger: #8c2a1f;
  --font-display: 'IM Fell English', Georgia, serif;
  --font-body: 'Work Sans', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-void);
  color: var(--parchment);
  font-family: var(--font-body);
  overflow-x: hidden;
}

/* Single deliberate animated moment: a slow firelight glow breathing behind the page */
.firelight {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 15% 100%, rgba(201, 84, 12, 0.22), transparent 60%),
    radial-gradient(ellipse 50% 35% at 85% 100%, rgba(232, 163, 61, 0.14), transparent 60%);
  animation: flicker 6s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.78; }
}

@media (prefers-reduced-motion: reduce) {
  .firelight { animation: none; }
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

/* ---------- Header / Ledger Bar ---------- */

.ledger-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 18px 28px;
  background: linear-gradient(180deg, var(--bg-panel-raised), var(--bg-panel));
  border-bottom: 3px solid var(--wood-trim);
}

.tavern-name {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 2rem;
  margin: 0;
  color: var(--flame-gold);
  letter-spacing: 0.5px;
  text-shadow: 0 0 18px rgba(232, 163, 61, 0.25);
}

.resources {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.resource-chip {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 0.95rem;
  color: var(--parchment-dim);
}

.resource-chip .icon { font-size: 1.1rem; }

.resource-chip .amount {
  font-weight: 600;
  color: var(--parchment);
  font-variant-numeric: tabular-nums;
}

.resource-chip .cap {
  font-size: 0.8rem;
  color: var(--parchment-dim);
}

.resource-chip .rate {
  font-size: 0.78rem;
  color: var(--flame-gold);
  font-variant-numeric: tabular-nums;
}

.day-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 140px;
}

.day-counter {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--parchment-dim);
}

.day-progress {
  width: 140px;
  height: 5px;
  background: var(--bg-void);
  border: 1px solid var(--wood-trim);
  border-radius: 3px;
  overflow: hidden;
}

.day-progress-fill {
  height: 100%;
  background: var(--ember);
  width: 0%;
  transition: width 0.3s linear;
}

/* ---------- Layout ---------- */

.main-layout {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: calc(100vh - 220px);
}

.sign-tabs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px 14px;
  min-width: 168px;
  background: var(--bg-void);
  border-right: 3px solid var(--wood-trim);
}

.sign-tab {
  font-family: var(--font-display);
  font-size: 1.15rem;
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-panel);
  border: 2px solid var(--wood-trim);
  border-radius: 3px;
  color: var(--parchment-dim);
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.sign-tab:hover {
  border-color: var(--wood-trim-light);
  color: var(--parchment);
}

.sign-tab.active {
  background: var(--bg-panel-raised);
  border-color: var(--ember);
  color: var(--flame-gold);
}

.content-panel {
  flex: 1;
  padding: 28px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---------- Buildings ---------- */

.serve-round-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  padding: 12px 20px;
  background: var(--bg-panel-raised);
  border: 2px solid var(--ember);
  border-radius: 4px;
  color: var(--flame-gold);
  font-family: var(--font-display);
  font-size: 1.15rem;
  transition: background 0.12s ease, transform 0.06s ease;
}

.serve-round-btn:hover {
  background: var(--ember-dim);
}

.serve-round-btn:active {
  transform: scale(0.97);
}

.serve-round-btn .hint {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--parchment-dim);
}

.building-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.building-card {
  background: var(--bg-panel);
  border: 2px solid var(--wood-trim);
  border-radius: 4px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

/* Keeps the Build button + cost row pinned to the same level across cards,
   regardless of how much description/effects text a building has. Setting
   margin-top:auto on the first bottom-aligned element pushes it (and
   everything after it) down to fill remaining space in the flex column. */
.building-card .b-cost {
  margin-top: auto;
}

.building-card .b-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.building-card .b-icon { font-size: 1.6rem; }

.building-card .b-name {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--flame-gold);
}

.building-card .b-count {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  color: var(--parchment-dim);
  font-size: 0.9rem;
}

.building-card .b-desc {
  color: var(--parchment-dim);
  font-size: 0.9rem;
  line-height: 1.4;
  min-height: 2.5em;
}

.building-card .b-effects {
  font-size: 0.82rem;
  color: var(--parchment-dim);
}

.building-card .b-cost {
  font-size: 0.85rem;
  color: var(--parchment-dim);
}

.building-card .b-cost .afford { color: var(--flame-gold); }
.building-card .b-cost .short { color: var(--danger); }

.building-card button.buy-btn {
  margin-top: 4px;
  padding: 9px 12px;
  background: var(--ember-dim);
  border: 1px solid var(--ember);
  border-radius: 3px;
  color: var(--parchment);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease;
}

.building-card button.buy-btn:hover:not(:disabled) {
  background: var(--ember);
}

.building-card button.buy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- Notice board ---------- */

.notice-board {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notice-item {
  background: var(--bg-panel);
  border-left: 3px solid var(--flame-gold);
  padding: 10px 14px;
  border-radius: 2px;
  font-size: 0.92rem;
  color: var(--parchment-dim);
}

.empty-state {
  color: var(--parchment-dim);
  font-style: italic;
}

/* ---------- Ledger tab ---------- */

.ledger-detail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 22px;
}

.ledger-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-panel);
  border-radius: 3px;
  font-size: 0.92rem;
}

.save-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.save-controls button {
  padding: 9px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--wood-trim-light);
  border-radius: 3px;
  color: var(--parchment);
  font-size: 0.88rem;
}

.save-controls button:hover { border-color: var(--flame-gold); }

.save-controls button.danger {
  border-color: var(--danger);
  color: #e0a99f;
}

.save-controls button.danger:hover {
  background: var(--danger);
  color: var(--parchment);
}

/* ---------- Badge strip (collapsed one-time purchases) ---------- */

.badge-strip {
  position: relative;
  z-index: 1;
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 28px;
  border-top: 1px solid var(--wood-trim);
  background: var(--bg-panel);
}

.building-badge {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg-panel-raised);
  border: 1px solid var(--wood-trim-light);
  color: var(--parchment-dim);
}

/* ---------- Tavern log ---------- */

.tavern-log {
  position: relative;
  z-index: 1;
  border-top: 3px solid var(--wood-trim);
  background: var(--bg-void);
  padding: 12px 28px;
  max-height: 110px;
  overflow-y: auto;
}

.log-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-entry {
  font-size: 0.85rem;
  color: var(--parchment-dim);
  font-style: italic;
}

/* Newest entry is the last DOM node (see ui.js renderLog) */
.log-entry:last-child {
  color: var(--parchment);
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .main-layout { flex-direction: column; }
  .sign-tabs {
    flex-direction: row;
    min-width: 0;
    border-right: none;
    border-bottom: 3px solid var(--wood-trim);
    overflow-x: auto;
  }
  .ledger-bar { flex-direction: column; align-items: flex-start; }
}

/* Accessibility: visible focus states */
button:focus-visible, .sign-tab:focus-visible {
  outline: 2px solid var(--flame-gold);
  outline-offset: 2px;
}
