/* Merchant Tycoon - styles */
:root {
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #201f1d;
  --border: #2c2c2a;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --gold: #f5c243;
  --gold-dim: #b8912c;
  --blue: #3987e5;
  --orange: #d95926;
  --green: #199e70;
  --amber: #c98500;
  --pink: #d55181;
  --up: #0ca30c;
  --down: #d03b3b;
  --radius: 12px;
  --shadow: 0 6px 20px rgba(0,0,0,0.45);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { background: var(--bg); color: var(--text); }
body {
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.tabular, .stat-value, .num, .shop-owned, .shop-rev, .cost, .bar-label,
.stat-row-value, .upg-cost, .modal-amount { font-variant-numeric: tabular-nums; }

#app {
  max-width: 940px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  position: sticky;
  top: 8px;
  z-index: 20;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, var(--gold), var(--gold-dim));
  color: #1a1300; font-weight: 800; font-size: 20px;
  border-radius: 9px;
  box-shadow: 0 0 14px rgba(245,194,67,0.35);
}
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }

.hud-stats { display: flex; gap: 18px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; min-width: 78px; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 18px; font-weight: 700; }
.stat-value.accent { color: var(--gold); }

.hud-controls { display: flex; gap: 8px; }
.ctrl-btn {
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.ctrl-btn:hover { border-color: var(--gold-dim); color: var(--text); }
.ctrl-btn:active { transform: translateY(1px); }

/* ---------- Tabs ---------- */
#tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.tab {
  flex: 1 1 auto;
  min-width: 88px;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--text); border-color: var(--gold-dim); }
.tab.active {
  background: linear-gradient(180deg, rgba(245,194,67,0.16), rgba(245,194,67,0.05));
  color: var(--gold);
  border-color: var(--gold-dim);
}
.tab-badge {
  display: none;
  background: var(--gold);
  color: #1a1300;
  font-size: 11px;
  font-weight: 800;
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
}
.tab-badge.show { display: inline-block; }

main { flex: 1; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-intro { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

/* ---------- Shops ---------- */
#shop-list { display: flex; flex-direction: column; gap: 10px; }

.shop {
  display: grid;
  grid-template-columns: 74px 1fr 150px;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}
.shop.affordable-mgr { border-color: rgba(245,194,67,0.4); }

.shop-icon {
  position: relative;
  width: 74px; height: 74px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 30% 25%, var(--surface-2), #141312);
  font-size: 34px;
  display: grid; place-items: center;
  cursor: pointer;
  overflow: hidden;
  font-family: inherit;
  color: var(--text);
}
.shop-icon:hover { border-color: var(--gold-dim); }
.shop-icon:active { transform: scale(0.97); }
.shop-icon.managed { cursor: default; }
.shop-icon .icon-fill {
  position: absolute; left: 0; bottom: 0; width: 100%;
  background: linear-gradient(180deg, rgba(245,194,67,0.28), rgba(245,194,67,0.12));
  height: 0%;
  pointer-events: none;
}
.shop-icon .icon-count {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 12px; font-weight: 800;
  color: var(--gold);
  background: rgba(0,0,0,0.55);
  padding: 0 5px; border-radius: 6px;
  text-shadow: 0 1px 2px #000;
}
.shop-icon .icon-glyph { position: relative; z-index: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }
.shop-icon.collect-pop .icon-glyph { animation: pop 0.28s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }

.shop-body { min-width: 0; }
.shop-top {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.shop-name { font-weight: 700; font-size: 15px; }
.shop-owned { font-size: 12px; color: var(--muted); }
.shop-rev { margin-left: auto; font-weight: 700; color: var(--gold); font-size: 14px; }
.shop-milestone { font-size: 11px; color: var(--muted); width: 100%; }

.bar {
  position: relative;
  height: 22px;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  position: absolute; left: 0; top: 0; height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dim), var(--gold));
  border-radius: 999px;
}
.bar-fill.idle { background: linear-gradient(90deg, #3a3a37, #4a4a45); }
.bar-fill.managed { background: linear-gradient(90deg, var(--green), #22c98a); }
.bar-label {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.shop-actions { display: flex; flex-direction: column; gap: 6px; }
.buy-btn, .mgr-btn {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 8px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
  font-weight: 600;
}
.buy-btn {
  background: linear-gradient(180deg, #23303f, #1b2733);
  color: #dbe7f5;
  border-color: #2b4257;
}
.buy-btn:hover:not(:disabled) { border-color: var(--blue); }
.buy-btn .buy-label { display: block; font-size: 12px; }
.buy-btn .cost { display: block; font-size: 13px; font-weight: 800; }
.mgr-btn {
  background: linear-gradient(180deg, #322a16, #241f12);
  color: #f0dfae;
  border-color: #4a3d1c;
  font-size: 12px;
}
.mgr-btn:hover:not(:disabled) { border-color: var(--gold); }
.mgr-btn.hired {
  background: linear-gradient(180deg, #143025, #0f241c);
  color: #7ee0b3;
  border-color: #1c5c42;
  cursor: default;
}
.buy-btn:disabled, .mgr-btn:disabled { opacity: 0.42; cursor: not-allowed; }
.buy-btn:active:not(:disabled), .mgr-btn:active:not(:disabled) { transform: translateY(1px); }
.cost.ok { color: #9fe0ff; }
.cost.no { color: var(--muted); }

/* ---------- Upgrades ---------- */
#upgrade-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.upg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upg.locked { opacity: 0.55; }
.upg-head { display: flex; align-items: center; gap: 8px; }
.upg-tag {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 7px; border-radius: 999px;
}
.upg-tag.global { background: rgba(57,135,229,0.18); color: #7fb4f2; }
.upg-tag.speed { background: rgba(25,158,112,0.18); color: #5fd6a6; }
.upg-tag.shop { background: rgba(213,81,129,0.18); color: #ef91b3; }
.upg-name { font-weight: 700; font-size: 14px; }
.upg-desc { font-size: 12px; color: var(--text-2); flex: 1; }
.upg-foot { display: flex; align-items: center; gap: 8px; }
.upg-cost { font-weight: 800; color: var(--gold); }
.upg-buy {
  margin-left: auto;
  background: linear-gradient(180deg, #322a16, #241f12);
  color: #f0dfae;
  border: 1px solid #4a3d1c;
  border-radius: 9px;
  padding: 6px 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.upg-buy:hover:not(:disabled) { border-color: var(--gold); }
.upg-buy:disabled { opacity: 0.4; cursor: not-allowed; }
.upg.owned {
  border-color: #1c5c42;
  background: linear-gradient(180deg, rgba(25,158,112,0.08), var(--surface));
}
.upg-owned-badge { color: #7ee0b3; font-weight: 800; font-size: 13px; margin-left: auto; }
.upg-lock { font-size: 12px; color: var(--muted); margin-left: auto; }
.empty-note { color: var(--muted); grid-column: 1 / -1; padding: 24px; text-align: center; }

/* ---------- Reinvest ---------- */
#reinvest-body { display: flex; flex-direction: column; gap: 14px; }
.reinvest-card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.reinvest-card h2 { font-size: 18px; margin-bottom: 8px; }
.reinvest-card p { color: var(--text-2); font-size: 14px; margin-bottom: 6px; }
.reinvest-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 14px 0;
}
.reinvest-metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
.reinvest-metric .m-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.reinvest-metric .m-value { font-size: 20px; font-weight: 800; color: var(--gold); }
.primary-btn {
  background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  color: #1a1300;
  border: none;
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.06); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }
.reinvest-locked { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ---------- Stats ---------- */
#stats-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.stat-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.stat-row-label { color: var(--text-2); font-size: 13px; }
.stat-row-value { font-weight: 700; font-size: 15px; }
.danger-zone { margin-top: 18px; }
.danger-btn {
  background: transparent; color: var(--down);
  border: 1px solid rgba(208,59,59,0.5);
  border-radius: 9px; padding: 9px 16px;
  font-weight: 700; cursor: pointer; font-family: inherit;
}
.danger-btn:hover { background: rgba(208,59,59,0.12); }
.danger-btn.confirming { background: var(--down); color: #fff; }

/* ---------- Help ---------- */
.help { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.help h2 { font-size: 16px; margin: 14px 0 8px; color: var(--gold); }
.help h2:first-child { margin-top: 0; }
.help ol, .help ul { margin-left: 20px; }
.help li { margin: 6px 0; color: var(--text-2); font-size: 14px; }
.help strong { color: var(--text); }

/* ---------- Footer ---------- */
#footer { margin-top: 16px; padding: 14px 8px; text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  display: grid; place-items: center;
  z-index: 60; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--gold-dim);
  border-radius: 16px;
  padding: 24px; max-width: 380px; width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal h2 { color: var(--gold); margin-bottom: 8px; }
.modal p { color: var(--text-2); font-size: 14px; margin-bottom: 6px; }
.modal-amount { font-size: 30px; font-weight: 800; color: var(--gold); margin: 12px 0; }
.modal-note { font-size: 12px; color: var(--muted); }
.modal .primary-btn { margin-top: 12px; }

/* ---------- Toasts ---------- */
#toast-wrap {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  z-index: 50; pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--gold-dim);
  color: var(--text);
  padding: 9px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease, toastOut 0.3s ease 1.6s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }

/* Floating collect number */
.float-cash {
  position: fixed;
  font-weight: 800; color: var(--gold);
  text-shadow: 0 2px 4px #000;
  pointer-events: none; z-index: 40;
  animation: floatUp 0.9s ease-out forwards;
  font-size: 15px;
}
@keyframes floatUp {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -46px); }
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .shop { grid-template-columns: 60px 1fr; grid-template-areas: "icon body" "actions actions"; }
  .shop-icon { grid-area: icon; width: 60px; height: 60px; font-size: 28px; }
  .shop-body { grid-area: body; }
  .shop-actions { grid-area: actions; flex-direction: row; }
  .shop-actions .buy-btn, .shop-actions .mgr-btn { flex: 1; }
  .hud-stats { gap: 12px; }
  .stat-value { font-size: 16px; }
  .brand-name { font-size: 16px; }
}
@media (max-width: 400px) {
  #app { padding: 8px; }
  .stat { min-width: 62px; }
  .hud-controls { width: 100%; }
  .hud-controls .ctrl-btn { flex: 1; }
}
