/* Croquy RP — charte : nuit, néon rose / violet / bleu, accent menthe. Pas de jaune/orange en décor. */
:root {
  --bg: #0b0716;
  --bg2: #120b24;
  --card: #1a1131;
  --card2: #221641;
  --line: rgba(196, 160, 255, 0.14);
  --text: #f4ecff;
  --muted: #a99cc7;
  --muted-strong: #cbbfe8;
  --pink: #f472b6;
  --violet: #a855f7;
  --blue: #60a5fa;
  --mint: #98fbca;
  --danger: #fb7185;
  --warn: #facc15; /* uniquement pour un avertissement */
  --grad: linear-gradient(135deg, #f472b6 0%, #a855f7 50%, #60a5fa 100%);
  --glow: 0 0 0 1px rgba(244, 114, 182, 0.35), 0 0 18px rgba(168, 85, 247, 0.35);
  --radius: 18px;
  --radius-sm: 12px;
  --font: 'Quicksand', 'Segoe UI', system-ui, sans-serif;
  --font-logo: 'Matemasie', 'Quicksand', 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, rgba(168, 85, 247, 0.18), transparent 60%),
              radial-gradient(900px 500px at 110% 10%, rgba(96, 165, 250, 0.12), transparent 60%),
              var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 16.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: var(--pink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0 0 0.6em; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.hidden { display: none !important; }

.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* --- Mise en page ------------------------------------------------------------ */
.page { max-width: 980px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px calc(32px + var(--safe-b)); }
.page.narrow { max-width: 720px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; min-height: 48px; }
.topbar h1 { font-size: 1.35rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { font-family: var(--font-logo); font-weight: 400; font-size: 2rem; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; letter-spacing: 0.5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.section { margin: 26px 0 10px; font-size: 1.05rem; color: var(--muted-strong); display: flex; align-items: center; gap: 8px; }

/* --- Boutons --------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform 0.1s, box-shadow 0.2s, background 0.2s;
}
.btn:hover { box-shadow: var(--glow); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--grad); border: none; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: rgba(251, 113, 133, 0.5); color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; background: transparent; color: var(--muted-strong);
  display: inline-grid; place-items: center; cursor: pointer; position: relative; flex: none; text-decoration: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: none; }
.badge { position: absolute; top: 6px; right: 6px; min-width: 10px; height: 10px; border-radius: 99px; background: var(--mint); box-shadow: 0 0 8px var(--mint); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); font-size: 0.85rem; }
.chip.on { border-color: var(--pink); box-shadow: var(--glow); }
button.chip { cursor: pointer; min-height: 36px; }

/* --- Champs ---------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field .label { font-weight: 600; font-size: 0.92rem; color: var(--muted-strong); }
.field .hint { font-size: 0.8rem; color: var(--muted); }
.input {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font-size: 16px; /* 16px : pas de zoom auto sur iPhone */
}
textarea.input { resize: vertical; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.25); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--pink); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }
input[type="color"].input { padding: 4px; width: 64px; }

/* --- Cartes ------------------------------------------------------------------------ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 14px; }
.story-card { position: relative; overflow: hidden; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; text-align: left; padding: 0; color: inherit; transition: box-shadow 0.2s, transform 0.15s; }
.story-card:hover { box-shadow: var(--glow); }
.story-card:active { transform: scale(0.99); }
.story-cover .avatars .avatar { width: 72px; height: 72px; font-size: 1.8rem; border-width: 3px; background: rgba(11, 7, 22, 0.55); }
.story-cover .avatars .avatar + .avatar { margin-left: -18px; }
.story-cover { aspect-ratio: 16 / 9; width: 100%; object-fit: cover; background: var(--grad); display: grid; place-items: center; font-family: var(--font-logo); font-size: 2.6rem; color: rgba(255, 255, 255, 0.92); }
.story-info { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.story-info h3 { font-size: 1.08rem; }
.story-card .more { position: absolute; top: 6px; right: 6px; background: rgba(11, 7, 22, 0.6); backdrop-filter: blur(6px); }
.tagline { color: var(--muted); font-size: 0.88rem; font-style: italic; }
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: var(--radius-sm); background: var(--card); border: 1px solid var(--line); cursor: pointer; text-align: left; color: inherit; width: 100%; }
.list-item:hover { box-shadow: var(--glow); }
.list-item .grow > * { overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.tabs { display: flex; gap: 6px; background: var(--bg2); padding: 4px; border-radius: 99px; border: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { flex: 1; min-height: 40px; border: none; border-radius: 99px; background: transparent; color: var(--muted-strong); font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--grad); color: #fff; }

.avatar { border-radius: 50%; object-fit: cover; flex: none; border: 2px solid var(--c, var(--violet)); background: var(--card2); }
.avatar.initial { display: inline-grid; place-items: center; font-weight: 700; color: var(--c, var(--violet)); }
.avatar.xs { width: 22px; height: 22px; font-size: 0.7rem; border-width: 1.5px; }
.avatar.sm { width: 32px; height: 32px; font-size: 0.85rem; }
.avatar.md { width: 46px; height: 46px; font-size: 1.1rem; }
.avatar.lg { width: 84px; height: 84px; font-size: 2rem; }
.avatars { display: flex; }
.avatars .avatar + .avatar { margin-left: -10px; }

/* --- Feuilles (bottom sheets) ------------------------------------------------------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(5, 2, 12, 0); display: flex; align-items: flex-end; justify-content: center; transition: background 0.2s; }
.sheet-wrap.open { background: rgba(5, 2, 12, 0.6); }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--bg2); border: 1px solid var(--line); border-bottom: none; border-radius: 24px 24px 0 0;
  transform: translateY(100%); transition: transform 0.22s ease-out; box-shadow: 0 -10px 40px rgba(168, 85, 247, 0.2);
}
.sheet.wide { max-width: 900px; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-grip { width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 20px; }
.sheet-head h2 { font-size: 1.15rem; }
.sheet-body { overflow-y: auto; padding: 4px 20px calc(20px + var(--safe-b)); overscroll-behavior: contain; }
.sheet.actions .sheet-body { padding-left: 8px; padding-right: 8px; }
.action-row { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 0 14px; border: none; border-radius: var(--radius-sm); background: transparent; color: var(--text); font-weight: 600; cursor: pointer; text-align: left; }
.action-row:hover { background: rgba(255, 255, 255, 0.05); }
.action-row.danger { color: var(--danger); }
@media (min-width: 720px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 24px; border-bottom: 1px solid var(--line); transform: translateY(20px); opacity: 0; transition: transform 0.2s, opacity 0.2s; }
  .sheet-wrap.open .sheet { opacity: 1; }
  .sheet-grip { display: none; }
}

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 80; max-width: min(92vw, 480px); padding: 12px 18px; border-radius: 14px; background: var(--card2); border: 1px solid var(--line); box-shadow: var(--glow); transition: opacity 0.2s, transform 0.2s; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); box-shadow: 0 0 18px rgba(251, 113, 133, 0.35); }
.toast.ok { border-color: var(--mint); }

/* --- Chat ----------------------------------------------------------------------------- */
body.chat-mode { overflow: hidden; }
.chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 860px; margin: 0 auto; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--safe-t)) 6px 6px; border-bottom: 1px solid var(--line); background: rgba(11, 7, 22, 0.85); backdrop-filter: blur(10px); }
.chat-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.chat-title .t { min-width: 0; }
.chat-title .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; }
.chat-title .t span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.78rem; color: var(--muted); }

.statebar { border-bottom: 1px solid var(--line); background: rgba(18, 11, 36, 0.7); padding: 6px 10px; font-size: 0.85rem; }
.statebar .chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; align-items: center; }
.statebar .chips::-webkit-scrollbar { display: none; }
.state-chip { flex: none; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; min-height: 34px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; max-width: 70vw; }
.state-chip .k { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
.state-chip .v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-chip.empty .v { color: var(--muted); font-style: italic; }
.tenues { display: grid; gap: 6px; padding: 8px 2px 4px; }
.tenues .state-chip { max-width: 100%; justify-content: flex-start; }

.messages { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; scroll-behavior: smooth; }
.msg { position: relative; max-width: 100%; user-select: text; -webkit-user-select: text; -webkit-touch-callout: none; }
.msg.char { padding: 12px 38px 12px 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); }
.msg.user { align-self: flex-end; max-width: 85%; padding: 10px 14px; border-radius: var(--radius) var(--radius) 6px var(--radius); background: color-mix(in srgb, var(--c, #f472b6) 22%, var(--card)); border: 1px solid color-mix(in srgb, var(--c, #f472b6) 50%, transparent); }
.msg.system { align-self: center; font-size: 0.8rem; color: var(--muted); font-style: italic; text-align: center; max-width: 90%; padding: 2px 12px; border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line); }
.msg.streaming { border-color: var(--violet); box-shadow: var(--glow); }
.msg .line + .line { margin-top: 6px; }
.msg .line.action { font-style: italic; color: var(--muted-strong); }
.msg em { color: var(--muted-strong); }
.msg .speech .avatar { vertical-align: -5px; margin-right: 6px; }
.msg .who { font-weight: 700; margin-right: 6px; }
.msg .who::after { content: ''; }
.msg .more { position: absolute; top: 2px; right: 2px; width: 36px; height: 36px; opacity: 0.35; }
.msg.user .more { left: -40px; right: auto; }
.msg:hover .more { opacity: 0.9; }
.msg-tools { display: flex; align-items: center; gap: 2px; margin-top: 8px; color: var(--muted); font-size: 0.85rem; flex-wrap: wrap; }
.msg-tools .count { min-width: 40px; text-align: center; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--violet); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; background: var(--pink); }
.typing i:nth-child(3) { animation-delay: 0.4s; background: var(--blue); }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.msg-edit textarea { width: 100%; min-height: 120px; }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: rgba(11, 7, 22, 0.9); }
.composer textarea { flex: 1; min-height: 46px; max-height: 200px; resize: none; border-radius: 22px; padding: 11px 16px; }
.send-btn { width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--grad); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send-btn.stop { background: var(--card2); border: 1px solid var(--danger); color: var(--danger); }
.send-btn .ico { width: 20px; height: 20px; }
.suggestions { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 0; }
.suggestions button { text-align: left; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }

/* --- Mémoire ---------------------------------------------------------------------- */
.pending { border: 1px solid var(--mint); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; box-shadow: 0 0 18px rgba(152, 251, 202, 0.15); background: rgba(152, 251, 202, 0.04); }
.pending h3 { color: var(--mint); font-size: 1rem; margin-bottom: 8px; }
.diff { display: grid; gap: 6px; margin-bottom: 12px; font-size: 0.92rem; }
.diff .old { color: var(--muted); text-decoration: line-through; }
.diff .new { color: var(--mint); }
.mem-section h3 { font-size: 0.95rem; color: var(--muted-strong); margin: 18px 0 8px; display: flex; align-items: center; justify-content: space-between; }
.mem-item { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.mem-item .grow { display: flex; flex-direction: column; gap: 6px; }
.mem-item.done { opacity: 0.5; }
.mem-item .input { min-height: 38px; padding: 7px 10px; font-size: 15px; }
.pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 0.82rem; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; max-height: 60vh; overflow: auto; }
.block { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--card); }
.block summary { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px; cursor: pointer; font-weight: 600; list-style: none; }
.block summary::-webkit-details-marker { display: none; }
.block .pre { margin: 0 10px 10px; }
.tok { color: var(--blue); font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.meter { height: 8px; border-radius: 9px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.meter span { display: block; height: 100%; background: var(--grad); }
.warn { color: var(--warn); }
.login { display: flex; flex-direction: column; gap: 14px; align-items: stretch; max-width: 360px; margin-top: 12vh; text-align: center; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); }
.status-dot.ok { background: var(--mint); box-shadow: 0 0 8px var(--mint); }
.status-dot.ko { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.char-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.char-pick button { display: inline-flex; gap: 8px; align-items: center; padding: 6px 14px 6px 6px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; min-height: 44px; }
.char-pick button.on { border-color: var(--pink); box-shadow: var(--glow); }
.avatar-edit { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
