/* ═══════════════════════════════════════════
   PAWN Arena — une salle d'analyse, la nuit
═══════════════════════════════════════════ */

:root {
  --ink: #172031;        /* fond */
  --panel: #1f2a3e;      /* panneau */
  --line: #2c3a53;       /* séparations */
  --chalk: #eef1f6;      /* texte */
  --muted: #93a0b5;      /* texte secondaire */
  --sq-light: #dde3ec;   /* cases claires */
  --sq-dark: #7c8da6;    /* cases foncées */
  --last: rgba(240, 195, 90, .42); /* dernier coup */

  /* couleurs des actions (tableau + plateau) */
  --capture: #e9705f;
  --check: #f0c35a;
  --castle: #5bbfb2;
  --promotion: #a895f5;
  --mate: #ff4f6a;

  --move: cubic-bezier(.65, 0, .35, 1);  /* déplacement sur l'écran */
  --out: cubic-bezier(.23, 1, .32, 1);   /* réponse à une action */
  --font: "Bricolage Grotesque", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--ink); color-scheme: dark; }
body {
  min-height: 100vh; font-family: var(--font); color: var(--chalk);
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
button, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--check); outline-offset: 2px; }

/* ── En-tête ── */
.top {
  display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 16px 32px;
  padding: 28px clamp(16px, 4vw, 48px) 0;
}
h1 { font-size: clamp(2rem, 4vw, 3rem); font-weight: 700; letter-spacing: -.02em; line-height: 1; font-variation-settings: "opsz" 96; }
.setup { display: flex; gap: 14px; flex-wrap: wrap; }
.setup label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); }
select {
  appearance: none; min-width: 190px; padding: 9px 34px 9px 12px; border-radius: 10px;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2393a0b5' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--line); font-size: .92rem; cursor: pointer;
}

/* ── Mise en page ── */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
  gap: clamp(20px, 3vw, 40px); padding: 24px clamp(16px, 4vw, 48px) 16px; align-items: start;
}
.board-zone { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.board-wrap { position: relative; width: min(100%, calc(100vh - 200px), 720px); aspect-ratio: 1; }

/* ── Échiquier ── */
.board {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 6px; overflow: hidden; touch-action: none; user-select: none;
  box-shadow: 0 0 0 1px rgba(255,255,255,.06), 0 30px 60px -20px rgba(0,0,0,.6);
}
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::after { content: ""; position: absolute; inset: 0; background: var(--last); }
.sq.selected::after { content: ""; position: absolute; inset: 0; background: rgba(91, 191, 178, .45); }
.sq.in-check { background-image: radial-gradient(circle, rgba(255, 79, 106, .9) 0, rgba(255, 79, 106, .45) 45%, transparent 72%); }
.sq.peek { box-shadow: inset 0 0 0 3px var(--check); }
/* coups possibles : un point, un anneau si c'est une prise */
.sq.target::before { content: ""; position: absolute; inset: 37%; border-radius: 50%; background: rgba(23, 32, 49, .32); z-index: 1; }
.sq.target.take::before { inset: 4%; background: none; box-shadow: inset 0 0 0 5px rgba(23, 32, 49, .32); }
.sq.hover-drop { box-shadow: inset 0 0 0 3px rgba(23, 32, 49, .45); }
/* coordonnées */
.coord { position: absolute; font-size: clamp(.55rem, 1.3vw, .72rem); font-weight: 700; pointer-events: none; }
.coord.file { right: 4px; bottom: 2px; }
.coord.rank { left: 4px; top: 2px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

/* pièces : un calque au-dessus des cases, déplacées avec transform */
.piece {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
  background-size: 100%; z-index: 2; cursor: grab;
  transition: transform 240ms var(--move), opacity 160ms ease-out;
  will-change: transform;
}
.piece.dragging { transition: none; z-index: 5; cursor: grabbing; filter: drop-shadow(0 8px 10px rgba(0,0,0,.35)); }
.piece.captured { opacity: 0; transform: var(--at) scale(.85) !important; pointer-events: none; }
.piece.entering { opacity: 0; }

/* choix de la promotion */
.promo {
  position: absolute; z-index: 10; width: 12.5%; display: flex; flex-direction: column;
  background: var(--chalk); border-radius: 8px; overflow: hidden;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
  transform-origin: top center; animation: pop 160ms var(--out);
}
.promo.from-bottom { transform-origin: bottom center; }
.promo button { aspect-ratio: 1; border: 0; background: transparent center / 88% no-repeat; cursor: pointer; transition: background-color 120ms ease; }
.promo button:hover { background-color: #c9d2df; }
@keyframes pop { from { opacity: 0; transform: scale(.95); } }

/* ── Vue 3D ── */
.board-wrap.is-3d { aspect-ratio: 5 / 4; width: min(100%, calc((100vh - 200px) * 1.25), 900px); }
.board-wrap.is-3d .board { display: none; }
.board3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: 14px; touch-action: none; cursor: pointer; }

/* ══ 3D en plein écran : le plateau occupe toute la page, l'interface flotte par-dessus ══ */
body.mode-3d { overflow: hidden; height: 100vh; }
body.mode-3d .board-wrap.is-3d { position: fixed; inset: 0; width: auto; aspect-ratio: auto; z-index: 0; }
body.mode-3d .board3d { border-radius: 0; }
body.mode-3d .top { position: relative; z-index: 2; pointer-events: none; }
body.mode-3d .top > * { pointer-events: auto; }
body.mode-3d .layout { display: block; padding: 0; }
body.mode-3d .log {
  position: fixed; z-index: 2; right: clamp(16px, 2.5vw, 40px); top: 128px; bottom: 44px; width: min(400px, 32vw);
  max-height: none; background: rgba(31, 42, 62, .78); backdrop-filter: blur(16px) saturate(1.2);
}
/* le conteneur s'efface : chaque élément flotte seul (sinon le plateau passerait devant) */
body.mode-3d .board-zone { display: contents; }
body.mode-3d .status-wrap, body.mode-3d .controls, body.mode-3d .hint {
  position: fixed; z-index: 2; left: 0; right: calc(min(400px, 32vw) + clamp(16px, 2.5vw, 40px));
  margin: 0 auto; width: max-content; max-width: 100%;
}
body.mode-3d .status-wrap { bottom: 84px; }
body.mode-3d .controls { bottom: 34px; }
body.mode-3d .hint { bottom: 10px; }
body.mode-3d .status { text-shadow: 0 2px 12px rgba(0, 0, 0, .6); }
body.mode-3d .controls button { background: rgba(31, 42, 62, .8); backdrop-filter: blur(10px); }
body.mode-3d .credits { position: fixed; z-index: 2; right: clamp(16px, 2.5vw, 40px); bottom: 10px; width: min(400px, 32vw); padding: 0; font-size: .66rem; line-height: 1.35; }
body.mode-3d .promo { width: 76px; }
body.demo-on .controls, body.demo-on .status { opacity: .4; pointer-events: none; }
.only-3d { display: none; }
body.mode-3d .only-3d { display: inline-block; }

/* menu des animations */
.demo-menu {
  margin: 0; inset: auto; position: fixed; padding: 6px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  flex-direction: column; gap: 2px; min-width: 210px;
}
.demo-menu:popover-open { display: flex; animation: pop 160ms var(--out); transform-origin: bottom left; }
.demo-menu button { border: 0; background: transparent; text-align: left; padding: 9px 12px; border-radius: 8px; }
@media (hover: hover) and (pointer: fine) { .demo-menu button:hover { background: rgba(255, 255, 255, .06); } }

/* ── En-tête : la description du modèle choisi ── */
.top { row-gap: 6px; }
.model-info { flex-basis: 100%; text-align: right; font-size: .82rem; color: var(--muted); min-height: 1.2em; }
#level-field[hidden] { display: none; }
body.mode-3d .top { padding-bottom: 0; }

/* ── Chargement d'un modèle et réflexion de l'IA ── */
.status-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.progress { width: 180px; height: 3px; border-radius: 3px; background: rgba(147, 160, 181, .25); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--chalk); transform-origin: left; transform: scaleX(0); transition: transform 200ms ease-out; }
body.thinking .status::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 10px; border-radius: 50%; background: var(--check); vertical-align: middle; animation: think 1s ease-in-out infinite; }
@keyframes think { 50% { opacity: .25; transform: scale(.7); } }
.hint { font-size: .74rem; color: #6c7a91; text-align: center; }
.mv.ai .san::after { content: "IA"; margin-left: auto; font-size: .6rem; font-weight: 500; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* ── Statut et boutons ── */
.status { min-height: 1.4em; font-size: 1.05rem; font-weight: 500; text-align: center; }
.status.alert { color: var(--check); }
.status.over { color: var(--mate); font-weight: 700; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
button {
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  font-size: .9rem; font-weight: 500; cursor: pointer;
  transition: transform 140ms var(--out), background-color 140ms ease, border-color 140ms ease;
}
button:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) { button:hover { border-color: #3d4e6c; background: #25324a; } }
button.primary { background: var(--chalk); color: var(--ink); border-color: var(--chalk); font-weight: 700; }
@media (hover: hover) and (pointer: fine) { button.primary:hover { background: #fff; } }

/* ── Tableau des coups ── */
.log {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; max-height: calc(100vh - 150px); min-height: 360px;
}
.log-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 18px 10px; }
h2 { font-size: 1.3rem; font-weight: 700; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 0 18px 12px; font-size: .78rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.tag { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tag.capture { background: var(--capture); }
.tag.check { background: var(--check); }
.tag.castle { background: var(--castle); }
.tag.promotion { background: var(--promotion); }
.tag.mate { background: var(--mate); box-shadow: 0 0 0 3px rgba(255, 79, 106, .25); }

.table-scroll { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); scrollbar-width: thin; scrollbar-color: #3a4a66 transparent; }
.moves { width: 100%; border-collapse: collapse; table-layout: fixed; }
.moves th {
  position: sticky; top: 0; z-index: 1; background: var(--panel);
  text-align: left; font-size: .78rem; font-weight: 500; color: var(--muted);
  padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.moves th.num, .moves td.num { width: 44px; text-align: right; padding-right: 10px; color: var(--muted); }
.moves td { padding: 7px 12px; vertical-align: top; border-bottom: 1px solid rgba(44, 58, 83, .55); }
.moves tr.fresh td { animation: fresh 900ms ease-out; }
@keyframes fresh { from { background: rgba(240, 195, 90, .14); } }
.mv { display: flex; flex-direction: column; gap: 2px; border-left: 3px solid transparent; padding-left: 8px; margin-left: -11px; border-radius: 2px; cursor: default; }
.mv.capture { border-color: var(--capture); }
.mv.check { border-color: var(--check); }
.mv.castle { border-color: var(--castle); }
.mv.promotion { border-color: var(--promotion); }
.mv.mate { border-color: var(--mate); }
.san { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.san img { width: 18px; height: 18px; }
.meta { display: flex; gap: 10px; font-size: .74rem; color: var(--muted); }
.meta .up { color: #b9e3c6; }
.meta .down { color: #f2b3aa; }
.empty { padding: 18px; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.note { padding: 12px 18px 16px; border-top: 1px solid var(--line); font-size: .74rem; line-height: 1.45; color: var(--muted); }

.credits { padding: 10px clamp(16px, 4vw, 48px) 18px; font-size: .72rem; color: #6c7a91; }

/* ── Téléphone / écran étroit ── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .board-wrap { width: min(100%, 560px); }
  .log { max-height: none; }
  .table-scroll { max-height: 420px; }
}

@media (prefers-reduced-motion: reduce) {
  .piece { transition: opacity 120ms ease; }
  .moves tr.fresh td, .promo { animation: none; }
}

h1 .home-link { color: inherit; text-decoration: none; }
h1 .home-link:hover { color: var(--muted); }
