:root {
  --bg: rgba(28, 33, 28, 0.86);
  --bg2: rgba(48, 56, 46, 0.95);
  --line: rgba(255, 255, 255, 0.12);
  --txt: #f4f1e6;
  --muted: #b9c0b0;
  --gold: #f5c84c;
  --green: #4ade80;
  --red: #ef4444;
  --blue: #4c9be8;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a5a2a; color: var(--txt);
  font-family: 'Fredoka', 'Segoe UI', system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; touch-action: none; display: block; cursor: crosshair; }
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------------------------------------------------- Barre du haut */
#topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: linear-gradient(var(--bg), rgba(28,33,28,0.6)); backdrop-filter: blur(6px);
  z-index: 10; flex-wrap: wrap; }
.stat { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,0.25); padding: 5px 10px;
  border-radius: 999px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.stat.clock { font-weight: 500; }
.bar { position: relative; width: 110px; height: 16px; background: rgba(0,0,0,0.45); border-radius: 999px; overflow: hidden; }
.bar.thin { width: 70px; height: 8px; }
.bar .fill { height: 100%; background: linear-gradient(90deg, #f7d64a, #f59e0b); border-radius: 999px; transition: width .2s; }
.bar .fill.xp { background: linear-gradient(90deg, #7dd3fc, #a78bfa); }
#energy-txt { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 16px; text-shadow: 0 1px 2px #000; }
.spacer { flex: 1; }
.icon-btn { background: rgba(0,0,0,0.3); border: 1px solid var(--line); border-radius: 12px; width: 40px; height: 40px;
  font-size: 18px; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,0.12); }
.icon-btn.off { opacity: 0.4; }

/* ---------------------------------------------------- Menu latéral */
#menu { position: fixed; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 10; }
#menu button { position: relative; width: 64px; height: 60px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg); font-size: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3); }
#menu button span { font-size: 10px; color: var(--muted); }
#menu button:hover { background: var(--bg2); }
.badge { position: absolute; top: -5px; right: -5px; background: var(--red); color: #fff; font-style: normal; font-size: 12px;
  min-width: 20px; height: 20px; border-radius: 999px; display: grid; place-items: center; font-weight: 700; }
.badge.dot { min-width: 14px; height: 14px; background: var(--green); }

#zoom { position: fixed; left: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 10; }
#zoom .icon-btn { width: 46px; height: 46px; font-size: 22px; background: var(--bg); }

/* ---------------------------------------------------- Bas */
#bottom { position: fixed; left: 0; right: 0; bottom: calc(8px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 10; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#context { max-width: calc(100vw - 20px); }
#context-main { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center;
  background: var(--bg); padding: 6px 10px; border-radius: var(--radius); border: 1px solid var(--line); min-height: 38px; }
#context-main:empty { display: none; }
.hint { font-size: 13px; color: var(--muted); }
.hint b { color: var(--txt); }
#hotbar { display: flex; gap: 6px; background: var(--bg); padding: 6px; border-radius: 18px; border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0,0,0,0.35); }
.slot { position: relative; width: 58px; height: 58px; border-radius: 12px; border: 2px solid transparent;
  background: rgba(255,255,255,0.07); display: grid; place-items: center; }
.slot:hover { background: rgba(255,255,255,0.14); }
.slot.active { border-color: var(--gold); background: rgba(245,200,76,0.18); box-shadow: 0 0 12px rgba(245,200,76,0.4); }
.slot-icon { font-size: 28px; }
.slot-key { position: absolute; top: 2px; left: 5px; font-size: 10px; color: var(--muted); }
.slot-sub { position: absolute; bottom: 1px; right: 5px; font-size: 12px; font-weight: 700; text-shadow: 0 1px 2px #000; }

.btn { background: rgba(255,255,255,0.1); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; font-weight: 500; }
.btn:hover:not(:disabled) { background: rgba(255,255,255,0.2); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.gold { background: rgba(245,200,76,0.25); border-color: rgba(245,200,76,0.5); }
.btn.blue { background: rgba(76,155,232,0.25); border-color: rgba(76,155,232,0.5); }
.btn.red { background: rgba(239,68,68,0.3); border-color: rgba(239,68,68,0.6); }
.chip { background: rgba(255,255,255,0.08); border: 2px solid transparent; border-radius: 999px; padding: 5px 12px; font-size: 15px; font-weight: 600; }
.chip.active { border-color: var(--gold); background: rgba(245,200,76,0.2); }

/* ---------------------------------------------------- Panneau */
#panel { position: fixed; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(980px, calc(100vw - 20px)); height: min(680px, calc(100vh - 40px)); background: rgba(30, 36, 30, 0.97);
  border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.55); display: flex; flex-direction: column; overflow: hidden; }
#panel.hidden { display: none; }
#panel-head { display: flex; align-items: center; gap: 8px; padding: 10px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,0.2); }
#panel-tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#panel-tabs button { background: transparent; border: none; padding: 9px 14px; border-radius: 10px; font-size: 15px; white-space: nowrap; color: var(--muted); }
#panel-tabs button.active { background: rgba(245,200,76,0.18); color: var(--txt); }
#panel-body { flex: 1; overflow: auto; padding: 14px 16px; -webkit-overflow-scrolling: touch; }
#panel-body h3 { margin: 4px 0 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#panel-body h4 { margin: 16px 0 6px; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }
.gold { color: var(--gold); } .bad { color: #ff8a8a; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.row { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 10px; background: rgba(255,255,255,0.04); margin-bottom: 5px; }
.row.locked { opacity: 0.45; }
.row .ico { font-size: 26px; width: 36px; text-align: center; position: relative; }
.row .ico small { position: absolute; right: -2px; bottom: -4px; font-size: 13px; }
.row .grow { flex: 1; min-width: 0; }
.row small { color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.big { font-size: 26px; font-weight: 700; margin: 4px 0; }
.big small { font-size: 14px; color: var(--muted); font-weight: 400; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.card { text-align: left; background: rgba(255,255,255,0.05); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.card:hover { background: rgba(255,255,255,0.1); }
.card.active { border-color: var(--gold); }
.card.locked { opacity: 0.45; }
.card-ico { width: 64px; height: 64px; border-radius: 12px; display: grid; place-items: center; background: radial-gradient(circle at 50% 60%, #5d9c45, #3f7a33); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25); }
.card-ico .bico .spr { width: 50px; height: 50px; }
.card-ico > .ic { width: 38px; height: 38px; }
.card-name { font-weight: 600; }
.card-cost { color: var(--gold); font-size: 14px; }
.card-desc { color: var(--muted); font-size: 12px; line-height: 1.3; }

/* arbre de recherche */
.tree-wrap { overflow: auto; border-radius: var(--radius); background: rgba(0,0,0,0.2); padding: 14px; max-height: calc(100% - 50px); }
.tree { position: relative; }
.tree svg { position: absolute; inset: 0; }
.tree path { fill: none; stroke: rgba(255,255,255,0.15); stroke-width: 3; }
.tree path.on { stroke: rgba(74,222,128,0.6); }
.node, .talent { position: absolute; text-align: left; border-radius: 12px; border: 2px solid var(--line); background: #2c332b; padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; }
.talent { position: relative; width: 100%; }
.node-h { font-weight: 600; font-size: 14px; display: flex; gap: 5px; align-items: center; }
.node-d { font-size: 12px; color: var(--muted); line-height: 1.25; flex: 1; }
.node-c { font-size: 12px; color: var(--gold); }
.node.done { border-color: rgba(74,222,128,0.6); background: #23402a; }
.node.ready, .talent.ready { border-color: var(--gold); background: #4a4220; box-shadow: 0 0 14px rgba(245,200,76,0.35); animation: glow 1.6s infinite; }
.node.avail { border-color: rgba(255,255,255,0.3); }
.node.locked, .talent.locked { opacity: 0.4; }
.talent.maxed { border-color: rgba(74,222,128,0.6); background: #23402a; }
.node:disabled, .talent:disabled { cursor: default; }
@keyframes glow { 50% { box-shadow: 0 0 22px rgba(245,200,76,0.6); } }
.tcols { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 14px; overflow-x: auto; }
.tcol h3 { justify-content: center; }
.tlink { width: 3px; height: 14px; background: rgba(255,255,255,0.2); margin: 0 auto; }
.rank { margin-left: auto; color: var(--gold); font-size: 13px; }
.help li, .help p { line-height: 1.5; }

/* ---------------------------------------------------- Info & toasts */
#info { position: fixed; z-index: 15; display: none; max-width: 280px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; font-size: 13px; line-height: 1.4; pointer-events: none; box-shadow: 0 6px 18px rgba(0,0,0,0.4); }
#info small { color: var(--muted); }
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: var(--bg); border: 1px solid var(--line); padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4); animation: tin .25s ease-out; transition: opacity .5s, transform .5s; }
.toast.good { border-color: rgba(74,222,128,0.6); }
.toast.bad { border-color: rgba(239,68,68,0.7); }
.toast.gold { border-color: var(--gold); background: rgba(70,58,20,0.95); }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-10px); } }

/* ---------------------------------------------------- Mobile */
@media (max-width: 760px) {
  .cols { grid-template-columns: 1fr; }
  #topbar { gap: 5px; padding: 6px; }
  .stat { font-size: 13px; padding: 4px 8px; }
  .bar { width: 70px; } .bar.thin { width: 40px; }
  #menu { top: auto; bottom: calc(150px + var(--safe-b)); transform: none; right: 6px; }
  #menu button { width: 50px; height: 48px; font-size: 20px; }
  #menu button span { display: none; }
  #zoom { top: auto; bottom: calc(150px + var(--safe-b)); transform: none; left: 6px; }
  .slot { width: 48px; height: 48px; } .slot-icon { font-size: 23px; }
  #panel { width: 100vw; height: calc(100vh - 50px); top: auto; bottom: 0; transform: translateX(-50%); border-radius: 20px 20px 0 0; }
  #panel-tabs button span { display: none; }
  #panel-tabs button { font-size: 20px; }
  .icon-btn { width: 34px; height: 34px; font-size: 16px; }
}

/* ---------------------------------------------------- Icônes images */
.ic { width: 1.25em; height: 1.25em; vertical-align: -0.28em; object-fit: contain; pointer-events: none; }
.slot-icon { display: grid; place-items: center; }
.slot-icon .ic { width: 32px; height: 32px; }
.slot-icon .bico .spr, .slot-icon .seedico .ic:not(.mini) { width: 32px; height: 32px; }
.row .ico .ic { width: 30px; height: 30px; }
.row .ico .bico .spr { width: 34px; height: 34px; }
.seedico, .bico { position: relative; display: inline-block; line-height: 0; }
.seedico .mini { position: absolute; right: -0.35em; bottom: -0.25em; width: 0.75em; height: 0.75em; }
.row .ico .seedico .mini, .slot-icon .seedico .mini { width: 16px; height: 16px; }
.bico .spr { width: 40px; height: 40px; object-fit: contain; }
.bico .mini { position: absolute; right: -6px; bottom: -4px; width: 20px; height: 20px; background: #fff; border-radius: 50%; padding: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.chip .ic { width: 22px; height: 22px; }
#info .ic { width: 18px; height: 18px; }
@media (max-width: 760px) { .slot-icon .ic { width: 26px; height: 26px; } }

.tbar { height: 6px; background: rgba(0,0,0,0.45); border-radius: 99px; margin: 4px 0; overflow: hidden; }
.tbar i { display: block; height: 100%; background: linear-gradient(90deg, #5fb8ff, #4ade80); border-radius: 99px; }

/* ---------------------------------------------------- Énergie */
.bar .fill.low { background: linear-gradient(90deg, #ef4444, #f97316); animation: lowpulse 1s infinite; }
@keyframes lowpulse { 50% { opacity: .55; } }
.eat-btn { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.1); font-size: 15px; display: grid; place-items: center; padding: 0; }
.eat-btn:hover { background: rgba(255,255,255,.22); }
.eat-btn.pulse { background: rgba(245,200,76,.35); border-color: var(--gold); animation: lowpulse 1s infinite; }
.btn.green { background: rgba(74,222,128,0.22); border-color: rgba(74,222,128,0.5); }
#jobs-btn.warn { background: rgba(249,115,22,.45); }
.hint .cost { color: var(--gold); margin-left: 6px; white-space: nowrap; }
.charpick { display: grid; grid-template-columns: repeat(4, minmax(0, 110px)); gap: 10px; margin-bottom: 12px; }
.charpick .card { align-items: center; padding: 8px; }
.charpick .spr { width: 72px; height: 96px; object-fit: contain; }
.charpick span { font-weight: 600; font-size: 14px; }
