/* Papy — feuille de style principale */

/* Thème : clair par défaut, sombre si le système le demande (mode « auto »),
   ou forcé par l'attribut data-theme posé sur <html> par theme.js. */
:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #f8f6f2;
  --border: #e4ded4;
  --text: #1f1b16;
  --muted: #6b6359;
  --accent: #c2620f;
  --accent-strong: #a14f08;
  --accent-soft: #fcebd9;
  --danger: #c0392b;
  --danger-soft: #fbe3e0;
  --success: #2f7d4a;
  --success-soft: #e0f2e6;
  --shadow: 0 1px 2px rgb(31 27 22 / 6%), 0 8px 24px rgb(31 27 22 / 6%);
  --radius: 14px;
  --radius-sm: 9px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15130f;
  --surface: #1f1c17;
  --surface-2: #26221c;
  --border: #36302a;
  --text: #f3eee6;
  --muted: #a59b8e;
  --accent: #f08c2e;
  --accent-strong: #ffa552;
  --accent-soft: #3a2614;
  --danger: #ef6b5b;
  --danger-soft: #3d1c18;
  --success: #5cc183;
  --success-soft: #16301f;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
}

/* Mode auto : mêmes valeurs que ci-dessus, sauf si l'utilisateur a forcé le clair. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15130f;
    --surface: #1f1c17;
    --surface-2: #26221c;
    --border: #36302a;
    --text: #f3eee6;
    --muted: #a59b8e;
    --accent: #f08c2e;
    --accent-strong: #ffa552;
    --accent-soft: #3a2614;
    --danger: #ef6b5b;
    --danger-soft: #3d1c18;
    --success: #5cc183;
    --success-soft: #16301f;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
  }
}

/* Bouton de thème : l'icône affichée correspond au choix courant. */
.theme-toggle .icon { display: none; }
:root:not([data-theme]) .theme-toggle .icon-auto,
:root[data-theme="light"] .theme-toggle .icon-light,
:root[data-theme="dark"] .theme-toggle .icon-dark { display: inline-block; }
.theme-floating { position: fixed; top: 16px; right: 16px; z-index: 60; }
.theme-label { display: none; }
@media (max-width: 820px) { .nav .theme-label { display: inline; } }

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

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

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

a { color: var(--accent); }
img { max-width: 100%; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
h2 { font-size: 1.25rem; }

.icon { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Navigation -------------------------------------------------------- */

.nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1200px; margin: 0 auto; height: var(--nav-h);
  display: flex; align-items: center; gap: 1rem; padding: 0 16px;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.2rem;
  color: var(--text); text-decoration: none; }
.brand img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); }

.nav-links { display: flex; align-items: center; gap: .25rem; margin-left: auto; list-style: none; padding: 0; margin-block: 0; }
.nav-links a, .nav-links summary, .nav-links button {
  display: flex; align-items: center; gap: .45rem; padding: .5rem .8rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font: inherit; font-weight: 500; cursor: pointer;
  background: none; border: 0;
}
.nav-links a:hover, .nav-links summary:hover, .nav-links button:hover { background: var(--surface-2); }
.nav-links a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.nav-group { position: relative; }
.nav-group summary { list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary .chevron { transition: transform .15s; }
.nav-group[open] summary .chevron { transform: rotate(180deg); }
.nav-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; padding: .4rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); list-style: none; margin: 0;
}

.nav-user { color: var(--muted); font-size: .9rem; padding: 0 .4rem; }
.nav .nav-toggle { display: none; margin-left: auto; }

@media (max-width: 820px) {
  .nav .nav-toggle { display: inline-flex; }
  .nav-links {
    display: none; position: absolute; left: 0; right: 0; top: var(--nav-h);
    flex-direction: column; align-items: stretch; padding: .75rem 16px 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .nav.open .nav-links { display: flex; }
  .nav-menu { position: static; box-shadow: none; border: 0; padding: 0 0 0 1rem; }
  .nav-user { padding: .5rem .8rem; }
}

/* ---- Mise en page ------------------------------------------------------ */

.container { max-width: 1100px; margin: 0 auto; padding: 2rem 16px 4rem; }
.container.narrow { max-width: 760px; }

.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.5rem; }
.page-header p { margin: .25rem 0 0; color: var(--muted); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-title { display: flex; align-items: center; gap: .5rem; font-size: 1.05rem; font-weight: 600; margin: 0 0 .75rem; }

.stack > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty .icon { width: 2.5rem; height: 2.5rem; opacity: .5; display: block; margin: 0 auto .75rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.tile {
  display: flex; flex-direction: column; gap: .4rem; padding: 1.25rem; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile .icon { width: 1.8rem; height: 1.8rem; color: var(--accent); }
.tile strong { font-size: 1.05rem; }
.tile span { color: var(--muted); font-size: .92rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--accent-soft); color: var(--accent-strong); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---- Formulaires ------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .8rem;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 6rem; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-grid { display: grid; gap: 1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-weight: 600; font-size: .95rem; line-height: 1; white-space: nowrap;
  padding: .65rem 1rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, color .15s;
}
.btn:focus-visible, .nav-links a:focus-visible, .nav-links summary:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-icon { padding: .55rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Messages flash ---------------------------------------------------- */

.flashes { position: fixed; z-index: 100; right: 16px; bottom: 16px; display: grid; gap: .5rem; max-width: min(420px, calc(100vw - 32px)); }
.flash {
  display: flex; align-items: flex-start; gap: .6rem; padding: .8rem 1rem; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: slide-in .25s ease-out;
}
.flash.success { border-left: 4px solid var(--success); }
.flash.error { border-left: 4px solid var(--danger); }
.flash button { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; line-height: 1; }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } }

/* ---- Boîtes de dialogue ------------------------------------------------ */

dialog {
  width: min(480px, calc(100vw - 32px)); padding: 1.5rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); backdrop-filter: blur(3px); }
dialog h2 { margin-bottom: .5rem; }
dialog .row.end { margin-top: 1.5rem; }

/* ---- Connexion ---------------------------------------------------------- */

.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 2rem 16px;
  background: radial-gradient(circle at 30% 10%, var(--accent-soft), transparent 55%), var(--bg);
}
.auth-card { width: min(400px, 100%); text-align: center; padding: 2rem 1.75rem; }
.auth-card img { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin-bottom: 1rem;
  border: 4px solid var(--surface); box-shadow: var(--shadow); }
.auth-card p { color: var(--muted); margin: 0 0 1.5rem; }
.auth-card form { display: grid; gap: .8rem; text-align: left; }
.code-input { text-align: center; letter-spacing: .3em; font-size: 1.4rem; font-weight: 700; text-transform: uppercase; }
.auth-footer { margin-top: 1.25rem; font-size: .9rem; }
.auth-footer button { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; }

/* ---- Quotes ------------------------------------------------------------- */

.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.toolbar .field { min-width: min(280px, 100%); flex: 1 1 280px; }

.quote-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.quote-item { display: flex; gap: .5rem; align-items: center; }
.quote-item form.grow { display: flex; gap: .5rem; align-items: center; }
.quote-id { flex: none; width: 2.4rem; height: 2.4rem; display: grid; place-items: center; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; font-size: .85rem; }

details.panel { border: 1px dashed var(--border); border-radius: var(--radius); padding: .25rem 1rem; }
details.panel[open] { padding-bottom: 1rem; border-style: solid; }
details.panel summary { cursor: pointer; font-weight: 600; padding: .6rem 0; display: flex; align-items: center; gap: .5rem; }

/* ---- Quiz --------------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip-link { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); text-decoration: none; font-size: .9rem; font-weight: 500; }
.chip-link:hover { border-color: var(--accent); }
.chip-link[aria-current="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.question-text { font-size: 1.15rem; font-weight: 500; white-space: pre-line; }
.answer-form { display: flex; gap: .5rem; margin-top: 1rem; }
.history { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.history li { padding: .25rem .7rem; border-radius: 999px; background: var(--danger-soft); color: var(--danger); font-size: .9rem; text-decoration: line-through; }

.result { text-align: center; padding: 2.5rem 1.5rem; }
.result .icon { width: 3rem; height: 3rem; }
.result.success .icon { color: var(--success); }
.result.failure .icon { color: var(--danger); }

/* ---- Table Deadlands ---------------------------------------------------- */

.hand { padding: 1rem; }
.hand-header { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.hand-header h3 { margin: 0; font-size: 1.05rem; }
.hand-cards { display: flex; flex-wrap: wrap; gap: .75rem; min-height: 40px; }
.playing-card { position: relative; width: 96px; perspective: 700px; }

/* Retournement d'une carte : dos -> tranche (90°) -> face. */
.playing-card.flip-out img { animation: card-flip-out .2s ease-in forwards; }
.playing-card.flip-in img { animation: card-flip-in .25s ease-out; }
@keyframes card-flip-out { to { transform: rotateY(90deg) scale(1.06); } }
@keyframes card-flip-in { from { transform: rotateY(-90deg) scale(1.06); } }
.playing-card.flip-out .hidden-mark, .playing-card.flip-in .hidden-mark { opacity: 0; }

/* Carte qui vient d'être piochée. */
.playing-card.dealt { animation: card-deal .3s ease-out; }
@keyframes card-deal { from { transform: translateY(-14px) rotate(-4deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .playing-card.flip-out img, .playing-card.flip-in img, .playing-card.dealt { animation: none; }
}
.playing-card img { display: block; width: 100%; border-radius: 6px; box-shadow: var(--shadow); }
.playing-card button.reveal { padding: 0; border: 0; background: none; cursor: zoom-in; display: block; width: 100%; border-radius: 6px; }
.playing-card button.reveal:hover img, .playing-card button.reveal:focus-visible img { box-shadow: 0 0 0 3px var(--accent); }
.playing-card .hidden-mark { position: absolute; top: 4px; left: 4px; padding: 2px 6px; border-radius: 999px;
  background: rgb(0 0 0 / 60%); color: #fff; font-size: .7rem; }
.playing-card .discard { position: absolute; top: -8px; right: -8px; padding: .3rem; border-radius: 50%; }
.draw-form { display: flex; gap: .4rem; align-items: center; margin-left: auto; }
.draw-form .select { width: auto; padding: .4rem .6rem; }
.section-sep { margin: 1.5rem 0 1rem; display: flex; align-items: center; gap: .75rem; color: var(--muted); font-weight: 600; }
.section-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---- Erreurs ------------------------------------------------------------ */

.error-code { font-size: 4rem; font-weight: 800; color: var(--accent); line-height: 1; margin-bottom: .5rem; }

@media (max-width: 560px) {
  .container { padding-top: 1.25rem; }
  .answer-form { flex-direction: column; }
  .playing-card { width: 72px; }
}

.mt { margin-top: 1rem; }
.row.center { justify-content: center; }

/* ---- Journal de mise à jour --------------------------------------------- */
.log {
  margin: 0; max-height: 420px; overflow: auto; padding: .9rem 1rem; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  font: .85rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}

/* ---- Tableaux de données / suivi du quiz -------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 -.25rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.data-table th, .data-table td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table th { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table a { font-weight: 600; text-decoration: none; }
.data-table a:hover { text-decoration: underline; }
.data-table code { font-size: .85rem; overflow-wrap: break-word; }
.data-table .col-bar { width: 32%; min-width: 140px; }
.data-table .col-text { min-width: 220px; max-width: 520px; overflow-wrap: anywhere; }

.progress-bar { display: block; width: 100%; height: 10px; }
.seg-total { fill: var(--surface-2); stroke: var(--border); stroke-width: .3; }
.seg-discovered { fill: var(--state-discovered); }
.seg-answered { fill: var(--state-answered); }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: .75rem; font-size: .85rem; color: var(--muted); }
.legend .dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; vertical-align: -.05rem; margin-right: .3rem; }
.legend .dot.seg-answered { background: var(--state-answered); }
.legend .dot.seg-discovered { background: var(--state-discovered); }
.legend .dot.seg-total { background: var(--surface-2); border: 1px solid var(--border); }

/* Cartouches d'état des questions : une couleur par état, en clair comme en sombre. */
:root { --state-answered: #2f7d4a; --state-answered-bg: #e0f2e6; --state-discovered: #b45309; --state-discovered-bg: #fdecd2;
        --state-undiscovered: #6b6359; --state-undiscovered-bg: #efebe5; }
:root[data-theme="dark"] { --state-answered: #6fd394; --state-answered-bg: #163222; --state-discovered: #f5a54a;
        --state-discovered-bg: #3a2614; --state-undiscovered: #a59b8e; --state-undiscovered-bg: #2a2620; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --state-answered: #6fd394; --state-answered-bg: #163222; --state-discovered: #f5a54a;
        --state-discovered-bg: #3a2614; --state-undiscovered: #a59b8e; --state-undiscovered-bg: #2a2620; }
}
.state-repondue { --state: var(--state-answered); --state-bg: var(--state-answered-bg); }
.state-decouverte { --state: var(--state-discovered); --state-bg: var(--state-discovered-bg); }
.state-non-decouverte { --state: var(--state-undiscovered); --state-bg: var(--state-undiscovered-bg); }
.state-pill {
  display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap;
  padding: .2rem .65rem .2rem .55rem; border-radius: 999px; font-size: .82rem; font-weight: 600;
  color: var(--state); background: var(--state-bg); border: 1px solid color-mix(in srgb, var(--state) 35%, transparent);
}
.state-pill::before, .state-dot {
  content: ""; display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--state); flex: none;
}
.state-dot { margin-right: .4rem; vertical-align: .05rem; }
.chip-link[aria-current="true"] .state-dot { box-shadow: 0 0 0 2px #fff; }
.back-link { display: inline-block; margin-bottom: .4rem; font-size: .9rem; text-decoration: none; }

/* ---- Onglets et listes de joueurs (suivi du quiz) ----------------------- */
.tabs { display: inline-flex; gap: .25rem; padding: .25rem; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); }
.tab { padding: .45rem .9rem; border-radius: calc(var(--radius-sm) - 3px); color: var(--muted);
  font-weight: 600; font-size: .92rem; text-decoration: none; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; align-items: start; }
.grid-2 > .card + .card { margin-top: 0; }
.player-list { list-style: none; margin: 0; padding: 0; columns: 2 180px; column-gap: 1.5rem; }
.player-list li { break-inside: avoid; display: flex; justify-content: space-between; gap: .5rem;
  padding: .35rem 0; border-bottom: 1px solid var(--border); }
.player-list a { font-weight: 600; text-decoration: none; }
.player-list a:hover { text-decoration: underline; }
.data-table a.plain-link { font-weight: 400; color: var(--text); }
