:root {
  --bg: #0d1916;
  --bg2: #11201b;
  --panel: #162a24;
  --panel2: #1c352d;
  --line: #2a4a3f;
  --ink: #f2ead8;
  --ink2: #b9b19c;
  --ink3: #7f8a7f;
  --gold: #e3b552;
  --gold2: #f6d58a;
  --goldDeep: #9c7426;
  --green: #5fd39a;
  --red: #ef6f5e;
  --radius: 14px;
  --display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 600px at 80% -10%, #1d3a30 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #17302a 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; }
h1, h2, h3 { font-family: var(--display); font-weight: 800; margin: 0; letter-spacing: -0.01em; }

/* ---------- boutons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 10px;
  padding: 10px 16px; font-weight: 600; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--gold); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #241a05; border-color: var(--gold); }
.btn.primary:disabled { background: var(--panel2); color: var(--ink3); border-color: var(--line); cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #5a2c25; }
.btn.wide { width: 100%; padding: 14px; font-size: 16px; }

/* ---------- connexion ---------- */
#auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 26px; box-shadow: 0 30px 80px -30px #000;
}
.brand { text-align: center; margin-bottom: 26px; }
.brand h1 { font-size: 40px; line-height: .95; margin-top: 12px; }
.brand h1 em { font-style: italic; color: var(--gold); }
.tagline { color: var(--ink2); margin: 10px 0 0; }
#auth-form { display: grid; gap: 14px; }
#auth-form label { display: grid; gap: 6px; font-size: 13px; color: var(--ink2); font-weight: 500; }
#auth-form input, .inline-form input, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; color: var(--ink);
  outline: none; width: 100%;
}
#auth-form input:focus, .inline-form input:focus, textarea:focus { border-color: var(--gold); }
.error { color: var(--red); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ---------- en-tête ---------- */
#game { max-width: 980px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px; background: linear-gradient(180deg, var(--bg) 70%, transparent);
}
.cash { font-family: var(--display); font-size: clamp(28px, 7vw, 42px); font-weight: 800; color: var(--gold2); line-height: 1; font-variant-numeric: tabular-nums; }
.rate { color: var(--ink2); font-family: var(--mono); font-size: 13px; margin-top: 4px; }
.rate span { color: var(--green); }
.sync {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; color: var(--ink2); white-space: nowrap;
}
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px #5fd39a22; }
.sync[data-state="saving"] .dot { background: var(--gold); animation: pulse 1s infinite; }
.sync[data-state="offline"] .dot, .sync[data-state="error"] .dot { background: var(--red); box-shadow: 0 0 0 3px #ef6f5e22; }
.sync[data-state="paused"] .dot { background: var(--ink3); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- onglets ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  background: #0b1512ee; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  position: relative; flex: 1; background: none; border: 0; display: grid; justify-items: center; gap: 2px;
  font-size: 10.5px; color: var(--ink3); padding: 6px 2px; border-radius: 10px; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tabs button span { font-size: 20px; line-height: 1; filter: grayscale(.8); transition: filter .15s; }
.tabs button.active { color: var(--gold2); }
.tabs button.active span { filter: none; }
.badge { position: absolute; top: 2px; right: calc(50% - 22px); min-width: 8px; height: 8px; border-radius: 4px; background: var(--gold); display: none; }
.badge.on { display: block; }

@media (min-width: 760px) {
  .tabs { position: sticky; top: 74px; bottom: auto; border: 1px solid var(--line); border-radius: 14px; margin-bottom: 16px; padding: 6px; }
  .tabs button { grid-auto-flow: column; gap: 8px; font-size: 13.5px; align-items: center; padding: 10px; }
  .tabs button span { font-size: 16px; }
  .badge { right: 8px; top: 8px; }
  #game { padding-bottom: 40px; }
}

/* ---------- vues ---------- */
.view { display: none; animation: fade .2s; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.view-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 10px 16px; margin: 6px 0 14px; }
.view-head h2 { font-size: 24px; }
.view-head .hint { width: 100%; margin: 0; }
.hint { color: var(--ink2); font-size: 13.5px; }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: 0; padding: 6px 12px; border-radius: 7px; font-family: var(--mono); font-size: 13px; color: var(--ink2); }
.seg button.on { background: var(--gold); color: #241a05; font-weight: 700; }

/* ---------- entreprises ---------- */
.biz-list { display: grid; gap: 10px; }
@media (min-width: 760px) { .biz-list { grid-template-columns: 1fr 1fr; } }
.biz {
  display: grid; grid-template-columns: 64px 1fr; gap: 6px 12px; align-items: center;
  background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
.biz.locked { opacity: .55; }
.biz.locked .biz-icon { filter: grayscale(1); }
.biz-icon {
  grid-row: span 2; position: relative; width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--goldDeep);
  background: radial-gradient(circle at 35% 30%, var(--panel2), var(--bg)); font-size: 30px; display: grid; place-items: center;
  transition: transform .1s; padding: 0;
}
.biz-icon:active { transform: scale(.92); }
.biz-icon.ready { border-color: var(--gold2); box-shadow: 0 0 0 4px #e3b55233, 0 0 18px #e3b55255; animation: glow 1.4s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 7px #e3b55211, 0 0 26px #e3b55233; } }
.biz-owned {
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); background: var(--gold); color: #241a05;
  font: 700 11px/1 var(--mono); padding: 3px 7px; border-radius: 999px; white-space: nowrap;
}
.biz-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; min-width: 0; }
.biz-name { font-family: var(--display); font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.biz-time { font: 500 12px var(--mono); color: var(--ink3); white-space: nowrap; }
.bar { position: relative; height: 26px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.bar-fill { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, #3aa874, var(--green)); }
.bar.fast .bar-fill {
  transform: scaleX(1);
  background: repeating-linear-gradient(-45deg, #3aa874 0 10px, #5fd39a 10px 20px); background-size: 28px 28px; animation: stripes .6s linear infinite;
}
@keyframes stripes { to { background-position: 28px 0; } }
.bar-label { position: absolute; inset: 0; display: grid; place-items: center; font: 700 13px var(--mono); color: #fff; text-shadow: 0 1px 2px #000a; }
.biz-buy {
  grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border: 1px solid var(--goldDeep); background: linear-gradient(180deg, #2a2a17, #1f2414); border-radius: 10px; padding: 9px 12px;
  transition: transform .08s, opacity .15s;
}
.biz-buy:active:not(:disabled) { transform: scale(.98); }
.biz-buy:disabled { opacity: .45; cursor: not-allowed; border-color: var(--line); background: var(--bg2); }
.biz-buy b { font-family: var(--mono); color: var(--gold2); }
.biz-buy small { color: var(--ink2); font-size: 12px; }
.biz-mile { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: var(--bg); overflow: hidden; }
.biz-mile i { display: block; height: 100%; background: var(--gold); width: 0; transition: width .3s; }

/* ---------- cartes managers / boosts ---------- */
.card-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.card .ic { font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center; background: var(--bg); border-radius: 12px; }
.card h4 { margin: 0; font: 600 14.5px var(--sans); }
.card p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink2); }
.card .btn { padding: 8px 12px; font: 700 13px var(--mono); white-space: nowrap; }
.card.done { opacity: .6; }
.card.done .btn { border: 0; background: none; color: var(--green); }
.empty { color: var(--ink3); text-align: center; padding: 30px 10px; grid-column: 1 / -1; }

/* ---------- investisseurs ---------- */
.inv-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; display: grid; gap: 12px; max-width: 520px; }
.inv-stat { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px dashed var(--line); padding-bottom: 10px; }
.inv-stat span { color: var(--ink2); }
.inv-stat b { font: 700 20px var(--mono); color: var(--gold2); }
.inv-stat.big b { font-size: 28px; color: var(--green); }

/* ---------- classement ---------- */
.rank-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-width: 640px; }
.rank-list li {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
}
.rank-list li.me { border-color: var(--gold); }
.rank-list .pos { font: 800 18px var(--display); color: var(--ink3); text-align: center; }
.rank-list li:nth-child(1) .pos { color: #f6d58a; }
.rank-list li:nth-child(2) .pos { color: #d7dde2; }
.rank-list li:nth-child(3) .pos { color: #d39a6a; }
.rank-list .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.rank-list .who small { display: block; font-weight: 400; color: var(--ink3); font-size: 12px; }
.rank-list .on::after { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-left: 6px; vertical-align: middle; }
.rank-list .amt { font: 700 14px var(--mono); color: var(--gold2); }

/* ---------- compte ---------- */
.settings { display: grid; gap: 12px; max-width: 640px; }
.set-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; }
.set-block h3 { font-size: 16px; }
.set-block.danger { border-color: #4a2a24; }
.me b { color: var(--gold2); }
.stats { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 0; font-size: 14px; }
.stats dt { color: var(--ink2); }
.stats dd { margin: 0; font-family: var(--mono); text-align: right; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form input { flex: 1 1 140px; width: auto; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }

/* ---------- modale / toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: #050a08cc; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--gold); border-radius: 20px; padding: 28px 24px; max-width: 360px; width: 100%; text-align: center; display: grid; gap: 12px; }
.modal-icon { font-size: 40px; }
.modal p { color: var(--ink2); margin: 0 0 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: var(--panel2); border: 1px solid var(--gold); color: var(--ink); padding: 12px 18px; border-radius: 12px;
  box-shadow: 0 20px 50px -10px #000; max-width: calc(100% - 32px); text-align: center; animation: pop .25s;
}
.toast b { color: var(--gold2); font-family: var(--mono); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } }
.float {
  position: fixed; pointer-events: none; z-index: 30; font: 700 14px var(--mono); color: var(--gold2);
  text-shadow: 0 2px 6px #000; animation: rise .9s ease-out forwards;
}
@keyframes rise { to { transform: translateY(-46px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
