:root {
  --bg: #F6F1E9;
  --surface: #FFFDF9;
  --ink: #1F1B16;
  --muted: #6E655A;
  --line: #E4DCCF;
  --accent: #B5532E;
  --accent-ink: #FFFFFF;
  --accent-soft: #F3E1D6;
  --user-bubble: #E9E0D2;
  --danger: #A8322A;
  --radius: 18px;
  --fs: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B1814; --surface: #25211C; --ink: #F2ECE3; --muted: #A99F92;
    --line: #3A342C; --accent: #E07A50; --accent-ink: #1B1814; --accent-soft: #3B2A21;
    --user-bubble: #322C25; --danger: #F08A80; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1B1814; --surface: #25211C; --ink: #F2ECE3; --muted: #A99F92;
  --line: #3A342C; --accent: #E07A50; --accent-ink: #1B1814; --accent-soft: #3B2A21;
  --user-bubble: #322C25; --danger: #F08A80; color-scheme: dark;
}
html.big { --fs: 21px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 var(--fs)/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }

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

/* Кнопки */
.btn {
  border: 0; border-radius: 14px; padding: 16px 20px; min-height: 58px;
  font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-wide { width: 100%; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: 1.3em;
  min-width: 52px; min-height: 52px; border-radius: 14px; color: var(--ink);
}
.icon-btn:active, .btn:active { transform: scale(.97); }
.icon-btn.round { border-radius: 50%; background: var(--surface); border: 1px solid var(--line); flex: none; }
.icon-btn.send { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.icon-btn.mic.on { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--danger) 20%, transparent); } }

/* Вход */
.login-wrap { width: 100%; max-width: 460px; margin: auto; padding: 32px 16px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand-mark { width: 64px; height: 64px; border-radius: 16px; display: block; }
.brand h1 { font-size: 1.8em; margin: 0; }
.lead { color: var(--muted); margin: 0 0 20px; font-size: 1.1em; }
.user-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.user-tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 12px; text-align: center; cursor: pointer; font-weight: 600; font-size: 1.1em;
}
.user-tile .av { display: block; font-size: 2.2em; margin-bottom: 6px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-who { font-size: 1.4em; font-weight: 700; margin: 0 0 8px; }
.label { color: var(--muted); }
#login-pass {
  padding: 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface);
  font-size: 1.2em; min-height: 58px;
}
#login-pass:focus { outline: none; border-color: var(--accent); }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }

/* Шапка */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.hello { flex: 1; margin: 0 4px; font-size: 1.35em; }
.chat-title { flex: 1; margin: 0; font-size: 1.1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-select { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px; font-size: .8em; max-width: 40%; }

/* Главная */
.home-main { width: 100%; max-width: 720px; margin: 0 auto; padding: 16px; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.preset {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; min-height: 84px; cursor: pointer;
}
.preset .pi { font-size: 2em; flex: none; width: 52px; height: 52px; display: grid; place-items: center; background: var(--accent-soft); border-radius: 14px; }
.preset .pt { font-weight: 700; font-size: 1.1em; display: block; }
.preset .ps { color: var(--muted); font-size: .88em; display: block; }
.section-title { font-size: 1em; color: var(--muted); margin: 28px 4px 8px; font-weight: 600; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history li { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.history .hopen { flex: 1; display: flex; gap: 12px; align-items: center; border: 0; background: none; text-align: left; padding: 14px; min-height: 60px; cursor: pointer; min-width: 0; }
.history .htitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.history .hdate { color: var(--muted); font-size: .8em; display: block; }
.history .hdel { color: var(--muted); font-size: 1em; }

/* Чат */
.chat-screen { height: 100dvh; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 780px; margin: 0 auto; }
.msg { max-width: 92%; padding: 12px 16px; border-radius: var(--radius); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.notice { align-self: center; color: var(--muted); font-size: .9em; background: none; text-align: center; }
.msg.err { align-self: center; color: var(--danger); border: 1px solid var(--danger); background: none; }
.msg p { margin: 0 0 .6em; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 .6em; padding-left: 1.3em; }
.msg h3, .msg h4 { margin: .4em 0; font-size: 1.05em; }
.msg pre { background: var(--bg); padding: 10px; border-radius: 10px; overflow-x: auto; font-size: .85em; }
.msg code { font-family: ui-monospace, monospace; font-size: .9em; }
.msg a { color: var(--accent); }
.msg img.thumb { max-width: 180px; max-height: 180px; border-radius: 10px; display: block; margin-bottom: 6px; }
.msg .file-chip { display: inline-block; background: var(--bg); border-radius: 8px; padding: 4px 10px; font-size: .85em; margin-bottom: 6px; }
.msg-actions { display: flex; gap: 4px; margin-top: 6px; }
.msg-actions button { white-space: nowrap; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 12px; font-size: .85em; cursor: pointer; min-height: 40px; }
.typing { color: var(--muted); font-style: italic; }

.attachments { display: flex; gap: 8px; padding: 0 12px; flex-wrap: wrap; max-width: 780px; margin: 0 auto; width: 100%; }
.attachments:empty { display: none; }
.att { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; font-size: .8em; display: flex; align-items: center; gap: 6px; }
.att img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.att button { border: 0; background: var(--danger); color: #fff; border-radius: 50%; width: 28px; height: 28px; cursor: pointer; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg);
  width: 100%; max-width: 780px; margin: 0 auto;
}
#input {
  flex: 1; min-width: 0; resize: none; max-height: 40vh; padding: 13px 14px; min-height: 52px;
  border-radius: 16px; border: 2px solid var(--line); background: var(--surface); line-height: 1.4;
}
#input:focus { outline: none; border-color: var(--accent); }

.btn.small { min-height: 44px; padding: 8px 14px; font-size: .85em; }
.pass-row { display: flex; gap: 8px; align-items: stretch; }
.pass-row #login-pass { flex: 1; min-width: 0; }
.pass-toggle { flex: none; border: 2px solid var(--line); }

.think-toggle { display: inline-flex; align-items: center; gap: 8px; flex: none; cursor: pointer; user-select: none;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: .85em; min-height: 44px; }
.think-toggle input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.think-toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.chat-title { cursor: pointer; }
.hemoji { font-size: 1.3em; width: 1.6em; text-align: center; flex: none; }

.btn-install { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent); }
.history li.pinned { border-color: var(--accent); }
.history .hdel { min-width: 44px; }
.history .hdel.on { filter: none; }
.history .hdel:not(.on)[aria-label^="Закрепить"] { filter: grayscale(1); opacity: .55; }
.msg-actions { flex-wrap: wrap; }

.chat-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 8px 12px 0; width: 100%; max-width: 780px; margin: 0 auto; }
.chat-tools .think-toggle { font-size: .8em; min-height: 40px; padding: 6px 12px; white-space: nowrap; color: var(--ink); }
button.think-toggle { font: inherit; font-size: .8em; }
.chat-tools { gap: 6px; }
.chat-tools .think-toggle { padding: 4px 10px; gap: 6px; font-size: .76em; min-height: 38px; }
.chat-tools .think-toggle input { width: 18px; height: 18px; }
.install-icon { font-size: 1.4em; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 50%; width: 48px; height: 48px; min-width: 48px; min-height: 48px; padding: 0; }
.install-login { align-self: center; margin-top: 4px; }
.toast { position: fixed; left: 50%; bottom: 150px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .85em; max-width: calc(100% - 32px); text-align: center; transition: .25s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.settings-btn { font-size: 1.3em; }
.settings .hint { color: var(--muted); font-size: .85em; margin: 0 4px 10px; }
.voice-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.voice { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.voice.on { border-color: var(--accent); background: var(--accent-soft); }
.voice-pick { flex: 1; display: flex; align-items: baseline; gap: 10px; border: 0; background: none; text-align: left; padding: 12px 14px; min-height: 52px; cursor: pointer; }
.vname { font-weight: 600; }
.vdesc { color: var(--muted); font-size: .85em; }
.vcheck { margin-left: auto; color: var(--accent); font-weight: 700; }
.voice-play { min-width: 48px; font-size: 1em; }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; min-height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; cursor: pointer; }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.logout { margin-top: 28px; border: 1px solid var(--line); color: var(--danger); }
.prep { border: 1px dashed var(--accent); color: var(--accent); margin-bottom: 10px; }
.history .hemoji { border: 0; background: none; cursor: pointer; font-size: 1.4em; min-width: 52px; min-height: 52px; border-radius: 12px; flex: none; }
.history .hemoji.playing { background: var(--accent-soft); animation: pulse 1.2s infinite; }
.history .hopen { padding-left: 4px; }
.msg-actions { flex-wrap: nowrap; }
.msg-actions button { padding: 6px 8px; font-size: .8em; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.msg.assistant { max-width: 100%; width: 100%; padding: 12px 14px; }
.msg-actions .vid-btn { margin-left: auto; }
.msg-actions .vid-btn.ready { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
@media (max-width: 350px) { .msg-actions button { font-size: .72em; padding: 6px 6px; } .msg.assistant { padding: 12px 10px; } .messages { padding-left: 8px; padding-right: 8px; } }
.set-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 10px; cursor: pointer; }
.set-row input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.set-row span { display: flex; flex-direction: column; gap: 2px; }
.set-row small { color: var(--muted); font-size: .8em; }
#creative-model { margin-bottom: 10px; }
.creative-log { white-space: pre-wrap; font: .75em/1.4 ui-monospace, monospace; color: var(--muted); margin: 0 0 12px; }
.creative-log:empty { display: none; }
.vid-note { font-size: .8em; color: var(--muted); margin-top: 6px; }
/* списки: номера и точки — обычный текст, чтобы копировались */
.msg ol.mk, .msg ul.mk { list-style: none; padding-left: 0; }
.msg .mk li { display: flex; gap: .45em; margin: .15em 0; }
.msg .mk-n { flex: none; min-width: 1.2em; font-variant-numeric: tabular-nums; color: var(--muted); }
.msg ol.mk .mk-n { font-weight: 700; color: var(--ink); }
/* секундомер видео */
.msg-actions .vid-timer { margin-left: auto; align-self: center; font-size: .8em; color: var(--muted); font-variant-numeric: tabular-nums; padding: 0 2px; }
.msg-actions .vid-timer.done { color: var(--ink); }
.msg-actions .vid-timer:not([hidden]) + .vid-btn { margin-left: 4px; }
/* кольцо отсчёта вокруг микрофона */
.icon-btn.mic { position: relative; }
.icon-btn.mic.countdown::before { content: ""; position: absolute; inset: -5px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p, 0) * 360deg), var(--line) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); }
.icon-btn.mic.countdown { background: var(--accent-soft); }
.msg-actions.tight button { font-size: .72em; padding: 6px 6px; }
.msg-actions.tight .vid-timer { font-size: .72em; }
.msg-actions.tighter button { font-size: .64em; padding: 6px 5px; }
.msg-actions.tighter { gap: 3px; }
/* заставка при запуске */
#splash { position: fixed; inset: 0; z-index: 1000; background: #F6F1E9; display: flex; align-items: center; justify-content: center; transition: opacity .15s ease; }
#splash.out { opacity: 0; pointer-events: none; }
#splash svg { width: 128px; height: 128px; overflow: visible; }
#splash svg * { transform-box: fill-box; transform-origin: center; }
#splash .sp-arc { stroke-dasharray: 100; stroke-dashoffset: 100; animation: sp-draw .28s cubic-bezier(.6,0,.3,1) forwards; }
#splash .sp-dot { transform: scale(0); animation: sp-pop .25s .25s forwards; }
@keyframes sp-draw { to { stroke-dashoffset: 0; } }
@keyframes sp-pop { 0% { transform: scale(0); } 40% { transform: scale(1.4); } 70% { transform: scale(.9); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { #splash .sp-arc, #splash .sp-dot { animation: none; stroke-dashoffset: 0; transform: none; } }
