/* Player pages. Mobile first: the rules below are written for a phone held
   upright; the @media blocks at the end widen the layout on larger screens.
   Touch targets are at least 44px high (48px for the game's buttons), text
   never goes below 16px, there is no zoom (see base.html), and nothing hides
   under the notch.

   This file is the layout, common to every style. The colors, fonts and
   ornaments come from the player's style, `styles/<style>.css`, loaded after
   it: it defines the variables --fond, --surface, --texte, --discret,
   --accent, --accent-texte, --bord, --lecture, --interface and --titre, for
   light and dark. */

:root {
  --ombre: 0 2px 10px rgb(0 0 0 / 0.12);
  --rayon: 10px;
  --marge: 1rem;
  color-scheme: light dark;
}

/* Light or dark: the phone's choice ("auto"), or the player's. */
:root[data-mode="clair"] {
  color-scheme: light;
}

:root[data-mode="sombre"] {
  color-scheme: dark;
}

/* Text size: every size is in rem, so the whole page follows. */
:root[data-texte="grand"] {
  font-size: 112.5%;
}

:root[data-texte="tres-grand"] {
  font-size: 125%;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom */
}

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--interface);
  font-size: 1rem;
  line-height: 1.5;
  /* Keep clear of the notch and of the rounded corners in landscape. */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Installed on the home screen, the page runs under a see-through status bar
   (black-translucent): this band hides the text scrolling beneath it. In a
   browser tab the inset is 0 and the band does not show. */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: env(safe-area-inset-top);
  background: var(--fond);
  z-index: 20;
}

a {
  color: var(--accent);
}

button {
  font: inherit;
  color: inherit;
}

/* --- Header ---------------------------------------------------------------- */

.entete {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.25rem + env(safe-area-inset-top)) var(--marge) 0.25rem;
  max-width: 64rem;
  margin: 0 auto;
}

.marque {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.reglages-lien {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  margin-left: auto;
  margin-right: -10px; /* the icon lines up with the margin, its target overflows */
  color: var(--discret);
  flex-shrink: 0;
}

.titre-livre {
  color: var(--discret);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contenu {
  max-width: 64rem;
  margin: 0 auto;
  padding: 0 var(--marge) 3rem;
}

/* --- Home ------------------------------------------------------------------ */

.accueil h1 {
  font-family: var(--lecture);
  font-size: 1.75rem;
  margin: 0.5rem 0 1rem;
}

.accueil h2 {
  font-size: 1.15rem;
  margin: 2rem 0 0.75rem;
}

.histoires,
.parties {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.histoire {
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  padding: var(--marge);
}

.histoire h2 {
  font-family: var(--lecture);
  margin: 0 0 0.75rem;
}

.parties a {
  display: flex;
  flex-direction: column;
  min-height: 48px;
  padding: 0.75rem var(--marge);
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  color: inherit;
  text-decoration: none;
}

.partie-titre {
  font-weight: 600;
}

.partie-etat {
  color: var(--discret);
  font-size: 0.9rem;
}

.bouton-principal {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: var(--rayon);
  background: var(--accent);
  color: var(--accent-texte);
  font-weight: 600;
  cursor: pointer;
}

/* --- Settings --------------------------------------------------------------- */

.reglages h1 {
  font-family: var(--titre);
  font-size: 1.75rem;
  margin: 0.25rem 0 1.25rem;
}

.reglages-retour {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.reglages-formulaire {
  display: grid;
  gap: 0.5rem;
}

.reglages-note {
  color: var(--discret);
  font-size: 0.9rem;
}

/* --- Adventure sheet: short line always on screen, full sheet on a tap ---- */

.fiche {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 10;
  margin: 0 calc(-1 * var(--marge));
  background: var(--fond);
  border-bottom: 1px solid var(--bord);
}

.fiche-courte {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 1rem;
  min-height: 48px;
  padding: 0.5rem 5.5rem 0.5rem var(--marge);
  position: relative;
  cursor: pointer;
  list-style: none;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

/* Our own marker instead of the browser's triangle. */
.fiche-courte::-webkit-details-marker {
  display: none;
}

.fiche-courte::after {
  content: "Fiche ▾";
  position: absolute;
  right: var(--marge);
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}

.fiche[open] .fiche-courte::after {
  content: "Fermer ▴";
}

.fiche-stats {
  font-weight: 600;
}

.insecable {
  white-space: nowrap;
}

.fiche-sac,
.fiche-courte .fiche-ennemi {
  color: var(--discret);
  font-size: 0.9rem;
}

.fiche-courte .fiche-ennemi {
  flex-basis: 100%;
  color: var(--accent);
}

/* On a phone, the full sheet opens over the story instead of pushing it down. */
.fiche-complete {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  max-height: 70vh;
  max-height: 70dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 var(--marge) var(--marge);
  background: var(--surface);
  box-shadow: var(--ombre);
}

.fiche-complete h2 {
  font-family: var(--lecture);
  font-size: 1.2rem;
  margin: 0;
  padding-top: 0.75rem;
}

.fiche-complete h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--discret);
  margin: 1.25rem 0 0.5rem;
}

.fiche-variables {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.fiche-variables th,
.fiche-variables td {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--bord);
}

.fiche-variables th {
  text-align: left;
  font-weight: 500;
}

.fiche-variables abbr {
  color: var(--discret);
  font-size: 0.85rem;
  text-decoration: none;
}

.fiche-variables td {
  text-align: right;
  font-weight: 700;
  font-size: 1.1rem;
}

.fiche-variables td:last-child {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--discret);
  padding-left: 0.5rem;
  width: 4.5rem;
}

.fiche-capacites dt {
  font-weight: 600;
}

.fiche-capacites dd {
  margin: 0 0 0.5rem;
  color: var(--discret);
}

.fiche-objets {
  margin: 0;
  padding-left: 1.25rem;
}

/* --- Story ----------------------------------------------------------------- */

.recit {
  padding-top: 1rem;
}

.scene {
  font-family: var(--lecture);
  font-size: 1.2rem;
  line-height: 1.65;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.scene p {
  margin: 0 0 1em;
}

.scene-numero {
  font-size: 1rem;
  font-weight: 400;
  text-align: center;
  color: var(--discret);
  margin: 0.5rem 0 1rem;
}

.scene-numero::before,
.scene-numero::after {
  content: " — ";
}

.journal {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0.6rem 0.9rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--rayon) var(--rayon) 0;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--discret);
}

.avis {
  margin: 1rem 0 0;
  padding: 0.6rem 0.9rem;
  border-radius: var(--rayon);
  background: var(--surface);
  border: 1px solid var(--accent);
  font-size: 0.95rem;
}

/* --- Actions --------------------------------------------------------------- */

.actions {
  margin-top: 1.5rem;
}

.actions > p {
  margin: 0 0 0.75rem;
  font-weight: 600;
}

.choix {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.choix button,
.boutons button {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom delay */
}

.choix button:hover,
.boutons button:hover {
  border-color: var(--accent);
}

.choix button:active,
.boutons button:active {
  background: var(--bord);
}

.choix button:focus-visible,
.boutons button:focus-visible,
.bouton-principal:focus-visible,
.options label:has(input:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Combat options: one row of large segments per group. */

.options legend {
  font-weight: 600;
  margin-bottom: 0.4rem;
  padding: 0;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  border: 0;
  margin: 0 0 1rem;
  padding: 0;
}

.options label {
  flex: 1 1 0;
  min-width: 6rem;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
}

.options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.options label:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-texte);
  font-weight: 600;
}

.boutons {
  display: grid;
  gap: 0.6rem;
}

.boutons button {
  text-align: center;
}

.boutons button:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-texte);
  font-weight: 600;
}

.fin {
  display: grid;
  gap: 1rem;
  justify-items: center;
  margin-top: 2rem;
}

.fin form {
  width: 100%;
}

.fin a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

/* While HTMX waits for the server, the buttons show it. */
.htmx-request button {
  opacity: 0.6;
}

/* --- Larger screens -------------------------------------------------------- */

@media (min-width: 40rem) {
  :root {
    --marge: 1.5rem;
  }

  .boutons {
    grid-template-columns: 2fr 1fr;
  }
}

/* Wide screens: the story on the left at a comfortable line length, the
   sheet in a column on the right, still sticky. */
@media (min-width: 64rem) {
  .partie {
    display: grid;
    grid-template-columns: minmax(0, 40rem) 20rem;
    justify-content: space-between;
    align-items: start;
    gap: 3rem;
  }

  .fiche {
    order: 2;
    top: 1rem;
    margin: 1rem 0 0;
    border: 1px solid var(--bord);
    border-radius: var(--rayon);
    background: var(--surface);
    overflow: hidden;
  }

  .fiche-complete {
    position: static;
    box-shadow: none;
    max-height: calc(100vh - 6rem);
  }

  .recit {
    order: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}
