:root {
  --bg-1: #1c140f;
  --bg-2: #2a1d14;
  --panel: #241a13;
  --panel-2: #2f2119;
  --border: #4a3524;
  --text: #f1e4d3;
  --text-dim: #b8a48c;
  --gold: #f2c14e;
  --gold-dim: #a9853a;
  --accent: #d9772b;
  --danger: #c2483c;
  --good: #6fae5c;
  --radius: 10px;
  --area-a: #3a2a1c;
  --area-b: #6b4a2a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: linear-gradient(160deg, var(--area-a), var(--area-b) 140%);
  color: var(--text);
  font-family: 'Georgia', 'Iowan Old Style', serif;
  transition: background 0.8s ease;
  -webkit-font-smoothing: antialiased;
}

body.area-0 { --area-a: #241a12; --area-b: #5b3d22; }
body.area-1 { --area-a: #16232b; --area-b: #2d5063; }
body.area-2 { --area-a: #1c2226; --area-b: #4a5a63; }
body.area-3 { --area-a: #241629; --area-b: #5a2f6b; }
body.area-4 { --area-a: #2b1414; --area-b: #7a1f2b; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0,0,0,0.35);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(4px);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: bold; font-size: 1.1rem; color: var(--gold); }
.brand-icon { font-size: 1.3rem; }

.resources { display: flex; gap: 14px; }
.resource {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.3);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  font-weight: bold;
}
.res-icon { font-size: 1rem; }
.res-val { color: var(--gold); }

#tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  padding: 8px 10px;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 19;
}
.tab-btn {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
}
.tab-btn.active {
  background: var(--panel-2);
  color: var(--gold);
  border-color: var(--border);
}

main { max-width: 900px; margin: 0 auto; padding: 16px; padding-bottom: 60px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: translateY(0);} }

h1 { margin: 0 0 4px; font-size: 1.4rem; color: var(--gold); }
.tab-sub { color: var(--text-dim); margin: 0 0 16px; font-size: 0.9rem; }

.area-banner { margin-bottom: 14px; }
.area-banner p { color: var(--text-dim); margin: 2px 0 0; font-style: italic; }

.shop-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 700px) {
  .shop-grid { grid-template-columns: 1fr 1.3fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h2 { margin: 0 0 10px; font-size: 1.05rem; color: var(--gold); }

.btn {
  font-family: inherit;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.95rem;
}
.btn:hover { border-color: var(--gold-dim); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1c1108; font-weight: bold; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: bold; }

.btn-action {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px;
  background: linear-gradient(180deg, #3c2a1a, #2a1d12);
  border: 1px solid var(--border);
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--gold);
  margin-bottom: 14px;
  user-select: none;
}
.btn-action:active { transform: scale(0.97); }
.btn-icon { font-size: 1.3rem; }
.btn-sub { font-size: 0.75rem; color: var(--text-dim); font-weight: normal; }

.craft-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.craft-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.craft-item.locked { opacity: 0.4; }
.craft-item-info { display: flex; flex-direction: column; }
.craft-item-name { font-weight: bold; }
.craft-item-cost { font-size: 0.78rem; color: var(--text-dim); }
.craft-item button { flex: 0 0 auto; }

.auto-craft { display: flex; flex-direction: column; gap: 6px; }
.auto-craft label { font-size: 0.8rem; color: var(--text-dim); }
.auto-craft select {
  font-family: inherit;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.customer-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  min-height: 108px;
  padding-bottom: 6px;
  margin-bottom: 14px;
}
.customer-card {
  flex: 0 0 auto;
  width: 108px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  position: relative;
}
.customer-card:active { transform: scale(0.95); }
.customer-card.no-stock { cursor: not-allowed; }
.customer-emoji { font-size: 1.8rem; }
.customer-wants { font-size: 0.72rem; color: var(--text-dim); margin: 2px 0; }
.customer-offer { font-weight: bold; color: var(--gold); font-size: 0.85rem; }
.patience-bar { height: 4px; background: rgba(255,255,255,0.15); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.patience-fill { height: 100%; background: var(--good); transition: width 0.2s linear; }
.patience-fill.low { background: var(--danger); }
.customer-empty { color: var(--text-dim); font-size: 0.85rem; padding: 20px 0; }

.inventory-row { display: flex; flex-wrap: wrap; gap: 8px; }
.inv-chip {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.8rem;
}
.inv-chip strong { color: var(--gold); }

.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card.locked { opacity: 0.5; }
.card-info { display: flex; flex-direction: column; gap: 2px; }
.card-title { font-weight: bold; }
.card-desc { font-size: 0.8rem; color: var(--text-dim); }
.card-meta { font-size: 0.78rem; color: var(--gold-dim); }
.card button { flex: 0 0 auto; }

.prestige-panel { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.prestige-stat {
  display: flex;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}
.prestige-stat strong { color: var(--gold); }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 340px;
  text-align: center;
}
.modal-box h2 { color: var(--gold); margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.prestige-preview { color: var(--gold); font-weight: bold; }

#toastLayer {
  position: fixed;
  top: 60px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  background: rgba(20,14,8,0.92);
  border: 1px solid var(--border);
  color: var(--gold);
  font-weight: bold;
  padding: 6px 12px;
  border-radius: 999px;
  animation: toastRise 1.4s ease forwards;
}
@keyframes toastRise {
  0% { opacity: 0; transform: translateY(6px); }
  15% { opacity: 1; transform: translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}
