/* BBHeardle — feuille de style unique.
   Sobre : une colonne, des bordures de 1 px, aucune ombre, beaucoup de blanc.
   Palette et typographie inspirées de l'identité d'Anthropic, avec des polices libres
   (les siennes sont propriétaires). */

/* ------------------------------------------------------------------ polices

   Les polices viennent de Google Fonts, chargées par un <link> dans chaque page HTML :
   rien à télécharger, rien à lancer en local. Ce sont les équivalents libres (OFL) des
   polices d'Anthropic, qui sont propriétaires : Inter Tight pour l'interface, Newsreader
   pour les titres, JetBrains Mono pour les codes de clés.

   Pour passer en auto-hébergé (aucune requête vers un tiers, CSP resserrée), voir
   « Auto-héberger les polices » dans le README : `npm run fonts`, on retire les <link>
   des pages, on remet des @font-face vers /fonts/, et on retire les deux domaines Google
   de la CSP dans lib/security.js.

   La pile de repli système ci-dessous garantit un site lisible même si Google est
   inaccessible.
   ------------------------------------------------------------------ thème */

:root {
  --font-sans: 'Inter Tight', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    Helvetica, Arial, sans-serif;
  --font-serif: 'Newsreader', ui-serif, Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius: 8px;
  --radius-sm: 5px;
  --gap: 1rem;
  --measure: 40rem;

  color-scheme: light;

  --bg: #f0eee6;
  --surface: #faf9f5;
  --surface-2: #f3f1e9;
  --text: #141413;
  --text-muted: #6f6e69;
  --border: #e0ddd2;
  --border-strong: #c9c5b7;
  --accent: #cc785c;
  --accent-hover: #b85f42;
  --accent-soft: #f6e6df;
  --on-accent: #ffffff;
  --ok: #4f6b4a;
  --ok-soft: #e6ece2;
  --ko: #b4472f;
  --ko-soft: #f7e4df;
}

/* Le clair est le thème par défaut : la préférence système n'est volontairement pas
   consultée. Le sombre ne s'applique que sur choix explicite, mémorisé en localStorage. */
:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #191919;
  --surface: #21201e;
  --surface-2: #292826;
  --text: #f0eee6;
  --text-muted: #a5a29a;
  --border: #35342f;
  --border-strong: #4a4842;
  --accent: #d97757;
  --accent-hover: #e08d70;
  --accent-soft: #34261f;
  --on-accent: #191919;
  --ok: #9bb894;
  --ok-soft: #232b21;
  --ko: #e08b74;
  --ko-soft: #33221e;
}

/* ------------------------------------------------------------------ base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
}

h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.25rem;
}
h3 {
  font-size: 1.0625rem;
}

p {
  margin: 0;
}

a {
  color: var(--text);
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}
a:hover {
  text-decoration-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ------------------------------------------------------------------ structure */

.shell {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding-bottom: 1.25rem;
  margin-bottom: 1.75rem;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin-right: auto;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-right: auto;
}

.brand small {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card + .card {
  margin-top: 1rem;
}

.card > h2,
.card > h3 {
  margin-bottom: 0.75rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Les formulaires combinent des .field (label + input) et un bouton : on aligne
   sur le bas pour que le bouton reste au niveau de l'input, pas du label. */
form.row {
  align-items: flex-end;
}

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

.spacer {
  flex: 1;
}

.hidden,
[hidden] {
  /* nécessaire car .stack/.row posent display:flex, qui l'emporterait sinon sur [hidden] */
  display: none !important;
}

/* ------------------------------------------------------------------ contrôles */

button {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.4375rem 0.875rem;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--text-muted);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding-inline: 0.5rem;
}

button.quiet:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

/* Bouton carré ne contenant qu'une icône (bascule de thème). */
button.icon-button {
  padding: 0.375rem;
  display: grid;
  place-items: center;
  line-height: 0;
}

button.icon-button svg {
  width: 1.125rem;
  height: 1.125rem;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* En clair on montre la lune (« passer en sombre »), en sombre le soleil.
   Bascule en CSS pure : aucun scintillement, et le JS n'a pas à toucher au DOM.
   Les sélecteurs restent plus spécifiques que `button.icon-button svg`, sinon le
   `display: block` de ce dernier ré-afficherait l'icône masquée. */
button.icon-button .icon-sun {
  display: none;
}

:root[data-theme='dark'] button.icon-button .icon-moon {
  display: none;
}

:root[data-theme='dark'] button.icon-button .icon-sun {
  display: block;
}

button.danger {
  color: var(--ko);
  border-color: var(--border-strong);
  background: transparent;
}

button.danger:hover:not(:disabled) {
  background: var(--ko-soft);
  border-color: var(--ko);
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.4375rem 0.625rem;
  width: 100%;
  min-width: 0;
}

input::placeholder {
  color: var(--text-muted);
}

input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.field {
  flex: 1 1 12rem;
}

form {
  margin: 0;
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.1875rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}

.badge.accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.badge.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}

.badge.ko {
  background: var(--ko-soft);
  border-color: var(--ko);
  color: var(--ko);
}

/* ------------------------------------------------------------------ messages */

.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
}

.notice.error {
  border-left-color: var(--ko);
  background: var(--ko-soft);
}

.notice.success {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

/* ------------------------------------------------------------------ modes

   Choix du mode : deviner la musique, ou deviner la cover. Contrairement aux catégories,
   les modes sont peu nombreux et le resteront — une rangée de boutons est donc tenable, et
   surtout elle montre le mode sans qu'on ait à ouvrir un menu. */

.mode-picker {
  display: inline-flex;
  align-self: flex-start;
  max-width: 100%;
  padding: 3px;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.mode-picker button {
  flex: none;
  padding: 0.35rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.mode-picker button:hover {
  color: var(--text);
}

.mode-picker button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ------------------------------------------------------------------ catégories

   Choix de la liste à jouer (anglais, français, rap FR, …). Menu déroulant : le nombre de
   catégories n'est pas borné et leurs libellés sont libres, donc une rangée de boutons
   finirait tôt ou tard par déborder de la carte — un <select> natif, jamais. */

.category-picker {
  align-self: flex-start;
  max-width: 100%;
}

/* La règle générique `input, select` impose width: 100%, ce qui étirerait le menu sur
   toute la largeur de la carte : ici il se cale sur son contenu. */
.category-picker select {
  width: auto;
  min-width: 12rem;
  max-width: 100%;
}

.category-picker select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ jeu */

.attempts {
  display: flex;
  gap: 0.25rem;
}

.attempts span {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.attempts span.used {
  background: var(--ko);
}

.attempts span.current {
  background: var(--accent);
}

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

/* La pochette à deviner. `image-rendering: pixelated` est TOUT le mode cover : le serveur
   sert une image minuscule (8×8 à la première tentative) et c'est le navigateur qui
   l'agrandit — en gros carrés nets, sans le flou d'un lissage. Sans cette ligne, on
   obtiendrait une bouillie interpolée au lieu de pixels francs. */

.cover {
  display: grid;
  place-items: center;
}

.cover img {
  width: min(320px, 78vw);
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--border);
}

.play-button {
  width: 3.5rem;
  height: 3.5rem;
  flex: none;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.play-button:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.play-button svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: currentColor;
}

.track {
  flex: 1;
  min-width: 0;
}

.track-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}

.track-bar > i {
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  background: var(--accent);
  border-radius: 3px;
}

.volume {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: none;
  color: var(--text-muted);
}

.volume svg {
  width: 1.125rem;
  height: 1.125rem;
  flex: none;
  fill: currentColor;
}

.volume svg .waves {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
}

/* Volume à zéro : le haut-parleur perd ses ondes. */
.volume.silent svg .waves {
  display: none;
}

/* La règle générique `input, select` impose width: 100%, une bordure et un fond : sur un
   curseur natif tout cela est à défaire. `accent-color` colore piste et pouce dans les
   deux thèmes, ce qui évite d'écrire les pseudo-éléments propres à chaque moteur. */
.volume input[type='range'] {
  width: 5.5rem;
  flex: none;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Le décalage négatif de la règle globale rognerait le curseur. */
.volume input[type='range']:focus-visible {
  outline-offset: 2px;
}

.combo {
  position: relative;
}

.suggestions {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  max-height: 15rem;
  overflow-y: auto;
}

.suggestions li {
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9375rem;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.suggestions li em {
  color: var(--text-muted);
  font-style: normal;
  font-size: 0.8125rem;
  margin-left: auto;
  white-space: nowrap;
}

.suggestions li[aria-selected='true'],
.suggestions li:hover {
  background: var(--surface-2);
}

.guesses {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.guesses li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.9375rem;
  padding: 0.4375rem 0.625rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--ko);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.guesses li b {
  font-weight: 500;
}

/* Tentative passée : pas une erreur de plus, juste un tour de piste sauté. */
.guesses li.skipped {
  border-left-color: var(--border);
}

.guesses li.skipped b {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}

.guesses li span {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

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

.reveal img {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  flex: none;
  object-fit: cover;
}

/* En mode cover, la pochette EST la réponse : elle passe au premier plan, enfin nette et en
   grand, au lieu de la vignette qui accompagne un morceau. */
.reveal.cover-reveal {
  flex-direction: column;
  align-items: flex-start;
}

.reveal.cover-reveal img {
  width: min(240px, 62vw);
  height: auto;
  aspect-ratio: 1;
}

.reveal-body {
  min-width: 0;
}

.reveal-body h3 {
  font-family: var(--font-serif);
  font-size: 1.1875rem;
}

/* ------------------------------------------------------------------ tableaux */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

th {
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
}

tbody tr:last-child td {
  border-bottom: none;
}

td.actions {
  text-align: right;
}

td.actions button {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

td.wrap {
  white-space: normal;
}

/* ------------------------------------------------------------------ divers */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
}

.tabs button[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.summary-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.summary-list li {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
}

.summary-list li:last-child {
  border-bottom: none;
}

.summary-list li > .num {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  min-width: 1.75rem;
}

.footnote {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.center {
  max-width: 22rem;
  margin: 3rem auto 0;
}

@media (max-width: 30rem) {
  .shell {
    padding: 1rem 0.875rem 3rem;
  }
  .reveal {
    flex-direction: column;
    align-items: flex-start;
  }
  /* On resserre pour laisser sa place à la barre de progression. */
  .player {
    gap: 0.75rem;
  }
  .volume input[type='range'] {
    width: 3.5rem;
  }
}
