/* Turing Machine — fiche de note. Mobile d'abord. */

:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #22252a;
  --muted: #6b7280;
  --line: #d9d4c8;
  --accent: #22252a;
  --danger: #b3261e;
  --ok: #1a7f37;
  --ko: #b3261e;
  --blue: #1e6fd9;
  --yellow: #b78a00;
  --purple: #8544ad;
  --field-bg: #fbfaf7;
  --dim-bg: #eceae3;
  --ok-bg: #e9f5ec;
  --ko-bg: #fbecea;
  --on-accent: #ffffff;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.4;
}

header {
  padding: 14px 16px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

h1 { font-size: 1.15rem; margin: 0; }
h1 .subtitle { font-weight: 400; color: var(--muted); font-size: 0.9rem; }
h2 { font-size: 1rem; margin: 0 0 6px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar label { font-size: 0.85rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.toolbar select { font-size: 1rem; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); }

main { padding: 0 12px 24px; max-width: 640px; margin: 0 auto; display: grid; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.hint { font-size: 0.78rem; color: var(--muted); margin: 0 0 10px; }
.legend { white-space: nowrap; }
.legend-eliminated { text-decoration: line-through; }
.legend-confirmed { font-weight: 700; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 8px 12px;
}
button.danger { color: var(--danger); border-color: var(--danger); }

/* --- Grilles de chiffres --- */

.digit-group { display: grid; gap: 6px; margin-bottom: 12px; }
.digit-group:last-child { margin-bottom: 0; }

.digit-group-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 0.95rem;
}
.digit-group-title .symbol { font-size: 1.3rem; line-height: 1; }

.digit-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }

.digit {
  min-height: 48px;
  font-size: 1.25rem;
  font-weight: 600;
  position: relative;
  border-width: 2px;
}
.digit.state-eliminated {
  color: var(--muted);
  background: var(--dim-bg);
  text-decoration: line-through;
}
.digit.state-eliminated::after {
  content: "✕";
  position: absolute; top: 2px; right: 6px;
  font-size: 0.7rem; text-decoration: none;
}
.digit.state-confirmed {
  border-color: currentColor;
  font-weight: 800;
  box-shadow: inset 0 0 0 2px currentColor;
}
.digit.state-confirmed::after {
  content: "●";
  position: absolute; top: 2px; right: 6px;
  font-size: 0.6rem;
}

.color-blue   { color: var(--blue); }
.color-yellow { color: var(--yellow); }
.color-purple { color: var(--purple); }
.digit.state-neutral { color: var(--ink); }

/* --- Manches --- */

#rounds { display: grid; gap: 12px; margin-bottom: 12px; }

.code-picker { display: grid; gap: 6px; }
.code-color { display: grid; grid-template-columns: 3.2rem repeat(5, 1fr); gap: 6px; align-items: center; }
.code-color .code-label { font-weight: 700; font-size: 0.85rem; display: flex; gap: 4px; align-items: center; }

.code-digit { min-height: 40px; font-size: 1.05rem; padding: 4px 0; }
.code-digit.selected {
  background: currentColor;
  border-color: currentColor;
  font-weight: 800;
}
.code-digit.selected span { color: var(--on-accent); }

#btn-add-round { width: 100%; min-height: 46px; font-weight: 600; }

/* --- Notes vérificateurs --- */

.verifier-note { display: grid; gap: 4px; margin-bottom: 10px; }
.verifier-note label { font-weight: 700; font-size: 0.9rem; }
.verifier-note textarea {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  min-height: 52px;
  resize: vertical;
  background: var(--field-bg);
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 8px 16px 20px;
}

@media (min-width: 480px) {
  h1 { font-size: 1.3rem; }
}

/* --- Partie simulée (v2) --- */

button.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  font-weight: 600;
}

.error { color: var(--danger); font-size: 0.85rem; font-weight: 600; }
.setup-actions { display: flex; gap: 8px; }

.catalog-details { font-size: 0.82rem; color: var(--muted); margin-bottom: 6px; }
.catalog-details ul { margin: 6px 0 0; padding-left: 18px; }
.catalog-details li { margin-bottom: 2px; }

.game-cards { font-weight: 700; font-size: 0.9rem; margin: 0 0 4px; white-space: pre-wrap; }
.game-score { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }

.game-end { font-weight: 700; padding: 10px; border-radius: 8px; margin: 8px 0; }
.game-won  { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }
.game-lost { background: var(--ko-bg); color: var(--ko); border: 1px solid var(--ko); }
ul.game-reveal { margin: 4px 0 10px; padding-left: 18px; font-size: 0.88rem; }
p.game-reveal { margin: 0; font-size: 0.88rem; font-weight: 700; }

#game-guess { display: grid; gap: 8px; margin-top: 10px; }
#btn-guess { min-height: 46px; font-weight: 700; }
#btn-guess:disabled { opacity: 0.45; cursor: not-allowed; }
.code-digit:disabled { cursor: default; }
.code-digit:disabled:not(.selected) { opacity: 0.4; }

.variant-list { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 4px; }
.variant-line {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  background: var(--field-bg);
}
.variant-line.struck {
  text-decoration: line-through;
  color: var(--muted);
  background: var(--dim-bg);
}
.variant-line.struck::after { content: " ✕"; }

.catalog-details > ul > li { margin-bottom: 6px; }
.catalog-details ul ul { margin: 2px 0 0; padding-left: 16px; list-style: circle; }

.game-official {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 2px 10px;
  margin: 0 0 6px;
}

/* --- Thème sombre (v3) --- */

:root[data-theme="dark"] {
  --bg: #15171b;
  --card: #1e2126;
  --ink: #e9e6dd;
  --muted: #9aa1ab;
  --line: #363b43;
  --danger: #ff7a70;
  --ok: #5fce7f;
  --ko: #ff7a70;
  --blue: #7db1ff;
  --yellow: #e8c95a;
  --purple: #c58fe0;
  --field-bg: #181b1f;
  --dim-bg: #2a2e35;
  --ok-bg: rgba(95, 206, 127, 0.14);
  --ko-bg: rgba(255, 122, 112, 0.14);
  --on-accent: #15171b;
}

input, select, textarea, button { color: var(--ink); }

button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.danger { color: var(--danger); border-color: var(--danger); }

/* --- Verticalisation (v3) : grille d'élimination et tentative finale --- */

#digit-grids {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
#digit-grids .digit-group { margin-bottom: 0; align-content: start; }
#digit-grids .digit-group-title { justify-content: center; }
#digit-grids .digit-row { grid-template-columns: 1fr; }

#game-guess .code-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
#game-guess .code-color { grid-template-columns: 1fr; }
#game-guess .code-color .code-label {
  justify-content: center;
  font-size: 1.15rem;
  min-height: 1.6rem;
}

/* --- Symboles SVG remplis (v3) --- */

svg.sym {
  width: 0.95em;
  height: 0.95em;
  vertical-align: -0.1em;
}
.sym-blue { fill: var(--blue); }
.sym-yellow { fill: var(--yellow); }
.sym-purple { fill: var(--purple); }
.digit-group-title svg.sym { width: 1.2em; height: 1.2em; }
.code-label svg.sym { width: 1.1em; height: 1.1em; }

/* --- Manches en lignes, comme la fiche papier (v3) --- */

.rounds-table {
  overflow-x: auto;
  display: grid;
  gap: 6px;
  padding-bottom: 4px;
  margin-bottom: 12px;
}
.round-row { display: grid; gap: 4px; align-items: center; }
.rounds-header .rh-sym,
.rounds-header .rh-letter { text-align: center; font-weight: 700; }
.rounds-header .rh-sym svg.sym { width: 1.15em; height: 1.15em; }

.cell {
  min-height: 42px;
  font-size: 1.1rem;
  font-weight: 700;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  padding: 0;
}
.code-cell { border-style: dashed; }
.code-cell.filled { border-style: solid; border-color: currentColor; }
.code-cell:disabled { opacity: 0.75; cursor: default; }
.verif-cell { color: var(--muted); font-size: 1rem; }
.verif-cell.res-yes { color: var(--ok); border-color: var(--ok); background: var(--ok-bg); }
.verif-cell.res-no  { color: var(--ko); border-color: var(--ko); background: var(--ko-bg); }

.round-num {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: none;
  border: none;
  padding: 0;
  min-height: 42px;
}
button.round-num.round-delete { cursor: pointer; text-decoration: underline dotted; }
.round-info { font-size: 0.72rem; color: var(--muted); text-align: center; }
.round-info.over { color: var(--danger); font-weight: 700; }
.round-row.locked { opacity: 0.55; }

/* --- Barre d'onglets (v3) --- */

#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 6px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
#tabbar button {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 600;
  min-height: 44px;
  border-radius: 10px;
}
#tabbar button.active {
  color: var(--ink);
  background: var(--dim-bg);
}
body { padding-bottom: 72px; }

#tabbar[hidden] { display: none; }
body.no-tabbar { padding-bottom: 12px; }

/* --- Mise en place façon livret (v3) --- */

.setup-head,
.setup-line {
  display: grid;
  grid-template-columns: 1.6rem 76px 96px;
  gap: 8px;
  align-items: center;
}
.setup-head { font-size: 0.72rem; color: var(--muted); margin-bottom: 4px; text-align: center; }
#setup-rows { display: grid; gap: 6px; margin-bottom: 10px; }
.setup-letter { font-weight: 800; text-align: center; }
.setup-line input {
  font: inherit;
  font-size: 1.05rem;
  text-align: center;
  min-height: 42px;
  border-radius: 8px;
  background: var(--field-bg);
}
.setup-crit { border: 1.5px solid var(--ok); font-weight: 700; }
.setup-verif { border: 1.5px solid var(--line); }
.setup-buttons { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

.setup-line[hidden] { display: none; }
