/* Logimages — thèmes clair et sombre, tokens d'abord (même système que Fléchette) */
:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --paper: #ffffff;
  --ink: #16191d;
  --muted: #5f6672;
  --line: #22262b;
  --hair: #d9dcd6;
  --def: #e6e8e1;
  --accent: #0f6f6a;
  --accent-ink: #ffffff;
  --accent-soft: #d7efec;
  --mark: #ffd54a;
  --mark-soft: #fff1b8;
  --danger: #b42318;
  --danger-soft: #fde3e0;
  --ok: #1f7a3e;
  --ok-soft: #dcf3e3;
  --focus: #0f6f6a;
  --cross: #8a919b;
  --shadow: 0 1px 2px rgba(20, 25, 30, 0.06), 0 8px 24px rgba(20, 25, 30, 0.06);
  --radius: 10px;
  --cell: 28px;
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-clue: "Archivo Narrow", "Arial Narrow", "Roboto Condensed", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15181b;
    --paper: #1f2327;
    --ink: #e8eaec;
    --muted: #9aa3ad;
    --line: #cfd4d9;
    --hair: #343a41;
    --def: #2b3036;
    --accent: #3cc9bf;
    --accent-ink: #0f1b1a;
    --accent-soft: #163d3a;
    --mark: #f2c94c;
    --mark-soft: #4a4020;
    --danger: #ff8a80;
    --danger-soft: #4a2320;
    --ok: #6fd48f;
    --ok-soft: #1f3d2a;
    --focus: #3cc9bf;
    --cross: #7d8590;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15181b;
  --paper: #1f2327;
  --ink: #e8eaec;
  --muted: #9aa3ad;
  --line: #cfd4d9;
  --hair: #343a41;
  --def: #2b3036;
  --accent: #3cc9bf;
  --accent-ink: #0f1b1a;
  --accent-soft: #163d3a;
  --mark: #f2c94c;
  --mark-soft: #4a4020;
  --danger: #ff8a80;
  --danger-soft: #4a2320;
  --ok: #6fd48f;
  --ok-soft: #1f3d2a;
  --focus: #3cc9bf;
  --cross: #7d8590;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); line-height: 1.5; font-size: 16px; }
h1, h2, h3 { line-height: 1.15; text-wrap: balance; margin: 0; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.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; }
.skip { position: absolute; left: 0.5rem; top: -3rem; background: var(--accent); color: var(--accent-ink); padding: 0.5rem 0.8rem; border-radius: 8px; z-index: 10; }
.skip:focus { top: 0.5rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hidden { display: none !important; }

button { font: inherit; cursor: pointer; border-radius: var(--radius); border: 1px solid var(--hair); background: var(--paper); padding: 0.5rem 0.9rem; color: var(--ink); min-height: 40px; transition: background 0.12s, border-color 0.12s; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: default; }
button:disabled:hover { border-color: var(--hair); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
button.primary:hover { filter: brightness(1.06); }
button.big { font-size: 1.1rem; padding: 0.8rem 1.4rem; min-height: 52px; }
button.subtle { background: transparent; border-color: transparent; color: var(--muted); }
button.subtle:hover { color: var(--ink); border-color: var(--hair); }
button.danger { color: var(--danger); }
.icon-btn { display: inline-flex; align-items: center; gap: 0.4rem; }
.brand { display: inline-flex; align-items: center; gap: 0.45rem; border: none; background: none; padding: 0.25rem 0.35rem; font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.logo { color: var(--accent); }
input, textarea { font: inherit; padding: 0.6rem 0.8rem; border-radius: var(--radius); border: 1px solid var(--hair); background: var(--paper); color: var(--ink); min-width: 0; min-height: 44px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[aria-invalid="true"] { border-color: var(--danger); }
input[type="number"] { width: 6.5rem; }
label, legend { font-size: 0.9rem; color: var(--muted); font-weight: 500; }
fieldset { border: none; padding: 0; margin: 0; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.error { color: var(--danger); }
.center { text-align: center; padding: 3rem 1rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
footer { margin-top: 2.5rem; text-align: center; }
.tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.1rem 0.45rem; border-radius: 999px; background: var(--def); color: var(--muted); font-weight: 700; }
.tag.ok { background: var(--ok-soft); color: var(--ink); }
kbd { font-family: inherit; font-size: 0.85rem; background: var(--bg); border: 1px solid var(--hair); border-bottom-width: 2px; border-radius: 6px; padding: 0.1rem 0.45rem; white-space: nowrap; }

/* segmented control (thème, outil) */
.seg { display: inline-flex; border: 1px solid var(--hair); border-radius: 999px; padding: 2px; background: var(--paper); }
.seg button { border: none; background: transparent; border-radius: 999px; padding: 0.3rem 0.65rem; min-height: 32px; display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--ink); }
.seg-label { display: none; }
@media (min-width: 700px) { .seg-label { display: inline; } }
.seg.tool button { min-height: 40px; padding: 0.4rem 0.9rem; font-size: 0.95rem; font-weight: 600; }
.seg.tool .seg-label { display: inline; }
.seg.tool .glyph { font-size: 1.1em; line-height: 1; }
.seg.tool .swatch { display: inline-block; width: 1.1em; height: 1.1em; border-radius: 4px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.seg.tool button.on .swatch { outline: 2px solid var(--ink); outline-offset: 1px; }

/* Palette de l'éditeur */
.palette { display: flex; flex-direction: column; gap: 0.4rem; }
.palette-item { display: flex; align-items: center; gap: 0.4rem; }
.palette-item .pick { flex: 1; justify-content: flex-start; gap: 0.6rem; }
.palette-item .pick.on { border-color: var(--accent); background: var(--accent-soft); }
.palette-item .swatch { width: 1.4rem; height: 1.4rem; border-radius: 6px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); flex: none; }
.palette-item input[type="color"] { width: 44px; min-height: 40px; padding: 2px; border-radius: 8px; border: 1px solid var(--hair); background: var(--paper); cursor: pointer; }
.palette-item .subtle { min-width: 40px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 0.55rem 1rem; border-radius: 999px; box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity 0.2s; pointer-events: none; max-width: 92vw; }
.toast.show { opacity: 1; }

/* Accueil */
.home { max-width: 880px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }
.home-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.25rem 0 1.5rem; }
.home-top .actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 2rem; align-items: center; padding: 1rem 0 2rem; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); font-weight: 800; letter-spacing: -0.02em; max-width: 18ch; }
.hero .muted { margin-top: 0.75rem; max-width: 46ch; font-size: 1.05rem; }
.demo { --d: 26px; display: grid; grid-template-columns: repeat(var(--n), var(--d)); grid-auto-rows: var(--d); gap: 2px; background: var(--line); border: 2px solid var(--line); border-radius: 6px; overflow: hidden; transform: rotate(-3deg); box-shadow: var(--shadow); }
.demo .d { background: var(--paper); }
.demo .d.on { background: var(--ink); }
.demo .d.cross { background: var(--paper); position: relative; }
.demo .d.cross::after { content: ""; position: absolute; inset: 30%; background: linear-gradient(45deg, transparent 42%, var(--cross) 42%, var(--cross) 58%, transparent 58%), linear-gradient(-45deg, transparent 42%, var(--cross) 42%, var(--cross) 58%, transparent 58%); }
.panel { background: var(--paper); border: 1px solid var(--hair); border-radius: 16px; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.1rem; box-shadow: var(--shadow); max-width: 520px; }
.panel fieldset { display: flex; flex-direction: column; gap: 0.4rem; }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.choices.four { grid-template-columns: repeat(4, 1fr); }
.choice { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; text-align: left; padding: 0.55rem 0.8rem; min-height: 52px; border-width: 2px; }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.choice-name { font-weight: 700; }
.choice-hint { font-size: 0.8rem; color: var(--muted); }
.custom-size { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; padding-top: 0.3rem; }
.play-hint { margin-top: -0.4rem; }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } .demo { display: none; } .choices.four { grid-template-columns: repeat(2, 1fr); } }

/* Sections secondaires de l'accueil */
.section { margin-top: 2rem; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.section h2, .card h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.section ul { list-style: none; margin: 0; padding: 0; }
.list { display: flex; flex-direction: column; gap: 0.4rem; max-width: 520px; }
.list li { display: flex; gap: 0.3rem; align-items: stretch; }
.list li.done .item-main { opacity: 0.8; }
.item-main { flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.8rem; text-align: left; min-width: 0; }
.item-main strong { font-weight: 700; }
.item-main .muted { font-size: 0.85rem; }
.list .subtle { min-width: 40px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; }
.gallery button { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; text-align: left; padding: 0.6rem 0.8rem; min-height: 56px; }
.gallery button.done { border-color: var(--ok); }
.gallery .name { font-weight: 700; display: inline-flex; align-items: center; gap: 0.35rem; }
.gallery .name .check { color: var(--ok); }
.gallery .hint { font-size: 0.8rem; color: var(--muted); }
.item-main .tag { margin-left: 0.2rem; }
.rules { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 0.9rem; margin: 0; max-width: 640px; }
.rules div { display: contents; }
.rules dt { justify-self: start; }
.rules dd { margin: 0; }

/* Pages jeu et éditeur */
.room { max-width: 1160px; margin: 0 auto; padding: 0.75rem 1rem 2rem; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; padding: 0.3rem 0 0.6rem; }
.topbar .code { display: inline-flex; align-items: baseline; gap: 0.5rem; background: var(--paper); border: 1px dashed var(--muted); border-radius: 8px; padding: 0.3rem 0.7rem; font-size: 0.9rem; }
.topbar .code strong { letter-spacing: 0.08em; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.topbar .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-left: auto; }
.status { font-size: 0.9rem; color: var(--muted); padding: 0.25rem 0; min-height: 1.6rem; }
.page-head { padding: 0.25rem 0 0.75rem; }
.page-head h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); font-weight: 800; letter-spacing: -0.02em; }
.page-head .muted { margin-top: 0.25rem; }

.play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); gap: 1.5rem 2rem; align-items: start; }
.play.solo { grid-template-columns: 1fr; }
@media (max-width: 860px) { .play { grid-template-columns: 1fr; } }
.board-section { min-width: 0; }
.side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.card { background: var(--paper); border: 1px solid var(--hair); border-radius: 16px; padding: 1.25rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 0.9rem; min-width: 0; }

/* Barre d'outils */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin: 0.9rem 0 0.5rem; }
.toolbar .spacer { flex: 1; }
.progress { position: relative; flex: 1 1 160px; height: 28px; background: var(--paper); border: 1px solid var(--hair); border-radius: 999px; overflow: hidden; }
.progress .bar { height: 100%; background: var(--accent-soft); transition: width 0.3s; }
.progress-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.check-result { padding: 0.5rem 0.8rem; border-radius: var(--radius); background: var(--ok-soft); border: 1px solid transparent; margin-top: 0.5rem; }
.check-result.has-errors { background: var(--danger-soft); }
.check-result.info { background: var(--accent-soft); }
.solved-banner { margin-top: 1rem; background: var(--paper); border: 1px solid var(--ok); border-radius: 14px; padding: 1.25rem; text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }
.solved-banner h2 { color: var(--ok); font-size: 1.4rem; }
.solved-banner .row { justify-content: center; }
.zoom { display: inline-flex; gap: 0.25rem; }
.zoom button { min-width: 40px; padding: 0.4rem; font-size: 1.1rem; line-height: 1; }

/* Plateau de logimage */
.board-wrap { position: relative; overflow: auto; padding: 0.5rem 3px 3px; -webkit-overflow-scrolling: touch; }
.board { border-collapse: collapse; table-layout: fixed; touch-action: none; user-select: none; -webkit-user-select: none; margin: 0 auto; font-variant-numeric: tabular-nums; }
.board:focus-visible { outline-offset: 4px; }
.board th, .board td { padding: 0; }
.board td.cell { width: var(--cell); height: var(--cell); min-width: var(--cell); background: var(--paper); border: 1px solid var(--hair); position: relative; cursor: pointer; transition: background 0.05s; }
.board td.cell:hover { background: var(--mark-soft); }
.board td.cell.filled { background: var(--ink); }
.board td.cell.filled:hover { background: var(--ink); }
.board td.cell.marked::after { content: ""; position: absolute; inset: 27%; background: linear-gradient(45deg, transparent 42%, var(--cross) 42%, var(--cross) 58%, transparent 58%), linear-gradient(-45deg, transparent 42%, var(--cross) 42%, var(--cross) 58%, transparent 58%); }
.board td.cell.cursor { box-shadow: inset 0 0 0 3px var(--accent); z-index: 1; }
.board td.cell.error { box-shadow: inset 0 0 0 3px var(--danger); }
.board td.cell.hint { box-shadow: inset 0 0 0 3px var(--mark); }
.board td.cell.ambiguous { box-shadow: inset 0 0 0 3px var(--mark); background: var(--mark-soft); }
.board td.cell.b5, .board th.clue-col.b5 { border-left: 2px solid var(--line); }
.board tr.b5 td.cell, .board tr.b5 th.clue-row { border-top: 2px solid var(--line); }
.board tr.first td.cell, .board th.clue-col { border-top: 2px solid var(--line); }
.board tr:last-child td.cell { border-bottom: 2px solid var(--line); }
.board td.cell.first, .board th.clue-row { border-left: 2px solid var(--line); }
.board td.cell:last-child { border-right: 2px solid var(--line); }
.board th.clue { background: var(--def); font-family: var(--font-clue); font-weight: 700; font-size: clamp(11px, calc(var(--cell) * 0.55), 18px); line-height: 1; color: var(--ink); border: 1px solid var(--hair); vertical-align: bottom; }
.board th.clue-col { vertical-align: bottom; padding-bottom: calc(var(--cell) * 0.12); }
.board th.clue-col .clues { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: calc(var(--cell) * 0.12); }
.board th.clue-row { text-align: right; padding-right: calc(var(--cell) * 0.15); }
.board th.clue-row .clues { display: flex; flex-direction: row; justify-content: flex-end; align-items: center; gap: calc(var(--cell) * 0.3); padding-left: calc(var(--cell) * 0.2); min-width: var(--cell); height: var(--cell); }
.board th.clue .clues span { display: inline-block; min-width: calc(var(--cell) * 0.5); text-align: center; }
.board th.clue .chip { background: var(--c); color: var(--on); border-radius: 4px; padding: 0 0.15em; min-width: calc(var(--cell) * 0.6) !important; line-height: 1.25; }
.board th.clue.done { color: var(--muted); }
.board th.clue.done .clues span { opacity: 0.5; text-decoration: line-through; }
.board th.corner { background: transparent; }
.board.editing td.cell { cursor: crosshair; }
.board.solved td.cell { cursor: default; }
.board.solved td.cell:hover { background: var(--paper); }
.board.solved td.cell.filled:hover { background: var(--ink); }
.board.solved td.cell.marked::after { display: none; }
.board.preview td.cell { cursor: default; }

/* Éditeur */
.analysis { padding: 0.6rem 0.8rem; border-radius: var(--radius); border: 1px solid var(--hair); background: var(--bg); display: flex; flex-direction: column; gap: 0.25rem; }
.analysis.ok { background: var(--ok-soft); border-color: var(--ok); }
.analysis.warn { background: var(--mark-soft); border-color: var(--mark); }
.analysis.bad { background: var(--danger-soft); border-color: var(--danger); }
.analysis .status { padding: 0; font-weight: 700; color: var(--ink); min-height: 0; }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; line-height: 1.25; min-height: 9rem; white-space: pre; resize: vertical; width: 100%; }
details.more summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; gap: 0.5rem; min-height: 40px; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: "▸"; color: var(--accent); transition: transform 0.15s; }
details.more[open] summary::before { transform: rotate(90deg); }
details.more .field { margin-top: 0.5rem; }

/* Aide */
dialog.help { border: 1px solid var(--hair); border-radius: 16px; background: var(--paper); color: var(--ink); padding: 1.5rem; max-width: min(92vw, 480px); box-shadow: var(--shadow); }
dialog.help::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.help h2 { margin-bottom: 1rem; }
dialog.help dl { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 0.9rem; margin: 0 0 1rem; }
dialog.help dl div { display: contents; }
dialog.help dt { justify-self: start; }
dialog.help dd { margin: 0; }
dialog.help .muted { margin-bottom: 1rem; font-size: 0.9rem; }

/* Mobile : barre compacte */
@media (max-width: 600px) {
  .home { padding: 0.75rem 0.9rem 2.5rem; }
  .room { padding: 0.5rem 0.75rem 2rem; }
  .topbar { gap: 0.4rem 0.6rem; }
  .topbar .actions { margin-left: auto; gap: 0.25rem; }
  .brand-name, .btn-label, .code-label { display: none; }
  .icon-btn { padding: 0.5rem; min-width: 40px; justify-content: center; }
  .topbar .code { padding: 0.25rem 0.6rem; }
  .toolbar { gap: 0.5rem 0.6rem; }
  .card, .panel { padding: 1rem; }
  .choices { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
  .board td.cell.filled { background: CanvasText; }
  .board td.cell.cursor, .board td.cell.error, .board td.cell.hint, .choice.on, .seg button.on { outline: 2px solid CanvasText; }
}
