:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --surface-2: #eeeae2;
  --border: #e0dbd0;
  --text: #1f1d1a;
  --muted: #6b665d;
  --accent: #c2603c;
  --accent-ink: #ffffff;
  --gold: #a86b12;
  --danger: #c0392b;
  --ok: #2f8f5b;
  --warn: #b7791f;
  --bar: #d0714c;
  --bar-bg: #e7e1d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .04);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #201f1d;
    --surface-2: #2b2a27;
    --border: #353330;
    --text: #efece6;
    --muted: #a19c93;
    --accent: #e0825f;
    --accent-ink: #1d110c;
    --gold: #f2c14e;
    --danger: #ef6b5b;
    --ok: #4cc08a;
    --warn: #f0b44c;
    --bar: #e0825f;
    --bar-bg: #2f2d2a;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

h2 { margin: 0; font-size: 20px; }
.subhead { margin: 22px 0 10px; font-size: 15px; }
.gold { color: var(--gold); }
.muted { color: var(--muted); }

/* ---------- Top bar & tabs ---------- */
.chrome {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px 24px;
  flex-wrap: wrap;
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 24px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.logo { font-size: 28px; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -.01em; line-height: 1.1; }
.brand-lab { font-size: 12px; color: var(--muted); }
.stats { display: flex; gap: 24px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat-value.money { color: var(--accent); font-size: 22px; }

.account-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
}
.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface);
  font-size: 15px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.tabbar {
  display: flex;
  gap: 2px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 10px 12px 11px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.tabbar button:hover { color: var(--text); }
.tabbar button.active { color: var(--text); border-bottom-color: var(--accent); }
.dot {
  display: none;
  position: absolute;
  top: 8px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.dot.on { display: block; }

/* ---------- Layout ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 20px 24px 60px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.pad { padding: 16px; }
.card.list { padding: 2px 16px; }
.empty { margin: 0; padding: 18px 0; color: var(--muted); font-size: 14px; text-align: center; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.section-head .note { margin: 4px 0 0; max-width: 560px; }

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Market strip ---------- */
.market { padding: 12px; margin-bottom: 22px; }
.market-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
}
.metric strong { font-size: 19px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric small { color: var(--muted); font-size: 12px; }
.mini-bar { height: 6px; margin-top: 6px; background: var(--bar-bg); border-radius: 999px; overflow: hidden; }
.mini-bar div { height: 100%; width: 0; background: var(--accent); }

.bottleneck {
  margin: 10px 0 0;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  color: var(--ok);
}
.bottleneck.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

/* ---------- Models ---------- */
.model-head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; font-size: 15px; }
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.model-progress { cursor: default; }
.slider { display: grid; grid-template-columns: auto minmax(0, 1fr) 48px; align-items: center; gap: 12px; font-size: 13px; }
.slider input { width: 100%; accent-color: var(--accent); }
.slider strong { text-align: right; font-variant-numeric: tabular-nums; }
.row.current { background: color-mix(in srgb, var(--accent) 8%, transparent); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.status { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }

/* ---------- Infrastructure cards ---------- */
.biz {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 150px;
  gap: 14px;
  align-items: center;
  padding: 14px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.biz-icon {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 34px;
  display: grid;
  place-items: center;
  transition: transform .1s;
}
.biz-icon:active { transform: scale(.94); }
.biz-icon.idle { border-color: var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 8px transparent; }
}
.biz-icon .owned {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.biz-top { display: flex; justify-content: space-between; align-items: baseline; gap: 2px 8px; flex-wrap: wrap; }
.biz-top h3 { margin: 0; font-size: 16px; }
.biz-rev { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }

.progress {
  position: relative;
  height: 26px;
  margin: 8px 0 6px;
  background: var(--bar-bg);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
}
.progress .bar { height: 100%; width: 0; background: var(--bar); }
.progress.fast .bar {
  background: repeating-linear-gradient(45deg, var(--bar) 0 10px, color-mix(in srgb, var(--bar) 70%, white) 10px 20px);
  background-size: 28px 28px;
  animation: stripes .5s linear infinite;
}
@keyframes stripes { to { background-position: 28px 0; } }
.biz-time {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.biz-meta { display: flex; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }

.biz-buy {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 72px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 13px;
}
.biz-buy .buy-cost { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.biz-buy:disabled { background: var(--surface-2); color: var(--muted); }

.biz.locked .biz-icon { filter: grayscale(1); opacity: .6; }
.biz.locked .progress, .biz.locked .biz-meta { opacity: .4; }

.locked-hint { text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Lists (customers, team, research…) ---------- */
.row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row.done { opacity: .55; }
.row.locked .row-icon { filter: grayscale(1); opacity: .6; }
.row-icon { font-size: 24px; text-align: center; }
.row-text strong { display: block; font-size: 15px; }
.row-text small { display: block; color: var(--muted); font-size: 12.5px; }
.count { color: var(--accent); font-variant-numeric: tabular-nums; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 13px;
  background: var(--accent);
  color: var(--accent-ink);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.btn:disabled { background: var(--surface-2); color: var(--muted); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.gold-btn:not(:disabled) { background: var(--gold); color: #fff; }

.note { color: var(--muted); font-size: 13.5px; margin: 0 0 12px; }
.note.small { font-size: 12px; margin: 10px 0 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.field input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

/* ---------- Account ---------- */
.account-cta { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.account-cta .note { margin: 2px 0 0; }
.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1px solid #dadce0;
  border-radius: 999px;
  background: #fff;
  color: #1f1f1f;
  font-weight: 600;
  font-size: 14px;
}
.google-btn:hover { background: #f7f8f8; }
.g-logo { display: inline-flex; }
.account-user { display: flex; align-items: center; gap: 12px; }
.account-user small { display: block; }
.account-photo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  font-size: 24px;
}

/* ---------- Leaderboard ---------- */
.lb-row { grid-template-columns: 44px minmax(0, 1fr) auto; }
.lb-row.me { background: color-mix(in srgb, var(--accent) 10%, transparent); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.rank { font-size: 20px; font-weight: 800; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-row:nth-child(-n+3) .rank { font-size: 26px; }
.lb-score { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.lb-cta { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); font-size: 14px; }

/* ---------- Toasts & modal ---------- */
.toasts {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  width: min(420px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
  animation: toastIn .25s ease-out;
  transition: opacity .3s;
}
.toast.out { opacity: 0; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, .45);
}
.modal-card {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-card h2 { margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px 6px; }
  .stats { order: 3; width: 100%; gap: 16px; }
  .container { padding: 16px 16px 60px; }
  .tabbar { padding: 0 8px; }
  .tab-label { font-size: 13px; }
  .market-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .stat-value { font-size: 15px; }
  .stat-value.money { font-size: 19px; }
  .metric strong { font-size: 16px; }
  .slider { grid-template-columns: minmax(0, 1fr) 48px; }
  .slider span { grid-column: 1 / -1; }
  .biz { grid-template-columns: 60px minmax(0, 1fr); }
  .biz-icon { width: 60px; height: 60px; font-size: 28px; }
  .biz-buy { grid-column: 1 / -1; height: auto; padding: 10px; flex-direction: row; gap: 10px; }
  .row { grid-template-columns: 30px minmax(0, 1fr); }
  .row > .btn, .row > .status { grid-column: 2; justify-self: start; }
  .lb-row { grid-template-columns: 36px minmax(0, 1fr) auto; }
}
