/* Topocalypse : même ossature que CaCarte (barre du haut, fenêtre « Carte », panneau), ambiance rouille et cendre. */
:root {
  --bg: #171310;
  --surface: #221c17;
  --surface-2: #2b241e;
  --text: #ece2d0;
  --muted: #a8998a;
  --border: #3d3229;
  --brand: #d06a2e;
  --brand-ink: #1a120c;
  --ok: #9fd36b;
  --ally: #6aa7ff;
  --danger: #e0614a;
  --gold: #e3b23c;
  --radius: 4px;
  --topbar: 52px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg) radial-gradient(ellipse at 20% 0%, #2d2118 0, transparent 60%); overflow: hidden; }
a { color: var(--brand); }
h2 { margin: 0.2rem 0 0.6rem; font-size: 1.2rem; }
h3 { margin: 1rem 0 0.4rem; font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.ok { color: var(--ok); }
.warn { color: var(--gold); }

/* Barre du haut */
.topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(#2a211a, #1c1611);
  border-bottom: 2px solid #4a3426;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 900; font-size: 1.25rem; letter-spacing: 0.04em; color: var(--text); text-decoration: none; text-transform: uppercase; }
.nav { display: flex; gap: 0.5rem; align-items: center; }
.who { color: var(--muted); font-size: 0.9rem; }

/* Fenêtres */
.layout {
  height: calc(100dvh - var(--topbar));
  display: grid;
  grid-template-columns: 1fr minmax(320px, 400px);
  gap: 10px;
  padding: 10px;
}
.win { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 2px solid #4a3a2e; border-radius: 6px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); overflow: hidden; }
.win-title { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.6rem; font-size: 0.85rem; font-weight: 700; background: linear-gradient(90deg, #6b3519, #3a2a1f 70%); color: #f3e2c8; }
.win-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 6px var(--brand); }
.win-btns { margin-left: auto; display: flex; gap: 4px; }
.win-btns i { width: 12px; height: 12px; border: 1px solid #b08a6a; border-radius: 2px; background: #3a2a1f; }
.win-status { padding: 0.3rem 0.6rem; font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--border); background: var(--surface-2); }
.map { flex: 1; min-height: 0; }
.panel-content { flex: 1; overflow: auto; padding: 0.8rem 0.9rem 1.2rem; }

/* Boutons et formulaires */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem; padding: 0.5rem 0.9rem; border: 1px solid #5a4636; border-radius: var(--radius); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; font-size: 0.85rem; padding: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.8rem 0; }
.form { display: grid; gap: 0.6rem; }
.form label, label { display: grid; gap: 0.25rem; font-size: 0.9rem; font-weight: 600; }
input[type='text'], input[type='password'], input[type='number'], input:not([type]) { width: 100%; padding: 0.5rem 0.6rem; border-radius: var(--radius); border: 1px solid #5a4636; background: #15110e; color: var(--text); font: inherit; }
input[type='range'] { width: 100%; accent-color: var(--brand); }
.row { display: flex; gap: 0.6rem; align-items: end; }
.row > * { flex: 1; }
.check { display: flex !important; gap: 0.5rem; align-items: flex-start; font-weight: 400 !important; }
.safety { padding: 0.7rem 0.8rem; border-radius: var(--radius); background: color-mix(in srgb, var(--gold) 12%, transparent); border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); font-size: 0.88rem; }
.safety p { margin: 0.3rem 0 0; }
.lore { line-height: 1.5; }
.badge { display: inline-block; padding: 0.1rem 0.45rem; border-radius: 99px; border: 1px solid currentColor; font-size: 0.75rem; font-weight: 700; }
.badge.ok { color: var(--ok); }

/* Base : ressources */
.base-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.base-head h2 { margin: 0; }
.base-head .link { margin-left: auto; }
.res { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0.6rem 0; }
.res-item { display: grid; padding: 0.4rem 0.5rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.res-item span { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.res-item b { font-size: 1.15rem; }
.res-item small { font-size: 0.72rem; color: var(--muted); }
.res-food b { color: #b9d77a; }
.res-wood b { color: #d5a26b; }
.res-scrap b { color: #b8c2cc; }
.alert { margin: 0.5rem 0; padding: 0.6rem 0.7rem; border-radius: var(--radius); background: color-mix(in srgb, var(--danger) 18%, transparent); border: 1px solid var(--danger); font-size: 0.9rem; animation: pulse 2s infinite; }
@keyframes pulse { 50% { border-color: transparent; } }

/* Carte sélectionnée */
.card { position: relative; margin: 0.6rem 0; padding: 0.7rem 0.8rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid #5a4636; }
.card h3 { margin: 0 1.5rem 0.3rem 0; }
.card.hint { border-color: var(--gold); }
.card.rel-moi { border-color: var(--ok); }
.card.rel-allie { border-color: var(--ally); }
.card.rel-autre { border-color: var(--danger); }
.card.drop, .card.build { border-color: var(--gold); }
.close { position: absolute; top: 0.3rem; right: 0.4rem; background: none; border: 0; color: var(--muted); font-size: 1.3rem; cursor: pointer; }

/* Onglets */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 0.8rem; border-bottom: 2px solid var(--border); }
.tab { flex: 1; padding: 0.45rem 0.3rem; border: 0; border-radius: 3px 3px 0 0; background: none; color: var(--muted); font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.tab.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--brand); }
.list { list-style: none; margin: 0.4rem 0; padding: 0; display: grid; gap: 0.4rem; }
.list li { padding: 0.45rem 0.55rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.list .btn.small { float: right; }
.sw { display: inline-block; width: 0.8rem; height: 0.8rem; margin-right: 0.4rem; border-radius: 2px; vertical-align: -1px; }
.journal .j-danger { border-left: 3px solid var(--danger); }
.journal .j-success { border-left: 3px solid var(--ok); }
.build-list { display: grid; gap: 6px; }
.build-item { display: flex; gap: 0.5rem; align-items: flex-start; text-align: left; padding: 0.5rem 0.6rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font: inherit; cursor: pointer; }
.build-item:hover, .build-item.on { border-color: var(--brand); }
.build-item[data-poor] { opacity: 0.55; }
.build-item .sw { width: 1.4rem; height: 1.4rem; flex: none; margin-top: 0.1rem; }
.build-item small { display: block; color: var(--muted); font-size: 0.8rem; }
.build-item small.cost { color: var(--gold); }

/* Marqueurs de la carte */
.mk { display: grid; justify-items: center; padding: 0.15rem 0.45rem; border-radius: 3px; border: 1px solid; font: 600 0.72rem system-ui, sans-serif; color: #fff; background: rgba(20, 15, 12, 0.85); cursor: pointer; white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }
.mk span { font-weight: 400; opacity: 0.8; font-size: 0.68rem; }
.mk-base.rel-moi { border-color: var(--ok); }
.mk-base.rel-allie { border-color: var(--ally); }
.mk-base.rel-autre { border-color: var(--danger); }
.mk-drop { border-color: var(--gold); color: var(--gold); }
.mk-horde { border-color: var(--danger); background: rgba(90, 20, 15, 0.9); }
.mk-horde.mine { animation: pulse 1s infinite; }
.mk-unit { border-color: var(--ok); color: var(--ok); }
.mk-unit.incoming { border-color: var(--danger); color: var(--danger); }
.maplibregl-ctrl-attrib { font-size: 0.7rem; }

/* Messages */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 50; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 0.6rem 0.9rem; border-radius: var(--radius); background: #2e251e; border: 1px solid #5a4636; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5); font-size: 0.9rem; }
.toast-success { border-color: var(--ok); }
.toast-error { border-color: var(--danger); }

/* Téléphone : carte en haut, panneau en bas */
@media (max-width: 760px) {
  body { overflow: auto; }
  .layout { height: auto; grid-template-columns: 1fr; grid-template-rows: 58dvh auto; padding: 6px; gap: 6px; }
  .win-map { height: 58dvh; }
  .panel { min-height: 40dvh; }
  .win-btns { display: none; }
  .res { grid-template-columns: repeat(3, 1fr); }
  .tab { font-size: 0.75rem; flex: 1 1 30%; }
}

/* Campagne : quête en cours, niveau, boîtes de dialogue */
.quest-now { margin: 0.5rem 0; padding: 0.55rem 0.7rem; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed #6a5442; }
.quest-now.done { border: 1px solid var(--ok); }
.quest-now p { margin: 0.3rem 0; }
.level { display: inline-block; padding: 0.05rem 0.45rem; border-radius: 3px; background: var(--brand); color: var(--brand-ink); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.chapter { font-size: 0.8rem; color: var(--gold); font-weight: 700; }
.tab.ping::after { content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 4px; border-radius: 50%; background: var(--ok); vertical-align: 2px; }
.quests .chapter-title { background: none; border: 0; padding: 0.4rem 0 0; font-size: 0.75rem; font-weight: 800; color: var(--gold); text-transform: uppercase; letter-spacing: 0.06em; }
.quests .current { border-color: var(--brand); }
.dialog-backdrop { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(8, 5, 3, 0.62); }
.dialog-backdrop[hidden] { display: none; }
.dialog { width: min(520px, 100%); animation: rise 0.25s ease-out; }
.dialog .win-title { font-size: 0.95rem; }
.dialog-count { margin-left: auto; font-weight: 400; opacity: 0.7; font-size: 0.8rem; }
.dialog-text { margin: 0; padding: 1rem 1.1rem 0.4rem; font-size: 1.05rem; line-height: 1.55; font-family: Georgia, 'Times New Roman', serif; }
.dialog .actions { padding: 0 1.1rem 0.4rem; justify-content: flex-end; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* Réveil : recherche d'une commune */
.form.inline { display: flex; gap: 6px; margin: 8px 0 4px; }
.form.inline input { flex: 1; min-width: 0; }
.wake-results { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }

/* Écran de chargement du réveil, posé sur la carte */
.map-loading { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(40, 33, 27, 0.92), rgba(16, 12, 9, 0.97)); }
.map-loading[hidden] { display: none; }
.ml-box { width: min(380px, 100%); text-align: center; }
.ml-line { margin: 0 0 14px; font-family: Georgia, 'Times New Roman', serif; font-size: 1.1rem; line-height: 1.5; min-height: 3.3em; }
.ml-bar { height: 10px; border: 2px solid var(--border); background: var(--surface-2); }
.ml-bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--brand) 0 8px, #a85424 8px 12px); transition: width 0.6s; }
.ml-small { margin: 10px 0 0; color: var(--muted); font-size: 0.8rem; }
@media (prefers-reduced-motion: reduce) { .ml-bar i { transition: none; } }

/* Abandon d'une communauté */
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.danger:hover, .btn.danger:focus-visible { background: var(--danger); color: var(--brand-ink); }
.card.danger-zone { border-color: var(--danger); }
