:root {
  --paper: #f5efe3;
  --card: #fbf7ee;
  --ink: #2b2521;
  --soft: #6f655c;
  --line: #ddd2bf;
  --p0: #b04f27;      /* première plume : terre cuite */
  --p1: #2c6168;      /* seconde plume : bleu canard */
  --p0-wash: #f3dfd2;
  --p1-wash: #d8e7e6;
  --ok: #4d7a3c;
  --bad: #b3322b;
  --display: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --text: 'Newsreader', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1916;
    --card: #24201c;
    --ink: #ece4d6;
    --soft: #a2978a;
    --line: #3b352e;
    --p0: #e58a5e;
    --p1: #7fbcc2;
    --p0-wash: #3a2a21;
    --p1-wash: #20353a;
    --ok: #9cc487;
    --bad: #ef8a80;
  }
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.2rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 6rem;
}

a { color: inherit; }

/* ---------- éléments communs ---------- */

.brand {
  display: inline-block;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--soft);
}
.brand b { font-weight: 600; color: var(--p0); }
.brand i { color: var(--p1); font-weight: 600; }

.label {
  font-family: var(--ui);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--soft);
}

.btn {
  font-family: var(--ui);
  font-size: .95rem;
  font-weight: 600;
  padding: .7rem 1.3rem;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.small { padding: .4rem .9rem; font-size: .85rem; }

.link {
  font-family: var(--ui);
  font-size: .85rem;
  color: var(--soft);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--ink); }

input[type=text], select, textarea {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: .6rem;
  padding: .6rem .8rem;
  width: 100%;
}
input[type=text]:focus, select:focus, textarea:focus {
  outline: 2px solid var(--p1);
  outline-offset: 1px;
  border-color: transparent;
}
:focus-visible { outline: 2px solid var(--p1); outline-offset: 2px; }

.error {
  font-family: var(--ui);
  font-size: .9rem;
  color: var(--bad);
  margin: .6rem 0 0;
  min-height: 1.2em;
}

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

/* ---------- accueil ---------- */

.hero { margin: 3.5rem 0 2.5rem; }
.hero h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 4.2rem);
  line-height: 1.02;
  letter-spacing: -.02em;
  margin: 0 0 1.2rem;
}
.hero h1 em:first-of-type { color: var(--p0); }
.hero h1 em:last-of-type { color: var(--p1); }
.hero p { color: var(--soft); max-width: 32rem; margin: 0; }

.form { display: grid; gap: 1.3rem; }
.form .row { display: grid; gap: .4rem; }
.form .two { display: grid; gap: 1.3rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .form .two { grid-template-columns: 3fr 2fr; } }

.modes { display: grid; gap: .7rem; }
@media (min-width: 560px) { .modes { grid-template-columns: repeat(3, 1fr); } }
.mode {
  position: relative;
  display: block;
  padding: .9rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: .8rem;
  background: var(--card);
  cursor: pointer;
  line-height: 1.35;
}
.mode input { position: absolute; opacity: 0; }
.mode strong { display: block; font-family: var(--display); font-size: 1.15rem; font-weight: 600; }
.mode span { font-size: .92rem; color: var(--soft); }
.mode:has(input:checked) { border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.mode:has(input:focus-visible) { outline: 2px solid var(--p1); outline-offset: 2px; }

.mine { margin-top: 3.5rem; }
.mine ul { list-style: none; padding: 0; margin: .6rem 0 0; }
.mine li { border-top: 1px solid var(--line); }
.mine a {
  display: block;
  padding: .7rem 0;
  font-family: var(--display);
  font-style: italic;
  text-decoration: none;
}
.mine a:hover { color: var(--p0); }

/* ---------- histoire ---------- */

.story-head { margin: 2.5rem 0 2.5rem; }
.story-head h1 {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(2rem, 7vw, 3rem);
  line-height: 1.1;
  letter-spacing: -.01em;
  margin: .5rem 0 1rem;
  overflow-wrap: anywhere;
}
.meta { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; align-items: center; }
.who { display: inline-flex; align-items: center; gap: .4rem; font-family: var(--ui); font-size: .9rem; font-weight: 600; }
.who.p0 { color: var(--p0); }
.who.p1 { color: var(--p1); }
.who.empty { color: var(--soft); font-weight: 400; font-style: italic; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; border: 1.5px solid currentColor; }
.dot.on { background: currentColor; }

.turn { position: relative; margin: 0 0 1.4rem; }
.turn .author {
  display: block;
  font-family: var(--ui);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: .15rem;
}
.turn.p0 .author { color: var(--p0); }
.turn.p1 .author { color: var(--p1); }
.turn .body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.turn .chip { margin-top: .4rem; }

@media (min-width: 900px) {
  .turn .author {
    position: absolute;
    right: calc(100% + 1.5rem);
    top: .55rem;
    white-space: nowrap;
    margin: 0;
  }
}

.turn.masked .bars { display: grid; gap: .55rem; padding: .5rem 0; }
.turn.masked .bars i { display: block; height: .7rem; border-radius: 999px; background: var(--line); }
.turn.masked .bars i:last-child { width: 55%; }
.turn.masked .count { font-family: var(--ui); font-size: .8rem; color: var(--soft); }
.turn .tail { font-style: italic; margin: .3rem 0 0; }
.turn .tail::before { content: '… '; color: var(--soft); }

.chip {
  display: inline-block;
  font-family: var(--ui);
  font-size: .78rem;
  font-weight: 600;
  padding: .15rem .6rem;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  color: var(--soft);
}
.chip.ok { border-color: var(--ok); color: var(--ok); }
.chip.todo { border-color: var(--bad); color: var(--bad); }

/* ---------- écrire / attendre ---------- */

.composer {
  margin-top: 2.2rem;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-top: 4px solid var(--mine);
  border-radius: 1rem;
  padding: 1.1rem 1.3rem 1rem;
}
.composer.p0, .waiting.p0, .banner.p0 { --mine: var(--p0); --wash: var(--p0-wash); }
.composer.p1, .waiting.p1, .banner.p1 { --mine: var(--p1); --wash: var(--p1-wash); }
.composer .label { color: var(--mine); }
.composer textarea {
  display: block;
  border: 0;
  background: transparent;
  padding: .5rem 0;
  min-height: 9rem;
  resize: none;
  line-height: 1.65;
  overflow: hidden;
}
.composer textarea:focus { outline: none; }
.composer .foot {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem 1rem;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: .9rem;
}
.composer .info { display: flex; flex-wrap: wrap; gap: .5rem .8rem; align-items: center; }
.count { font-family: var(--ui); font-size: .85rem; color: var(--soft); font-variant-numeric: tabular-nums; }
.count.over { color: var(--bad); font-weight: 700; }
.composer .next { margin: .2rem 0 1rem; display: grid; gap: .35rem; }
.composer .next input { font-size: 1rem; max-width: 18rem; }

.waiting {
  margin-top: 2.2rem;
  text-align: center;
  padding: 2rem 1.5rem;
  border-radius: 1rem;
  background: var(--wash);
}
.waiting h2 { font-family: var(--display); font-style: italic; font-weight: 400; font-size: 1.6rem; margin: 0 0 .3rem; }
.waiting p { margin: 0; color: var(--soft); font-size: 1rem; }
.dots { display: inline-flex; gap: .35rem; margin-bottom: .9rem; }
.dots i { width: .5rem; height: .5rem; border-radius: 50%; background: var(--mine); animation: bob 1.4s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes bob { 0%, 60%, 100% { transform: none; opacity: .35; } 30% { transform: translateY(-5px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; } .btn { transition: none; } }

.invite { margin-top: 1.5rem; }
.invite h2, .join h2 { font-family: var(--display); font-weight: 600; font-size: 1.3rem; margin: 0 0 .3rem; }
.invite p, .join p { margin: 0 0 1rem; color: var(--soft); font-size: 1rem; }
.copy { display: flex; gap: .6rem; }
.copy input { font-family: var(--ui); font-size: .9rem; min-width: 0; }
.copy .btn { flex: none; }

.banner {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: .8rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.3rem;
  border-radius: 1rem;
  background: var(--wash);
  font-size: 1.05rem;
}
.banner .acts { display: flex; gap: .5rem; }

.actions { margin-top: 2rem; display: flex; flex-wrap: wrap; gap: .6rem 1.5rem; }

.fin { text-align: center; margin: 3rem 0 2rem; }
.fin span { font-family: var(--display); font-style: italic; font-size: 1.5rem; color: var(--soft); }
.fin span::before, .fin span::after { content: '·'; margin: 0 .8rem; }
.fin .acts { margin-top: 1.5rem; display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

.join { margin-top: 1rem; }
.join .form { margin-top: 1.2rem; }

/* ---------- impression : seulement le texte ---------- */

@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .brand, .meta, .actions, .fin .acts, .composer, .waiting, .invite, .banner, .turn .author, .chip { display: none !important; }
  #app { max-width: none; padding: 0; }
}
