@font-face { font-family: 'Fredoka'; src: url('../assets/fonts/Fredoka.ttf') format('truetype'); font-weight: 300 700; }
@font-face { font-family: 'Nunito'; src: url('../assets/fonts/Nunito.ttf') format('truetype'); font-weight: 200 900; }

:root {
  --bg: #1f1419;
  --panel: #3a2830;
  --panel2: #4a3440;
  --panel3: #2c1e24;
  --frame: #7a4560;
  --frame2: #a8617f;
  --accent: #ff7aa8;
  --accent2: #7fd4c1;
  --gold: #ffd166;
  --text: #fff1f5;
  --muted: #d7b8c6;
  --dim: #9d7f8c;
  --bad: #ff6b6b;
  --warn: #ffc15e;
  --ok: #8ce99a;
  --slot: 44px;
  --ui-scale: 1;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Nunito', system-ui, sans-serif; font-size: 14px; user-select: none; }
canvas#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; zoom: var(--ui-scale); }
#ui > * { pointer-events: auto; }
#ui .passthrough { pointer-events: none; }
#screens { position: fixed; inset: 0; pointer-events: none; }
#screens > * { pointer-events: auto; }
h1, h2, h3, .title { font-family: 'Fredoka', sans-serif; font-weight: 600; margin: 0; }
.hidden { display: none !important; }
img { -webkit-user-drag: none; }

/* ---------- panneaux ---------- */
.panel {
  background: linear-gradient(180deg, #43303a 0%, var(--panel) 40%, #33242b 100%);
  border: 3px solid var(--frame); border-radius: 14px;
  box-shadow: 0 8px 28px #0009, inset 0 1px 0 #ffffff22, inset 0 0 0 1px #00000044;
  padding: 10px;
}
.panel .head {
  display: flex; align-items: center; gap: 10px; margin: -10px -10px 10px; padding: 7px 12px;
  background: linear-gradient(180deg, #ff8fb6, #e2608e); border-radius: 10px 10px 4px 4px;
  font-family: 'Fredoka'; font-size: 17px; color: #fff; text-shadow: 0 2px 0 #9b2f58;
  border-bottom: 3px solid #b8406c;
}
.panel .head .x { margin-left: auto; cursor: pointer; width: 26px; height: 26px; border-radius: 50%; background: #0003; display: grid; place-items: center; font-size: 16px; }
.panel .head .x:hover { background: #0006; }
.sub { font-family: 'Fredoka'; color: var(--gold); font-size: 14px; margin: 8px 0 5px; letter-spacing: 0.3px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }

/* ---------- boutons ---------- */
.btn {
  font-family: 'Fredoka'; font-size: 16px; font-weight: 500; color: #fff; border: none; cursor: pointer;
  padding: 9px 18px; border-radius: 999px;
  background: linear-gradient(180deg, #ff9cc0, #ec6a98);
  box-shadow: 0 4px 0 #a8406a, 0 6px 14px #0006, inset 0 2px 0 #ffffff66;
  text-shadow: 0 1px 0 #a8406a; transition: transform .06s, filter .1s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a8406a, inset 0 2px 0 #ffffff44; }
.btn.mint { background: linear-gradient(180deg, #9fe8d7, #5fc2ab); box-shadow: 0 4px 0 #2f8a76, 0 6px 14px #0006, inset 0 2px 0 #ffffff66; text-shadow: 0 1px 0 #2f8a76; }
.btn.choco { background: linear-gradient(180deg, #a06a4e, #74442d); box-shadow: 0 4px 0 #3e2214, 0 6px 14px #0006, inset 0 2px 0 #ffffff33; text-shadow: 0 1px 0 #3e2214; }
.btn.gold { background: linear-gradient(180deg, #ffe08a, #f4b73c); box-shadow: 0 4px 0 #a8721a, 0 6px 14px #0006, inset 0 2px 0 #ffffff77; text-shadow: 0 1px 0 #a8721a; }
.btn.small { font-size: 13px; padding: 5px 12px; }
.btn:disabled { filter: grayscale(0.8) brightness(0.7); cursor: default; transform: none; }
input[type=text], input[type=number], input[type=password], select {
  font-family: 'Nunito'; font-size: 14px; color: var(--text); background: var(--panel3); border: 2px solid var(--frame);
  border-radius: 8px; padding: 6px 9px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input[type=range] { accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
label.row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
label.row > span:first-child { min-width: 170px; color: var(--muted); }

/* ---------- cases d'inventaire ---------- */
.grid { display: grid; gap: 3px; grid-template-columns: repeat(10, var(--slot)); }
.slot {
  width: var(--slot); height: var(--slot); position: relative; border-radius: 8px; cursor: pointer;
  background: radial-gradient(circle at 50% 40%, #3e2b33, #24171d); box-shadow: inset 0 2px 5px #000a, inset 0 0 0 1px #ffffff10;
}
.slot:hover { background: radial-gradient(circle at 50% 40%, #6a4555, #3b2530); box-shadow: inset 0 0 0 2px var(--accent); }
.slot img { position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px); object-fit: contain; pointer-events: none; filter: drop-shadow(0 2px 1px #0008); }
.slot .n { position: absolute; right: 3px; bottom: 1px; font-weight: 800; font-size: 12px; text-shadow: 0 0 3px #000, 0 1px 1px #000; pointer-events: none; }
.slot.ghost img { opacity: 0.25; filter: grayscale(1); }
.slot.locked { opacity: 0.35; cursor: default; }
.slot.cant img { filter: grayscale(0.9) brightness(0.7); }
.slot.sel { box-shadow: inset 0 0 0 2px var(--gold), 0 0 10px var(--gold); }
.slot .bar { position: absolute; left: 4px; right: 4px; bottom: 3px; height: 4px; background: #0008; border-radius: 3px; overflow: hidden; }
.slot .bar i { display: block; height: 100%; background: var(--ok); }
.slot .key { position: absolute; left: 4px; top: 1px; font-size: 10px; color: var(--muted); font-weight: 800; }

/* ---------- barre du bas ---------- */
#hotbar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 5px; }
#hotbar .bar { display: flex; gap: 4px; padding: 6px; }
#hotbar .hp { width: 440px; height: 12px; border-radius: 8px; background: #0009; overflow: hidden; border: 2px solid var(--frame); }
#hotbar .hp i { display: block; height: 100%; background: linear-gradient(90deg, #ff6b8a, #ffa2b8); transition: width .2s; }
#hotbar .equip { display: flex; gap: 4px; align-items: center; }
.hand-label { font-size: 12px; color: var(--muted); text-align: center; text-shadow: 0 1px 2px #000; min-height: 16px; }

#craftq { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap-reverse; gap: 3px; max-width: 360px; }
#research-box { position: absolute; left: 10px; top: 10px; width: 300px; padding: 8px 10px; cursor: pointer; }
#research-box .t { display: flex; gap: 8px; align-items: center; font-family: 'Fredoka'; }
#research-box img { width: 34px; height: 34px; }
.progress { height: 10px; border-radius: 6px; background: #0008; overflow: hidden; margin-top: 5px; border: 1px solid #ffffff15; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, #7fd4c1, #b5f0e3); }
.progress.pink i { background: linear-gradient(90deg, #ff7aa8, #ffb3cc); }
#minimap-box { position: absolute; right: 10px; top: 10px; padding: 6px; }
#minimap { width: 230px; height: 230px; display: block; border-radius: 8px; cursor: pointer; image-rendering: pixelated; }
#minimap-info { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); padding: 4px 2px 0; }
#hoverinfo { position: absolute; right: 10px; top: 290px; width: 260px; padding: 8px 10px; pointer-events: none !important; }
#hoverinfo .name { font-family: 'Fredoka'; font-size: 16px; color: var(--gold); }
#hoverinfo .line { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 13px; }
#hoverinfo .line img { width: 20px; height: 20px; }
.st-ok { color: var(--ok); } .st-warn { color: var(--warn); } .st-bad { color: var(--bad); }

#toasts { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none !important; }
.toast { background: #2a1c22ee; border: 2px solid var(--frame); padding: 7px 16px; border-radius: 999px; font-weight: 700; box-shadow: 0 4px 12px #0007; animation: toastIn .25s ease-out; }
.toast.bad { border-color: var(--bad); color: #ffd1d1; } .toast.warn { border-color: var(--warn); } .toast.ok { border-color: var(--ok); }
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } }
.float { position: absolute; pointer-events: none !important; font-weight: 800; color: #fff; text-shadow: 0 1px 3px #000; animation: floatUp 1.4s ease-out forwards; white-space: nowrap; font-size: 13px; }
@keyframes floatUp { to { transform: translateY(-40px); opacity: 0; } }
.nametag { position: absolute; pointer-events: none !important; transform: translate(-50%, -100%); font-weight: 800; font-size: 12px; text-shadow: 0 1px 3px #000, 0 0 2px #000; white-space: nowrap; }

#alerts { position: absolute; right: 250px; top: 12px; display: flex; flex-direction: column; gap: 4px; }
.alert-ic { width: 38px; height: 38px; border-radius: 50%; background: #c0304a; display: grid; place-items: center; font-size: 20px; animation: pulse 1s infinite; cursor: pointer; border: 2px solid #ffb3c0; }
@keyframes pulse { 50% { transform: scale(1.12); } }

#chat { position: absolute; left: 10px; bottom: 120px; width: 420px; display: flex; flex-direction: column; gap: 2px; pointer-events: none !important; }
#chat .line { background: #0007; padding: 3px 8px; border-radius: 6px; font-size: 13px; animation: toastIn .2s; }
#chat-input { position: absolute; left: 10px; bottom: 90px; width: 420px; }
#netstatus { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); font-size: 12px; color: var(--muted); background: #0006; padding: 2px 10px; border-radius: 999px; pointer-events: none !important; }
#fps { position: absolute; right: 250px; bottom: 8px; font-size: 11px; color: var(--muted); pointer-events: none !important; font-family: monospace; }
#hurt { position: absolute; inset: 0; pointer-events: none !important; box-shadow: inset 0 0 120px #ff204080; opacity: 0; transition: opacity .3s; }

/* ---------- fenêtres ---------- */
.window { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-height: 94vh; overflow: auto; }
.window.left { left: calc(50% - 10px); transform: translate(-100%, -50%); }
.window.right { left: calc(50% + 10px); transform: translate(0, -50%); }
.cols { display: flex; gap: 14px; align-items: flex-start; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab { flex: 1; text-align: center; padding: 6px 4px; border-radius: 8px 8px 0 0; background: var(--panel3); cursor: pointer; font-family: 'Fredoka'; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.on { background: var(--panel2); color: #fff; border-bottom-color: var(--accent); }
.tab img { width: 30px; height: 30px; display: block; margin: 0 auto 2px; }
.recipes { display: grid; grid-template-columns: repeat(8, var(--slot)); gap: 3px; min-height: 230px; align-content: start; }
.recipes .row-sep { grid-column: 1 / -1; height: 2px; }
.machine { min-width: 380px; }
.machine .flow { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.machine .arrowbox { flex: 1; min-width: 80px; }
.kv { display: flex; justify-content: space-between; font-size: 13px; margin: 2px 0; }
.kv b { color: var(--gold); font-weight: 700; }
.fluidbar { width: 26px; height: 90px; border-radius: 8px; background: #0008; position: relative; overflow: hidden; border: 2px solid #ffffff20; }
.fluidbar i { position: absolute; left: 0; right: 0; bottom: 0; }
.fluidbox { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.recipe-pick { display: grid; grid-template-columns: repeat(8, var(--slot)); gap: 3px; margin-top: 6px; }
.statusline { font-weight: 700; margin: 4px 0; }
.chart { width: 100%; height: 80px; background: #0006; border-radius: 8px; display: block; }

/* ---------- info-bulle ---------- */
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: #1d1318f2; border: 2px solid var(--frame2); border-radius: 10px; padding: 8px 11px; max-width: 340px; box-shadow: 0 6px 18px #000a; font-size: 13px; }
.tooltip .tt-title { font-family: 'Fredoka'; font-size: 15px; color: var(--gold); margin-bottom: 4px; }
.tooltip .ing { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.tooltip .ing img { width: 22px; height: 22px; }
.tooltip .ing.miss { color: var(--bad); }
.tooltip hr { border: 0; border-top: 1px solid #ffffff22; margin: 6px 0; }
.cursor-item { position: fixed; z-index: 60; pointer-events: none; width: 40px; height: 40px; transform: translate(6px, 6px); }
.cursor-item img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 3px 3px #000a); }
.cursor-item span { position: absolute; right: -4px; bottom: -4px; font-weight: 800; font-size: 13px; text-shadow: 0 0 3px #000; }

/* ---------- arbre technologique ---------- */
#tech { position: absolute; inset: 20px; display: flex; gap: 12px; }
#tech .tree { flex: 1; position: relative; overflow: auto; border-radius: 10px; background: radial-gradient(circle at 30% 20%, #3b2831, #22161b); }
#tech .inner { position: relative; }
#tech svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.tnode { position: absolute; width: 112px; height: 104px; border-radius: 12px; padding: 6px; text-align: center; cursor: pointer; font-size: 11.5px; line-height: 1.15; background: #3a2830; border: 3px solid #5a3a48; box-shadow: 0 4px 10px #0007; }
.tnode img { width: 44px; height: 44px; display: block; margin: 0 auto 3px; }
.tnode.done { border-color: #4caf7a; background: #2e3f33; }
.tnode.avail { border-color: var(--gold); }
.tnode.locked { opacity: 0.55; }
.tnode.cur { border-color: var(--accent); box-shadow: 0 0 16px var(--accent); }
.tnode.sel { outline: 3px solid #fff; }
.tnode .packs { display: flex; justify-content: center; gap: 2px; margin-top: 3px; }
.tnode .packs i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; border: 1px solid #0008; }
.tnode .lvl { position: absolute; right: 5px; top: 3px; font-size: 10px; color: var(--gold); }
.tnode .q { position: absolute; left: 5px; top: 3px; font-size: 10px; background: var(--accent); border-radius: 8px; padding: 0 4px; }
#tech .side { width: 330px; display: flex; flex-direction: column; gap: 8px; }
#tech .side .unl { display: flex; flex-wrap: wrap; gap: 3px; }

/* ---------- carte ---------- */
#bigmap { position: absolute; inset: 20px; padding: 6px; }
#bigmap canvas { width: 100%; height: calc(100% - 34px); display: block; border-radius: 8px; image-rendering: pixelated; cursor: grab; }

/* ---------- écrans ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
.menu-bg { position: absolute; inset: 0; background-size: cover; background-position: center; filter: saturate(1.05); animation: slowzoom 40s ease-in-out infinite alternate; }
@keyframes slowzoom { from { transform: scale(1.02); } to { transform: scale(1.12) translate(-1.5%, 1%); } }
.menu-veil { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 60%, #0000 30%, #1a0f14cc 100%); }
.menu-col { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.menu-col .logo { width: min(620px, 80vw); filter: drop-shadow(0 10px 20px #000a); animation: bob 4s ease-in-out infinite; }
.menu-col .logo-text { font-family: 'Fredoka'; font-size: 86px; font-weight: 700; color: #fff; letter-spacing: 2px; text-shadow: 0 6px 0 #d14d80, 0 10px 24px #000a; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-0.5deg); } }
.menu-col .btn { width: 300px; font-size: 19px; }
.menu-foot { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; color: #ffffffaa; font-size: 12px; text-shadow: 0 1px 2px #000; }
.dialog { min-width: 520px; max-width: 92vw; max-height: 90vh; overflow: auto; }
.dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.savelist { display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow: auto; margin: 6px 0; }
.saveitem { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 8px; background: var(--panel3); cursor: pointer; border: 2px solid transparent; }
.saveitem:hover { border-color: var(--frame2); }
.saveitem.sel { border-color: var(--accent); }
.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loading .progress { width: 460px; height: 16px; }
.tip { max-width: 560px; text-align: center; color: var(--muted); font-style: italic; }
.spinner { width: 58px; height: 58px; border-radius: 50%; background: conic-gradient(#ff7aa8 0 25%, #fff 0 50%, #ff7aa8 0 75%, #fff 0); animation: spin 1.2s linear infinite; box-shadow: 0 0 0 5px #7a4560; }
@keyframes spin { to { transform: rotate(360deg); } }

/* intro */
#intro { background: #000; overflow: hidden; }
#intro .slide { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0; transition: opacity 1.4s ease; }
#intro .slide.on { opacity: 1; }
#intro .slide.kb1 { animation: kb1 14s linear forwards; } #intro .slide.kb2 { animation: kb2 14s linear forwards; }
@keyframes kb1 { from { transform: scale(1.05); } to { transform: scale(1.2) translate(-2%, -1%); } }
@keyframes kb2 { from { transform: scale(1.2) translate(2%, 1%); } to { transform: scale(1.04); } }
#intro .sub-text { position: absolute; left: 50%; bottom: 7vh; transform: translateX(-50%); width: min(1000px, 90vw); text-align: center; font-family: 'Fredoka'; font-size: clamp(18px, 2.3vw, 30px); color: #fff; text-shadow: 0 2px 8px #000, 0 0 3px #000; background: #0006; padding: 12px 22px; border-radius: 16px; transition: opacity .5s; }
#intro .skip { position: absolute; right: 22px; bottom: 18px; color: #fffa; font-size: 13px; }
#intro .veil { position: absolute; inset: 0; background: linear-gradient(180deg, #0005, #0000 30%, #0000 60%, #0008); }

/* mort / victoire */
#death { position: absolute; inset: 0; display: grid; place-items: center; background: #3a0010aa; }
#death .panel { text-align: center; padding: 22px 34px; }
#victory { position: absolute; inset: 0; display: grid; place-items: center; background: #0008; }
#victory .panel { text-align: center; max-width: 700px; }
#victory img { width: 100%; border-radius: 10px; margin: 8px 0; }

/* tutoriel */
#tuto { position: absolute; left: 10px; top: 96px; width: 300px; padding: 8px 10px; }
#tuto .obj { display: flex; gap: 8px; align-items: flex-start; margin: 5px 0; font-size: 13px; }
#tuto .obj .ck { width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--frame2); flex: none; margin-top: 1px; display: grid; place-items: center; font-size: 12px; }
#tuto .obj.done .ck { background: var(--ok); border-color: var(--ok); color: #1a3a20; }
#tuto .obj.done { color: var(--dim); text-decoration: line-through; }
#tuto .hint { font-size: 12px; color: var(--muted); margin-top: 6px; background: #0004; padding: 6px 8px; border-radius: 8px; }

.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.help-grid kbd { background: #fff2; border-radius: 5px; padding: 1px 7px; font-family: 'Fredoka'; border-bottom: 2px solid #0006; }
::-webkit-scrollbar { width: 10px; height: 10px; } ::-webkit-scrollbar-thumb { background: var(--frame); border-radius: 6px; } ::-webkit-scrollbar-track { background: #0003; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table td { padding: 3px 6px; border-bottom: 1px solid #ffffff10; }
.stats-table img { width: 22px; height: 22px; vertical-align: middle; }
