/* ===== Le Compagnon de Dagda — thème celtique sombre ===== */
:root {
  --ink:        #12161b;
  --ink-2:      #1a1f27;
  --panel:      #212832;
  --panel-2:    #283040;
  --line:       #384252;
  --text:       #e8e2d2;
  --text-dim:   #a9a495;
  --muted:      #7f8698;
  --gold:       #c9a54e;
  --gold-soft:  #e0c682;
  --green:      #6ea67a;
  --red:        #c66a5a;
  --red-soft:   #e08a7a;
  --blue:       #6d8fb0;
  --radius:     14px;
  --radius-sm:  9px;
  --shadow:     0 6px 22px rgba(0,0,0,.35);
  --safe-b:     env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'EB Garamond', Georgia, serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d2530 0%, var(--ink) 60%) fixed;
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
input, select, textarea, button { font-family: inherit; font-size: 1rem; }

.title-fantasy { font-family: 'Cinzel', serif; letter-spacing: .5px; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.container { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; flex: 1; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Connexion ---------- */
#screen-login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: linear-gradient(180deg, var(--panel), var(--ink-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 36px 28px; box-shadow: var(--shadow);
}
.crest { font-size: 42px; color: var(--gold); }
.crest-sm { color: var(--gold); font-size: 20px; }
.login-card h1 { margin: 10px 0 6px; font-size: 1.7rem; color: var(--gold-soft); line-height: 1.2; }
.subtitle { color: var(--text-dim); margin: 0 0 22px; font-size: .95rem; }
#login-form { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 12px 14px; background: rgba(18,22,27,.9);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-name { color: var(--gold-soft); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; justify-content: center; }
#game-name { color: var(--gold-soft); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-status { font-size: .78rem; color: var(--muted); min-width: 62px; text-align: right; }
.save-status.saving { color: var(--gold); }

/* ---------- Boutons ---------- */
.btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); padding: 10px 16px; border-radius: var(--radius-sm);
  transition: transform .05s ease, background .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--gold), #b08a34); border-color: #8f6f27; color: #1c1608; font-weight: 600; }
.btn-secondary { background: var(--panel-2); border-color: var(--blue); color: var(--gold-soft); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: .9rem; }
.btn-mini { padding: 5px 10px; font-size: .82rem; border-radius: 7px; }
.btn-round { padding: 8px 12px; min-width: 44px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.btn.danger { color: var(--red-soft); border-color: #6a3a34; }
.btn.danger:hover { background: #3a2320; }
.error-msg { color: var(--red-soft); font-size: .9rem; margin: 4px 0 0; }

input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--ink-2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }

/* ---------- Liste des parties ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2, .section-head h3 { margin: 0; }
.section-head h2 { color: var(--gold-soft); }
.parties-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.party-card {
  background: linear-gradient(180deg, var(--panel), var(--ink-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  box-shadow: var(--shadow);
}
.party-card:hover { border-color: var(--gold); }
.party-sigil { font-size: 26px; color: var(--gold); }
.party-info { flex: 1; min-width: 0; }
.party-info h3 { margin: 0 0 3px; color: var(--gold-soft); font-family: 'Cinzel', serif; font-size: 1.1rem; }
.party-meta { color: var(--muted); font-size: .82rem; }
.party-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.party-del { font-size: 1.15rem; line-height: 1; padding: 6px; }
.party-del:hover { color: var(--red-soft); }
.badge { font-family: 'EB Garamond', serif; font-size: .72rem; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 8px; border-radius: 20px; border: 1px solid var(--line); color: var(--text-dim); }
.badge.mode-narratif { border-color: var(--blue); color: var(--blue); }
.badge.mode-simplifie { border-color: var(--gold); color: var(--gold-soft); }
.badge.mode-mortel { border-color: var(--red); color: var(--red-soft); }

/* ---------- Jeu ---------- */
.game-main { padding-bottom: calc(84px + var(--safe-b)); }
.panel-card {
  background: linear-gradient(180deg, var(--panel), var(--ink-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.panel-title { margin: 0 0 14px; color: var(--gold-soft); font-family: 'Cinzel', serif; font-size: 1.15rem; }
.panel-subtitle { margin: 0; color: var(--gold-soft); font-family: 'Cinzel', serif; font-size: .98rem; }

/* PV */
.pv-block { margin-bottom: 16px; }
.pv-label { display: flex; justify-content: space-between; font-size: .95rem; margin-bottom: 6px; }
.pv-label b { color: var(--red-soft); font-size: 1.15rem; }
.pv-bar { height: 16px; background: var(--ink); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; }
.pv-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #7a3d34, var(--red-soft)); transition: width .3s; }
.pv-controls { display: flex; gap: 8px; margin-top: 10px; justify-content: center; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { display: flex; flex-direction: column; gap: 5px; position: relative; }
.stat-wide { grid-column: 1 / -1; }
.stat-name { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.stat .btn-mini { position: absolute; right: 6px; bottom: 6px; padding: 3px 8px; }
.stat input { padding-right: 44px; }
.talent-desc { margin: 12px 0 0; font-style: italic; font-size: .92rem; min-height: 1px; }

.chapter-row { display: flex; align-items: center; justify-content: space-between; margin-top: 16px;
  padding-top: 14px; border-top: 1px dashed var(--line); }
.chapter-ctrl { display: flex; align-items: center; gap: 8px; }
.chapter-ctrl input { width: 78px; text-align: center; }

/* Armes */
.armes-list, .inventory-list, .saves-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.arme-row { display: grid; grid-template-columns: 1fr 92px auto; gap: 8px; align-items: center; }
.arme-row .bonus-field { display: flex; align-items: center; gap: 4px; }
.arme-row .bonus-field span { font-size: .8rem; color: var(--text-dim); }
.icon-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 6px; }
.icon-btn:hover { color: var(--red-soft); }

/* Inventaire */
.inventory-list li { display: flex; align-items: center; gap: 10px; background: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; }
.inventory-list li.saved { border-color: var(--gold); }
.inv-check { width: 22px; height: 22px; accent-color: var(--gold); flex: none; }
.inv-name { flex: 1; background: transparent; border: none; padding: 4px; color: var(--text); }
.inv-name:focus { outline: none; border-bottom: 1px solid var(--gold); }
.inv-name.done { text-decoration: line-through; color: var(--muted); }
.save-flag { font-size: .7rem; color: var(--gold); border: 1px solid var(--gold); border-radius: 4px; padding: 1px 5px; cursor: pointer; }
.save-flag.off { color: var(--muted); border-color: var(--line); }
.check-inline { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.check-inline input { width: 20px; height: 20px; accent-color: var(--gold); }
.boulons-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.boulons-row input { width: 70px; text-align: center; }

/* Dés */
.dice-card { text-align: center; }
.dice-display { min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; margin-bottom: 14px; }
.dice-faces { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.die {
  width: 62px; height: 62px; border-radius: 12px; background: linear-gradient(160deg, #f4ecd8, #cfc5a8);
  color: #201a0e; display: grid; place-items: center; font-size: 34px; font-weight: 700;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.15), var(--shadow); position: relative;
}
.die.rolling { animation: tumble .5s ease; }
@keyframes tumble { 0%{transform:rotate(-12deg) scale(.8)} 50%{transform:rotate(10deg) scale(1.1)} 100%{transform:rotate(0) scale(1)} }
.die.adjusted { outline: 2px solid var(--gold); }
.dice-total { font-family: 'Cinzel', serif; font-size: 2.4rem; color: var(--gold-soft); line-height: 1; }
.dice-caption { font-size: .95rem; }
.dice-buttons { display: flex; gap: 12px; justify-content: center; }
.btn-dice { flex: 1; max-width: 200px; }
.chance-assist { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.chance-dice-adjust { display: flex; gap: 16px; justify-content: center; margin-top: 8px; }
.chance-die-ctrl { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chance-die-ctrl .adj-btns { display: flex; gap: 6px; }
.dice-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.dice-log li { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; padding: 6px 8px; background: var(--ink-2); border-radius: 7px; }
.dice-log .roll-when { color: var(--muted); font-size: .78rem; white-space: nowrap; }

/* Combat */
.combat-vs { display: flex; align-items: stretch; gap: 10px; margin-bottom: 14px; }
.fighter { flex: 1; background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.fighter-me { border-color: var(--green); }
.fighter-enemy { border-color: var(--red); }
.fighter-name { display: block; font-family: 'Cinzel', serif; font-size: .95rem; color: var(--gold-soft); margin-bottom: 6px; }
.hp { font-size: 1.5rem; font-weight: 700; }
.fighter-me .hp { color: var(--green); }
.fighter-enemy .hp { color: var(--red-soft); }
.mini-bar { height: 8px; background: var(--ink); border-radius: 10px; overflow: hidden; margin: 6px 0; }
.mini-fill { height: 100%; transition: width .3s; }
.mini-fill.me { background: var(--green); }
.mini-fill.enemy { background: var(--red-soft); }
.vs-sep { align-self: center; font-size: 1.4rem; }
.combat-actions { display: flex; gap: 10px; margin-bottom: 12px; }
.combat-actions .btn { flex: 1; }
.combat-result { text-align: center; min-height: 24px; font-family: 'Cinzel', serif; margin-bottom: 8px; }
.combat-result.hit { color: var(--green); }
.combat-result.miss { color: var(--muted); }
.combat-result.win { color: var(--gold-soft); font-size: 1.2rem; }
.combat-result.lose { color: var(--red-soft); font-size: 1.2rem; }
.combat-log { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 240px; overflow-y: auto; font-size: .88rem; }
.combat-log li { padding: 5px 8px; background: var(--ink-2); border-radius: 6px; border-left: 3px solid var(--line); }
.combat-log li.me { border-left-color: var(--green); }
.combat-log li.enemy { border-left-color: var(--red); }

/* Cartes */
.map-select-row { display: flex; gap: 8px; align-items: center; }
.map-select-row select { width: auto; min-width: 120px; }
.map-controls {
  position: sticky; top: 48px; z-index: 15;
  background: var(--panel-2);
  margin: 0 -16px 12px; padding: 8px 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.map-toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.map-zoom { display: flex; align-items: center; gap: 8px; }
.map-zoom .stat-name { margin-right: 2px; }
.map-zoom #zoom-lbl { margin-left: auto; }
.tool-btn { display: flex; align-items: center; gap: 5px; padding: 6px 10px; border: 1px solid var(--line);
  background: var(--ink-2); border-radius: 8px; cursor: pointer; color: var(--text); font-size: .85rem; }
.tool-btn.active { border-color: var(--gold); background: var(--panel-2); }
.tool-swatch { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.3); }
.map-scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #ffffff; padding: 8px; }
.map-canvas { position: relative; width: max-content; margin: 0 auto; touch-action: none; }
.map-grid { display: grid; gap: 2px; touch-action: none; width: max-content; background: #d3d7de; }
.map-cell { width: var(--cell, 30px); height: var(--cell, 30px); background: #ffffff; display: grid; place-items: center;
  color: #2a2f38; cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: none; overflow: hidden; }
.map-cell.t-sol   { background: #e2e5ea; }
.map-cell.t-mur   { background: #3a3f47; }
.map-cell.t-porte { background: #f6e2a6; color: #6b4e12; }
.map-cell.t-eau   { background: #a9d3ec; }
.map-cell.t-escalier { background: #ece0b4; color: #6b5a12; }
.map-cell.t-marqueur { background: #e6c19a; color: #5a3a18; font-weight: 700; }
.map-cell.t-depart { background: #b6e0c0; color: #1e5230; }

/* Repères de lecture : petites croix aux intersections */
.map-guides { position: absolute; top: 0; left: 0; pointer-events: none; }
.xmark { position: absolute; }
.xmark::before, .xmark::after { content: ''; position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); }
.xmark::before { width: var(--arm); height: var(--th); }   /* bras horizontal */
.xmark::after  { width: var(--th);  height: var(--arm); }  /* bras vertical */
.xmark-5::before, .xmark-5::after { background: #7d8492; }        /* niveau 2 */
.xmark-center::before, .xmark-center::after { background: #454b59; } /* niveau 5, plus foncé */

/* Calque de texte au-dessus de la grille */
.map-labels { position: absolute; top: 0; left: 0; pointer-events: none; }
.map-label {
  position: absolute; white-space: nowrap; transform: translateY(-2px);
  background: rgba(255,255,255,.88); color: #1a2230; border: 1px solid #b9beca;
  border-radius: 5px; padding: 1px 5px; font-size: 12px; font-weight: 600; line-height: 1.35;
  box-shadow: 0 1px 3px rgba(0,0,0,.18); max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.map-config { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 12px; }
.mini-field { display: flex; flex-direction: column; gap: 3px; font-size: .78rem; color: var(--text-dim); }
.mini-field input { width: 76px; padding: 6px 8px; }
.map-name-field { flex: 1; min-width: 140px; }
.map-name-field input { width: 100%; }

/* Notes */
.notes-area { width: 100%; min-height: 320px; resize: vertical; line-height: 1.6; }

/* Sauvegardes */
.saves-list li { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; display: flex; align-items: center; gap: 12px; }
.save-info { flex: 1; }
.save-info .save-chap { font-family: 'Cinzel', serif; color: var(--gold-soft); }
.save-info .save-when { color: var(--muted); font-size: .8rem; }
.danger-card { border-color: #4a2a26; }

/* Tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: rgba(18,22,27,.96); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tab-btn { flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab-ico { font-size: 20px; filter: grayscale(.3); }
.tab-lbl { font-size: .68rem; }
.tab-btn.active { color: var(--gold-soft); }
.tab-btn.active .tab-ico { filter: none; transform: translateY(-1px); }

/* Modale */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: linear-gradient(180deg, var(--panel), var(--ink-2)); border: 1px solid var(--gold);
  border-radius: var(--radius); padding: 22px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; color: var(--gold-soft); font-family: 'Cinzel', serif; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal label { display: block; margin-bottom: 12px; }
.modal .stat-name { display: block; margin-bottom: 5px; }

/* Toast */
.toast { position: fixed; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--gold); color: var(--text);
  padding: 10px 18px; border-radius: 24px; z-index: 60; box-shadow: var(--shadow); font-size: .9rem;
  animation: toastin .2s ease; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Création du personnage ---------- */
.create-main { padding-bottom: 40px; }
.create-intro { text-align: center; font-style: italic; color: var(--text-dim); margin: 8px 0 18px; }
.create-stats { display: grid; grid-template-columns: 1fr; gap: 12px; }
.cstat { background: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px; text-align: center; }
.cstat-name { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.cstat-val { font-family: 'Cinzel', serif; font-size: 2.6rem; color: var(--gold-soft); line-height: 1.1; }
.cstat-formula { font-size: .78rem; color: var(--muted); margin-bottom: 8px; }
.cstat-dice { font-size: .85rem; color: var(--gold); min-height: 1.1em; margin-bottom: 6px; }

.talent-cards { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.talent-card { text-align: left; cursor: pointer; background: var(--ink-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px;
  transition: border-color .15s, background .15s, transform .05s; }
.talent-card:hover { border-color: var(--gold-soft); }
.talent-card:active { transform: translateY(1px); }
.talent-card.selected { border-color: var(--gold); background: var(--panel-2); box-shadow: 0 0 0 1px var(--gold) inset; }
.talent-card-head { display: flex; align-items: center; gap: 10px; }
.talent-card-ico { font-size: 24px; }
.talent-card-name { font-family: 'Cinzel', serif; font-size: 1.05rem; color: var(--gold-soft); flex: 1; }
.talent-card-check { color: var(--gold); font-weight: 700; opacity: 0; transition: opacity .15s; }
.talent-card.selected .talent-card-check { opacity: 1; }
.talent-card-desc { margin: 8px 0 0; font-size: .9rem; line-height: 1.5; color: var(--text-dim); }

/* Desktop */
@media (min-width: 720px) {
  .stat-grid { grid-template-columns: 1fr 1fr 1fr; }
  .stat-wide { grid-column: auto; }
  .tab-lbl { font-size: .75rem; }
  .create-stats { grid-template-columns: 1fr 1fr 1fr; }
  .talent-cards { grid-template-columns: 1fr 1fr; }
}
