/* Thème sombre, sobre, médiéval-fantasy — volontairement léger :
   pas de dégradés animés, pas de polices distantes, pas d'images de fond
   lourdes. Le Raspberry Pi Zero 2 W sert ces fichiers statiques tels quels. */

/* Thème sombre, médiéval-fantasy, pensé pour PC uniquement — toujours léger :
   pas d'image de fond, pas de police téléchargée (polices système), juste
   quelques dégradés CSS et ombres pour donner du relief. */

:root {
    --bg: #14100f;
    --bg-panel: #1f1a17;
    --bg-panel-alt: #241d19;
    --border: #3a2f28;
    --border-light: #4a3c32;
    --text: #e9e0d4;
    --text-muted: #a9998a;
    --accent: #b3823f;
    --accent-hover: #c99a52;
    --accent-glow: rgba(179, 130, 63, 0.35);
    --danger: #a5433a;
    --success: #4c7a4a;
    --info: #3f6b83;
    --radius: 8px;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
    --font-heading: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 1024px;
    background:
        radial-gradient(ellipse 1200px 600px at 50% -10%, #241b14 0%, transparent 60%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.55;
}

h1, h2, h3 {
    font-family: var(--font-heading);
    letter-spacing: 0.02em;
}

a { color: var(--accent); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-panel-alt) 100%);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: relative;
}
.topbar::after {
    content: "";
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-glow), transparent);
}

.brand {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.03em;
    color: var(--text);
}
.brand:hover { text-decoration: none; color: var(--accent); }

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-pill {
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.2rem 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.inline-form { display: inline; }
.link-button {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    padding: 0;
    transition: color 0.15s ease;
}
.link-button:hover { color: var(--accent-hover); text-decoration: underline; }

.container {
    max-width: 1024px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.auth-card {
    max-width: 420px;
    margin: 2rem auto;
    background: linear-gradient(160deg, var(--bg-panel) 0%, var(--bg-panel-alt) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 1.75rem 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-card h1 {
    margin-top: 0;
    font-size: 1.5rem;
    text-align: center;
}

.field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.85rem; color: var(--text-muted); }
.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.6rem 0.7rem;
    font-size: 1rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.field-checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.field-checkbox label { margin: 0; }

.field-error {
    color: #e08a80;
    font-size: 0.8rem;
    margin: 0;
}

.btn-primary, .btn-secondary {
    display: inline-block;
    width: 100%;
    text-align: center;
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-primary {
    background: linear-gradient(160deg, var(--accent-hover) 0%, var(--accent) 100%);
    color: #1a1512;
    font-weight: 600;
    box-shadow: var(--shadow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--bg-panel);
    border-color: var(--border);
    color: var(--text);
    box-shadow: var(--shadow);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.btn-secondary:active { transform: translateY(0); }

.auth-switch {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.profile-list { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; }
.profile-list dt { color: var(--text-muted); }
.profile-list dd { margin: 0; }

.hint { color: var(--text-muted); font-size: 0.9rem; }

.flash-stack { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.flash {
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-left-width: 3px;
    font-size: 0.9rem;
    box-shadow: var(--shadow);
}
.flash-success { border-left-color: var(--success); color: #bfe0bd; }
.flash-danger { border-left-color: var(--danger); color: #f0c2bc; }
.flash-info { border-left-color: var(--info); color: #bfe0f0; }

/* --- Campagnes (Phase 2) --- */
.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin: 1rem 0 1.5rem;
}
.action-row .btn-secondary { width: auto; }

.campaign-list, .member-list { list-style: none; padding: 0; margin: 0; }
.campaign-item, .member-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    transition: border-color 0.15s ease, transform 0.12s ease;
}
.campaign-item:hover { border-color: var(--border-light); transform: translateX(2px); }
.campaign-item a {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    color: var(--text);
}
.campaign-item a:hover { text-decoration: none; }
.campaign-name { font-weight: 600; }

.role-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.role-badge.role-mj { border-color: var(--accent); color: var(--accent); }
.role-badge.role-joueur { border-color: var(--info); color: #8fc2db; }

.info-box {
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    margin: 1rem 0;
}
.info-box code {
    background: var(--bg);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    color: var(--accent);
}

.link-danger { color: var(--danger); }
.link-danger:hover { color: #d16358; }

.field textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.6rem 0.7rem;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
}
.field input[type="number"] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.6rem 0.7rem;
    font-size: 1rem;
    max-width: 140px;
}

/* --- Fiche de personnage (Phase 3) --- */
.wide-card { max-width: 760px; }

.field-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem 1rem;
}
.field-grid.six { grid-template-columns: repeat(6, 1fr); }

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.sheet-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.sheet-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
}
.sheet-panel.wide { grid-column: 1 / -1; }
.sheet-panel h2 { margin-top: 0; font-size: 1.1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }

.sheet-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.sheet-table th, .sheet-table td {
    text-align: left;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
}
.sheet-table tbody tr:hover { background: var(--bg-panel-alt); }
.sheet-table .proficient-row { color: var(--text); font-weight: 600; }
.sheet-table tr:not(.proficient-row) { color: var(--text-muted); }

.combat-stats { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; }
.stat-box, .slot-box {
    background: var(--bg-panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.9rem;
    text-align: center;
    flex: 1;
    transition: border-color 0.15s ease;
}
.stat-box:hover { border-color: var(--border-light); }
.stat-label { display: block; font-size: 0.75rem; color: var(--text-muted); }
.stat-value { display: block; font-size: 1.3rem; font-weight: 700; color: var(--accent); text-shadow: 0 0 12px var(--accent-glow); }

.hp-box { margin-bottom: 0.75rem; }
.hp-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; margin-top: 0.5rem; }
.hp-form label { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--text-muted); gap: 0.2rem; }
.hp-form input { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 0.4rem; width: 90px; }

.btn-secondary.small { width: auto; padding: 0.4rem 0.8rem; font-size: 0.85rem; display: inline-block; }

.checkbox-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.3rem 1rem; }
.checkbox-grid.three { grid-template-columns: repeat(3, 1fr); }
.checkbox-grid ul { list-style: none; margin: 0; padding: 0; display: contents; }
.checkbox-grid li { display: flex; align-items: center; gap: 0.4rem; }

.slot-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0.75rem 0; }
.slot-box { min-width: 90px; }
.slot-actions { display: flex; gap: 0.5rem; justify-content: center; margin-top: 0.3rem; font-size: 0.8rem; }
.slot-input { display: inline-flex; flex-direction: column; font-size: 0.75rem; color: var(--text-muted); margin: 0.2rem 0.4rem 0.2rem 0; }
.slot-input input { width: 50px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); }

details { margin-top: 0.75rem; }
details summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; }
.inline-add-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.6rem; }
.inline-add-form input[type="text"],
.inline-add-form input[type="number"],
.inline-add-form select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.4rem 0.5rem;
    font-size: 0.9rem;
}
.inline-add-form label { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.3rem; }

.qty-input { width: 55px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; color: var(--text); padding: 0.2rem; }

.notes-block { white-space: pre-wrap; background: var(--bg-panel-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; }

/* --- Dés & journal des jets (Phase 4) --- */
.private-toggle {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.action-cell { display: flex; gap: 0.6rem; align-items: center; white-space: nowrap; }

.quick-dice-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.75rem; }

.roll-log { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.roll-entry {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 1rem;
}
.roll-entry-header { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.roll-time { margin-left: auto; font-size: 0.75rem; }
.roll-entry-label { font-weight: 600; margin-top: 0.15rem; }
.roll-entry-formula { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

.roll-entry.roll-critical { border-color: var(--success); }
.roll-entry.roll-fumble { border-color: var(--danger); }

.roll-banner {
    margin-top: 0.5rem;
    padding: 0.4rem 0.7rem;
    border-radius: var(--radius);
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.03em;
}
.roll-banner-critical { background: rgba(76, 122, 74, 0.25); color: #bfe0bd; }
.roll-banner-fumble { background: rgba(165, 67, 58, 0.25); color: #f0c2bc; }

/* --- Combat (Phase 5) --- */
.combat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}
.combat-table tr.active-turn {
    background: rgba(179, 130, 63, 0.15);
    outline: 1px solid var(--accent);
}
.combat-table tr.hidden-combatant { opacity: 0.6; }
.hp-inline { display: inline-flex; align-items: center; gap: 0.3rem; }
.init-edit { display: inline-block; margin-left: 0.4rem; }
.init-edit summary { font-size: 0.8rem; }
.init-edit .inline-form { display: flex; gap: 0.3rem; margin-top: 0.3rem; }

/* --- Table virtuelle : carte & tokens (Phase 6) --- */
.map-canvas {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 1rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    touch-action: none;
    background: var(--bg-panel);
}
.map-image { display: block; width: 100%; height: auto; user-select: none; pointer-events: none; }

.map-grid-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(to right, rgba(233, 224, 212, 0.15) 0 1px, transparent 1px calc(100% / var(--grid-cells))),
        repeating-linear-gradient(to bottom, rgba(233, 224, 212, 0.15) 0 1px, transparent 1px calc(100% / var(--grid-cells)));
}

.token {
    position: absolute;
    aspect-ratio: 1 / 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--accent);
    background: var(--bg-panel-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}
.token img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.token-fallback { font-size: 1.1rem; }
.token.token-movable { cursor: grab; }
.token.token-movable.dragging { cursor: grabbing; border-color: var(--success); z-index: 10; }
.token.token-hidden { opacity: 0.5; border-style: dashed; }

.monster-portrait { max-width: 220px; border-radius: var(--radius); border: 1px solid var(--border); margin: 0.5rem 0 1rem; display: block; }

/* --- Recherche/filtre en liste (amélioration) --- */
.list-filter {
    width: 100%;
    max-width: 320px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem 0.75rem;
    margin: 0.75rem 0;
    font-size: 0.95rem;
}
.campaign-item.filtered-out { display: none; }

/* --- Descriptions dépliables attaques/sorts (amélioration) --- */
.row-description-toggle { cursor: pointer; }
.row-hidden { display: none; }
.row-description {
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: pre-wrap;
    border-top: none;
}

/* --- Combat : combattant ayant déjà joué ce round (amélioration) --- */
.combat-table tr.acted-turn { opacity: 0.55; }
.combat-table tr.acted-turn td:nth-child(2)::after { content: " ✓"; color: var(--success); }

/* --- Animation de jet de dé (amélioration) --- */
.dice-roll-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 8, 7, 0.55);
    backdrop-filter: blur(3px);
    z-index: 1000;
    opacity: 0;
    animation: dice-overlay-in 0.2s ease forwards;
}
.dice-roll-overlay.dice-roll-leaving { animation: dice-overlay-out 0.35s ease forwards; }

.dice-die {
    position: relative;
    width: 150px;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--bg-panel-alt) 0%, var(--bg-panel) 100%);
    border: 3px solid var(--accent);
    box-shadow: var(--shadow-lg), 0 0 0 6px rgba(179, 130, 63, 0.12);
    border-radius: 22px;
    transform: translateY(-260px) scale(0.6);
    opacity: 0;
    animation: dice-drop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.dice-die.dice-die-landed {
    opacity: 1;
    animation: dice-land 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.dice-die.dice-die-critical { border-color: var(--success); box-shadow: var(--shadow-lg), 0 0 26px rgba(76, 122, 74, 0.65); }
.dice-die.dice-die-fumble { border-color: var(--danger); box-shadow: var(--shadow-lg), 0 0 26px rgba(165, 67, 58, 0.65); }

/* Silhouettes approximatives par type de dé — purement décoratif, CSS pur */
.dice-die.dice-shape-4 { clip-path: polygon(50% 6%, 96% 92%, 4% 92%); border-radius: 8px; }
.dice-die.dice-shape-8 { clip-path: polygon(50% 2%, 98% 50%, 50% 98%, 2% 50%); border-radius: 6px; }
.dice-die.dice-shape-10, .dice-die.dice-shape-100 { clip-path: polygon(50% 2%, 96% 36%, 80% 96%, 20% 96%, 4% 36%); border-radius: 6px; }
.dice-die.dice-shape-12 { clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0% 50%); border-radius: 6px; }
.dice-die.dice-shape-20 { clip-path: polygon(30% 2%, 70% 2%, 98% 30%, 98% 70%, 70% 98%, 30% 98%, 2% 70%, 2% 30%); border-radius: 6px; }

.dice-die-number {
    font-family: var(--font-heading);
    font-size: 2.9rem;
    font-weight: 700;
    color: var(--text);
}
.dice-die-breakdown {
    position: absolute;
    bottom: -1.7rem;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.dice-die-formula {
    position: absolute;
    bottom: -3.4rem;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.dice-die-badge {
    position: absolute;
    top: -1.9rem;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.dice-die-badge.critical { color: var(--success); }
.dice-die-badge.fumble { color: var(--danger); }

@keyframes dice-drop {
    0%   { transform: translateY(-260px) scale(0.6); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes dice-land {
    0%   { transform: scale(1.15); opacity: 1; }
    60%  { transform: scale(0.95); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes dice-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes dice-overlay-out {
    from { opacity: 1; }
    to { opacity: 0; }
}
