/* Six Coups d'Œil : coquille de l'application (écrans autour du jeu).
   Style « papier découpé » de src/render/art/style.js : aplats, contour crème épais, ombre
   portée décalée, tons de la palette « ocre ». Les couleurs réservées du jeu (rouge menace
   #e63b2e, or des bonus #ffc933, cyan du joueur #35d0e0) ne servent pas à l'interface. */

:root {
  --cream: #f6ecd2;
  --ink: #2a1c16;
  --paper: #4a3328;
  --paper-2: #5c4132;
  --near: #6b4a34;
  --mid: #a8683f;
  --sand: #e8c98a;
  --accent: #2f7f86;
  --accent-2: #3a949b;
  --warn: #d9893a;
  --danger: #8a3324;
  --shadow: rgba(20, 12, 10, 0.38);
  --slab: "Rockwell", "Roboto Slab", "Courier New", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --fs: clamp(15px, calc(0.5vw + 0.62vh + 3.2px), 21px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #3b2a24;
  color: var(--cream);
  font: 400 var(--fs)/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------ chargement */

.boot {
  position: absolute;
  left: 0;
  right: 0;
  top: 44%;
  margin: 0;
  padding: 0 1em;
  text-align: center;
  font: 700 1.5em/1.3 var(--slab);
  text-shadow: 3px 4px 0 var(--shadow);
}
.boot-slow { top: 56%; font: 400 1em/1.4 var(--sans); opacity: 0; animation: reveal 0s linear 12s forwards; }
.boot-error { top: 50%; color: var(--cream); }
/* page ouverte comme un fichier (file://) : index.html le repère, on dit quoi faire à la place */
.boot-file { display: none; top: 40%; font: 400 1.05em/1.5 var(--sans); }
.boot-file strong { font-family: var(--slab); font-size: 1.35em; display: block; margin-bottom: 0.5em; }
.boot-file code { font: 700 1em var(--slab); background: rgba(42, 28, 22, 0.6); padding: 0.1em 0.4em; border-radius: 4px; }
.from-file .boot-file { display: block; }
.from-file .boot:not(.boot-file) { display: none; }
@keyframes reveal { to { opacity: 1; } }

/* ------------------------------------------------------------------ écrans et panneaux */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.4vw;
  padding: 3vh 3vw;
  pointer-events: auto;
  overflow: auto;
  animation: appear 0.22s ease-out;
}
.veil-soft { background: rgba(42, 28, 22, 0.38); }
.veil-strong { background: rgba(42, 28, 22, 0.62); }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }

.panel {
  position: relative;
  background: var(--paper);
  color: var(--cream);
  border: 4px solid var(--cream);
  border-radius: 8px;
  box-shadow: 7px 9px 0 var(--shadow);
  padding: clamp(14px, 2.6vh, 30px) clamp(16px, 2.2vw, 36px);
  max-width: min(92vw, 1120px);
  max-height: 94vh;
  overflow: auto;
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { transform: translateY(10px); } to { transform: none; } }

h1, h2, h3 { font-family: var(--slab); font-weight: 700; margin: 0 0 0.45em; line-height: 1.1; }
h2 { font-size: 1.85em; }
h3 { font-size: 1.12em; }
p { margin: 0 0 0.7em; }
.lead { font-size: 1.08em; }
.strong { font-weight: 700; }
.hint { font-size: 0.9em; opacity: 0.85; }
.notice { font-size: 0.95em; color: var(--sand); min-height: 1.3em; }
.notice:empty { min-height: 0; margin: 0; }
.note { font-size: 1em; padding: 0.6em 0.8em; border: 2px dashed rgba(246, 236, 210, 0.5); border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ boutons */

.actions { display: flex; flex-wrap: wrap; gap: 0.6em; margin-top: 1em; align-items: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  font: 700 1em/1.15 var(--slab);
  color: var(--cream);
  background: var(--near);
  border: 3px solid var(--cream);
  border-radius: 6px;
  padding: 0.6em 1em;
  box-shadow: 4px 5px 0 var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background-color 0.15s ease;
}
.btn:hover:not(:disabled) { background: #7e5a40; }
.btn:active:not(:disabled) { transform: translate(2px, 3px); box-shadow: 2px 2px 0 var(--shadow); }
.btn-primary { background: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-quiet { background: rgba(42, 28, 22, 0.35); border-color: rgba(246, 236, 210, 0.6); box-shadow: none; }
.btn-quiet:hover:not(:disabled) { background: rgba(42, 28, 22, 0.6); }
.btn-danger { background: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #9c3c2b; }
.btn-small { font-size: 0.9em; padding: 0.45em 0.8em; }
.btn-big { font-size: 1.35em; padding: 0.7em 1.2em; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-hint {
  font: 600 0.68em/1 var(--sans);
  border: 1.5px solid currentColor;
  border-radius: 4px;
  padding: 0.2em 0.4em;
  opacity: 0.8;
}

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--sand); outline-offset: 3px; }
.btn:focus-visible { outline: 3px solid var(--sand); outline-offset: 3px; box-shadow: 0 0 0 3px var(--ink), 4px 5px 0 var(--shadow); }

input[type="text"] {
  font: 700 1.2em/1.2 var(--slab);
  color: var(--ink);
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 6px;
  padding: 0.4em 0.6em;
  width: 100%;
  min-width: 0;
}
input[type="text"]:focus-visible { outline: 3px solid var(--sand); outline-offset: 2px; }
input[type="radio"], input[type="checkbox"], input[type="range"] { accent-color: var(--accent); }
input[type="radio"], input[type="checkbox"] { width: 1.15em; height: 1.15em; margin: 0; }

/* ------------------------------------------------------------------ titre */

.screen-title { justify-content: flex-start; padding-left: 6vw; }
.panel-title {
  max-width: min(46vw, 640px);
  background: rgba(74, 51, 40, 0.94);
  transform: rotate(-0.8deg);
  padding-top: clamp(22px, 4.2vh, 44px);
}
.game-title {
  font-size: clamp(46px, 6.3vw, 108px);
  line-height: 0.92;
  margin: 0 0 0.18em;
  text-shadow: 4px 5px 0 var(--shadow);
}
.game-title .t-oeil { color: var(--sand); }
.pitch { font-size: 1.15em; max-width: 30em; }
.menu { display: grid; gap: 0.7em; margin: 1.1em 0 0.9em; justify-items: start; }
.menu .btn { min-width: 15em; justify-content: space-between; }
.menu .btn-small { min-width: 0; }
.menu-row { display: flex; flex-wrap: wrap; gap: 0.55em; }
.privacy { font-size: 0.86em; opacity: 0.85; margin: 0; max-width: 32em; }

.panel-top3 {
  position: absolute;
  right: 5vw;
  bottom: 7vh;
  width: min(380px, 30vw);
  transform: rotate(1.2deg);
  padding: 0.9em 1.2em;
}
.panel-top3 h2 { font-size: 1.2em; }
.top3 { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35em; }
.top3 li { display: grid; grid-template-columns: 1.8em minmax(0, 1fr) auto; gap: 0.6em; align-items: center; }
.top3 .pos { font: 700 0.95em/1.8em var(--slab); text-align: center; background: var(--cream); color: var(--ink); border-radius: 50%; width: 1.8em; height: 1.8em; }
.top3 .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.top3 .pts { font: 700 1em var(--slab); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ caméra */

.panel-camera { max-width: min(92vw, 720px); }
.steps { list-style: none; margin: 1em 0; padding: 0; display: grid; gap: 0.45em; }
.step { display: flex; align-items: center; gap: 0.7em; opacity: 0.55; }
.step.active, .step.done { opacity: 1; }
.step .mark {
  width: 1.4em;
  height: 1.4em;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--cream);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 700 0.85em/1 var(--sans);
}
.step.done .mark { background: var(--accent); }
.step.done .mark::before { content: "✓"; }
.step.active .mark { border-color: var(--sand) transparent var(--sand) transparent; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error {
  background: var(--danger);
  border: 3px solid var(--cream);
  border-radius: 6px;
  padding: 0.8em 1em;
  margin: 0.8em 0;
}
.error h3 { margin-bottom: 0.3em; }
.error p { margin: 0; }

/* ------------------------------------------------------------------ placement */

.panel-placement { max-width: min(94vw, 1040px); width: min(94vw, 1040px); }
.placement { display: grid; grid-template-columns: minmax(240px, 1.05fr) minmax(240px, 1fr); gap: 1.4em; align-items: start; }
.preview-wrap { position: relative; }
.preview {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  max-height: 46vh;
  object-fit: contain;
  background: #3b2a24;
  border: 4px solid var(--cream);
  border-radius: 6px;
  box-shadow: 5px 6px 0 var(--shadow);
}
.checks { list-style: none; margin: 0 0 0.6em; padding: 0; display: grid; gap: 0.45em; }
.check { display: flex; align-items: flex-start; gap: 0.6em; }
.check .icon {
  flex: none;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 800 0.9em/1 var(--sans);
  color: var(--cream);
  background: #7a6a5a;
  border: 2px solid var(--cream);
}
.check.ok .icon { background: var(--accent); }
.check.warn .icon { background: var(--warn); color: var(--ink); }
.check.bad .icon { background: var(--danger); }
.check.warn { color: #ffe2b8; }
.fs-note { font-size: 0.92em; margin-top: 0.9em; padding: 0.5em 0.8em; border-left: 4px solid var(--sand); background: rgba(42, 28, 22, 0.35); }

/* ------------------------------------------------------------------ étalonnage */

.screen-calibration { pointer-events: none; }
.screen-calibration .panel { pointer-events: auto; max-width: min(92vw, 620px); text-align: center; }
.screen-calibration .actions { justify-content: center; }
.chip {
  margin: 0;
  font-size: 0.88em;
  padding: 0.35em 0.9em;
  border-radius: 999px;
  background: rgba(42, 28, 22, 0.72);
  border: 2px solid rgba(246, 236, 210, 0.55);
  color: var(--cream);
}
.chip-corner { position: absolute; left: 2vw; bottom: 2.5vh; opacity: 0.8; }

/* ------------------------------------------------------------------ partie */

.screen-play { pointer-events: none; padding: 0; display: block; animation: none; }
.corner { position: absolute; top: 10px; right: 12px; display: flex; gap: 8px; pointer-events: auto; transition: opacity 0.3s ease; }
.corner .btn { font-size: 0.82em; background: rgba(42, 28, 22, 0.55); }
/* mention passagère : sous la ligne des consignes du HUD (CAPTION, y = 130 ± 33 dans le terrain
   1600 × 900, hud-layout.js), au bord droit du terrain, à l'échelle de celui-ci : jamais sur la
   consigne « Regarde chaque étoile… » ni sur les jetons du coin haut droit */
.chip-note {
  --field: min(100vw / 1600, 100vh / 900);
  position: absolute;
  top: calc((100vh - 900 * var(--field)) / 2 + 176 * var(--field));
  right: calc((100vw - 1600 * var(--field)) / 2 + 12px);
  max-width: min(32em, 46vw);
  pointer-events: none;
}
body.cursor-idle #stage { cursor: none; }
body.cursor-idle .corner { opacity: 0; }
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3vh 3vw;
  background: rgba(42, 28, 22, 0.55);
  pointer-events: auto;
  animation: appear 0.15s ease-out;
}
.panel-pause { max-width: min(92vw, 680px); text-align: center; }
.panel-pause .actions { justify-content: center; }
.slack { font-size: 0.92em; color: var(--sand); }
.slack.low { color: #ffd08a; font-weight: 700; }

.panel-small { max-width: 520px; text-align: center; }
.big-line { font: 700 1.4em/1.3 var(--slab); margin: 0; }
.panel-ready { max-width: min(92vw, 620px); text-align: center; }
.panel-ready .actions { justify-content: center; }

/* ------------------------------------------------------------------ fin de partie */

.screen-over { flex-wrap: wrap; align-content: center; align-items: flex-start; }
/* largeurs en em : elles suivent la taille du texte (--fs grandit avec l'écran) */
.panel-over { flex: 0 1 34em; min-width: 0; }
.panel-over-board { flex: 0 1 37em; min-width: 0; display: flex; flex-direction: column; }
.final-score { display: flex; align-items: baseline; gap: 0.6em; margin: 0.2em 0 0.5em; }
.final-score .label { font: 700 0.9em var(--sans); text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
.final-score .value { font: 700 3.1em/1 var(--slab); font-variant-numeric: tabular-nums; text-shadow: 3px 4px 0 var(--shadow); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4em 1.2em; margin: 0 0 0.8em; }
.stats .wide { grid-column: 1 / -1; }
.stats dt { font-size: 0.8em; opacity: 0.75; }
.stats dd { margin: 0; font: 700 1.05em var(--slab); }
.submit { display: grid; gap: 0.35em; }
.submit label { font-weight: 700; }
.name-row { display: flex; align-items: center; gap: 0.6em; }
.count { font: 600 0.85em var(--sans); opacity: 0.8; min-width: 3.2em; text-align: right; }
.count.over { color: #ffd08a; opacity: 1; }
.field-error { color: #ffd08a; font-weight: 600; margin: 0; min-height: 1.3em; font-size: 0.92em; }
.submit .actions { margin-top: 0.2em; }
.submit-result p { margin: 0.4em 0 0; }
.submit-result .result-main { font: 700 1.08em var(--slab); }

/* ------------------------------------------------------------------ classement */

.panel-board { max-width: min(94vw, 760px); width: min(94vw, 760px); }
.panel-over-board { width: auto; }
.board-block { display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 0.35em; border-bottom: 3px solid var(--cream); }
.tab {
  font: 700 0.95em/1 var(--slab);
  color: var(--cream);
  background: transparent;
  border: 2px solid rgba(246, 236, 210, 0.5);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 0.5em 0.9em;
  cursor: pointer;
}
.tab:hover { background: rgba(246, 236, 210, 0.12); }
.tab[aria-selected="true"] { background: var(--cream); color: var(--ink); border-color: var(--cream); }
.board-status { font-size: 0.9em; margin: 0.5em 0; opacity: 0.85; }
.board-status.offline { color: #ffd08a; opacity: 1; }
.board-block > .btn { align-self: flex-start; margin-bottom: 0.5em; }
.board-scroll { overflow: auto; max-height: calc(94vh - 15em); min-height: 0; }
/* des lignes restent cachées dessous : fondu au bas de la zone (board.js) */
.board-scroll.more {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 2.4em), rgba(0, 0, 0, 0.15));
  mask-image: linear-gradient(to bottom, #000 calc(100% - 2.4em), rgba(0, 0, 0, 0.15));
}
.panel-over-board .board-scroll { max-height: calc(94vh - 11em); }
.board { width: 100%; table-layout: fixed; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.board col.c-rank { width: 3.4em; }
.board col.c-score { width: 6.6em; }
.board col.c-level { width: 4.8em; }
.board th { font: 700 0.75em/1.2 var(--sans); text-transform: uppercase; letter-spacing: 0.06em; color: rgba(246, 236, 210, 0.75); text-align: left; padding: 0.35em 0.5em; }
/* en-tête fixe quand la zone défile */
.board thead th { position: sticky; top: 0; z-index: 1; background: var(--paper); }
.board th:nth-child(1), .board th:nth-child(3), .board th:nth-child(4) { text-align: right; }
.board td { padding: 0.3em 0.5em; border-top: 1px solid rgba(246, 236, 210, 0.14); vertical-align: baseline; }
.board td.rank, .board td.score, .board td.level { text-align: right; }
.board td.rank { font: 700 1em var(--slab); }
.board td.score { font: 700 1em var(--slab); }
.board td.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board tbody tr:nth-child(odd) { background: rgba(246, 236, 210, 0.05); }
/* même spécificité que les lignes impaires, déclarée après : ta ligne est surlignée à tout rang */
.board tbody tr.me { background: var(--accent); outline: 3px solid var(--cream); outline-offset: -3px; }

/* ------------------------------------------------------------------ réglages */

.panel-settings { max-width: min(94vw, 980px); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9em 1.4em; }
fieldset { border: 2px solid rgba(246, 236, 210, 0.35); border-radius: 6px; padding: 0.5em 0.9em 0.8em; margin: 0; min-width: 0; }
legend { font: 700 1.05em var(--slab); padding: 0 0.35em; }
.option { display: flex; align-items: center; gap: 0.55em; padding: 0.22em 0; cursor: pointer; }
.option small { opacity: 0.75; }
.slider { display: grid; grid-template-columns: 5.5em minmax(0, 1fr) 3.4em; align-items: center; gap: 0.6em; padding: 0.15em 0; }
.slider input { width: 100%; }
.vol { text-align: right; font-variant-numeric: tabular-nums; }
.choice .hint { margin: 0.4em 0 0; }
.choice .actions { margin-top: 0.3em; }

/* ------------------------------------------------------------------ comment jouer */

.panel-howto { max-width: min(96vw, 1240px); }
.rules { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1em; }
.rule { display: flex; flex-direction: column; gap: 0.4em; }
.rule .illus {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  background: #c9868f;
  border: 3px solid var(--cream);
  border-radius: 6px;
  box-shadow: 4px 5px 0 var(--shadow);
}
.rule h3 { margin: 0.3em 0 0; display: flex; align-items: center; gap: 0.4em; }
.rule .num { display: inline-flex; align-items: center; justify-content: center; width: 1.6em; height: 1.6em; flex: none; border-radius: 50%; background: var(--cream); color: var(--ink); font-size: 0.85em; }
.rule p { font-size: 0.95em; margin: 0; }
.keys { margin-top: 1em; font-size: 0.92em; opacity: 0.9; }

/* ------------------------------------------------------------------ petites hauteurs, petites largeurs */

@media (max-height: 760px) {
  .screen { padding: 2vh 2.5vw; }
  h2 { font-size: 1.6em; }
  .btn-big { font-size: 1.22em; padding: 0.6em 1em; }
  .menu { margin: 0.8em 0 0.7em; }
  .final-score .value { font-size: 2.6em; }
}

@media (max-width: 1100px) {
  .rules { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .panel-title { max-width: 60vw; }
}

@media (max-width: 900px) {
  .screen-over { flex-direction: column; align-items: stretch; }
  .placement { grid-template-columns: 1fr; }
  .panel-top3 { display: none; }
}

/* ------------------------------------------------------------------ mouvement réduit */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .panel-title, .panel-top3 { transform: none; }
}
