:root {
  --bg: #f6f4ee; --side: #efece3; --panel: #ffffff; --text: #24231f; --muted: #6f6c62; --faint: #9a968a;
  --line: rgba(36, 35, 31, .12); --line-strong: rgba(36, 35, 31, .22); --bubble: #ebe7dc; --accent: #c96442;
  --on-accent: #fff; --danger: #b3261e; --danger-bg: #fbeaea; --hover: rgba(36, 35, 31, .06);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624; --side: #1f1e1d; --panel: #30302e; --text: #ecebe6; --muted: #a8a59b; --faint: #7d7a72;
    --line: rgba(236, 235, 230, .12); --line-strong: rgba(236, 235, 230, .24); --bubble: #3a3936; --accent: #d97757;
    --danger: #f2b8b5; --danger-bg: #3d2524; --hover: rgba(236, 235, 230, .07);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.5 var(--sans); }
body { overflow: hidden; -webkit-text-size-adjust: 100%; }
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font: 500 30px/1 var(--serif); margin: 0 auto 12px; }
.primary { background: var(--accent); color: var(--on-accent); border: 0; border-radius: 12px; padding: 12px 22px; font-weight: 500; min-height: 48px; }
.error { color: var(--danger); min-height: 1.5em; }

.login { height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-box { max-width: 340px; text-align: center; }
.login-box h1 { font: 500 26px/1.2 var(--serif); margin: 0 0 8px; }
.login-box p { color: var(--muted); }

.app { display: grid; grid-template-columns: 260px minmax(0, 1fr); height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 10px 12px; min-height: 0; }
.new-chat { display: flex; align-items: center; gap: 8px; justify-content: center; border: 1px solid var(--line-strong);
  background: var(--panel); border-radius: 10px; padding: 10px; min-height: 44px; margin-bottom: 12px; }
.new-chat span { font-size: 20px; line-height: 1; }
.chat-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-row { display: flex; align-items: center; border-radius: 8px; }
.chat-row:hover, .chat-row.on { background: var(--hover); }
.chat-row.on .chat-item { color: var(--text); }
.del-chat { flex: none; width: 32px; height: 32px; margin-left: 4px; border: 0; background: none; border-radius: 6px; color: var(--faint);
  display: grid; place-items: center; }
.del-chat:hover { color: var(--danger); background: var(--danger-bg); }
@media (hover: hover) { .chat-row:not(:hover) .del-chat:not(:focus-visible) { visibility: hidden; } }
.chat-item { flex: 1; min-width: 0; text-align: left; border: 0; background: none; border-radius: 8px; padding: 10px 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 40px; }
.chat-item .busy { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 8px; vertical-align: 1px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; border-bottom: 1px solid var(--line); min-height: 52px; }
.title { flex: 1; margin: 0; font: 500 16px/1.3 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.menu { display: none; }
.model select { appearance: none; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px;
  padding: 6px 30px 6px 12px; font-size: 14px; color: var(--muted); max-width: 30vw; min-height: 36px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }

.feed { flex: 1; overflow-y: auto; padding: 20px 16px 8px; overscroll-behavior: contain; }
.messages, .working, .empty { max-width: 760px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding-top: 18vh; }
.messages { display: flex; flex-direction: column; gap: 14px; }
.me { align-self: flex-end; background: var(--bubble); border-radius: 18px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.me .chips { margin-top: 6px; }
.ai { font: 17px/1.6 var(--serif); overflow-wrap: anywhere; }
.ai p { margin: 0 0 .7em; } .ai p:last-child { margin-bottom: 0; }
.ai pre { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: 14px; }
.ai code { font-size: .9em; } .ai a { color: var(--accent); }
.ai img { max-width: 100%; }
.steps { color: var(--faint); font-size: 14px; }
.steps summary { cursor: pointer; list-style: none; padding: 2px 0; }
.steps summary::-webkit-details-marker { display: none; }
.steps summary::before { content: "›"; display: inline-block; margin-right: 6px; transition: transform .15s; }
.steps[open] summary::before { transform: rotate(90deg); }
.steps ol { margin: 4px 0 0; padding-left: 22px; }
.note { font-size: 14px; color: var(--muted); }
.note.bad { color: var(--danger); background: var(--danger-bg); padding: 8px 12px; border-radius: 10px; }

.card { border: 1px solid var(--line); background: var(--panel); border-radius: 14px; overflow: hidden; max-width: 420px; }
.card video, .card img { display: block; width: 100%; max-height: 60vh; background: #000; object-fit: contain; }
.card audio { width: 100%; display: block; padding: 10px; }
.card .meta { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-size: 14px; }
.card .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .size { color: var(--faint); display: block; font-size: 12px; }
.card .caption { padding: 0 12px 10px; font-size: 14px; color: var(--muted); }
.btn { border: 1px solid var(--line-strong); border-radius: 9px; padding: 6px 12px; text-decoration: none; color: var(--text);
  font-size: 14px; white-space: nowrap; min-height: 34px; display: inline-flex; align-items: center; }
.btn:hover { background: var(--hover); }

.working { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 12px 0; }
@keyframes pulse { 50% { opacity: .3; transform: scale(.8); } }

.composer { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.box { display: flex; align-items: flex-end; gap: 6px; border: 1px solid var(--line-strong); background: var(--panel);
  border-radius: 22px; padding: 6px; }
.box textarea { flex: 1; border: 0; background: none; resize: none; outline: none; padding: 8px 4px; max-height: 40vh; font-size: 16px; line-height: 1.45; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .35; }
.attachments, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:not(:empty) { margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px;
  padding: 5px 8px 5px 10px; font-size: 13px; max-width: 100%; }
.chip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip .p { color: var(--faint); }
.chip.bad { color: var(--danger); }
.chip button { border: 0; background: none; padding: 0 2px; color: var(--faint); font-size: 18px; line-height: 1; min-width: 24px; min-height: 24px; }
.me .chip { background: transparent; }

.scrim { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: min(82vw, 300px); z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .app.drawer .side { transform: none; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
  .menu { display: grid; margin-left: -8px; }
  .top { padding-left: 12px; padding-right: 12px; }
  .feed { padding-left: 14px; padding-right: 14px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .me { max-width: 90%; }
}

.archive summary { cursor: pointer; color: var(--faint); font-size: 14px; padding: 12px 12px 6px; list-style: none; }
.archive summary::-webkit-details-marker { display: none; }
.archive summary::before { content: "›"; display: inline-block; margin-right: 6px; transition: transform .15s; }
.archive[open] summary::before { transform: rotate(90deg); }
.archive .chat-row { width: 100%; }

.ask { border: 1px solid var(--line-strong); background: var(--panel); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; max-width: 520px; }
.ask { position: relative; }
.ask .close-ask { position: absolute; top: 4px; right: 4px; width: 40px; height: 40px; border: 0; background: none; border-radius: 10px;
  color: var(--faint); font-size: 24px; line-height: 1; }
.ask .close-ask:hover { background: var(--hover); color: var(--text); }
.ask.done .close-ask { display: none; }
.ask .q:first-of-type { padding-right: 36px; }
.ask .q { font: 17px/1.5 var(--serif); }
.ask .opts { display: flex; flex-direction: column; gap: 6px; }
.ask .opt { text-align: left; border: 1px solid var(--line-strong); background: var(--bg); border-radius: 10px; padding: 10px 12px; min-height: 44px; display: flex; flex-direction: column; gap: 2px; }
.ask .opt:hover:not(:disabled) { border-color: var(--accent); }
.ask .opt .l { font-weight: 500; }
.ask .opt .d { font-size: 13px; color: var(--muted); }
.ask .opt.chosen { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ask.done .opt:not(.chosen) { opacity: .5; }
.ask .send-answer { align-self: flex-start; }
.ask .own { font-size: 14px; color: var(--muted); }
.ask .own::before { content: "Свой вариант: "; }
.mic.rec { background: var(--danger-bg); color: var(--danger); animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .55; } }
.mic:disabled { opacity: .35; }
@media (prefers-reduced-motion: reduce) { .mic.rec { animation: none; } }
.cats { position: relative; width: 132px; height: 22px; flex: none; overflow: hidden; --freya: #d9893f; --runa: #6f6a66; }
@media (prefers-color-scheme: dark) { .cats { --runa: #b3ada7; } }
.cat { position: absolute; bottom: 0; left: 0; width: 26px; height: 17px; }
.cat.freya { color: var(--freya); } .cat.runa { color: var(--runa); }
.cat .l1, .cat .l2 { transform-box: fill-box; transform-origin: top; }
.cats:not(.nap) .cat .l1 { animation: legs .28s ease-in-out infinite alternate; }
.cats:not(.nap) .cat .l2 { animation: legs .28s ease-in-out infinite alternate-reverse; }
@keyframes legs { from { transform: rotate(-22deg); } to { transform: rotate(22deg); } }
/* Руна убегает, Фрея догоняет */
.chase .cat { animation: run 2.6s linear infinite, bob .28s ease-in-out infinite alternate; }
.chase .runa { animation-delay: -.55s, 0s; }
.back { transform: scaleX(-1); }
.back .cat { animation: run 2.6s linear infinite, bob .28s ease-in-out infinite alternate; }
.back .freya { animation-delay: -.55s, 0s; }
/* Фрея убегает, Руна догоняет — в другую сторону */
@keyframes run { from { translate: -30px 0; } to { translate: 136px 0; } }
@keyframes bob { to { margin-bottom: 2px; } }
/* носятся туда-обратно */
.zoomies .cat { animation: zoom 3.2s ease-in-out infinite, bob .28s ease-in-out infinite alternate; }
.zoomies .freya { animation-delay: -.4s, 0s; }
@keyframes zoom {
  0% { translate: 0 0; scale: 1 1; } 45% { translate: 104px 0; scale: 1 1; } 50% { translate: 104px 0; scale: -1 1; }
  95% { translate: 0 0; scale: -1 1; } 100% { translate: 0 0; scale: 1 1; }
}
/* Руна спит, Фрея подкрадывается и прыгает */
.nap .runa { left: 92px; scale: -1 1; transform-origin: bottom; transform: scaleY(.72); animation: breathe 1.6s ease-in-out infinite; }
.nap .runa .legs { display: none; }
.nap .freya { animation: sneak 4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scaleY(.64); } }
@keyframes sneak {
  0% { translate: 0 0; } 60% { translate: 56px 0; } 70% { translate: 62px 1px; }
  80% { translate: 72px -9px; } 88% { translate: 66px 0; } 100% { translate: 0 0; }
}
.cloud, .ball { display: none; position: absolute; }
/* драка: сбегаются, клубок пыли с лапами и искрами, разбегаются */
.fight .cat { animation: bob .28s ease-in-out infinite alternate; }
.fight .freya { animation: fightA 3.6s ease-in-out infinite; }
.fight .runa { left: 104px; scale: -1 1; animation: fightB 3.6s ease-in-out infinite; }
@keyframes fightA { 0% { translate: 0 0; opacity: 1; } 22% { translate: 40px 0; opacity: 1; } 24%, 76% { translate: 40px 0; opacity: 0; }
  78% { translate: 40px -6px; opacity: 1; } 100% { translate: -6px 0; opacity: 1; } }
@keyframes fightB { 0% { translate: 0 0; opacity: 1; } 22% { translate: -38px 0; opacity: 1; } 24%, 76% { translate: -38px 0; opacity: 0; }
  78% { translate: -38px -6px; opacity: 1; } 100% { translate: 4px 0; opacity: 1; } }
.fight .cloud { display: block; left: 46px; bottom: 0; width: 40px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 30% 60%, var(--freya) 0 22%, transparent 23%), radial-gradient(circle at 68% 45%, var(--runa) 0 24%, transparent 25%),
    radial-gradient(ellipse at center, color-mix(in srgb, var(--faint) 55%, transparent) 0 62%, transparent 64%);
  animation: brawl 3.6s linear infinite; }
@keyframes brawl { 0%, 23% { opacity: 0; scale: .3; } 26% { opacity: 1; scale: 1; }
  30% { rotate: 25deg; translate: 2px -1px; } 36% { rotate: -20deg; translate: -2px 0; } 42% { rotate: 30deg; translate: 1px -2px; }
  48% { rotate: -25deg; translate: -1px 0; } 54% { rotate: 20deg; translate: 2px -1px; } 60% { rotate: -30deg; translate: 0 0; }
  66% { rotate: 15deg; translate: -2px -1px; } 72% { rotate: -10deg; opacity: 1; scale: 1; } 77%, 100% { opacity: 0; scale: .3; rotate: 0deg; } }
.cloud i { position: absolute; font: 700 10px/1 var(--sans); font-style: normal; color: var(--accent); top: 0; left: 50%; opacity: 0; animation: spark .6s ease-out infinite; }
.cloud i:nth-child(1) { --x: -16px; } .cloud i:nth-child(2) { --x: 14px; animation-delay: .2s; } .cloud i:nth-child(3) { --x: 2px; animation-delay: .4s; color: var(--text); }
@keyframes spark { 0% { opacity: 1; translate: 0 4px; } 100% { opacity: 0; translate: var(--x) -10px; } }
/* клубок: Фрея гонит его, Руна следом */
.yarn .ball { display: block; bottom: 0; left: 0; width: 9px; height: 9px; border-radius: 50%;
  background: repeating-linear-gradient(45deg, var(--accent) 0 2px, color-mix(in srgb, var(--accent) 55%, white) 2px 3.5px);
  animation: roll 3s linear infinite -.85s; }
@keyframes roll { from { translate: -10px 0; rotate: 0deg; } to { translate: 146px 0; rotate: 1080deg; } }
.yarn .cat { animation: run 3s linear infinite, bob .28s ease-in-out infinite alternate; }
.yarn .freya { animation-delay: -.42s, 0s; } .yarn .runa { animation-delay: -.05s, 0s; }
@media (prefers-reduced-motion: reduce) { .cats *, .cats { animation: none !important; } .cloud, .ball { display: none !important; } .cat.freya { translate: 40px 0; } .cat.runa { translate: 72px 0; } }
