/* Ouvertures — feuille de style unique.
   Thème clair par défaut, thème sombre automatique (prefers-color-scheme).
   Toutes les zones tactiles font au moins 44 px. */

:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --surface-2: #efe9dd;
  --text: #1c2420;
  --muted: #56635c;
  --faint: #86918b;
  --line: #ddd5c6;
  --brand: #1e3a2f;
  --brand-ink: #f4ecd8;
  --brand-ink-soft: rgba(244, 236, 216, 0.7);
  --brand-hover: rgba(244, 236, 216, 0.14);
  --accent: #23664a;
  --star: #a8740a;
  --trap-bg: #fff4de;
  --trap-line: #dfa037;
  --trap-ink: #6a4300;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101412;
    --surface: #19201c;
    --surface-2: #222b26;
    --text: #e8e5dc;
    --muted: #a4afa9;
    --faint: #76817b;
    --line: #2e3833;
    --brand: #132720;
    --brand-ink: #efe6cf;
    --brand-ink-soft: rgba(239, 230, 207, 0.66);
    --accent: #78c9a0;
    --star: #e5b648;
    --trap-bg: #2f250f;
    --trap-line: #b5872e;
    --trap-ink: #f2d89f;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

a,
button {
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

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

.mono {
  font-family: var(--mono);
}

/* ---------- Barre du haut (fixe, sous la barre d'état iOS) ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--brand);
  color: var(--brand-ink);
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.appbar-row {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0 6px;
  gap: 2px;
  max-width: 760px;
  margin: 0 auto;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--brand-ink);
  cursor: pointer;
}

.icon-btn:active {
  background: var(--brand-hover);
}

.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  font-size: 15px;
  padding-right: 10px;
}

.crumbs::-webkit-scrollbar {
  display: none;
}

.crumbs a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 5px;
  color: var(--brand-ink-soft);
  text-decoration: none;
  border-radius: 8px;
}

.crumbs a:active {
  background: var(--brand-hover);
}

.crumbs .sep {
  color: var(--brand-ink-soft);
  opacity: 0.6;
  padding: 0 1px;
}

.crumbs .current {
  padding: 0 5px;
  font-weight: 650;
  color: var(--brand-ink);
}

.crumbs .app-title {
  padding: 0 10px;
  font-size: 20px;
  font-weight: 750;
  letter-spacing: 0.01em;
  color: var(--brand-ink);
}

/* Sélecteur du mode entraînement */
.trainer {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 12px 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.22);
}

.segmented button {
  min-height: 44px;
  padding: 4px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--brand-ink-soft);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
  cursor: pointer;
}

.segmented button[aria-checked="true"] {
  background: var(--brand-ink);
  color: var(--brand);
}

/* ---------- Contenu ---------- */

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* Le contenu reçoit le focus à chaque changement de page (lecteurs d'écran) : pas de contour. */
main:focus,
main:focus-visible {
  outline: none;
}

.loading,
.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 0;
}

.title {
  font-size: 27px;
  line-height: 1.2;
  font-weight: 750;
  margin: 2px 0 6px;
  letter-spacing: -0.01em;
}

.title .side {
  font-weight: 500;
  color: var(--muted);
}

.lead {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 16px;
}

.star {
  color: var(--star);
  margin-left: 6px;
}

.badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--star);
  color: var(--star);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 14px 0;
}

.panel h2,
.section-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-title {
  margin: 26px 2px 10px;
}

.panel h3 {
  margin: 4px 0 4px;
  font-size: 17px;
}

.panel p {
  margin: 0 0 8px;
}

.panel p:last-child {
  margin-bottom: 0;
}

.panel.mine {
  border-color: var(--accent);
  border-width: 1.5px;
}

/* Cartes de l'accueil */
.card {
  display: block;
  margin-bottom: 14px;
  padding: 22px 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: transform 0.12s ease;
}

.card:active {
  transform: scale(0.985);
}

.card-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 25px;
  font-weight: 750;
  line-height: 1.2;
}

.card-title .side {
  font-size: 18px;
  font-weight: 550;
  color: var(--muted);
}

.side-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--text);
  flex: none;
}

.side-dot.w {
  background: #fbf8f1;
}

.side-dot.b {
  background: #151515;
}

.card-moves {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 17px;
  color: var(--muted);
}

.card-meta {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
}

.foot {
  margin-top: 28px;
  text-align: center;
  font-size: 13px;
  color: var(--faint);
}

/* Recherche : 17 px minimum, sinon Safari zoome quand on touche le champ */
.search {
  margin: 18px 0 10px;
}

.search input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}

.search input::placeholder {
  color: var(--faint);
}

.count {
  margin: 6px 2px 8px;
  font-size: 14px;
  color: var(--muted);
}

/* Lien « Vue d'ensemble » */
.overview {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 56px;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  font-weight: 650;
}

.overview small {
  font-weight: 400;
  color: var(--muted);
  font-size: 14px;
}

.overview:active,
.link-row:active,
.row-link:active {
  background: var(--surface-2);
}

/* ---------- Arbre des variantes ---------- */

.tree-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 14px 0 6px;
}

.toggle,
.btn {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.toggle[aria-pressed="true"] {
  border-color: var(--star);
  color: var(--star);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--star);
}

.btn-link {
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.tree,
.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree ul {
  margin-left: 21px;
  padding-left: 6px;
  border-left: 1px solid var(--line);
}

.row {
  display: flex;
  align-items: stretch;
  min-height: 48px;
}

.twisty,
.twisty-spacer {
  flex: none;
  width: 44px;
  min-height: 44px;
}

.twisty {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.twisty .chev {
  display: inline-block;
  font-size: 22px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.twisty[aria-expanded="true"] .chev {
  transform: rotate(90deg);
}

.twisty-spacer::before {
  content: "";
  display: block;
  width: 5px;
  height: 5px;
  margin: 21px auto 0;
  border-radius: 50%;
  background: var(--line);
}

.row-link,
.link-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border-radius: 10px;
}

.row-link {
  flex: 1;
  padding: 7px 10px 7px 2px;
}

.row-name {
  font-weight: 600;
  font-size: 16.5px;
  line-height: 1.3;
}

.row-moves,
.row-path,
.row-transpo {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.row-moves {
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-transpo {
  color: var(--accent);
}

.group > .row .row-name {
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Listes de liens (suites, résultats de recherche) */
.links {
  list-style: none;
  margin: 0;
  padding: 0;
}

.links li + li {
  margin-top: 8px;
}

.link-row {
  min-height: 52px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.link-row.group .row-name {
  color: var(--muted);
}

/* Petits jetons « ? » dans les aperçus de coups (non interactifs) */
.chip {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 3px;
  border: 1px dashed currentColor;
  border-radius: 5px;
  text-align: center;
  line-height: 1.25;
  opacity: 0.8;
}

/* ---------- Fiche : feuille de partie ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.sheet {
  display: grid;
  grid-template-columns: max-content 1fr 1fr;
  column-gap: 14px;
  row-gap: 2px;
  align-items: center;
  font-family: var(--mono);
  font-size: 17px;
}

.sheet .num {
  justify-self: end;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.mv {
  min-height: 30px;
  display: flex;
  align-items: center;
}

.mv.trunk {
  color: var(--faint);
}

.mv.own {
  font-weight: 700;
}

.sheet-sep {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 4px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.sheet-sep::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--accent);
  opacity: 0.5;
}

/* Coup masqué : bouton à toucher pour révéler */
button.masked {
  min-height: 44px;
  min-width: 76px;
  justify-content: center;
  padding: 0 10px;
  border: 1.5px dashed var(--accent);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

button.masked:active {
  background: var(--surface-2);
}

.mv.revealed {
  color: var(--accent);
}

/* Pièges */
.trap {
  margin: 12px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--trap-bg);
  border: 1px solid var(--trap-line);
  border-left-width: 6px;
}

.trap-head {
  font-weight: 750;
  color: var(--trap-ink);
  margin-bottom: 6px;
}

.trap-moves {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 16.5px;
  font-weight: 650;
}

.tm {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}

.tm .num {
  color: var(--trap-ink);
  opacity: 0.75;
  font-weight: 500;
}

.trap-moves .mv {
  min-height: 30px;
}

.trap-moves button.masked {
  min-width: 64px;
  min-height: 44px;
}

.trap p {
  margin: 0;
}

.err-detail {
  font-size: 13px;
  color: var(--faint);
}

.inline-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Écrans étroits (iPhone SE) : libellés du sélecteur plus serrés */
@media (max-width: 360px) {
  .segmented button {
    font-size: 13px;
    padding: 4px 3px;
  }
  .sheet {
    column-gap: 10px;
  }
}
