:root {
  --bg: #17140f;
  --panel: #221d16;
  --panel-2: #2b251c;
  --line: #3d3427;
  --text: #ece3d0;
  --muted: #a99c84;
  --accent: #d9a441;
  --accent-2: #8fc06b;
  --danger: #d4624f;
  --portal: #4fd1c5;
  --pnj: #f2c14e;
  --monster: #e0604f;
  --note: #9aa7ff;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: normal; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; color: var(--accent); margin-top: 1.4em; }

/* Barre du haut */
.top {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .7rem 1.4rem; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-family: Georgia, serif; font-size: 1.35rem; color: var(--text); }
.top nav { display: flex; gap: .2rem; }
.top nav a { color: var(--muted); padding: .35rem .7rem; border-radius: var(--radius); }
.top nav a.active, .top nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.search { position: relative; margin-left: auto; }
.search input { width: 240px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 4px); width: 320px; max-height: 60vh; overflow: auto;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); z-index: 30;
}
.dropdown a { display: flex; gap: .6rem; align-items: center; padding: .45rem .7rem; color: var(--text); }
.dropdown a:hover { background: var(--line); text-decoration: none; }
.dropdown .empty { padding: .6rem; color: var(--muted); }

main { max-width: 1200px; margin: 0 auto; padding: 1.4rem; }
.foot { text-align: center; padding: 2rem; color: var(--muted); font-size: .85rem; }
.foot a { color: var(--muted); }

/* Formulaires */
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: .45rem .6rem; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 7rem; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .8rem; }
label > input, label > select, label > textarea { margin-top: .25rem; }
label.check { display: flex; gap: .5rem; align-items: center; }
label.check input { width: auto; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  background: var(--accent); color: #1b1408; border: 0; border-radius: 6px; padding: .45rem .9rem; font: inherit; font-weight: 600;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: normal; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
body.editing #map-edit-toggle { background: var(--accent-2); color: #10200a; border-color: var(--accent-2); font-weight: 600; }
.edit-only, .auth-only, .login-only, .logout-only { display: none !important; }
body.editing .edit-only, body.logged .auth-only { display: inline-flex !important; }
body.needs-login .login-only { display: inline !important; }
body.can-logout .logout-only { display: inline-flex !important; }

/* Listes */
.list-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.list-head h1 { margin: 0; }
.list-head .filter { margin-left: auto; width: 220px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  color: var(--text); display: flex; flex-direction: column;
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card .thumb { height: 120px; background: var(--panel-2) center/cover no-repeat; image-rendering: pixelated; }
.card .thumb.sprite { background-size: contain; background-origin: content-box; padding: 10px; }
.card .body { padding: .6rem .8rem; }
.card .sub { color: var(--muted); font-size: .85rem; }
.region-title { margin-top: 1.5rem; }
.empty-state { color: var(--muted); padding: 2rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Fiche */
.entity-head { display: flex; gap: 1.2rem; align-items: flex-start; margin-bottom: 1rem; }
.entity-head .sprite { width: 96px; height: 96px; object-fit: contain; image-rendering: pixelated; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); }
.entity-head .actions { margin-left: auto; display: flex; gap: .5rem; }
.badge { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.map { color: var(--portal); } .badge.pnj { color: var(--pnj); } .badge.monster { color: var(--monster); } .badge.quest { color: var(--note); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.2rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; margin: 1rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; white-space: pre-line; }
.prose { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .2rem 1.2rem; }
.prose img { max-width: 100%; }
.prose .missing { color: var(--danger); border-bottom: 1px dashed var(--danger); cursor: help; }
.links { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }
.links li { display: flex; gap: .6rem; align-items: center; }
.links .meta { color: var(--muted); font-size: .85rem; }
.coord { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; background: var(--panel-2); padding: 0 .35rem; border-radius: 4px; color: var(--accent); }

/* Carte */
.map-toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; color: var(--muted); font-size: .9rem; }
.map-toolbar .status { margin-left: auto; font-family: ui-monospace, Consolas, monospace; color: var(--accent); min-width: 6ch; text-align: right; }
.map-hint { font-size: .85rem; color: var(--accent-2); }
.map-scroll { overflow: auto; max-width: 100%; background: #0e0c09; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.map-frame { display: grid; width: max-content; }
.map-frame .corner { background: transparent; }
.map-frame .col-labels, .map-frame .row-labels { display: grid; font-family: Georgia, serif; color: var(--text); font-size: 13px; }
.map-frame .col-labels span, .map-frame .row-labels span { display: flex; align-items: center; justify-content: center; }
.map-frame .col-labels span.hl, .map-frame .row-labels span.hl { color: var(--accent); font-weight: bold; }
.stage { position: relative; user-select: none; }
.stage img.map-img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.stage .grid {
  position: absolute; inset: 0; pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(0,0,0,.35) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0,0,0,.35) 1px, transparent 1px);
}
.stage .cell-hl { position: absolute; pointer-events: none; outline: 2px solid rgba(255,255,255,.7); background: rgba(255,255,255,.12); display: none; }
.stage:hover .cell-hl { display: block; }
body.editing .stage { cursor: crosshair; }

.marker {
  position: absolute; transform: translate(-50%, -50%); display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 2; border-radius: 6px; touch-action: none;
}
.marker img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }
.marker .pin {
  width: 72%; height: 72%; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px; color: #111; box-shadow: 0 0 0 2px rgba(0,0,0,.6);
}
.marker.portal .pin { background: transparent; box-shadow: none; }
.marker.portal svg { width: 100%; height: 100%; animation: spin 4s linear infinite; filter: drop-shadow(0 0 3px rgba(0,0,0,.8)); }
.marker.pnj .pin { background: var(--pnj); }
.marker.monster .pin { background: var(--monster); color: #fff; }
.marker.note .pin { background: var(--note); }
.marker:hover { outline: 2px solid #fff; z-index: 3; }
.marker.dragging { opacity: .7; outline: 2px dashed var(--accent-2); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .marker.portal svg { animation: none; } }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: .5rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .3rem; vertical-align: middle; }

/* Infobulle */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 300px;
  background: rgba(20, 16, 11, .97); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: .6rem .8rem; font-size: .88rem; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
.tooltip .tt-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .3rem; }
.tooltip .tt-head img { width: 40px; height: 40px; object-fit: contain; image-rendering: pixelated; }
.tooltip strong { color: var(--accent); font-size: 1rem; }
.tooltip .tt-row { color: var(--muted); }
.tooltip .tt-row b { color: var(--text); font-weight: 600; }
.tooltip .tt-preview { width: 100%; margin-top: .4rem; border-radius: 4px; image-rendering: pixelated; }
.tooltip ul { margin: .2rem 0 0; padding-left: 1.1rem; }
.tooltip .tt-note { margin-top: .3rem; white-space: pre-line; }

/* Modale */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  width: min(560px, 94vw); padding: 1.2rem 1.4rem;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin-bottom: 1rem; }
dialog .modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
dialog .modal-actions .left { margin-right: auto; }
dialog .error { color: var(--danger); font-size: .9rem; }
.img-preview { max-width: 100%; max-height: 140px; image-rendering: pixelated; display: block; margin-top: .4rem; border-radius: 4px; }
.help { font-size: .8rem; color: var(--muted); margin: -.5rem 0 .8rem; }

@media (max-width: 700px) {
  .search input { width: 150px; }
  .entity-head { flex-wrap: wrap; }
}
