:root {
  --paper: #f6efe3;
  --paper-deep: #ece1cd;
  --card: #fcf8f1;
  --ink: #2d231c;
  --ink-soft: #6c5b4d;
  --ink-faint: #a8978a;
  --rule: #3b2f26;
  --edge: #e0d1ba;
  --accent: #b4532f;
  --accent-dark: #8e3d20;
  --accent-soft: #f3dccb;
  --sage: #66744f;
  --cell-bg: #fffaf2;
  --clue: #ead8bc;
  --clue-on: #e3b889;
  --word: #fbe7b3;
  --cur: #f1c160;
  --wrong: #f3cabd;

  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Archivo', 'Segoe UI', system-ui, sans-serif;
  --narrow: 'Archivo Narrow', 'Arial Narrow', 'Roboto Condensed', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .15 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
input, textarea { font: inherit; color: inherit; }
code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: .9em;
  background: var(--paper-deep);
  padding: 1px 5px;
  border-radius: 4px;
}
.sc { font-family: var(--serif); font-weight: 600; letter-spacing: .08em; }
.muted { color: var(--ink-soft); font-size: 14px; }

/* --- En-tête --- */

.masthead { border-bottom: 3px double var(--rule); }
.masthead-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 26px 20px 12px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 24px;
  flex-wrap: wrap;
}
.brand {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.015em;
  cursor: default;
}
.brand em { font-weight: 400; color: var(--accent); }
.brand small {
  display: block;
  margin-top: 8px;
  font: 500 11.5px var(--sans);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.tabs { display: flex; gap: 2px; margin-bottom: -2px; flex-wrap: wrap; }
.tab {
  position: relative;
  background: none;
  border: 0;
  padding: 8px 12px 10px;
  font-weight: 500;
  font-size: 15px;
  color: var(--ink-soft);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.on { color: var(--ink); }
.tab.on::after {
  content: '';
  position: absolute;
  left: 10px; right: 10px; bottom: 2px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
  transform: rotate(-1.2deg);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 30px 20px 70px;
}

.page-head h1, .play-head h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(28px, 4vw, 40px);
  letter-spacing: -.02em;
  line-height: 1.1;
  margin: 0 0 8px;
}
.lede { color: var(--ink-soft); max-width: 62ch; margin: 0 0 22px; }
.note {
  max-width: 62ch;
  margin: -8px 0 22px;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--accent-soft);
  border-radius: 6px;
  color: var(--accent-dark);
}

/* --- Boutons et champs --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14.5px;
  border-radius: 7px;
  border: 1.5px solid var(--ink);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent-dark); color: #fff8ee; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { border-color: rgba(59, 47, 38, .25); background: transparent; }
.btn.ghost:hover { border-color: var(--ink); background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13.5px; }
.btn.wide { width: 100%; padding: 12px; font-size: 15.5px; }
.btn.armed { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }

.link {
  background: none;
  border: 0;
  padding: 2px 0;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 14px;
  text-decoration: underline;
  text-decoration-color: var(--ink-faint);
  text-underline-offset: 3px;
}
.link:hover { color: var(--ink); }
.link.danger:hover, .link.armed { color: var(--accent-dark); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.field > span {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
input:not([type]), input[type=search], textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid #d6c5ab;
  border-radius: 7px;
  background: #fffdf8;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:not([type]):focus, input[type=search]:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.45; }
input[type=range] { accent-color: var(--accent); flex: 1; }
input[type=checkbox] { accent-color: var(--accent); }

/* --- Dictionnaire --- */

.add-card {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 12px;
  padding: 18px 18px 6px;
  margin-bottom: 26px;
  background: var(--card);
  border: 1px solid var(--edge);
  border-top: 3px solid var(--accent);
  border-radius: 4px 4px 10px 10px;
}
.add-card .field { flex: 1 1 180px; }
.add-card .field.grow { flex: 3 1 260px; }
.add-card .btn { margin-bottom: 16px; }
.add-preview { flex-basis: 100%; margin: -8px 0 10px; min-height: 20px; font-size: 13.5px; color: var(--ink-soft); }
.add-preview.warn { color: var(--accent-dark); }

.dico-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 10px;
}
.dico-toolbar input[type=search] { max-width: 240px; padding: 7px 11px; }
.spacer { flex: 1; }

.bulk {
  padding: 14px 16px;
  margin-bottom: 16px;
  background: var(--card);
  border: 1px dashed var(--ink-faint);
  border-radius: 8px;
}
.bulk p { margin: 0 0 10px; font-size: 14px; color: var(--ink-soft); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

.dico-list { list-style: none; margin: 0; padding: 0; border-top: 1.5px solid var(--rule); }
.entry {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px dashed #d7c7af;
}
.entry-word { font-family: var(--serif); font-weight: 600; font-size: 17px; letter-spacing: .08em; white-space: nowrap; }
.entry-leader { flex: 1; min-width: 16px; border-bottom: 2px dotted #cbb99f; transform: translateY(-5px); }
.entry-clue { font-family: var(--serif); font-style: italic; color: var(--ink-soft); text-align: right; max-width: 58%; }
.entry-actions { display: flex; gap: 12px; margin-left: 8px; opacity: .55; transition: opacity .15s; }
.entry:hover .entry-actions { opacity: 1; }
.entry-actions .link { font-size: 13px; }
.entry .prio {
  align-self: center;
  width: 22px; height: 22px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  color: #c9b49a;
}
.entry .prio svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.entry .prio:hover { color: var(--accent); }
.entry .prio.on { color: var(--accent); }
.entry .prio.on svg { fill: currentColor; }
.entry.editing { display: block; }
.edit-form { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-form input { flex: 1 1 150px; }
.edit-form input.grow { flex: 3 1 240px; }
.empty { list-style: none; padding: 28px 4px; color: var(--ink-soft); font-family: var(--serif); font-style: italic; }
.prio-legend { margin: 14px 0 0; font-size: 13px; }
.dico-foot { display: flex; justify-content: flex-end; gap: 20px; margin-top: 28px; }

/* --- Atelier --- */

.atelier {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.panel {
  position: sticky;
  top: 20px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 10px;
}
.range { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); }
.range output { width: 22px; text-align: right; font-weight: 600; color: var(--ink); }
.gen-status { margin: 12px 0 0; min-height: 22px; font-size: 14px; color: var(--ink-soft); }

.preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 340px;
  border: 1.5px dashed #cdbba1;
  border-radius: 10px;
  color: var(--ink-faint);
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
}
.preview-bar { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-soft); cursor: pointer; }
.unplaced { font-size: 13.5px; color: var(--ink-soft); text-align: center; margin: 4px 0 14px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.print-title { display: none; }

/* --- La grille --- */

.grid-host {
  --cell: 48px;
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 10px 0 18px;
}
.grid {
  display: grid;
  grid-auto-rows: var(--cell);
  gap: 1px;
  width: max-content;
  background: var(--rule);
  border: 2px solid var(--rule);
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 18px 36px -24px rgba(70, 45, 20, .55);
}
.cell { position: relative; width: var(--cell); height: var(--cell); background: var(--cell-bg); }
.cell.letter { display: flex; align-items: center; justify-content: center; }
.playable .cell.letter, .playable .clue-part { cursor: pointer; }
.cell .ch {
  font-family: var(--serif);
  font-weight: 600;
  font-size: calc(var(--cell) * .56);
  line-height: 1;
  color: var(--ink);
}
.cell.void {
  background: repeating-linear-gradient(45deg, #ece0cb 0 2px, #e3d4bb 2px 5px);
}
.cell.clue { display: flex; flex-direction: column; background: var(--clue); }
.clue-part {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1px 2px;
  text-align: center;
}
.clue.two .clue-part + .clue-part { border-top: 1px solid rgba(59, 47, 38, .55); }
.ct {
  display: block;
  width: 100%;
  max-height: 100%;
  overflow: hidden;
  font-family: var(--narrow);
  font-size: 10px;
  line-height: 1.07;
  color: #36281d;
}
.ct.breakable { hyphens: auto; -webkit-hyphens: auto; overflow-wrap: break-word; }

.arrow { position: absolute; z-index: 3; line-height: 0; color: var(--rule); pointer-events: none; }
.arrow svg { width: 100%; height: 100%; fill: currentColor; overflow: visible; }
.arrow .stem { fill: none; stroke: currentColor; stroke-width: 1.4; }
.a-r  { width: 7px;  height: 9px;  right: -8px;  top: 50%; transform: translateY(-50%); }
.a-d  { width: 9px;  height: 7px;  bottom: -8px; left: 50%; transform: translateX(-50%); }
.a-rd { width: 12px; height: 15px; right: -12px; top: calc(50% - 3px); }
.a-dr { width: 15px; height: 12px; bottom: -12px; left: calc(50% - 3px); }

.letter.in-word { background: var(--word); }
.letter.wrong { background: var(--wrong); }
.letter.wrong .ch { color: var(--accent-dark); }
.letter.cur { background: var(--cur); }
.letter.revealed .ch { color: var(--accent); }
.clue-part.clue-on { background: var(--clue-on); }
.grid.solved .letter { background: #edf0dc; }
.grid.solved .letter .ch { color: #3f4c2b; }

/* --- Jeu --- */

.play-head { text-align: center; margin-bottom: 14px; }
.play-head .link { display: block; margin: 0 auto 6px; }
.clue-bar {
  position: sticky;
  top: 8px;
  z-index: 10;
  display: flex;
  align-items: baseline;
  gap: 10px;
  max-width: 640px;
  min-height: 50px;
  margin: 0 auto 8px;
  padding: 11px 16px;
  background: var(--card);
  border: 1px solid var(--edge);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  box-shadow: 0 8px 20px -16px rgba(70, 45, 20, .5);
}
.clue-dir { color: var(--accent); font-weight: 600; }
.clue-text { flex: 1; font-family: var(--serif); font-size: 18px; line-height: 1.3; }
.clue-len { font-size: 13px; color: var(--ink-faint); white-space: nowrap; }
.play-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.keyboard { display: none; }
@media (pointer: coarse) {
  .keyboard {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 540px;
    margin: 16px auto 0;
    padding: 8px 2px calc(8px + env(safe-area-inset-bottom));
    background: var(--paper);
    touch-action: manipulation;
  }
}
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1;
  max-width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 1.5px 0 #cbb798;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.key:active { background: var(--cur); }
.key.wide { flex: 1.5; max-width: 66px; font-size: 19px; }

/* --- Mes grilles --- */

.grids-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.grids-list .empty { grid-column: 1 / -1; }
.grid-card {
  padding: 14px 16px 16px;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 10px;
}
.thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 150px;
  margin-bottom: 12px;
  border-radius: 6px;
  background: var(--paper-deep);
  overflow: hidden;
}
.mini { display: grid; gap: 1px; background: var(--rule); border: 1.5px solid var(--rule); }
.mini i { background: var(--cell-bg); }
.mini i.c { background: var(--clue); }
.mini i.x { background: #e3d4bb; }
.grid-card h3 { margin: 0 0 2px; font-family: var(--serif); font-weight: 600; font-size: 20px; }
.grid-card .meta { margin: 0; font-size: 13px; color: var(--ink-soft); }
.grid-card .card-msg { margin: 6px 0 0; font-family: var(--serif); font-style: italic; font-size: 14px; color: var(--ink-soft); }
.grid-card .card-msg:empty { display: none; }
.grid-card.pick {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.grid-card.pick:hover {
  border-color: #cdb99c;
  transform: translateY(-2px);
  box-shadow: 0 14px 26px -20px rgba(70, 45, 20, .6);
}
.card-title { font-family: var(--serif); font-weight: 600; font-size: 20px; line-height: 1.2; margin-bottom: 2px; }
.tag {
  align-self: flex-start;
  margin-bottom: 8px;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
  background: var(--paper-deep);
  color: var(--ink-soft);
}
.tag.new { background: var(--accent-soft); color: var(--accent-dark); }
.tag.ongoing { background: var(--word); color: #7a5a14; }
.tag.done { background: #e3e8d2; color: #4a5733; }

/* Barre de publication (admin) */
.publish-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #e8f0dc;
  border-bottom: 1px solid #cdd9b8;
  font-size: 14px;
}
.publish-bar.dirty { background: var(--accent-soft); border-bottom-color: #e6c3aa; }
.publish-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 20px;
}
.publish-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--sage); }
.publish-bar.dirty .publish-dot { background: var(--accent); }
.publish-bar .btn:disabled { cursor: default; }

/* --- Fenêtres --- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(45, 35, 28, .38);
  animation: fade .25s ease;
}
.card {
  width: 100%;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 30px 60px -24px rgba(40, 25, 10, .55);
  animation: rise .45s cubic-bezier(.2, .8, .2, 1);
}
.finish-card { max-width: 440px; padding: 30px 30px 26px; text-align: center; }
.fleuron { font-family: var(--serif); font-size: 30px; color: var(--accent); line-height: 1; }
.finish-kicker { margin: 10px 0 12px; font-size: 11.5px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-soft); }
.finish-msg { margin: 0 0 24px; font-family: var(--serif); font-style: italic; font-size: 24px; line-height: 1.3; white-space: pre-line; }
.share-card { max-width: 520px; padding: 24px 26px 20px; }
.share-card h2 { margin: 0 0 8px; font-family: var(--serif); font-weight: 600; font-size: 24px; }
.share-card p { margin: 0 0 14px; color: var(--ink-soft); font-size: 14.5px; }
.share-card .note { margin: 0 0 14px; }
.share-row { display: flex; gap: 8px; margin-bottom: 14px; }
.share-row input { font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast .link { color: #f3c9a8; text-decoration-color: currentColor; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* --- Petits écrans --- */

@media (max-width: 760px) {
  .masthead-inner { padding-top: 18px; }
  .brand { font-size: 28px; }
  main { padding: 22px 14px 40px; }
  .atelier { grid-template-columns: 1fr; }
  .panel { position: static; }
  .entry { flex-wrap: wrap; row-gap: 2px; }
  .entry-leader { display: none; }
  .entry-word { flex: 1; }
  .entry-clue { order: 5; flex-basis: 100%; max-width: none; text-align: left; padding-left: 32px; }
  .entry-actions { opacity: 1; }
  .clue-text { font-size: 16px; }
  .play-head h1 { font-size: 26px; }
}

/* --- Impression --- */

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; }
  .masthead, .publish-bar, .page-head, .panel, .preview-bar, .actions, .unplaced,
  .play-head .link, .clue-bar, .play-actions, .keyboard, .toast, .overlay { display: none !important; }
  main { padding: 0; }
  .atelier { display: block; }
  .print-title { display: block; text-align: center; font-family: var(--serif); font-size: 26px; margin: 0 0 16px; }
  .grid { box-shadow: none; }
}

.admin .panel { top: 60px; }

/* Utilisation des mots dans les grilles (admin) */
.entry-used {
  align-self: center;
  padding: 1px 8px;
  border: 0;
  border-radius: 10px;
  background: var(--word);
  color: #7a5a14;
  font: 600 11.5px var(--sans);
  white-space: nowrap;
  cursor: pointer;
}
.dico-toolbar select {
  padding: 7px 10px;
  border: 1.5px solid #d6c5ab;
  border-radius: 7px;
  background: #fffdf8;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}
