:root {
  --bg: #050812;
  --panel: rgba(16, 20, 38, 0.92);
  --panel2: #1c2240;
  --line: #3a4270;
  --text: #eef0ff;
  --muted: #9aa2c8;
  --gold: #ffd23a;
  --accent: #5fd0ff;
  --danger: #ff6a5a;
  --ok: #7be07b;
  --font: 'Pixelify Sans', ui-monospace, 'Courier New', monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; }

#view { position: fixed; inset: 0; touch-action: none; }
#view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }

/* ---------- boutons pixel ---------- */
.pbtn {
  background: var(--panel2); border: 2px solid var(--line); border-radius: 4px; padding: 8px 14px;
  font-size: 15px; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35), 0 2px 0 rgba(0, 0, 0, 0.4);
  transition: transform 0.06s, background 0.15s;
}
.pbtn:hover { background: #262e58; }
.pbtn:active { transform: translateY(2px); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.35); }
.pbtn.icon { width: 42px; height: 42px; padding: 0; font-size: 18px; display: grid; place-items: center; }
.pbtn.primary { background: #2f6f3a; border-color: #5fb86a; }
.pbtn.primary:hover { background: #38834a; }
.pbtn.danger { background: #6a2a2a; border-color: #b85a5a; }
.pbtn.big { width: 100%; font-size: 20px; padding: 12px; }
.pbtn:disabled { opacity: 0.45; cursor: default; }

/* ---------- HUD haut ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topbar {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px;
  display: flex; align-items: flex-start; gap: 8px; justify-content: center; pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#btnMenu { flex: none; }
#topRight { display: flex; gap: 6px; flex: none; }
#btnSpeed { min-width: 52px; height: 42px; padding: 0 10px; font-size: 16px; }
#gauge {
  position: relative; flex: 1; max-width: 560px; height: 62px; border: 2px solid #c8a24a; border-radius: 4px;
  overflow: hidden; background: #000; box-shadow: 0 0 0 2px #2a1e08, 0 4px 0 rgba(0, 0, 0, 0.5); cursor: pointer;
}
#gauge.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 2px #2a1e08, 0 0 30px 8px var(--gold); } 100% { box-shadow: 0 0 0 2px #2a1e08, 0 4px 0 rgba(0, 0, 0, 0.5); } }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
#gaugeText {
  position: absolute; left: 0; right: 0; top: 4px; text-align: center; line-height: 1.1;
  text-shadow: 2px 0 #000, -2px 0 #000, 0 2px #000, 0 -2px #000, 2px 2px #000;
}
#ageName { font-size: 19px; font-weight: 700; letter-spacing: 1px; color: #fff6d0; text-transform: uppercase; }
#ageSub { font-size: 13px; color: #e8ecff; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; }
#gaugeBar { position: absolute; left: 4px; right: 4px; bottom: 4px; height: 7px; background: rgba(0, 0, 0, 0.65); border: 1px solid #000; }
#gaugeFill { height: 100%; width: 0; background: linear-gradient(#ffe680, #e8a820); transition: width 0.4s; }
#gaugeFill.research { background: linear-gradient(#a8f0ff, #3ab0e8); }

#goals {
  position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 70px); left: 50%; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; max-width: min(560px, calc(100vw - 16px));
  pointer-events: none;
}
.goal {
  font-size: 12px; padding: 2px 6px; border-radius: 3px; background: rgba(10, 12, 26, 0.78); border: 1px solid #333a60;
  white-space: nowrap;
}
.goal.ok { border-color: #3f8a4a; color: var(--ok); }

#toasts {
  position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 100px); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(520px, calc(100vw - 24px));
}
.toast {
  background: var(--panel); border: 2px solid var(--line); border-radius: 4px; padding: 7px 12px; font-size: 14px;
  text-align: center; animation: tin 0.25s ease-out; transition: opacity 0.5s;
}
.toast.age { border-color: var(--gold); color: #fff3c0; }
.toast.civ { border-color: var(--accent); }
.toast.warn { border-color: var(--danger); }
@keyframes tin { from { transform: translateY(-8px); opacity: 0; } }
#fps { position: absolute; right: 8px; top: 64px; font-size: 12px; color: var(--muted); text-shadow: 1px 1px #000; }

/* ---------- pinceaux (bas) ---------- */
#bottombar {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 8px max(8px, env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: flex-end; justify-content: center; pointer-events: none;
}
#bottombar > * { pointer-events: auto; }
#sizes { display: flex; flex-direction: column; gap: 4px; background: var(--panel); border: 2px solid var(--line); border-radius: 4px; padding: 4px; }
.size { width: 30px; height: 26px; border: 2px solid transparent; background: transparent; border-radius: 3px; cursor: pointer; display: grid; place-items: center; }
.size i { display: block; width: var(--s); height: var(--s); background: #dfe4ff; border-radius: 50%; }
.size.on { border-color: var(--gold); background: rgba(255, 210, 58, 0.15); }
#brushes {
  display: flex; gap: 10px; overflow-x: auto; background: var(--panel); border: 2px solid var(--line); border-radius: 4px;
  padding: 6px 8px; max-width: calc(100vw - 70px); scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.group { display: flex; flex-direction: column; gap: 3px; flex: none; }
.group > span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; padding-left: 2px; }
.group > div { display: flex; gap: 5px; }
.brush {
  width: 58px; height: 62px; flex: none; background: #141a34; border: 2px solid #2c3462; border-radius: 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 3px 2px;
}
.brush img { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.brush b { font-size: 11px; font-weight: 400; line-height: 1; white-space: nowrap; }
.brush:hover { background: #1c2448; }
.brush.on { border-color: var(--gold); background: #2a2a18; box-shadow: 0 0 0 1px #000, inset 0 0 10px rgba(255, 210, 58, 0.25); }
.group.cata .brush.on { border-color: #ff7a40; }

/* ---------- menu principal ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: flex-start; padding: 24px 6vw; pointer-events: none; }
.screen > * { pointer-events: auto; }
.menuBox { width: min(360px, 100%); display: flex; flex-direction: column; gap: 6px; }
.logo {
  margin: 0; font-size: clamp(48px, 9vw, 78px); line-height: 1; letter-spacing: 2px; color: #ffe9a8;
  text-shadow: 4px 4px 0 #b4442c, 8px 8px 0 #2a0e08;
}
.logo span { color: #7fe0ff; text-shadow: 4px 4px 0 #2c62b4, 8px 8px 0 #081a2a; }
.tag { margin: 6px 0 22px; color: var(--muted); font-size: 18px; text-shadow: 2px 2px #000; }
.menuBtns { display: flex; flex-direction: column; gap: 10px; }
.foot { color: var(--muted); font-size: 13px; margin-top: 18px; text-shadow: 1px 1px #000; }

/* ---------- panneaux ---------- */
#panel { position: fixed; inset: 0; background: rgba(2, 4, 12, 0.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.panelBox {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 2px solid var(--line);
  border-radius: 6px; padding: 14px 16px 18px; box-shadow: 0 8px 0 rgba(0, 0, 0, 0.5);
}
.panelHead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.panelHead h2 { margin: 0; font-size: 24px; color: #ffe9a8; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field > label, .field > .lbl { font-size: 14px; color: var(--muted); }
.field input[type=text], .field input[type=number] {
  font-family: inherit; font-size: 17px; padding: 8px 10px; background: #0c1028; color: var(--text); border: 2px solid var(--line); border-radius: 4px;
  user-select: text; -webkit-user-select: text;
}
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .pbtn { flex: 1; min-width: 90px; padding: 8px 6px; }
.seg .pbtn.on { border-color: var(--gold); background: #3a3218; }
.check { display: flex; align-items: center; gap: 10px; font-size: 16px; cursor: pointer; margin: 10px 0; }
.check input { width: 20px; height: 20px; accent-color: #e8b020; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.saves { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.save { display: flex; gap: 10px; align-items: center; background: #10142e; border: 2px solid #283060; border-radius: 4px; padding: 6px; }
.save img { width: 96px; height: 48px; image-rendering: pixelated; border: 1px solid #000; flex: none; background: #000; }
.save .info { flex: 1; min-width: 0; }
.save .info b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save .info small { color: var(--muted); font-size: 12px; }
.save .acts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.save .acts .pbtn { padding: 6px 8px; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 16px; }
.help { font-size: 13px; color: var(--muted); line-height: 1.5; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 14px; }

#loading { position: fixed; inset: 0; background: rgba(2, 4, 12, 0.75); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 20; gap: 14px; }
.spinner { width: 28px; height: 28px; background: var(--gold); animation: spin 0.8s steps(4) infinite; box-shadow: 0 0 0 4px #2a1e08; }
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { font-size: 18px; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  #topbar { gap: 6px; left: 6px; right: 6px; }
  .pbtn.icon { width: 38px; height: 38px; font-size: 16px; }
  #btnSpeed { min-width: 42px; height: 38px; padding: 0 6px; font-size: 14px; }
  #gauge { height: 54px; }
  #ageName { font-size: 15px; }
  #ageSub { font-size: 11px; }
  #goals { top: calc(max(8px, env(safe-area-inset-top)) + 60px); }
  .goal { font-size: 11px; padding: 1px 5px; }
  #toasts { top: calc(max(8px, env(safe-area-inset-top)) + 112px); }
  .toast { font-size: 13px; }
  .brush { width: 50px; height: 54px; }
  .brush img { width: 26px; height: 26px; }
  .brush b { font-size: 10px; }
  #brushes { gap: 8px; padding: 5px 6px; max-width: calc(100vw - 62px); }
  .size { width: 26px; height: 22px; }
  .screen { justify-content: center; align-items: flex-end; padding-bottom: 40px; }
  .menuBox { text-align: center; }
}
