:root {
  /* Tons d'échiquier : parchemin, noyer, laiton. */
  --bg: #f2ece1;
  --panel: #fbf8f2;
  --text: #2b2118;
  --muted: #7b6d5c;
  --border: #e3d9c8;
  --accent: #5a3b23;
  --accent-hover: #472d19;
  --brass: #b8913f;
  --brass-soft: #f3e4bd;
  --wood: #4f321d;
  --wood-deep: #35200f;
  --ivory: #f6eedd;
  --p1: #a3262a;
  --p2: #1e3a72;
  --serif: "Cormorant Garamond", Garamond, Georgia, serif;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }

#app {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: 100vh;
}

#stage {
  position: relative; overflow: hidden;
  background: radial-gradient(ellipse at 50% 38%, #f8f3ea 0%, #ebe2d2 62%, #ddd1bb 100%);
}
#view3d { position: absolute; inset: 0; }
#view3d canvas { display: block; }

#viewbar {
  position: absolute; top: 12px; left: 12px;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  background: rgba(251, 248, 242, 0.88); padding: 6px; border-radius: 8px;
  border: 1px solid var(--border); box-shadow: 0 2px 8px rgba(53, 32, 15, 0.08);
}
#viewbar label { font-size: 13px; padding: 0 6px; }

#banner {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  background: var(--wood-deep); color: var(--ivory); padding: 10px 20px; border-radius: 8px;
  font-family: var(--serif); font-size: 22px; font-weight: 700; text-align: center;
  border: 1px solid var(--brass); box-shadow: 0 8px 24px rgba(53, 32, 15, 0.3);
}
#banner small { display: block; font-family: system-ui, sans-serif; font-size: 13px; font-weight: 400; opacity: 0.8; }

#tooltip {
  position: absolute; pointer-events: none; background: rgba(43, 33, 24, 0.94); color: var(--ivory);
  font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: pre-line; max-width: 240px;
}

#toast {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #8a1c1c; color: white; padding: 8px 14px; border-radius: 6px; font-size: 14px;
}

#panel {
  background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
#panel h1 { margin: 0 0 4px; font-family: var(--serif); font-size: 34px; font-weight: 700; letter-spacing: 0.5px; line-height: 1; }
#panel h2 {
  margin: 0 0 8px; font-family: var(--serif); font-size: 17px; font-weight: 700; font-variant: small-caps;
  color: var(--accent); letter-spacing: 0.8px;
}
section { border-top: 1px solid var(--border); padding-top: 12px; }

#status { font-weight: 600; display: flex; align-items: center; gap: 8px; }
#scores { margin-top: 6px; font-size: 14px; color: var(--muted); }
#scores b { color: var(--text); }

.form { display: grid; gap: 6px; margin-bottom: 8px; }
/* minmax(0, …) : un long libellé d'adversaire ne doit pas élargir le panneau (débordement sur téléphone). */
.form label { display: grid; grid-template-columns: 110px minmax(0, 1fr); align-items: center; font-size: 14px; }
.form select, .form input { min-width: 0; }
.form label.sub { margin-top: -2px; color: var(--muted); }
.form label.sub span { padding-left: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.grow { flex: 1; display: flex; align-items: center; gap: 6px; font-size: 13px; }
.grow input { flex: 1; accent-color: var(--accent); }
.muted { color: var(--muted); font-size: 14px; }

button, .button, select, input[type=number] {
  font: inherit; font-size: 14px; padding: 5px 10px; border-radius: 6px;
  border: 1px solid #dccfb9; background: #fffdf8; color: var(--text);
}
button, .button { cursor: pointer; }
a.button { text-decoration: none; }
button:hover, .button:hover { background: #f3ebdc; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--ivory); }
button.primary:hover { background: var(--accent-hover); }
button.active { background: var(--wood-deep); color: var(--ivory); border-color: var(--wood-deep); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.p1 { background: var(--p1); }
.dot.p2 { background: var(--p2); }

.replay input { flex: 1; min-width: 0; accent-color: var(--accent); }
#history {
  margin: 8px 0 0; padding: 0; list-style: none; max-height: 260px; overflow-y: auto;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; font-family: ui-monospace, Consolas, monospace; font-size: 13px;
}
#history li { padding: 2px 6px; border-radius: 4px; cursor: pointer; }
#history li:hover { background: #f3ebdc; }
#history li.p1 { color: var(--p1); }
#history li.p2 { color: var(--p2); }
#history li.current { background: var(--brass-soft); }

#selection .attack { color: #b4520f; font-weight: 600; }

/* --- Vue 2D : un échiquier en marqueterie ------------------------------------------------------ */
#view2d {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 64px 12px 12px;
  container-type: size;
}
.board2d {
  /* Côté des cases : le plateau entier (cadre, sorties, coordonnées) tient dans la vue. */
  --s: min(100cqw - 44px, 100cqh - 96px);
  display: grid; grid-template-columns: 16px var(--s); grid-template-rows: 22px var(--s) 22px 14px;
  grid-template-areas: ". exit-top" "ranks cells" ". exit-bottom" ". files";
  gap: 5px 6px; padding: 9px 14px 7px 8px; border-radius: 10px;
  background: linear-gradient(150deg, var(--wood) 0%, var(--wood-deep) 100%);
  box-shadow: 0 14px 34px rgba(53, 32, 15, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.board2d .exit-top { grid-area: exit-top; }
.board2d .exit-bottom { grid-area: exit-bottom; }
.cells2d {
  grid-area: cells; position: relative; display: grid;
  outline: 1px solid var(--brass); outline-offset: 2px;  /* filet de laiton autour des cases */
}
.ranks2d, .files2d {
  display: grid; font-family: var(--serif); font-size: 13px; font-weight: 600; color: var(--ivory); opacity: 0.75;
  place-items: center;
}
.ranks2d { grid-area: ranks; }
.files2d { grid-area: files; }

.cell2d {
  position: relative; cursor: pointer; display: flex; align-items: center; justify-content: center;
  /* Couleur de hauteur (style) × fil du bois, horizontal ou vertical en damier comme une marqueterie. */
  background-size: cover; background-blend-mode: multiply; color: var(--text);
}
.cell2d.grain-h { background-image: var(--grain-h); }
.cell2d.grain-v { background-image: var(--grain-v); }
.cell2d.dark { color: var(--ivory); }
.cell2d .h { position: absolute; top: 1px; left: 3px; font-family: var(--serif); font-size: 12px; font-weight: 700; opacity: 0.8; }
.cell2d svg { width: 70%; height: 70%; filter: drop-shadow(0 1px 1.5px rgba(30, 15, 5, 0.55)); }
.cell2d.last { box-shadow: inset 0 0 0 3px #e2bd4f; }
.cell2d.selected { box-shadow: inset 0 0 0 3px var(--ivory), inset 0 0 0 5px var(--wood-deep); }
.cell2d.move::after {
  content: ""; position: absolute; width: 34%; height: 34%; border-radius: 50%; background: var(--marker); opacity: 0.75;
  box-shadow: 0 0 0 2px rgba(246, 238, 221, 0.8);
}
.cell2d.attack { box-shadow: inset 0 0 0 4px #e0701a; }

/* Dénivelés entre cases voisines, comme des courbes de niveau : trait fin = 1, trait épais = 2 (le maximum). */
.steps2d { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; fill: none; }
.steps2d .seam { stroke: rgba(40, 24, 10, 0.2); stroke-width: 0.015; }
.steps2d .step1 { stroke: rgba(36, 20, 8, 0.72); stroke-width: 0.05; stroke-linecap: round; }
.steps2d .step2 { stroke: #1f1108; stroke-width: 0.13; stroke-linecap: round; }

.exit2d {
  border-radius: 4px; font-family: var(--serif); font-size: 14px; font-weight: 600; letter-spacing: 0.5px;
  color: rgba(246, 238, 221, 0.7); display: flex; align-items: center; justify-content: center;
  border: 1px dashed rgba(184, 145, 63, 0.55);
}
.exit2d.active { background: var(--marker); color: white; border: 1px solid var(--brass); cursor: pointer; }

/* Légende du terrain, sous le score. */
#legend { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 6px; font-size: 13px; color: var(--muted); }
#legend span { display: inline-flex; align-items: center; gap: 5px; }
#legend .ramp { width: 56px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(53, 32, 15, 0.25); }
#legend svg { width: 24px; height: 12px; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
  #stage { height: 60vh; }
  #panel { border-left: none; border-top: 1px solid var(--border); }
  /* Barre de vue sur une seule ligne, pour ne pas couvrir le haut du plateau. */
  #viewbar { top: 8px; left: 8px; gap: 4px; padding: 4px; }
  #viewbar button { font-size: 13px; padding: 4px 8px; }
  #view2d { padding-top: 48px; }
}
