/* CHAINS & CROWNS — Interface */
:root {
    --bg: #0c0806;
    --panel: rgba(255, 240, 220, 0.04);
    --line: rgba(255, 220, 180, 0.12);
    --text: #f4ece0;
    --muted: #b6a690;
    --ember: #e8822a;
    --gold: #f2b34a;
    --imperial: #1f3b7a;
    --danger: #e4572e;
    --sq-light: #e6d3b3;
    --sq-dark: #5b3a26;
    --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: radial-gradient(ellipse at 50% 0%, #2a160c 0%, var(--bg) 60%) fixed;
    color: var(--text);
    font-family: "Space Grotesk", system-ui, sans-serif;
    min-height: 100vh;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; padding: 24px 16px 60px; }

/* ---------- Accueil ---------- */
#introScreen { display: grid; place-items: center; }
.intro { max-width: 680px; text-align: center; }
.kicker { color: var(--ember); letter-spacing: 4px; text-transform: uppercase; font-size: 12px; font-weight: 700; }
.title { font-family: "Permanent Marker", cursive; font-weight: 400; font-size: clamp(48px, 11vw, 96px); line-height: 1; margin: 12px 0 20px; }
.title .chains { color: var(--ember); }
.title .amp { color: var(--muted); font-size: 0.6em; }
.title .crowns { color: var(--text); }
.intro-text { color: var(--muted); line-height: 1.7; margin-bottom: 28px; }
.intro-text strong { color: var(--text); }
.intro-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; text-align: left; }
.intro-form label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.intro-form input, .intro-form select {
    background: #160e09; color: var(--text); border: 1px solid var(--line); border-radius: 10px;
    padding: 12px; font: inherit; font-size: 15px;
}
.intro-form .btn { grid-column: 1 / -1; }
.champion { margin-top: 18px; color: var(--gold); font-size: 14px; min-height: 1em; }
.history { margin-top: 24px; text-align: left; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; background: var(--panel); }
.history summary { cursor: pointer; font-weight: 700; color: var(--ember); }
.history ul { margin-top: 12px; padding-left: 18px; color: var(--muted); line-height: 1.8; font-size: 14px; }

.btn {
    background: var(--ember); color: #1a0d05; border: 0; border-radius: 10px; padding: 14px 22px;
    font: inherit; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; font-size: 13px; cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 0 24px rgba(232, 130, 42, 0.35); }
.btn:focus-visible, .square:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }

/* ---------- Jeu ---------- */
.hud { max-width: 1100px; margin: 0 auto 16px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; }
.hud-side { display: grid; gap: 6px; }
.hud-side.player { text-align: right; justify-items: end; }
.hud-label { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); }
.captured { display: flex; flex-wrap: wrap; gap: 2px; min-height: 28px; }
.captured svg { width: 26px; height: 26px; }
.hud-center { text-align: center; }
.chrono { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.info { color: var(--muted); font-size: 14px; min-height: 1.4em; }
.info.alert { color: var(--danger); font-weight: 700; }

.arena { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: start; }
.board-wrap { width: min(100%, 82vh); margin: 0 auto; }
.board {
    display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); aspect-ratio: 1;
    border: 6px solid #2a1a10; border-radius: 10px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--line);
}
.square { position: relative; display: grid; place-items: center; border: 0; padding: 0; cursor: pointer; background: var(--sq-light); min-width: 0; min-height: 0; overflow: hidden; }
.square.dark { background: var(--sq-dark); }
.square .coord { position: absolute; font-size: 10px; font-weight: 700; opacity: 0.55; pointer-events: none; }
.square .coord.file { bottom: 2px; right: 4px; }
.square .coord.rank { top: 2px; left: 4px; }
.square.dark .coord { color: var(--sq-light); }
.square:not(.dark) .coord { color: var(--sq-dark); }
.square.last::before { content: ""; position: absolute; inset: 0; background: rgba(242, 179, 74, 0.32); }
.square.selected::before { content: ""; position: absolute; inset: 0; background: rgba(232, 130, 42, 0.45); }
.square.target::after { content: ""; position: absolute; width: 26%; height: 26%; border-radius: 50%; background: rgba(20, 10, 4, 0.35); pointer-events: none; }
.square.target.capture::after { width: 86%; height: 86%; background: transparent; border: 5px solid rgba(20, 10, 4, 0.35); }
.square.check { box-shadow: inset 0 0 0 4px var(--danger), inset 0 0 30px rgba(228, 87, 46, 0.8); }

.piece-svg { width: 92%; height: 92%; position: relative; z-index: 1; pointer-events: none; overflow: visible; }

/* ---------- Animations des calques des sprites ---------- */
.flamme { animation: flicker 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes flicker { 0%, 100% { opacity: 0.85; transform: scale(1); } 50% { opacity: 1; transform: scale(1.08); } }

.square.selected .embleme { animation: bob 0.9s ease-in-out infinite; transform-box: fill-box; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.piece-svg.arrive { animation: arrive 0.32s cubic-bezier(.2, .8, .3, 1); }
@keyframes arrive { from { transform: translate(var(--dx), var(--dy)); } to { transform: translate(0, 0); } }

.piece-svg.captured-out { animation: shatter 0.35s ease-in forwards; }
@keyframes shatter { to { transform: scale(0.4) rotate(-20deg); opacity: 0; } }

.square.check .embleme { animation: alarm 0.6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes alarm { to { transform: rotate(-6deg); } }

@media (prefers-reduced-motion: reduce) {
    .flamme, .square.selected .embleme, .square.check .embleme, .piece-svg.arrive, .piece-svg.captured-out { animation: none; }
}

/* ---------- Panneau latéral ---------- */
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.side h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: 10px; }
.moves { max-height: 52vh; overflow-y: auto; padding-left: 26px; font-variant-numeric: tabular-nums; font-size: 14px; line-height: 1.9; }
.moves li span { display: inline-block; min-width: 64px; }
.side-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.side-actions .btn { flex: 1; padding: 12px; }

/* ---------- Modales ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 3, 2, 0.75); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: #160e09; border: 1px solid var(--line); border-radius: 18px; padding: 28px; text-align: center; max-width: 420px; width: 100%; }
.modal-box h2 { font-family: "Permanent Marker", cursive; font-weight: 400; font-size: 32px; margin-bottom: 14px; }
.promo-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.promo-choices button { background: var(--sq-light); border: 0; border-radius: 10px; aspect-ratio: 1; cursor: pointer; display: grid; place-items: center; }
.promo-choices button:hover { box-shadow: 0 0 0 3px var(--ember); }
.grade { font-family: "Permanent Marker", cursive; font-size: 96px; line-height: 1; color: var(--gold); }
.grade-label { color: var(--ember); font-weight: 700; margin-bottom: 12px; }
#endDetails { color: var(--muted); line-height: 1.6; }

.back-link { position: fixed; left: 16px; bottom: 14px; color: var(--muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--text); }

@media (max-width: 900px) {
    .arena { grid-template-columns: 1fr; }
    .board-wrap { width: 100%; }
    .moves { max-height: 180px; }
    .hud { grid-template-columns: 1fr 1fr; }
    .hud-center { grid-column: 1 / -1; grid-row: 1; }
}
@media (max-width: 520px) {
    .intro-form { grid-template-columns: 1fr; }
    .square .coord { font-size: 8px; }
    .board { border-width: 3px; }
}

/* ---------- Mode duel en ligne ---------- */
.intro-form .full { grid-column: 1 / -1; }
.search { display: grid; justify-items: center; gap: 18px; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--ember); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.note { color: var(--muted); font-size: 12px; line-height: 1.6; max-width: 520px; }
#searchScreen { display: grid; place-items: center; }
#searchScreen.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
