:root {
  --bg: #0d0b09;
  --panel: rgba(24, 19, 14, 0.96);
  --panel2: rgba(36, 28, 19, 0.97);
  --edge: #4a3a24;
  --gold: #e8b96a;
  --gold2: #c9964a;
  --text: #f3e8d3;
  --dim: #b9a887;
  --green: #7cc06a;
  --red: #e05252;
  --blue: #6a9bd0;
  --shadow: 0 10px 40px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: #0d0b09; cursor: crosshair; }

.hidden { display: none !important; }

/* ================= OVERLAYS ================= */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 4, 3, 0.72);
  backdrop-filter: blur(4px);
  animation: fadein 0.25s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.06);
  padding: 28px 32px;
  max-width: 620px;
  width: 92%;
  max-height: 90vh;
  overflow: auto;
  color: var(--text);
}
.panel-wide { max-width: 940px; }
.panel h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px; letter-spacing: 1px; color: var(--gold);
  margin-bottom: 18px; text-align: center;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.panel-dim { color: var(--dim); font-size: 14px; font-weight: normal; }
.panel-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.panel-buttons.col { flex-direction: column; align-items: stretch; }

button {
  font-family: inherit; font-size: 15px; cursor: pointer;
  background: linear-gradient(180deg, #3a2e1e, #2a2013);
  color: var(--text); border: 1px solid var(--edge); border-radius: 8px;
  padding: 11px 20px; transition: all 0.12s ease;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 3px 8px rgba(0,0,0,0.4);
}
button:hover { background: linear-gradient(180deg, #4c3c26, #36291a); border-color: var(--gold2); color: #fff; transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.primary { background: linear-gradient(180deg, #b8863c, #8a5f24); border-color: #d9a960; color: #1c1408; font-weight: 700; }
button.primary:hover { background: linear-gradient(180deg, #d0a053, #a27633); }
button.danger { background: linear-gradient(180deg, #7a2c2c, #551f1f); border-color: #a34848; }
button.small { padding: 6px 12px; font-size: 13px; }

/* ================= MAIN MENU ================= */
#menu { z-index: 60; background: #050403; }
#menu-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 70%, rgba(232,150,80,0.16), transparent 60%),
              linear-gradient(180deg, #160e22 0%, #24102e 35%, #4a1f1a 68%, #1a0e08 100%);
}
#menu-bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 20% 90%, rgba(255,180,80,0.25), transparent 40%);
  animation: emberglow 6s ease-in-out infinite alternate;
}
@keyframes emberglow { from { opacity: 0.5; } to { opacity: 1; } }
.menu-card {
  position: relative; z-index: 2; text-align: center;
  padding: 40px 50px; border-radius: 16px;
  background: rgba(12, 8, 6, 0.55);
  border: 1px solid rgba(232,185,106,0.35);
  box-shadow: 0 0 80px rgba(232,150,80,0.15), inset 0 0 60px rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
}
.menu-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 64px; letter-spacing: 6px; color: #f7e4c0; font-weight: 700;
  text-shadow: 0 2px 0 #6b4a1e, 0 6px 24px rgba(0,0,0,0.8);
}
.menu-subtitle {
  font-size: 22px; letter-spacing: 14px; color: var(--gold);
  margin-top: 2px; text-shadow: 0 2px 8px rgba(0,0,0,0.7);
}
.menu-flourish { color: var(--gold2); letter-spacing: 10px; margin: 16px 0 6px; }
.menu-tag { font-style: italic; color: var(--dim); margin-bottom: 26px; }
#menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 320px; margin: 0 auto; }
#menu-buttons button { font-size: 17px; padding: 14px; letter-spacing: 1px; }
.menu-footer { margin-top: 30px; color: var(--dim); font-size: 12px; letter-spacing: 1px; }

/* ================= HUD ================= */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud > * { pointer-events: auto; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(10,7,5,0.92), rgba(10,7,5,0.65));
  border-bottom: 1px solid rgba(232,185,106,0.3);
  gap: 12px;
}
.tb-group { display: flex; align-items: center; gap: 14px; }
.tb-center { flex-direction: column; align-items: center; gap: 1px; text-align: center; }
#hud-location { font-family: Georgia, serif; font-size: 16px; color: var(--gold); letter-spacing: 1px; }
#hud-miles { font-size: 12px; color: var(--dim); }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 44px; }
.stat-icon { font-size: 16px; line-height: 1; }
.stat-label { font-size: 11px; color: var(--text); }
.stat.money .stat-icon { color: #7fd46a; }
.datebox {
  width: 46px; border: 1px solid #6b5a3a; border-radius: 6px; overflow: hidden; text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
.datebox-month { background: #6b4a1e; color: #f7e4c0; font-size: 10px; letter-spacing: 2px; padding: 1px 0; }
.datebox-day { background: #f3e8d3; color: #2a2013; font-size: 17px; font-weight: 700; line-height: 1.2; }

#partybar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: flex-end;
}
.member {
  width: 96px; background: rgba(14,10,7,0.9);
  border: 1px solid var(--edge); border-radius: 8px;
  padding: 5px 6px; position: relative; overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  transition: all 0.15s ease;
}
.member.leader { border-color: var(--gold); }
.member.dead { opacity: 0.55; }
.member-top { display: flex; align-items: center; gap: 5px; margin-bottom: 4px; }
.member-avatar {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--edge);
  background: radial-gradient(circle at 50% 28%, #2e2618, #14100c); flex: none;
  position: relative; overflow: hidden;
}
.member-avatar .ic-svg { width: 100%; height: 100%; display: block; }
.member-name { font-size: 12px; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-status { font-size: 9px; color: var(--red); position: absolute; top: 2px; right: 4px; }
.meter-row { display: flex; flex-direction: column; gap: 2px; }
.meter { height: 4px; background: rgba(255,255,255,0.12); border-radius: 2px; overflow: hidden; }
.meter > div { height: 100%; border-radius: 2px; transition: width 0.3s ease; }
.meter.hp > div { background: linear-gradient(90deg, #5fae4c, #8ed06a); }
.meter.hunger > div { background: linear-gradient(90deg, #c97a3a, #e0a55a); }
.meter.thirst > div { background: linear-gradient(90deg, #3a78c9, #6aa8e0); }
.meter.morale > div { background: linear-gradient(90deg, #a05ac0, #c88ae0); }
.member-sick { position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, rgba(120,220,90,0.15), transparent); }
.pbbtn {
  width: 40px; height: 44px; font-size: 18px; padding: 0;
  background: rgba(14,10,7,0.9); border: 1px solid var(--edge); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

#hud-bottom { position: absolute; bottom: 14px; left: 14px; display: flex; align-items: flex-end; gap: 14px; }
#wagon-status {
  background: rgba(14,10,7,0.9); border: 1px solid var(--edge); border-radius: 8px;
  padding: 8px 10px; display: flex; align-items: center; gap: 8px;
}
.ws-icon { font-size: 20px; }
.ws-bar { width: 90px; height: 8px; background: rgba(255,255,255,0.12); border-radius: 4px; overflow: hidden; }
#wagon-status-fill { height: 100%; background: linear-gradient(90deg, #a06a2e, #d9a960); transition: width 0.3s; }
.ws-label { font-size: 10px; color: var(--dim); }

#prompt {
  position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: rgba(10,7,5,0.9); border: 1px solid var(--gold2); border-radius: 8px;
  padding: 8px 16px; font-size: 14px; color: var(--gold); letter-spacing: 1px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5); animation: pulsel 1.6s ease-in-out infinite;
}
@keyframes pulsel { 0%,100% { box-shadow: 0 4px 14px rgba(0,0,0,0.5), 0 0 0 rgba(232,185,106,0);} 50% { box-shadow: 0 4px 14px rgba(0,0,0,0.5), 0 0 18px rgba(232,185,106,0.5);} }

#crosshair {
  position: fixed; z-index: 30; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  pointer-events: none; transform: translate(var(--cx,0), var(--cy,0));
}
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: rgba(255,255,255,0.9); box-shadow: 0 0 4px rgba(0,0,0,0.9); }
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }
#crosshair .dot { position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: #ffd98a; }

/* ================= DIALOGUE ================= */
#dialogue-box {
  position: absolute; bottom: 150px; left: 50%; transform: translateX(-50%);
  width: min(640px, 92%); background: rgba(14,10,7,0.94);
  border: 1px solid var(--gold2); border-radius: 12px; padding: 16px 20px;
  box-shadow: var(--shadow);
}
#dialogue-name { color: var(--gold); font-family: Georgia, serif; font-size: 16px; margin-bottom: 6px; }
#dialogue-text { color: var(--text); font-size: 15px; line-height: 1.45; }
.dialogue-actions { display: flex; gap: 10px; margin-top: 12px; justify-content: flex-end; }

/* ================= MINIMAP ================= */
#minimap {
  position: absolute; top: 70px; right: 14px; width: 300px;
  background: rgba(12,9,6,0.92); border: 1px solid var(--gold2); border-radius: 10px;
  padding: 10px; box-shadow: var(--shadow);
}
#minimap canvas { width: 100%; border-radius: 6px; }
.minimap-title { text-align: center; font-family: Georgia, serif; color: var(--gold); font-size: 12px; letter-spacing: 2px; margin-top: 6px; }

/* ================= JOURNEY MAP ================= */
#journeymap-canvas { width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--edge); box-shadow: inset 0 0 30px rgba(0,0,0,0.35); }

/* ================= CAMP ================= */
#camp-break { position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 40; }
#camp-break button { padding: 10px 24px; font-size: 14px; letter-spacing: 1px; box-shadow: 0 4px 18px rgba(0,0,0,0.6), 0 0 22px rgba(255,150,60,0.4); }
.member:hover { border-color: var(--gold); }

/* ================= TOASTS ================= */
#toast-stack { position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: rgba(16,11,7,0.95); border: 1px solid var(--gold2); border-radius: 8px;
  padding: 9px 18px; font-size: 14px; color: var(--text);
  box-shadow: var(--shadow); animation: toastin 0.25s ease;
}
.toast.warn { border-color: #c06a3a; }
.toast.good { border-color: #6ab05a; }
.toast.bad { border-color: #c04a4a; color: #ffd0d0; }
@keyframes toastin { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ================= SHOP / INVENTORY / CRAFT ================= */
.shop-grid, .inv-grid, .craft-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
}
.item-card {
  background: var(--panel2); border: 1px solid var(--edge); border-radius: 10px;
  padding: 10px; position: relative; transition: all 0.12s;
}
.item-card:hover { border-color: var(--gold2); transform: translateY(-2px); }
.item-card .ic-icon { font-size: 30px; text-align: center; }
.item-card .ic-name { font-size: 13px; font-weight: 700; text-align: center; margin-top: 4px; }
.item-card .ic-sub { font-size: 11px; color: var(--dim); text-align: center; }
.item-card .ic-price { font-size: 13px; color: #7fd46a; text-align: center; margin-top: 4px; }
.item-card .ic-row { display: flex; gap: 4px; justify-content: center; margin-top: 8px; }
.item-card .ic-count { position: absolute; top: 6px; right: 8px; font-size: 12px; color: var(--gold); font-weight: 700; }
.item-card.soldout { opacity: 0.45; }
.cat-tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 14px; }
.cat-tabs button.act { background: linear-gradient(180deg, #b8863c, #8a5f24); border-color: #d9a960; color: #1c1408; font-weight: 700; }
.shop-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 720px) { .shop-cols { grid-template-columns: 1fr; } }
.shop-side h2 { font-size: 15px; color: var(--gold); margin: 12px 0 8px; text-align: center; }
.shop-note { text-align: center; color: var(--dim); font-size: 12px; margin-top: 10px; }
.quan-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; }
.quan-row button { padding: 3px 10px; font-size: 14px; }
.buy-sell { display: flex; gap: 6px; justify-content: center; margin-top: 8px; }

.setup-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px) { .setup-row { grid-template-columns: 1fr; } }
.setup-col h2 { font-size: 15px; color: var(--gold); margin-bottom: 10px; text-align: center; }
.pick-card {
  display: flex; gap: 10px; align-items: center; background: var(--panel2);
  border: 1px solid var(--edge); border-radius: 10px; padding: 9px 12px; margin-bottom: 8px; cursor: pointer;
  transition: all 0.12s;
}
.pick-card:hover { border-color: var(--gold2); }
.pick-card.selected { border-color: var(--gold); background: rgba(232,185,106,0.1); }
.pick-card .pc-avatar { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--edge); flex: none; overflow: hidden; background: radial-gradient(circle at 50% 28%, #2e2618, #14100c); }
.pick-card .pc-avatar .ic-svg { width: 100%; height: 100%; display: block; }
.pick-card .pc-name { font-weight: 700; font-size: 14px; }
.pick-card .pc-sub { font-size: 11px; color: var(--dim); }
.pick-card .pc-check { margin-left: auto; color: var(--gold); font-weight: 700; }
.skill-dots { color: var(--gold); font-size: 12px; letter-spacing: 2px; }
label.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--dim); }
input[type=text], select {
  background: #18120b; color: var(--text); border: 1px solid var(--edge); border-radius: 8px;
  padding: 10px 12px; font-size: 15px; font-family: inherit;
}
input[type=range] { width: 100%; accent-color: #c9964a; }
.setup-money { text-align: center; font-size: 20px; color: #7fd46a; margin: 10px 0; }
.diff-row { display: flex; gap: 8px; justify-content: center; }

#fade { position: fixed; inset: 0; background: #000; z-index: 45; opacity: 0; transition: opacity 0.6s; pointer-events: none; }
.dead-title { color: #e05252 !important; }
.victory-title { color: #7fd46a !important; }

.event-banner {
  background: linear-gradient(90deg, rgba(120,220,90,0.12), transparent);
  border-left: 3px solid #6ab05a; padding: 4px 8px; font-size: 12px; color: #c8ffb0;
}

.credits-body { text-align: center; line-height: 1.7; }
.credits-big { font-family: Georgia, serif; font-size: 26px; color: var(--gold); letter-spacing: 3px; }
.credits-sub { color: var(--dim); letter-spacing: 4px; font-size: 12px; }
.credits-spacer { height: 18px; }
.credits-line { color: var(--text); }
.credits-name { font-size: 20px; color: var(--gold); font-family: Georgia, serif; }
.credits-dim { color: var(--dim); font-size: 12px; }

.howto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
@media (max-width: 720px) { .howto-grid { grid-template-columns: 1fr; } }
.ht { background: var(--panel2); border: 1px solid var(--edge); border-radius: 8px; padding: 8px 12px; }
.ht b { color: var(--gold); display: block; font-size: 13px; }
.ht span { font-size: 12px; color: var(--dim); }
.howto-body { font-size: 14px; line-height: 1.6; color: var(--text); }

.vol-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.vol-row label { width: 90px; color: var(--dim); font-size: 13px; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: #161009; }
::-webkit-scrollbar-thumb { background: #4a3a24; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #6b5a3a; }

/* SVG icon alignment */
.ic-svg { vertical-align: middle; display: inline-block; }
.ic-emoji { font-size: 1.4em; line-height: 1; vertical-align: middle; }
.stat .ic-svg { width: 20px; height: 20px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); }
.item-card .ic-svg { width: 30px; height: 30px; margin: 0 auto; display: block; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.55)); }
.pbbtn .ic-svg { width: 20px; height: 20px; }
#wagon-status .ic-svg { width: 22px; height: 22px; }
.member-status .ic-svg { width: 14px; height: 14px; }

/* ================= BLACKJACK (SALOON) ================= */
.bj-money { text-align: center; font-size: 15px; color: var(--dim); margin-bottom: 10px; }
.bj-money b { color: #7fd46a; }
.bj-table {
  background: radial-gradient(ellipse at 50% 30%, #1c5a36, #0d3a20 72%);
  border: 6px solid #2a160a; border-radius: 16px; padding: 18px;
  box-shadow: inset 0 0 44px rgba(0,0,0,0.6), 0 8px 30px rgba(0,0,0,0.5);
  position: relative;
}
.bj-felt-label {
  position: absolute; top: 9px; left: 50%; transform: translateX(-50%);
  font-family: Georgia, serif; letter-spacing: 3px; font-size: 11px; color: rgba(232,185,106,0.75);
}
.bj-hand { margin-bottom: 14px; }
.bj-hand-label { font-family: Georgia, serif; color: var(--gold); font-size: 13px; letter-spacing: 1px; margin-bottom: 6px; }
.bj-hand-label span { color: var(--dim); }
.bj-cards { display: flex; gap: 8px; min-height: 92px; align-items: flex-start; flex-wrap: wrap; }
.bj-card { filter: drop-shadow(0 3px 4px rgba(0,0,0,0.5)); }
.bj-card .ic-svg { display: block; }
.bj-empty { color: rgba(255,255,255,0.25); font-size: 30px; }
.bj-msg { min-height: 22px; text-align: center; color: #ffe6b0; font-size: 14px; margin-top: 8px; }
.bj-betrow { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 14px 0 8px; }
.bj-bet { color: var(--gold); font-size: 16px; }
.bj-bet b { color: #ffe6b0; }
.bj-actions { display: flex; gap: 10px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
.bj-actions button { min-width: 84px; }
