:root {
  --bg: #0d0f14;
  --panel: rgba(20, 23, 30, 0.92);
  --panel-solid: #161a22;
  --panel-2: #1e232d;
  --line: rgba(232, 222, 200, 0.12);
  --line-2: rgba(232, 222, 200, 0.22);
  --text: #ece4d4;
  --muted: #9a9384;
  --amber: #e8a33d;
  --amber-2: #f3c26a;
  --teal: #4fb3a9;
  --red: #d9605a;
  --green: #6cbf5a;
  --blue: #5aa9ff;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.screen { position: fixed; inset: 0; }

/* ------------------------------------------------------------ boutons */
.btn {
  background: #2a303c; border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 12px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #343b49; border-color: rgba(232, 222, 200, 0.35); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--amber); color: #1b1306; border-color: #f6c77c; font-weight: 700; }
.btn.primary:hover { background: var(--amber-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { background: #5a2626; border-color: #8a3a3a; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
input, select {
  background: #11141a; border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 9px; outline: none; min-width: 0;
}
input:focus, select:focus { border-color: var(--amber); }

/* ------------------------------------------------------------ accueil */
#lobby { display: grid; place-items: center; overflow: auto; }
#lobby-canvas { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; filter: saturate(.9) brightness(.55); }
.lobby-card {
  position: relative; width: min(940px, calc(100vw - 32px)); margin: 32px auto; padding: 28px 30px 22px;
  background: rgba(14, 16, 22, 0.88); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}
.lobby-head { text-align: center; margin-bottom: 18px; }
.logo {
  font-family: var(--display); font-size: 46px; letter-spacing: .04em; margin: 0; color: var(--amber-2);
  text-shadow: 0 2px 0 #6b3d0c, 0 6px 24px rgba(232, 163, 61, 0.35);
}
.tagline { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.identity { display: flex; gap: 24px; align-items: flex-end; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field input, .field select { color: var(--text); font-size: 13px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.swatches { display: flex; gap: 6px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; box-shadow: inset 0 0 0 2px rgba(0,0,0,.35); }
.swatch.on { border-color: #fff; }
.lobby-cols { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
.lobby-section { background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.lobby-section h2 { font-family: var(--display); font-size: 19px; margin: 0 0 10px; color: var(--text); font-weight: 600; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.room-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; margin-bottom: 10px; min-height: 60px; }
.room { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 9px 10px; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 8px; }
.room .rname { font-weight: 650; }
.room .rmeta { color: var(--muted); font-size: 12px; grid-column: 1; }
.room .ractions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; }
.room .rplayers { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.empty { color: var(--muted); font-style: italic; padding: 12px 4px; }
.join-code { display: flex; gap: 8px; }
.join-code input { flex: 1; text-transform: uppercase; letter-spacing: .15em; }
.create-form { display: flex; flex-direction: column; gap: 10px; }
.create-form .btn { margin-top: 4px; padding: 10px; }
.lobby-status { text-align: center; min-height: 18px; margin: 14px 0 0; color: var(--amber-2); }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.how div { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: 9px; background: rgba(255,255,255,.03); border: 1px solid var(--line); font-size: 12px; }
.how b { font-family: var(--display); font-size: 14px; color: var(--amber-2); font-weight: 600; }
.how span { color: var(--muted); }
.create-form .check { color: var(--muted); }
@media (max-width: 760px) { .how { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .lobby-cols { grid-template-columns: 1fr; } .logo { font-size: 34px; } }

/* ------------------------------------------------------------ jeu */
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: default; image-rendering: pixelated; }
.panel { background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(4px); }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 10px;
  background: linear-gradient(180deg, rgba(12, 14, 19, 0.95), rgba(12, 14, 19, 0.82)); border-bottom: 1px solid var(--line-2); z-index: 5;
}
.tb-left { display: flex; flex-direction: column; min-width: 190px; }
.colony-name { font-family: var(--display); font-size: 16px; font-weight: 600; color: var(--amber-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.clock { font-size: 12px; color: var(--muted); white-space: nowrap; }
.clock b { color: var(--text); font-weight: 600; }
.resources { flex: 1; display: flex; gap: 4px; justify-content: center; flex-wrap: nowrap; overflow: hidden; }
.res { display: flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 6px; background: rgba(255,255,255,.04); white-space: nowrap; }
.res img { width: 20px; height: 20px; image-rendering: pixelated; }
.res b { font-variant-numeric: tabular-nums; }
.res.warn b { color: var(--red); }
.tb-right { display: flex; align-items: center; gap: 8px; }
.speed { display: flex; gap: 2px; background: rgba(0,0,0,.3); border-radius: 7px; padding: 2px; }
.speed button { background: transparent; border: 0; padding: 4px 8px; border-radius: 5px; cursor: pointer; color: var(--muted); font-weight: 700; font-size: 12px; }
.speed button.on { background: var(--amber); color: #1b1306; }
.speed button:hover:not(.on) { background: rgba(255,255,255,.08); color: var(--text); }
.players { display: flex; gap: 4px; }
.player-chip { display: flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 10px; background: rgba(255,255,255,.05); font-size: 12px; max-width: 110px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

#colonist-bar { position: absolute; top: 52px; left: 8px; display: flex; gap: 6px; z-index: 4; flex-wrap: wrap; max-width: calc(100vw - 340px); }
.colonist {
  width: 62px; padding: 4px 3px 5px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line-2); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; position: relative; user-select: none;
}
.colonist:hover { border-color: rgba(232, 222, 200, 0.45); }
.colonist.sel { border-color: #fff; box-shadow: 0 0 0 1px #fff inset; }
.colonist.drafted { background: rgba(110, 70, 20, 0.85); }
.colonist.downed { background: rgba(110, 30, 30, 0.85); }
.colonist canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.colonist .cname { font-size: 11px; max-width: 58px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mood { width: 52px; height: 4px; background: rgba(0,0,0,.5); border-radius: 2px; margin-top: 2px; overflow: hidden; }
.mood > i { display: block; height: 100%; }
.colonist .flag { position: absolute; top: 2px; right: 3px; font-size: 10px; font-weight: 800; }

#alerts { position: absolute; top: 56px; right: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; z-index: 4; max-width: 280px; }
.alert { background: var(--panel); border: 1px solid var(--line-2); border-left: 3px solid var(--amber); border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 12px; }
.alert.bad { border-left-color: var(--red); }
.alert.danger { border-left-color: var(--red); background: rgba(90, 24, 24, 0.92); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px rgba(217, 96, 90, 0.35); } }

#toasts { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 6; pointer-events: none; }
.toast { pointer-events: auto; cursor: pointer; padding: 8px 14px; border-radius: 8px; background: var(--panel-solid); border: 1px solid var(--line-2); box-shadow: var(--shadow); max-width: 560px; font-size: 13px; animation: slide .25s ease-out; }
.toast.good { border-color: rgba(108, 191, 90, 0.6); }
.toast.bad { border-color: rgba(232, 163, 61, 0.7); }
.toast.danger { border-color: var(--red); background: #3a1616; font-weight: 600; }
@keyframes slide { from { opacity: 0; transform: translateY(-8px); } }

#bottombar { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; z-index: 5; background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow); }
.tab-btn { background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 7px 13px; cursor: pointer; font-weight: 600; }
.tab-btn:hover { background: rgba(255,255,255,.07); }
.tab-btn.on { background: rgba(232, 163, 61, 0.18); border-color: rgba(232, 163, 61, 0.6); color: var(--amber-2); }
.tab-btn.draft { background: rgba(232, 163, 61, 0.15); border-color: rgba(232, 163, 61, 0.5); }
.tab-btn.draft.on { background: var(--amber); color: #1b1306; }
#bottombar .sep { width: 1px; background: var(--line-2); margin: 4px 2px; }

#menu { position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%); z-index: 5; padding: 10px; max-width: min(860px, calc(100vw - 20px)); }
.menu-cats { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.menu-cats button { background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.menu-cats button.on { color: var(--text); border-color: var(--amber); background: rgba(232,163,61,.12); }
.menu-grid { display: flex; gap: 6px; flex-wrap: wrap; }
.tool {
  width: 84px; min-height: 84px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 4px;
  background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; text-align: center; font-size: 11px; position: relative;
}
.tool img { width: 36px; height: 36px; image-rendering: pixelated; }
.tool:hover { border-color: rgba(232, 222, 200, 0.45); background: rgba(255,255,255,.05); }
.tool.on { border-color: var(--amber); background: rgba(232,163,61,.15); }
.tool.locked { opacity: .45; }
.tool .cost { color: var(--muted); font-size: 10px; }
.tool .key { position: absolute; top: 3px; left: 5px; font-size: 9px; color: var(--muted); }

#inspector { position: absolute; right: 8px; bottom: 8px; width: 330px; max-height: calc(100vh - 120px); overflow: auto; z-index: 4; padding: 12px; }
.insp-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.insp-head canvas, .insp-head img { width: 40px; height: 40px; image-rendering: pixelated; background: rgba(0,0,0,.25); border-radius: 6px; }
.insp-title { font-family: var(--display); font-size: 18px; font-weight: 600; line-height: 1.15; }
.insp-sub { color: var(--muted); font-size: 12px; }
.insp-close { margin-left: auto; background: transparent; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.insp-tabs { display: flex; gap: 3px; margin: 6px 0 8px; }
.insp-tabs button { flex: 1; background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 6px; padding: 4px; cursor: pointer; font-size: 12px; color: var(--muted); }
.insp-tabs button.on { color: var(--text); border-color: var(--amber); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12px; margin: 6px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.bar-row { display: grid; grid-template-columns: 84px 1fr 40px; gap: 8px; align-items: center; font-size: 12px; margin: 4px 0; }
.bar { height: 8px; background: rgba(0,0,0,.5); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; }
.bar-row .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.thoughts { list-style: none; margin: 4px 0; padding: 0; font-size: 12px; }
.thoughts li { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px dashed var(--line); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.skill { display: grid; grid-template-columns: 90px 1fr 22px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: rgba(255,255,255,.07); border: 1px solid var(--line); }
.insp-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 10px 0 4px; }
.bill { background: rgba(0,0,0,.25); border: 1px solid var(--line); border-radius: 7px; padding: 7px; margin: 5px 0; font-size: 12px; }
.bill-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.bill-ctrl { display: flex; gap: 5px; align-items: center; margin-top: 5px; }
.bill-ctrl select { padding: 3px 5px; font-size: 12px; }
.bill-ctrl input { width: 56px; padding: 3px 5px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 3px 0; cursor: pointer; }

#log-panel { position: absolute; left: 8px; bottom: 8px; width: 360px; z-index: 4; display: flex; flex-direction: column; padding: 6px; }
#log { max-height: 150px; overflow-y: auto; font-size: 12px; display: flex; flex-direction: column; gap: 2px; padding: 2px 4px 6px; }
#log .entry { cursor: default; }
#log .entry.click { cursor: pointer; }
#log .entry.click:hover { color: #fff; }
#log .t { color: var(--muted); font-size: 11px; margin-right: 5px; font-variant-numeric: tabular-nums; }
#log .good { color: #a6dc8f; }
#log .bad { color: #f0b46a; }
#log .danger { color: #ff8f86; font-weight: 600; }
#log .chat b { font-weight: 700; }
#log .sys { color: var(--muted); font-style: italic; }
#chat-input { width: 100%; font-size: 12px; padding: 6px 8px; }

#hoverinfo { position: absolute; left: 376px; bottom: 12px; font-size: 12px; color: var(--muted); z-index: 3; pointer-events: none; text-shadow: 0 1px 2px #000; max-width: 360px; }
#tool-hint { position: absolute; top: 108px; left: 50%; transform: translateX(-50%); background: var(--panel-solid); border: 1px solid var(--amber); border-radius: 8px; padding: 6px 12px; font-size: 12px; z-index: 5; pointer-events: none; }
#tooltip { position: fixed; z-index: 20; background: #0f1218; border: 1px solid var(--line-2); border-radius: 7px; padding: 7px 10px; font-size: 12px; max-width: 300px; pointer-events: none; box-shadow: var(--shadow); white-space: pre-line; }
#conn-lost { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); background: #5a2626; border: 1px solid var(--red); padding: 8px 16px; border-radius: 8px; z-index: 30; font-weight: 600; }

/* ------------------------------------------------------------ fenêtres */
.modal { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(5, 6, 9, 0.55); }
.modal-card { width: min(980px, calc(100vw - 30px)); max-height: calc(100vh - 80px); display: flex; flex-direction: column; background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-title { font-family: var(--display); font-size: 20px; margin: 0; font-weight: 600; }
.modal-head .close { margin-left: auto; background: transparent; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 14px 16px; overflow: auto; }

.work-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.work-table th { font-weight: 600; color: var(--muted); padding: 4px; text-align: center; font-size: 11px; }
.work-table th.wname { writing-mode: vertical-rl; transform: rotate(180deg); height: 86px; vertical-align: bottom; }
.work-table td { border-top: 1px solid var(--line); padding: 3px; text-align: center; }
.work-table td.cname { text-align: left; white-space: nowrap; padding-right: 10px; font-weight: 600; }
.prio { width: 34px; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: rgba(0,0,0,.3); cursor: pointer; font-weight: 800; position: relative; }
.prio .lvl { position: absolute; bottom: 1px; right: 3px; font-size: 9px; font-weight: 500; color: var(--muted); }
.prio.p1 { color: #ffd27a; border-color: rgba(232,163,61,.7); }
.prio.p2 { color: #e8dcc0; }
.prio.p3 { color: #b9b2a2; }
.prio.p4 { color: #7d776b; }
.work-help { color: var(--muted); font-size: 12px; margin-bottom: 10px; }

.research-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.rcard { padding: 10px; border-radius: 9px; border: 1px solid var(--line); background: rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 6px; }
.rcard.done { border-color: rgba(108, 191, 90, 0.5); }
.rcard.current { border-color: var(--amber); box-shadow: 0 0 0 1px var(--amber) inset; }
.rcard.locked { opacity: .55; }
.rcard h3 { margin: 0; font-size: 15px; font-family: var(--display); }
.rcard p { margin: 0; color: var(--muted); font-size: 12px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; font-size: 13px; }
.help-cols h3 { font-family: var(--display); margin: 6px 0; }
.help-cols ul { margin: 0; padding-left: 18px; }
.help-cols li { margin: 3px 0; }
kbd { background: #2a303c; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; font-family: var(--font); }
@media (max-width: 900px) { #log-panel { width: 260px; } #hoverinfo { left: 276px; } .help-cols { grid-template-columns: 1fr; } }
