/* Back-office de Tentaclue : une mise en page d'administration classique (barre latérale,
   fil d'Ariane, en-tête de page, cartes et tableaux), aux couleurs de Tentaclue : encre
   violette, papier lilas, corail du poulpe, et une couleur de réponse du jeu par espace. */

@font-face { font-family: "Zilla Slab"; font-weight: 700; font-display: swap; src: url("/static/fonts/zilla-slab-700-latin.woff2") format("woff2"); }
@font-face { font-family: "Figtree"; font-weight: 300 900; font-display: swap; src: url("/static/fonts/figtree-latin.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --encre: #1b1140;
  --fond: #f3f0fa;
  --surface: #ffffff;
  --surface-2: #f8f6fc;
  --survol: #f3f0fa;
  --trait: #e3ddf0;
  --doux: #625a80;
  --corail: #ff615e;
  --corail-fonce: #e8463f;
  --ventouse: #fcd4b0;
  --brique: #a52914;
  --sur-brique: #ffffff;
  --ok: #1f7a3d;
  --ok-fond: #e3f4e8;
  --focus-ring: #d13a33;
  /* La barre latérale reste violet nuit dans les deux thèmes. */
  --nuit: #1b1140;
  --nuit-texte: #c9bdf0;
  /* Les couleurs des réponses du jeu : une par espace. */
  --a0: #d63a3a; --a1: #2f6fdf; --a2: #f2b705; --a3: #2f9a2a;
  --text: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 12px;
  --ombre: 0 1px 2px rgba(27, 17, 64, .06), 0 1px 1px rgba(27, 17, 64, .04);
  --sidebar: 256px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --encre: #f3f0fa;
    --fond: #120b2c;
    --surface: #1d1444;
    --surface-2: #231950;
    --survol: #271c58;
    --trait: #352a6b;
    --doux: #a99fcb;
    --ventouse: #4a2a3a;
    --brique: #ff8a7a;
    --sur-brique: #1b1140;
    --ok: #6fe3a5;
    --ok-fond: #173a2a;
    --focus-ring: #ff8a7a;
    --nuit: #0d0826;
    --ombre: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--fond); color: var(--encre);
  font: 400 .9375rem/1.55 var(--text); font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration-color: var(--corail); text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 700; text-wrap: balance; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75em; }
[hidden] { display: none !important; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--doux); }

/* ---------- Champs et boutons ---------- */
label { display: block; font-weight: 600; margin-bottom: .35em; font-size: .9rem; }
.field { margin-bottom: 1.1em; }
.hint { color: var(--doux); font-size: .85rem; margin: .4em 0 0; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; min-height: 44px; padding: .6em .8em; font: inherit; font-size: 1rem; color: var(--encre);
  background: var(--surface); border: 1px solid var(--trait); border-radius: 8px;
}
input:hover { border-color: var(--doux); }
input:focus-visible { outline-offset: 1px; border-color: var(--focus-ring); }
input[aria-invalid=true] { border-color: var(--brique); }
input[readonly] { background: var(--surface-2); }
.field-error { color: var(--brique); font-weight: 600; font-size: .85rem; margin: .4em 0 0; }
.field-error::before { content: "⚠ "; }
input.code { font-size: 1.4rem; letter-spacing: .3em; text-align: center; padding-left: 1.1em; }
input.code.recovery { letter-spacing: .12em; padding-left: .8em; text-transform: uppercase; }
input.code.recovery::placeholder { text-transform: none; color: color-mix(in srgb, var(--doux) 60%, transparent); }
input[type=checkbox] { width: 1.1em; height: 1.1em; accent-color: var(--corail-fonce); margin: 0; }
.check { display: inline-flex; align-items: center; gap: .5em; font-weight: 400; margin: 0; cursor: pointer; min-height: 32px; }
.checks { display: flex; flex-wrap: wrap; gap: .25em 1.4em; }
fieldset.bare { border: 0; padding: 0; margin: 0 0 1.1em; min-width: 0; }
fieldset.bare legend { font-weight: 600; font-size: .9rem; padding: 0; margin-bottom: .35em; }

.pw { position: relative; }
.pw input { padding-right: 6em; }
.pw .pw-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%); min-height: 36px; padding: 0 .7em;
  font-size: .85rem; font-weight: 600; color: var(--encre); background: transparent; border: 0; border-radius: 6px;
}
.pw .pw-toggle:hover { background: var(--survol); }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 40px; padding: .5em 1em; font: 600 .9375rem/1.2 var(--text); text-decoration: none;
  color: #1b1140; background: var(--corail); border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  touch-action: manipulation; transition: background-color .15s ease, border-color .15s ease;
}
button:hover, .btn:hover { background: var(--corail-fonce); }
button.quiet, .btn.quiet { background: var(--surface); color: var(--encre); border-color: var(--trait); }
button.quiet:hover, .btn.quiet:hover { background: var(--survol); border-color: var(--doux); }
button.danger { background: var(--surface); color: var(--brique); border-color: color-mix(in srgb, var(--brique) 45%, transparent); }
button.danger:hover { background: color-mix(in srgb, var(--brique) 8%, var(--surface)); border-color: var(--brique); }
button.danger.solid { background: var(--brique); color: var(--sur-brique); border-color: var(--brique); }
button.danger.solid:hover { background: color-mix(in srgb, var(--brique) 85%, #000); }
button.small, .btn.small { min-height: 32px; padding: .3em .7em; font-size: .85rem; }
button.full { width: 100%; }
button:disabled { opacity: .55; cursor: progress; }
/* Au doigt, chaque cible fait 44 px au moins, y compris les petites (Afficher, liens-boutons). */
@media (pointer: coarse), (max-width: 600px) {
  button, .btn, button.small, .btn.small, .pw .pw-toggle, .link-button, details.help summary { min-height: 44px; }
  details.help summary { padding: .7em 0; }
}
@media (prefers-reduced-motion: reduce) { button, .btn { transition: none; } }
.link-button { min-height: 36px; padding: 0; background: none; border: 0; color: var(--encre); font-weight: 600;
  text-decoration: underline; text-decoration-color: var(--corail); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.link-button:hover { background: none; text-decoration-color: currentColor; }
.error { color: var(--brique); font-weight: 600; margin: .7em 0 0; }
.error:empty { margin: 0; }

/* ---------- Connexion et invitation : carte centrée ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 16px; }
.auth-brand { display: inline-flex; align-items: center; gap: .55em; margin-bottom: 24px; font: 700 1.5rem/1 "Zilla Slab", Georgia, serif; text-decoration: none; }
.auth-brand img { width: 44px; height: 44px; }
.auth-card { width: 100%; max-width: 26rem; background: var(--surface); border: 1px solid var(--trait); border-radius: 16px; padding: 32px; box-shadow: var(--ombre); }
.auth-card.wide { max-width: 34rem; }
.auth-card h1 { font-size: 1.4rem; margin-bottom: .3em; }
.auth-card .lead { color: var(--doux); margin-bottom: 1.6em; }
.auth-foot { margin-top: 20px; color: var(--doux); font-size: .85rem; text-align: center; max-width: 26rem; }
.auth-foot a { display: inline-block; padding: 12px 4px; }

details.help { margin-top: 1.4em; border-top: 1px solid var(--trait); padding-top: .8em; }
details.help summary { cursor: pointer; font-weight: 600; display: list-item; padding: .5em 0; }
details.help summary::marker { color: var(--corail-fonce); }
details.help p { color: var(--doux); font-size: .9rem; }

ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 1.4em; }
ol.steps > li { counter-increment: step; position: relative; padding: 0 0 1.4em 3rem; border-left: 2px solid var(--trait); margin-left: .9rem; }
ol.steps > li:last-child { border-left-color: transparent; padding-bottom: 0; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: -.95rem; top: -.1rem; width: 1.8rem; height: 1.8rem;
  display: grid; place-items: center; border-radius: 50%; font-weight: 700; font-size: .9rem;
  background: var(--corail); color: #1b1140;
}
ol.steps h2 { margin: .15em 0 .7em; }
.qr { display: block; width: 184px; height: 184px; margin: .4em 0 .8em; padding: 8px; background: #fff; border: 1px solid var(--trait); border-radius: 8px; image-rendering: pixelated; }
.secret { display: block; padding: .55em .8em; background: var(--surface-2); border: 1px dashed var(--trait); border-radius: 8px; letter-spacing: .03em; word-spacing: .2em; font-size: .9rem; font-weight: 600; }

.keep { background: color-mix(in srgb, var(--ventouse) 60%, var(--surface)); border: 1px solid var(--ventouse); border-radius: 10px; padding: .9em 1.1em; margin: 1em 0; }
.keep p { margin: 0; }
.codes { list-style: none; padding: 0; margin: 1em 0 1.4em; display: grid; grid-template-columns: repeat(2, 1fr); gap: .5em; }
.codes li { padding: .5em; text-align: center; font-weight: 700; letter-spacing: .08em; background: var(--surface-2); border: 1px solid var(--trait); border-radius: 8px; }

/* ---------- Coque : barre latérale + contenu ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  background: var(--nuit); color: var(--nuit-texte); padding: 20px 14px; overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: .6em; padding: 4px 10px 20px; color: #f3f0fa; text-decoration: none; }
.sidebar .brand img { width: 34px; height: 34px; }
.sidebar .brand strong { display: block; font: 700 1.3rem/1 "Zilla Slab", Georgia, serif; }
.sidebar .brand small { display: block; font-size: .78rem; color: var(--nuit-texte); margin-top: .2em; }
.sidebar nav ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.sidebar nav a {
  position: relative; display: flex; align-items: center; gap: .75em; min-height: 44px; padding: 0 12px;
  border-radius: 8px; color: var(--nuit-texte); font-weight: 600; text-decoration: none;
}
.sidebar nav a:hover { background: rgba(243, 240, 250, .07); color: #f3f0fa; }
.sidebar nav a[aria-current=page] { background: rgba(243, 240, 250, .12); color: #f3f0fa; }
.sidebar nav a[aria-current=page]::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--corail); }
.sidebar .nav-label { padding: 18px 12px 6px; font-size: .78rem; color: color-mix(in srgb, var(--nuit-texte) 75%, transparent); }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(243, 240, 250, .12); padding-top: 14px; }
.me { display: flex; align-items: center; gap: .7em; padding: 4px 10px 10px; }
.avatar { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--corail); color: #1b1140; font-weight: 700; font-size: .85rem; }
.me strong { display: block; color: #f3f0fa; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.me small { display: block; font-size: .8rem; }
.side-btn { width: 100%; justify-content: flex-start; gap: .75em; background: transparent; color: var(--nuit-texte); border: 0; padding: 0 12px; min-height: 44px; }
.side-btn:hover { background: rgba(243, 240, 250, .07); color: #f3f0fa; }
.sidebar :focus-visible { outline-color: #ff8a7a; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 32px;
  background: color-mix(in srgb, var(--fond) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--trait);
}
.menu-btn { display: none; background: var(--surface); color: var(--encre); border-color: var(--trait); padding: 0 .6em; }
.menu-btn:hover { background: var(--survol); }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: .4em; padding: 0; margin: 0; color: var(--doux); font-size: .875rem; }
.crumbs li + li::before { content: "/"; margin-right: .4em; color: color-mix(in srgb, var(--doux) 60%, transparent); }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--encre); text-decoration: underline; }
.crumbs [aria-current] { color: var(--encre); font-weight: 600; }
.site-link { margin-left: auto; }

.content { width: 100%; max-width: 72rem; padding: 28px 32px 64px; }
.content:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin: .3em 0 0; color: var(--doux); max-width: 44em; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--radius); box-shadow: var(--ombre); margin-bottom: 20px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--trait); }
.card-head p { margin: .2em 0 0; color: var(--doux); font-size: .875rem; }
.card-body { padding: 20px; }
.card-body > :last-child { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; margin-bottom: 20px; }
.grid-2 .card { margin-bottom: 0; }
.count { display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; padding: 0 .45em; margin-left: .4em; border-radius: 99px; background: var(--survol); color: var(--doux); font-size: .78rem; font-weight: 700; vertical-align: middle; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 12px 20px; vertical-align: middle; }
thead th { font-size: .8rem; font-weight: 600; color: var(--doux); background: var(--surface-2); border-bottom: 1px solid var(--trait); white-space: nowrap; }
tbody td { border-bottom: 1px solid var(--trait); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:not(.group):hover td { background: var(--surface-2); }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions > * + * { margin-left: 6px; }
td .sub { display: block; color: var(--doux); font-size: .825rem; overflow-wrap: anywhere; }
td strong { font-weight: 600; }
@media (min-width: 601px) { .rtable td:first-child { min-width: 15rem; } }
tr.group th { padding: 10px 20px; font-size: .8rem; font-weight: 700; color: var(--encre); background: var(--surface-2); border-bottom: 1px solid var(--trait); border-top: 1px solid var(--trait); }
tbody tr.group:first-child th { border-top: 0; }
td.loading, td.empty-cell { color: var(--doux); text-align: center; padding: 32px 20px; }
.load-error { display: flex; align-items: center; justify-content: center; gap: 1em; flex-wrap: wrap; color: var(--brique); font-weight: 600; }
.load-error p { margin: 0; }
td.when { white-space: nowrap; color: var(--doux); }
.space-name { display: inline-flex; align-items: center; gap: .6em; font-weight: 600; }
.dot { width: .7em; height: .7em; border-radius: 50%; background: var(--band); flex: none; }
[data-hue="0"] { --band: var(--a0); } [data-hue="1"] { --band: var(--a1); } [data-hue="2"] { --band: var(--a2); } [data-hue="3"] { --band: var(--a3); }

/* Badges */
.pill { display: inline-flex; align-items: center; gap: .4em; padding: .1em .6em; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--survol); color: var(--encre); margin: .15em .3em .15em 0; white-space: nowrap; }
.pill[data-hue]::before { content: ""; width: .55em; height: .55em; border-radius: 50%; background: var(--band); }
.pill.super { background: var(--encre); color: var(--surface); }
.pill.here { background: var(--ventouse); }
.pill.on { background: var(--ok-fond); color: var(--ok); }
.pill.off { background: color-mix(in srgb, var(--brique) 12%, var(--surface)); color: var(--brique); }

.empty { padding: 36px 20px; text-align: center; color: var(--doux); }
.empty p { margin: 0 auto; max-width: 30em; }
.result { margin-top: 1.2em; padding: 1em; background: var(--surface-2); border: 1px solid var(--trait); border-radius: 10px; }
.result p { margin: 0 0 .5em; }
.link-box { display: flex; gap: .5em; }
.link-box input { flex: 1; min-width: 0; }
.spaced { margin-top: 1.2em; }

/* Fenêtres modales */
dialog {
  width: min(30rem, calc(100vw - 32px)); padding: 0; color: var(--encre);
  background: var(--surface); border: 1px solid var(--trait); border-radius: 14px; box-shadow: 0 20px 60px rgba(13, 8, 38, .35);
}
dialog::backdrop { background: rgba(13, 8, 38, .55); }
dialog > form, dialog > .dialog-body { padding: 24px; }
dialog h2 { font-size: 1.15rem; margin-bottom: .5em; }
dialog .buttons { display: flex; gap: .6em; justify-content: flex-end; margin-top: 1.4em; }
dialog.confirm { padding: 24px; }
dialog.confirm p { margin: 0; color: var(--doux); }

/* Message d'état en bas de l'écran : annoncé sans voler le focus, il s'efface seul. */
.status {
  position: fixed; right: 24px; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 100;
  transform: translateY(150%); opacity: 0; pointer-events: none;
  max-width: min(26rem, calc(100vw - 32px)); padding: .8em 1.1em; border-radius: 10px;
  background: #1b1140; color: #f3f0fa; font-weight: 600; box-shadow: 0 10px 30px rgba(13, 8, 38, .3);
  transition: transform .25s cubic-bezier(.2, .8, .3, 1), opacity .2s ease;
}
.status.shown { transform: translateY(0); opacity: 1; }
@media (prefers-reduced-motion: reduce) { .status { transition: none; } }

/* ---------- Écrans étroits : la barre latérale devient un tiroir ---------- */
.scrim { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; width: min(var(--sidebar), 86vw);
    transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility 0s .2s;
    box-shadow: 0 0 40px rgba(13, 8, 38, .4);
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform .2s ease; }
  .scrim.open { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(13, 8, 38, .5); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  th.hide-md, td.hide-md { display: none; }
}
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  /* Tableaux empilés : chaque ligne devient une fiche, chaque valeur précédée de son libellé. */
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td, .rtable th { display: block; width: 100%; }
  .rtable tbody tr { padding: 12px 14px; border-bottom: 1px solid var(--trait); }
  .rtable tbody tr:last-child { border-bottom: 0; }
  .rtable td { padding: 2px 0; border: 0 !important; background: none !important; text-align: left; }
  .rtable td.hide-sm, .rtable td.hide-md { display: block; }
  .rtable td[data-label]::before { content: attr(data-label) " : "; color: var(--doux); font-weight: 400; }
  .rtable td.actions { white-space: normal; padding-top: 8px; }
  .rtable td.actions > * { margin: 4px 8px 0 0; }
  .rtable td.actions > * + * { margin-left: 0; }
  .rtable tr.group { padding: 0; }
  .rtable tr.group th { padding: 8px 14px; }
  .rtable td.loading, .rtable td.empty-cell { text-align: center; padding: 20px 0; }
  .card-head, .card-body { padding-left: 14px; padding-right: 14px; }
  .auth-card { padding: 24px 20px; }
  .page-actions, .page-actions .btn, .page-actions button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .sidebar, .sidebar.open { transition: none; } }
