:root {
  --bg: #14110f;
  --bg-2: #1c1815;
  --card: #221d19;
  --card-hover: #2a241f;
  --line: #3a322b;
  --text: #ece4d8;
  --muted: #a39684;
  --accent: #d9a35b;
  --accent-2: #b8763a;
  --danger: #e0715c;
  --user: #8fb3c9;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #2a2018 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: rgba(20, 17, 15, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-size: 1.25rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.topbar-title { flex: 1; min-width: 0; font-family: var(--serif); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  width: 38px; height: 38px; cursor: pointer; font-size: 1.1rem;
}
.icon-btn:hover { border-color: var(--line); background: var(--bg-2); }
.icon-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.view { max-width: 980px; margin: 0 auto; padding: 24px 18px 40px; }

/* Accueil */
.hero-banner { text-align: center; padding: 28px 0 18px; }
.hero-banner h1 { font-family: var(--serif); font-size: clamp(2rem, 6vw, 3.2rem); margin: 0 0 8px; font-weight: 500; }
.hero-banner p { color: var(--muted); max-width: 600px; margin: 0 auto; }
.section-title { font-family: var(--serif); font-weight: 500; font-size: 1.3rem; margin: 34px 0 14px; color: var(--accent); }

.plot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.plot-card {
  text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 6px;
  transition: transform .15s, background .15s, border-color .15s;
}
.plot-card:hover, .plot-card:focus-visible { background: var(--card-hover); border-color: var(--accent-2); transform: translateY(-2px); outline: none; }
.plot-emoji { font-size: 1.8rem; }
.plot-genre { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.plot-title { font-family: var(--serif); font-size: 1.2rem; }
.plot-pitch { color: var(--muted); font-size: .92rem; }
.plot-card.custom { border-style: dashed; }

.mature-block { margin-top: 34px; border-top: 1px solid var(--line); padding-top: 14px; }
.mature-block summary { cursor: pointer; color: var(--muted); font-size: .95rem; margin-bottom: 14px; }

.story-list { display: flex; flex-direction: column; gap: 8px; }
.story-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.story-item .open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; cursor: pointer; text-align: left; padding: 0; }
.story-item .meta { color: var(--muted); font-size: .85rem; }
.story-item .name { font-family: var(--serif); font-size: 1.05rem; }
.story-item .del { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 6px; border-radius: 8px; }
.story-item .del:hover { color: var(--danger); background: var(--bg-2); }

.site-footer { margin-top: 50px; text-align: center; color: var(--muted); font-size: .8rem; }

/* Partie */
#view-play { padding-bottom: 0; display: flex; flex-direction: column; min-height: calc(100dvh - 59px); }
.story { flex: 1; font-family: var(--serif); font-size: 1.16rem; line-height: 1.75; max-width: 720px; width: 100%; margin: 0 auto; padding-bottom: 24px; }
.turn { margin: 0 0 22px; animation: fade .35s ease; }
.turn p { margin: 0 0 .9em; }
.turn.narrator p:first-child::first-letter { }
.turn.user {
  font-family: var(--sans); font-size: .98rem; color: var(--user);
  border-left: 2px solid var(--user); padding: 4px 0 4px 14px;
}
.turn.user.suggest { color: var(--accent); border-color: var(--accent); }
.turn.user .tag { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; opacity: .75; }
.turn.error { color: var(--danger); font-family: var(--sans); font-size: .95rem; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; margin-left: 2px; }
.thinking { color: var(--muted); font-style: italic; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.composer {
  position: sticky; bottom: 0; max-width: 720px; width: 100%; margin: 0 auto;
  background: linear-gradient(to top, var(--bg) 75%, transparent);
  padding: 18px 0 calc(14px + env(safe-area-inset-bottom));
}
.composer-modes { display: flex; gap: 6px; margin-bottom: 8px; }
.mode-btn {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; font-size: .88rem; color: var(--muted);
}
.mode-btn.active { border-color: var(--accent); color: var(--text); background: var(--card); }
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.composer-row:focus-within { border-color: var(--accent-2); }
#input { flex: 1; resize: none; border: 0; background: transparent; outline: none; padding: 8px 4px; max-height: 180px; line-height: 1.45; }
.mic-btn, .send-btn {
  flex: none; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg-2); cursor: pointer; font-size: 1.1rem;
}
.send-btn { background: var(--accent); color: #1b140d; border-color: var(--accent); font-weight: 700; }
.send-btn:disabled, .mic-btn:disabled { opacity: .45; cursor: not-allowed; }
.mic-btn.listening { background: var(--danger); border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(224,113,92,.6); } 50% { box-shadow: 0 0 0 8px rgba(224,113,92,0); } }
.composer-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Boutons */
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: .88rem; }
.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.ghost:disabled { opacity: .4; cursor: not-allowed; }
.primary { background: var(--accent); color: #1b140d; border: 0; border-radius: 10px; padding: 9px 18px; cursor: pointer; font-weight: 600; }
.primary:disabled { opacity: .6; }

/* Dialogues */
dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--bg-2); color: var(--text); padding: 0; width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.dlg { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; font-family: var(--serif); font-weight: 500; }
.dlg label { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; }
.dlg input:not([type]), .dlg input[type="text"], .dlg textarea, .dlg select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
.dlg input:focus, .dlg textarea:focus, .dlg select:focus { border-color: var(--accent-2); }
.voice-row { display: flex; gap: 8px; }
.voice-row select { flex: 1; min-width: 0; }
.dlg .switch-row { flex-direction: row; align-items: center; gap: 10px; }
.dlg hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.form-error { color: var(--danger); margin: 0; min-height: 0; font-size: .9rem; }
.form-error:empty { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

@media (max-width: 600px) {
  .brand { font-size: 1.05rem; }
  body.playing .brand-text { display: none; }
  .topbar { gap: 6px; padding: 8px 10px; }
  .story { font-size: 1.08rem; }
  .composer-tools .ghost { font-size: .8rem; padding: 5px 9px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Comptes */
.account-btn {
  height: 38px; min-width: 38px; padding: 0 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-2); font-size: .9rem; max-width: 160px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.account-btn.logged { border-color: var(--accent-2); color: var(--accent); }
.guest-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-top: 10px;
  color: var(--muted); font-size: .92rem;
}
.small-btn { padding: 7px 14px; font-size: .88rem; }
.gate { text-align: center; padding: 40px 0; }
.gate h2 { font-family: var(--serif); font-weight: 500; }
.gate-actions { display: flex; gap: 10px; justify-content: center; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; cursor: pointer; color: var(--muted); }
.tab.active { color: var(--text); border-color: var(--accent); }
.tab-panel, #form-profile { display: flex; flex-direction: column; gap: 14px; }
#acc-user { display: flex; flex-direction: column; gap: 12px; }
#acc-user[hidden] { display: none !important; }
.dlg input[type="email"], .dlg input[type="password"] { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
.dlg details summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
.dlg details[open] { display: flex; flex-direction: column; gap: 10px; }
.acc-links { display: flex; flex-wrap: wrap; gap: 8px; }
.link-btn { text-decoration: none; display: inline-flex; align-items: center; }
.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
.story-item .exp { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; text-decoration: none; }
.story-item .exp:hover { color: var(--text); background: var(--bg-2); }
