:root {
  --bg: #14111c;
  --panel: #1d1928;
  --panel2: #261f35;
  --text: #f1edf8;
  --muted: #9a92ab;
  --accent: #c77dff;
  --accent2: #ff7eb6;
  --me: #3b2a5e;
  --her: #231d31;
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 820px; margin: 0 auto; }

header { display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: var(--panel);
  border-bottom: 1px solid #2d2640; }
.who { display: flex; align-items: center; gap: 12px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); font-size: 20px; color: #fff; }
.avatar svg { width: 100%; height: 100%; }
.avatar { overflow: hidden; }
.avatar .eyes ellipse { fill: #fff; transform-box: fill-box; transform-origin: center; animation: blink 5.5s infinite; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
.avatar .blush { fill: #ff9ec7; opacity: .0; transition: opacity .6s; }
.avatar .brows path { fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; display: none; }
.avatar .brows .b-n { display: block; }
.avatar .mouth path, .avatar .mouth ellipse { display: none; transition: opacity .3s; }
.avatar .mouth path { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.avatar .mouth .m-wide, .avatar .mouth .m-open { fill: #fff; stroke: none; }
.avatar .mouth .m-smile { display: block; }
.avatar[data-mood="joy"] .m-smile, .avatar[data-mood="excitement"] .m-smile, .avatar[data-mood="playfulness"] .m-smile, .avatar[data-mood="hurt"] .m-smile,
.avatar[data-mood="irritation"] .m-smile, .avatar[data-mood="sadness"] .m-smile, .avatar[data-mood="worry"] .m-smile { display: none; }
.avatar[data-mood="joy"] .m-wide { display: block; }
.avatar[data-mood="excitement"] .m-open { display: block; }
.avatar[data-mood="playfulness"] .m-smirk { display: block; }
.avatar[data-mood="hurt"] .m-sad, .avatar[data-mood="sadness"] .m-sad { display: block; }
.avatar[data-mood="irritation"] .m-flat, .avatar[data-mood="worry"] .m-flat { display: block; }
.avatar[data-mood="hurt"] .b-n, .avatar[data-mood="sadness"] .b-n, .avatar[data-mood="worry"] .b-n, .avatar[data-mood="missing"] .b-n, .avatar[data-mood="irritation"] .b-n { display: none; }
.avatar[data-mood="hurt"] .b-w, .avatar[data-mood="sadness"] .b-w, .avatar[data-mood="worry"] .b-w, .avatar[data-mood="missing"] .b-w { display: block; }
.avatar[data-mood="irritation"] .b-a { display: block; }
.avatar[data-mood="shyness"] .blush, .avatar[data-mood="affection"] .blush { opacity: .85; }
.avatar[data-mood="joy"] .blush, .avatar[data-mood="excitement"] .blush, .avatar[data-mood="dreamy"] .blush, .avatar[data-mood="missing"] .blush { opacity: .35; }
.avatar[data-mood="shyness"] .eyes { transform: translateX(1.6px); }
.avatar[data-mood="dreamy"] .eyes ellipse { transform: scaleY(.55); animation: none; }
.avatar.speaking .mouth { transform-box: fill-box; transform-origin: 24px 34px; animation: talk .32s ease-in-out infinite; }
@keyframes talk { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.55); } }
.msg.typing { animation: blinkdots 1.1s ease-in-out infinite; }
@keyframes blinkdots { 0%, 100% { opacity: .35; } 50% { opacity: .8; } }
.dbg { font-size: 11px; color: #cfc8de; background: var(--panel2); border-radius: 8px; padding: 8px; white-space: pre-wrap; word-break: break-word; max-height: 40dvh; overflow: auto; }
details.diag { margin-top: 8px; font-size: 13px; color: var(--muted); }
details.diag summary { cursor: pointer; padding: 6px 0; }
.avatar.speaking { animation: pulse 1.1s ease-in-out infinite; }
.avatar.listening { box-shadow: 0 0 0 4px rgba(255,126,182,.35); }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.name { font-weight: 600; font-size: 16px; }
.stage { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button.icon { background: var(--panel2); width: 40px; height: 40px; border-radius: 12px; font-size: 18px; opacity: .55; }
button.icon.on { opacity: 1; background: #3b2a5e; }

main { flex: 1; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: var(--radius); line-height: 1.4;
  white-space: pre-wrap; word-wrap: break-word; font-size: 16px; }
.msg.user { align-self: flex-end; background: var(--me); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--her); border-bottom-left-radius: 6px; }


footer { display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px); background: var(--panel); border-top: 1px solid #2d2640; }
textarea { flex: 1; resize: none; max-height: 140px; background: var(--panel2); color: var(--text);
  border: 1px solid #36304a; border-radius: 20px; padding: 11px 16px; font: inherit; font-size: 16px; outline: none; }
textarea:focus { border-color: var(--accent); }
button.mic { opacity: 1; width: 44px; height: 44px; border-radius: 50%; }
button.mic.rec { background: var(--accent2); animation: pulse 1s infinite; }
button.send { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 18px; }
button:disabled { opacity: .4; cursor: default; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 10; padding: 14px; }
.modal.hidden, .toast.hidden { display: none; }
.modal-card { background: var(--panel); border-radius: 16px; width: 100%; max-width: 560px; max-height: 86dvh;
  display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid #2d2640; }
.modal-body { overflow-y: auto; padding: 8px 16px; flex: 1; }
.modal-body h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fact { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid #2a2438; font-size: 14px; }
.fact button { background: none; color: var(--muted); font-size: 16px; }
.summary { font-size: 13px; color: #cfc8de; padding: 6px 0; border-bottom: 1px solid #2a2438; }
.modal-add { display: flex; gap: 8px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid #2d2640; }
.modal-add input { flex: 1; background: var(--panel2); color: var(--text); border: 1px solid #36304a; border-radius: 10px; padding: 10px; font: inherit; font-size: 15px; }
.modal-add button { background: var(--accent); color: #1a1226; border-radius: 10px; padding: 0 16px; font-weight: 600; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #3a3050; padding: 10px 16px;
  border-radius: 12px; font-size: 14px; z-index: 20; max-width: 90%; text-align: center; }
.rel-top { text-align: center; padding: 10px 0 4px; }
.rel-top .big { font-size: 34px; }
.rel-top .stage-name { font-size: 18px; font-weight: 600; margin-top: 2px; }
.rel-top .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 34px; align-items: center; gap: 10px; font-size: 14px; padding: 4px 0; }
.bar { height: 8px; border-radius: 6px; background: var(--panel2); overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.bar.emo > i { background: linear-gradient(90deg, #7ea8ff, #c77dff); }
.bar-row .val { color: var(--muted); font-size: 12px; text-align: right; }
.ms { font-size: 14px; padding: 6px 0; border-bottom: 1px solid #2a2438; display: flex; justify-content: space-between; gap: 10px; }
.ms span:last-child { color: var(--muted); font-size: 12px; white-space: nowrap; }
.rel-note { font-size: 12px; color: var(--muted); padding: 12px 0 6px; line-height: 1.45; }
.who { cursor: pointer; }
.pdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: #666; vertical-align: middle; }
.pdot.on { background: #4ade80; } .pdot.away { background: #fbbf24; } .pdot.sleep { background: #7c83ff; }
.msg { position: relative; }
.msg.has-react { margin-bottom: 12px; }
.msg .react { position: absolute; right: -4px; bottom: -13px; font-size: 15px; line-height: 1; background: var(--panel2); border: 1px solid #36304a; border-radius: 12px; padding: 2px 5px; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.msg.voice { min-width: 220px; }
.vrow { display: flex; align-items: center; gap: 10px; }
.vplay { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-size: 14px; flex: none; }
.vwave { display: flex; align-items: center; gap: 2px; height: 28px; flex: 1; }
.vwave i { width: 3px; border-radius: 2px; background: #6a5f87; display: block; }
.vwave i.done { background: var(--accent2); }
.vdur { font-size: 12px; color: var(--muted); min-width: 28px; text-align: right; }
.vtr { background: var(--panel2); color: var(--muted); font-size: 11px; border-radius: 8px; padding: 3px 6px; }
.vtext { margin-top: 8px; font-size: 14px; color: #d8d1e8; white-space: pre-wrap; }
.vtext.hidden { display: none; }
.empty { color: var(--muted); font-size: 14px; padding: 12px 0; }

/* Zdjęcie profilowe zamiast rysunku; nastrój pokazuje ramka */
.avatar { position: relative; }
.avatar .photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.avatar.has-photo { background: #2d2640; box-shadow: 0 0 0 2px var(--accent); transition: box-shadow .6s; }
.avatar.has-photo .photo { display: block; }
.avatar.has-photo svg { display: none; }
.avatar.has-photo[data-mood="joy"], .avatar.has-photo[data-mood="excitement"], .avatar.has-photo[data-mood="playfulness"] { box-shadow: 0 0 0 2px #ffd166; }
.avatar.has-photo[data-mood="hurt"], .avatar.has-photo[data-mood="sadness"], .avatar.has-photo[data-mood="worry"], .avatar.has-photo[data-mood="missing"] { box-shadow: 0 0 0 2px #6d8bd6; }
.avatar.has-photo[data-mood="irritation"] { box-shadow: 0 0 0 2px #e0645c; }
.avatar.has-photo.listening { box-shadow: 0 0 0 4px rgba(255,126,182,.55); }

/* Awatar przy jej dymkach (jak w komunikatorze): tylko przy ostatnim dymku w serii */
.msg.assistant { margin-left: 36px; max-width: 78%; }
.msg.assistant::before { content: ''; position: absolute; left: -36px; bottom: 0; width: 28px; height: 28px; border-radius: 50%;
  background: url(/avatar.jpg) center / cover, linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 0 0 1px #3a3350; }
.msg.assistant:has(+ .msg.assistant)::before { display: none; }
/* Animowane kropki "pisze..." */
.msg.typing { animation: none; padding: 13px 16px; }
.dots { display: inline-flex; gap: 5px; align-items: center; height: 10px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: #b9b1cf; animation: dotbounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes dotbounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Ustawienia */
.settings { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px 16px; }
.setrow { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; background: var(--panel2); border-radius: 12px; padding: 12px 14px; color: var(--text); font: inherit; }
.setrow .si { font-size: 22px; }
.setrow .st { display: flex; flex-direction: column; gap: 2px; }
.setrow small { color: var(--muted); font-size: 12.5px; line-height: 1.3; }
.setrow.on::after { content: 'włączone'; margin-left: auto; font-size: 12px; color: #7ee0a0; }
