:root {
  --bg: #0f1220;
  --panel: #171a2b;
  --panel-2: #1e2237;
  --text: #e7e9f3;
  --muted: #9aa0b8;
  --accent: #6366f1;
  --accent-2: #818cf8;
  --me: #6366f1;
  --them: #262a41;
  --danger: #f87171;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* --- Scrollbar au thème de la page --- */
* { scrollbar-width: thin; scrollbar-color: var(--accent) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(var(--accent-2), var(--accent));
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
::-webkit-scrollbar-corner { background: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.muted a { color: var(--accent-2); }
.muted code {
  background: var(--panel-2); padding: 1px 5px; border-radius: 5px;
  font-size: .92em;
}
.error { color: var(--danger); font-size: 0.9rem; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* --- Login --- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--panel); border-radius: 18px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card input, .composer textarea {
  background: var(--panel-2); border: 1px solid #2b3050; color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 1rem; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button, #send {
  background: var(--accent); color: white; border: none; border-radius: 12px;
  padding: 12px 14px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.login-card button:active { transform: translateY(1px); }

/* --- Topbar --- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid #23273f;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent));
  flex: 0 0 auto;
}
.title { display: flex; flex-direction: column; line-height: 1.15; flex: 1; }
.title .status { font-size: .8rem; color: #6ee7a8; }
.ghost { background: transparent; border: none; font-size: 1.3rem; cursor: pointer; }
.relation {
  font-size: .78rem; font-weight: 700; color: var(--accent-2);
  background: var(--panel-2); padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.relation:empty { display: none; }

/* --- Layout 2 colonnes : personnage à gauche (grand), dialogue à droite --- */
#chat { flex-direction: row; }

/* Colonne gauche : visage Live2D en grand, sur un décor représentatif du perso */
#stage {
  position: relative; flex: 1.5 1 0; height: 100dvh; overflow: hidden;
  background: #0f1220 center bottom / cover no-repeat;
}
#live2d-canvas { position: relative; z-index: 1; display: block; width: 100%; height: 100%; }
body.no-avatar #stage { display: none; }

/* Décors (scènes SVG) par personnage */
#stage.theme-hiyori  { background-image: url("/backgrounds/hiyori.svg"); }
#stage.theme-mao     { background-image: url("/backgrounds/mao.svg"); }
#stage.theme-haru    { background-image: url("/backgrounds/haru.svg"); }
#stage.theme-natori  { background-image: url("/backgrounds/natori.svg"); }
#stage.theme-rice    { background-image: url("/backgrounds/rice.svg"); }
#stage.theme-mark    { background-image: url("/backgrounds/mark.svg"); }
#stage.theme-wanko   { background-image: url("/backgrounds/wanko.svg"); }
#stage.theme-default { background-image: url("/backgrounds/default.svg"); }

/* Colonne droite : dialogue */
#chat-panel {
  flex: 1 1 0; min-width: 320px; max-width: 460px;
  height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid #23273f;
}

/* Empilé sur écran étroit (mobile) : personnage en haut, dialogue en bas */
@media (max-width: 820px) {
  #chat { flex-direction: column; }
  #stage { flex: 0 0 auto; height: 42vh; min-height: 200px; }
  #chat-panel {
    min-width: 0; max-width: none; flex: 1 1 auto;
    border-left: none; border-top: 1px solid #23273f;
  }
}

/* --- Messages --- */
.messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.bubble {
  max-width: 78%; padding: 10px 14px; border-radius: 18px;
  font-size: 1rem; line-height: 1.35; white-space: pre-wrap; word-wrap: break-word;
  animation: pop .18s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; } }
.bubble.them { background: var(--them); align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.me { background: var(--me); color: white; align-self: flex-end; border-bottom-right-radius: 6px; }
.day-sep { align-self: center; color: var(--muted); font-size: .78rem; margin: 8px 0; }

/* --- Typing --- */
.typing { display: flex; gap: 4px; padding: 0 20px 4px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

/* --- Composer --- */
.composer {
  display: flex; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid #23273f;
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; line-height: 1.35;
}
#send { flex: 0 0 auto; width: 48px; }
.composer .mic {
  flex: 0 0 auto; width: 44px; background: transparent; border: none;
  font-size: 1.3rem; cursor: pointer; border-radius: 12px; color: var(--text);
}
.composer .mic.rec { background: rgba(248,113,113,.18); animation: micpulse 1s infinite; }
.composer .mic:disabled { opacity: .5; }
@keyframes micpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,.5); }
  50% { box-shadow: 0 0 0 6px rgba(248,113,113,0); }
}

/* --- Bandeau d'état (toast) --- */
.toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 60; max-width: 92%; text-align: center;
  background: var(--panel); color: var(--text);
  border: 1px solid #2b3050; border-radius: 999px;
  padding: 11px 20px; font-size: .95rem; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); cursor: default;
}
.toast.rec {
  background: #d94a4a; color: #fff; border-color: #d94a4a; cursor: pointer;
  animation: toastpulse 1.1s infinite;
}
@keyframes toastpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217,74,74,.5); }
  50% { box-shadow: 0 0 0 12px rgba(217,74,74,0); }
}

/* --- Barre du mode vocal --- */
.voice-bar {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 999px;
  padding: 9px 10px 9px 20px; box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
#voice-status { font-weight: 600; white-space: nowrap; }
.voice-stop {
  background: var(--accent); color: #fff; border: none; border-radius: 999px;
  padding: 8px 16px; font-weight: 600; cursor: pointer;
}
#voice-btn.active { background: var(--accent); border-radius: 10px; }
.voice-bar.error { border-color: var(--danger); }
.voice-bar.error #voice-status { color: var(--danger); }

/* --- Jeux --- */
.game-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.game-opt {
  border: 2px solid transparent; background: var(--panel-2); color: var(--text);
  border-radius: 12px; padding: 16px 10px; cursor: pointer; text-align: center;
  font-size: .95rem; font-weight: 600;
}
.game-opt .emoji { display: block; font-size: 1.6rem; margin-bottom: 4px; }
.game-opt:active { transform: translateY(1px); }
#rps-btn { grid-column: 1 / -1; }
.rps { margin-top: 16px; text-align: center; }
.rps-choices { display: flex; justify-content: center; gap: 14px; margin-top: 10px; }
.rps-choices button {
  font-size: 2rem; background: var(--panel-2); border: none;
  border-radius: 12px; padding: 10px 16px; cursor: pointer;
}

/* --- Attentions sur le personnage (barre bien visible sous le perso) --- */
.care-actions {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 3;
  display: flex; flex-direction: row; gap: 10px;
  background: rgba(15,18,32,.55); padding: 8px 12px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.care-actions button {
  width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--panel-2); color: #fff; font-size: 1.4rem;
  box-shadow: 0 3px 10px rgba(0,0,0,.3);
}
.care-actions button:active { transform: scale(.94); }

/* --- Humeur & rappels --- */
.mood-row { display: flex; gap: 8px; margin-top: 8px; }
.mood-row button {
  flex: 1; font-size: 1.6rem; background: var(--panel-2); border: 2px solid transparent;
  border-radius: 12px; padding: 8px 0; cursor: pointer;
}
.mood-row button.sel { border-color: var(--accent); }
.reminder-add { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.reminder-add input, .reminder-add button {
  background: var(--panel-2); border: 1px solid #2b3050; color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: .95rem;
}
#rem-text { flex: 1 1 100%; }
#rem-time { flex: 1 1 auto; }
#rem-add { flex: 1 1 auto; border: none; }

/* Calendrier / agenda */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 10px; }
#cal-title { font-weight: 700; text-transform: capitalize; }
.cal-head .ghost { font-size: 1.5rem; padding: 0 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: .7rem; color: var(--muted); padding: 2px 0; }
.cal-cell {
  position: relative; aspect-ratio: 1; border: none; background: var(--panel-2); color: var(--text);
  border-radius: 8px; cursor: pointer; font-size: .9rem;
}
.cal-cell.empty { background: transparent; cursor: default; }
.cal-cell.today { outline: 2px solid var(--accent-2); }
.cal-cell.sel { background: var(--accent); color: #fff; }
.cal-dot {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent-2);
}
.cal-cell.sel .cal-dot { background: #fff; }
.rem-day { margin-top: 14px; }
#rem-day-title { display: block; text-transform: capitalize; margin-bottom: 4px; color: var(--text); }

/* Réactions rapides sous ses messages */
.reacts {
  display: flex; gap: 2px; align-self: flex-start; margin: -4px 0 6px 6px;
  opacity: .35; transition: opacity .15s;
}
.reacts:hover, .bubble.them:hover + .reacts { opacity: 1; }
.reacts.done { opacity: 1; }
.reacts button {
  border: none; background: transparent; cursor: pointer; font-size: 1rem;
  line-height: 1; padding: 2px 3px; border-radius: 8px; transition: transform .12s, background .12s;
}
.reacts button:hover { transform: scale(1.35); background: var(--panel-2); }
.reacts.done button { font-size: 1.15rem; cursor: default; }

/* Selfie (image envoyée par KarAi) */
.bubble.them.img { padding: 5px; }
.bubble.them.img .selfie {
  display: block; width: 200px; max-width: 60vw; border-radius: 12px;
}
.bubble.them.img .cap { padding: 6px 4px 2px; font-size: .9rem; }

/* Hub « Mon quotidien » : onglets */
.hub-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.hub-tab {
  flex: 1; border: none; background: var(--panel-2); color: var(--muted);
  padding: 9px 6px; border-radius: 10px; cursor: pointer; font-size: .85rem;
}
.hub-tab.active { background: var(--accent); color: #fff; }
.hub-pane.hidden { display: none; }

/* Objectifs / habitudes */
.habit-add { display: flex; gap: 8px; }
.habit-add input {
  flex: 1; background: var(--panel-2); border: 1px solid #2b3050; color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: .95rem;
}
.habit-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.habit-list li {
  display: flex; align-items: center; gap: 10px; background: var(--panel-2);
  border-radius: 12px; padding: 10px 12px;
}
.habit-check {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid #3a4066;
  background: transparent; cursor: pointer; font-size: 1rem; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.habit-list li.done .habit-check { background: #22c55e; border-color: #22c55e; }
.habit-list li.done .habit-name { color: var(--muted); text-decoration: line-through; }
.habit-name { flex: 1; font-size: .95rem; }
.habit-streak { font-size: .8rem; color: #f59e0b; white-space: nowrap; }
.habit-del { border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: .95rem; }
.text-input {
  width: 100%; background: var(--panel-2); border: 1px solid #2b3050; color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: .95rem;
}

/* Ambiance jour / nuit (voile sur le décor) */
.daynight {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  transition: background 3s ease; background: transparent;
}
.daynight.dn-dawn  { background: linear-gradient(rgba(255,183,120,.16), rgba(255,120,90,.05)); }
.daynight.dn-day   { background: linear-gradient(rgba(255,255,255,.04), transparent); }
.daynight.dn-dusk  { background: linear-gradient(rgba(255,140,70,.18), rgba(120,70,160,.16)); }
.daynight.dn-night { background: linear-gradient(rgba(20,30,75,.40), rgba(8,12,35,.50)); }

/* Moment détente */
.relax-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.relax-opt {
  border: none; background: var(--panel-2); color: var(--text); border-radius: 14px;
  padding: 20px 10px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 8px; font-size: .9rem;
}
.relax-opt .emoji { font-size: 1.8rem; }
.relax-opt:hover { background: #2b3050; }
.breathe { margin-top: 18px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.breathe.hidden { display: none; }
.breathe-circle {
  width: 150px; height: 150px; border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, #818cf8, #6366f1);
  display: flex; align-items: center; justify-content: center; color: #fff;
  font-size: 1rem; transform: scale(.6); transition: transform 4s ease-in-out;
  box-shadow: 0 0 40px rgba(129,140,248,.5);
}

/* ===== Jeu : La vie de KarAi ===== */
.game-hero {
  width: 100%; margin-bottom: 12px; background: linear-gradient(135deg, #6366f1, #a855f7) !important;
  color: #fff !important; flex-direction: row !important; justify-content: center; gap: 8px; font-weight: 700;
}
.game-hero small { opacity: .85; font-weight: 400; font-size: .72rem; }
.life-card { max-width: 560px; }
.life-hud { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; font-size: .9rem; font-weight: 600; }
.life-hud span { background: var(--panel-2); padding: 5px 10px; border-radius: 8px; }
.life-xp { height: 6px; background: var(--panel-2); border-radius: 4px; margin: 8px 0 12px; overflow: hidden; }
.life-xp #life-xp-bar { height: 100%; width: 0; background: linear-gradient(90deg, #818cf8, #a855f7); transition: width .4s; }

.life-needs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.need { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 8px; font-size: .8rem; }
.bar { height: 9px; background: var(--panel-2); border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 5px; transition: width .4s; }
.bar.ok span { background: #22c55e; } .bar.mid span { background: #f59e0b; } .bar.low span { background: #ef4444; }
.bar.hp span { background: linear-gradient(90deg,#ef4444,#f87171); } .bar.mp span { background: #38bdf8; }

.life-stats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.stat-chip { background: var(--panel-2); border-radius: 8px; padding: 4px 9px; font-size: .8rem; }
.life-skills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.skill-chip { background: rgba(168,85,247,.18); color: #d8b4fe; border-radius: 8px; padding: 4px 9px; font-size: .78rem; }
.life-quest { font-size: .84rem; background: var(--panel-2); border-radius: 10px; padding: 9px 11px; margin-bottom: 12px; }

.life-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.life-tab { flex: 1; border: none; background: var(--panel-2); color: var(--muted); padding: 8px 4px; border-radius: 10px; cursor: pointer; font-size: .82rem; }
.life-tab.active { background: var(--accent); color: #fff; }
.life-pane.hidden { display: none; }
.life-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.life-cell {
  border: none; background: var(--panel-2); color: var(--text); border-radius: 12px;
  padding: 12px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: .82rem;
}
.life-cell .emoji { font-size: 1.5rem; }
.life-cell small { color: var(--muted); font-size: .72rem; }
.life-cell:hover { background: #2b3050; }
.life-log-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: .84rem; }
.life-log-list li { background: var(--panel-2); border-radius: 8px; padding: 7px 10px; }

/* Donjon (combat) */
.adv-enemy { margin-bottom: 12px; }
.adv-party { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.fighter { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.fighter.enemy { background: rgba(239,68,68,.12); }
.f-name { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.fighter small { color: var(--muted); font-size: .74rem; }
.fighter .bar { margin: 4px 0; }
.adv-log {
  height: 96px; overflow-y: auto; background: var(--panel-2); border-radius: 10px;
  padding: 8px 10px; font-size: .8rem; display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px;
}
.adv-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.adv-actions button { border: none; background: var(--accent); color: #fff; border-radius: 10px; padding: 11px; cursor: pointer; font-size: .9rem; }
.adv-actions button:disabled { opacity: .4; cursor: default; }
.adv-start-row { display: flex; flex-direction: column; }

/* ===== Monde 2D (overworld) ===== */
.world-hero { background: linear-gradient(135deg, #16a34a, #0891b2) !important; }
.world-screen {
  position: fixed; inset: 0; z-index: 60; background: #1a1f2e;
  display: block; overflow: hidden;
}
.world-screen.hidden { display: none; }
#world-canvas {
  width: 100%; height: 100%; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none;
}
.world-close {
  position: absolute; top: 12px; right: 12px; z-index: 62;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.5); color: #fff; font-size: 1.1rem; cursor: pointer;
}
.world-hint {
  position: absolute; top: 12px; left: 12px; z-index: 62;
  background: rgba(0,0,0,.45); color: #fff; font-size: .78rem;
  padding: 6px 10px; border-radius: 10px; max-width: 60vw;
}
.world-pad {
  position: absolute; left: 18px; bottom: 22px; z-index: 62;
  width: 156px; height: 156px; opacity: .82; touch-action: none; user-select: none;
}
.pad-btn {
  position: absolute; width: 52px; height: 52px; border: none; border-radius: 12px;
  background: rgba(255,255,255,.18); color: #fff; font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.pad-btn:active { background: rgba(255,255,255,.4); }
.pad-up { left: 52px; top: 0; } .pad-down { left: 52px; top: 104px; }
.pad-left { left: 0; top: 52px; } .pad-right { left: 104px; top: 52px; }
@media (min-width: 900px) { .world-pad { opacity: .5; } }

/* HUD du monde : niveau/or + besoins + objectif */
.world-hud {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 62;
  width: min(420px, calc(100% - 100px));
  background: rgba(15,18,30,.82); border-radius: 12px; padding: 8px 12px; color: #fff;
  font-size: .82rem; backdrop-filter: blur(3px);
}
.whud-row { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.whud-xp { flex: 1; height: 6px; background: rgba(255,255,255,.15); border-radius: 4px; overflow: hidden; }
#whud-xpbar { display: block; height: 100%; width: 0; background: linear-gradient(90deg,#818cf8,#a855f7); }
.whud-stats-btn { border: none; background: rgba(255,255,255,.15); color: #fff; border-radius: 8px; padding: 2px 7px; cursor: pointer; }
.whud-needs { display: flex; gap: 10px; margin-top: 6px; }
.whud-need { display: flex; align-items: center; gap: 4px; flex: 1; }
.whud-need .bar { flex: 1; height: 8px; }
.whud-obj { margin-top: 6px; font-size: .78rem; color: #c7d2fe; }
.world-stats { margin-top: 6px; font-size: .76rem; color: #cbd5e1; line-height: 1.5; }
.world-stats.hidden { display: none; }
.world-toast {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%); z-index: 63;
  background: rgba(34,197,94,.92); color: #fff; font-size: .85rem; font-weight: 600;
  padding: 8px 14px; border-radius: 12px; max-width: 80vw; text-align: center;
}
.world-toast.hidden { display: none; }

.world-a {
  position: absolute; right: 26px; bottom: 40px; z-index: 62;
  width: 66px; height: 66px; border-radius: 50%; border: none;
  background: rgba(99,102,241,.85); color: #fff; font-size: 1.4rem; font-weight: 800;
  cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.world-a:active { background: rgba(99,102,241,1); transform: scale(.94); }

.world-dialog {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 63;
  display: flex; align-items: center; gap: 12px;
  background: rgba(15,18,30,.94); border: 2px solid #6366f1; border-radius: 16px;
  padding: 14px 16px; box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.world-dialog.hidden { display: none; }
.wd-portrait {
  width: 56px; height: 56px; flex-shrink: 0; border-radius: 10px;
  image-rendering: pixelated; background: #2b3050; object-fit: cover;
}
.wd-body { flex: 1; min-width: 0; }
.wd-name { display: block; font-weight: 700; font-size: .8rem; color: #a5b4fc; margin-bottom: 2px; }
.wd-text { margin: 0; font-size: .98rem; line-height: 1.35; color: #fff; }
.wd-more { color: #a5b4fc; align-self: flex-end; animation: wdblink 1s infinite; }
@keyframes wdblink { 50% { opacity: .2; } }

.rem-empty { color: var(--muted); font-size: .85rem; list-style: none; }
.rem-list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.rem-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--panel-2); border-radius: 10px; padding: 8px 12px; font-size: .88rem;
}
.rem-list button { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 1.05rem; }

/* --- Panneau de réglages (modal) --- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 420px;
  background: var(--panel); border-radius: 18px; padding: 18px 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head strong { font-size: 1.15rem; }
.setting label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.model-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.model-opt {
  border: 2px solid transparent; background: var(--panel-2); color: var(--text);
  border-radius: 12px; padding: 14px 10px; cursor: pointer; text-align: center;
  font-size: .95rem; font-weight: 600; transition: border-color .15s, transform .05s;
}
.model-opt:active { transform: translateY(1px); }
.model-opt.selected { border-color: var(--accent); }
.model-opt .emoji { display: block; font-size: 1.6rem; margin-bottom: 4px; }
.setting + .setting { margin-top: 20px; }
#proactive-freq {
  width: 100%; background: var(--panel-2); border: 1px solid #2b3050; color: var(--text);
  border-radius: 12px; padding: 11px 12px; font-size: 1rem; margin-bottom: 10px;
}
.secondary {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--accent);
  border-radius: 12px; padding: 11px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.secondary:active { transform: translateY(1px); }
.secondary:disabled { opacity: .6; cursor: default; }
.hours {
  margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  font-size: .9rem;
}
.hours > span { flex-basis: 100%; color: var(--muted); }
.hours label { display: inline-flex; align-items: center; gap: 6px; }
.hours select {
  background: var(--panel-2); border: 1px solid #2b3050; color: var(--text);
  border-radius: 8px; padding: 6px 8px; font-size: .95rem;
}
.slider {
  width: 100%; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 999px; background: var(--panel-2); outline: none; margin-top: 10px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px;
  border-radius: 50%; background: var(--accent); cursor: pointer; border: none;
}
.slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent); cursor: pointer; border: none;
}

/* --- Thème clair --- */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0f7; --panel: #ffffff; --panel-2: #f2f4fb; --text: #1b1e2c;
    --muted: #5a6072; --them: #e7e9f3;
  }
  .topbar, .composer { border-color: #e2e5f0; }
  #chat-panel { border-color: #e2e5f0; }
}
