:root {
  --bg: #0d0c0e;
  --surface: #18161a;
  --surface-2: #1c1a1e;
  --line: #2e2a2f;
  --line-soft: #221f23;
  --text: #f2eeea;
  --text-2: #ddd6d0;
  --muted: #9c948e;
  --faint: #6e6762;
  --accent: #b23a32;
  --accent-text: #e8746a;
  --accent-soft: #3a1c1b;
  --accent-line: #5a2a27;
  --persona: #b9a6d6;
  --ok: #8fc2a8;
  --gold: #e8b86a;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fade: linear-gradient(to top, rgba(13,12,14,.96) 0%, rgba(13,12,14,.55) 38%, rgba(13,12,14,0) 62%);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; }
body { min-height: 100vh; overscroll-behavior-y: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
a { color: var(--accent-text); }
.hidden { display: none !important; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { 0% { background-position: -200px 0; } 100% { background-position: 200px 0; } }

#view { padding: 18px 16px 110px; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; animation: rise .18s ease-out; }
#view.flush { padding: 0 0 170px; gap: 0; }

.eyebrow { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--accent-text); font-weight: 600; }
.title { margin: 2px 0 0; font-family: var(--serif); font-size: 32px; font-weight: 700; line-height: 1; }
.sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.lead { margin: 8px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 38px; height: 38px; }

.pill { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; min-height: 44px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; max-width: 46%; }
.pill span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono { display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-weight: 700; flex: none; }
.ava { width: 30px; height: 30px; border-radius: 15px; font-size: 17px; background: #2a2233; color: var(--persona); }
.btn-ghost { height: 44px; padding: 0 16px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.icon-btn { position: relative; width: 44px; height: 44px; flex: none; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; padding: 0; }
.icon-btn .count { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; }

.searchrow { display: flex; gap: 8px; }
.search { flex: 1; display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); min-width: 0; }
.search input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--text); font-size: 15px; }
input::placeholder, textarea::placeholder { color: #8a837e; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 12px; border-radius: 17px; font-weight: 600; font-size: 13px; background: transparent; color: #cfc8c2; border: 1px solid var(--line); display: flex; align-items: center; gap: 6px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.tag { background: var(--accent-soft); border-color: var(--accent-line); color: #f2c9c3; padding-right: 8px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.card { position: relative; display: block; aspect-ratio: 5 / 7; border-radius: 18px; overflow: hidden; border: 0; padding: 0; text-align: left; color: var(--text); background: var(--surface); }
.card > img, .card > .mono { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; font-size: 84px; }
.card .shade { position: absolute; inset: 0; background: var(--fade); }
.badge { position: absolute; top: 8px; left: 8px; display: flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 10px; background: rgba(0,0,0,.55); font-size: 11px; font-weight: 600; }
.star { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; padding: 0; }
.star span { width: 28px; height: 28px; border-radius: 14px; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; color: #d8d2cc; }
.star.on span { color: var(--gold); }
.card .meta { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.card .nm { font-family: var(--serif); font-size: 22px; font-weight: 700; line-height: 1; overflow-wrap: anywhere; }
.card .ds { font-size: 12px; color: #cfc8c2; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tg { padding: 2px 7px; border-radius: 8px; background: rgba(242,238,234,.14); font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.skeleton { aspect-ratio: 5 / 7; border-radius: 18px; background: linear-gradient(90deg, #161418 0, #201d22 50%, #161418 100%) no-repeat; background-size: 400px 100%; animation: shimmer 1.2s infinite linear; }

.empty { padding: 40px 16px; text-align: center; color: var(--muted); line-height: 1.5; }
.empty b { display: block; color: var(--text); font-family: var(--serif); font-size: 24px; margin-bottom: 6px; }

/* карточка персонажа */
.hero { position: relative; height: 58vh; min-height: 360px; max-height: 520px; overflow: hidden; }
.hero > img, .hero > .mono { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; font-size: 160px; }
.hero .shade { position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(13,12,14,.35) 0%, rgba(13,12,14,0) 20%, rgba(13,12,14,0) 48%, rgba(13,12,14,.85) 82%, var(--bg) 100%); }
.hero .tl, .hero .tr { position: absolute; top: 14px; display: flex; gap: 8px; }
.hero .tl { left: 14px; } .hero .tr { right: 14px; }
.round { width: 44px; height: 44px; border-radius: 22px; background: rgba(0,0,0,.5); border: 0; color: var(--text); display: flex; align-items: center; justify-content: center; padding: 0; }
.round.on { color: var(--gold); }
.hero .meta { position: absolute; left: 20px; right: 20px; bottom: 6px; display: flex; flex-direction: column; gap: 8px; }
.hero h1 { margin: 0; font-family: var(--serif); font-size: 40px; font-weight: 700; line-height: 1; overflow-wrap: anywhere; }
.hero .tg { font-size: 12px; padding: 4px 10px; border-radius: 10px; }
.sheet-body { padding: 14px 20px 0; display: flex; flex-direction: column; gap: 18px; }
.char-short { margin: 0; font-size: 14.5px; color: #b8b0aa; line-height: 1.5; }
.persona-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); text-align: left; width: 100%; }
.persona-row .ava { width: 36px; height: 36px; border-radius: 18px; font-size: 20px; }
.persona-row .who { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.persona-row small { font-size: 12px; color: var(--muted); }
.persona-row b { font-size: 15px; }
.persona-row em { font-style: normal; font-size: 13px; color: var(--accent-text); font-weight: 600; }
.section h2, .sec-h { margin: 0 0 8px; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent-text); font-weight: 600; }
.section p { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--text-2); white-space: pre-line; overflow-wrap: anywhere; }
.section p.clamp { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.more { align-self: flex-start; background: none; border: 0; padding: 8px 0; color: var(--accent-text); font-weight: 600; font-size: 14px; }
.cstory { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--surface-2); }
.cstory .go { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; min-height: 44px; justify-content: center; background: none; border: 0; padding: 0; text-align: left; }
.cstory .go b { font-size: 14.5px; }
.cstory .go span, .cstory time { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots { width: 44px; height: 44px; flex: none; border-radius: 22px; background: transparent; border: 0; color: #cfc8c2; display: flex; align-items: center; justify-content: center; padding: 0; }
.actions3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.btn-sm { height: 44px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); font-size: 13px; font-weight: 500; }
.btn-sm.danger { border-color: #3a2222; color: var(--accent-text); }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 16px calc(20px + env(safe-area-inset-bottom)); background: rgba(13,12,14,.94); backdrop-filter: blur(8px); border-top: 1px solid var(--line-soft); z-index: 5; }
.bottom-bar .in { max-width: 528px; margin: 0 auto; display: flex; gap: 10px; }
.btn-primary { height: 54px; border-radius: 14px; background: var(--accent); border: 0; color: #fff; font-size: 16px; font-weight: 600; width: 100%; }
.btn-secondary { height: 54px; border-radius: 14px; border: 1px solid #3a3438; background: transparent; color: var(--text); font-size: 15px; font-weight: 600; width: 100%; }
.bottom-bar .btn-primary { flex: 1.4; } .bottom-bar .btn-secondary { flex: 1; }
button:disabled { opacity: .55; }

.viewer { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .round { position: absolute; top: 14px; right: 14px; }

/* форма */
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .lbl { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input, .field textarea, .area { width: 100%; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--text); font-size: 15px; line-height: 1.45; outline: none; resize: vertical; }
.field input { height: 48px; resize: none; }
.field input:focus, .field textarea:focus, .area:focus { border-color: #5a4a4c; }
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.cover-pick { display: flex; gap: 14px; align-items: stretch; }
.cover-box { width: 120px; height: 168px; flex: none; border-radius: 16px; border: 1.5px dashed #4a4246; background: #141215; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #cfc8c2; overflow: hidden; padding: 0; }
.cover-box img { width: 100%; height: 100%; object-fit: cover; }
.cover-box.has { border-style: solid; border-color: var(--line); }
.cover-pick .txt { display: flex; flex-direction: column; justify-content: center; gap: 6px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.cover-pick .txt b { color: var(--text-2); font-size: 14px; }
.tagpick { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.tagpick h3 { margin: 0 0 6px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.tchip { height: 36px; padding: 0 13px; border-radius: 18px; font-weight: 600; font-size: 13px; background: transparent; color: #cfc8c2; border: 1px solid #3a3438; }
.tchip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.greets { display: flex; flex-direction: column; gap: 8px; }
.greet { text-align: left; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-size: 13.5px; line-height: 1.45; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.greet.on { border-color: var(--accent); color: var(--text); }

/* импорт */
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface); }
.seg button { height: 40px; border-radius: 10px; border: 0; background: transparent; color: #cfc8c2; font-weight: 600; font-size: 13.5px; }
.seg button.on { background: var(--text); color: var(--bg); }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 190px; border-radius: 18px; border: 1.5px dashed #4a4246; background: #141215; color: #cfc8c2; text-align: center; padding: 20px 24px; width: 100%; }
.drop b { font-size: 15px; color: var(--text); }
.drop span { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.drop.has { border-style: solid; border-color: var(--accent-line); }
.toggles { display: flex; flex-direction: column; padding: 4px 16px; border-radius: 16px; background: var(--surface); border: 1px solid #2a262b; }
.toggles label { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.toggles label + label { border-top: 1px solid var(--line-soft); }
.toggles span { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggles b { font-size: 15px; }
.toggles small { font-size: 12.5px; color: var(--muted); }
.toggles input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
.progress { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--accent-line); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.steps { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.steps .done { color: var(--ok); } .steps .doing { color: var(--text); } .steps .failed { color: var(--accent-text); }

/* истории */
.story-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--surface-2); }
.story { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; text-align: left; }
.thumb { width: 52px; height: 52px; border-radius: 14px; overflow: hidden; flex: none; position: relative; }
.thumb img, .thumb .mono { width: 100%; height: 100%; object-fit: cover; font-size: 28px; }
.story .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.story .row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.story .name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.story .time { font-size: 12px; color: var(--muted); flex: none; }
.story .as { font-size: 12.5px; color: var(--persona); }
.story .snip { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check { width: 28px; height: 28px; flex: none; border-radius: 14px; border: 1.5px solid #5a5257; display: flex; align-items: center; justify-content: center; color: transparent; }
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sel-bar { position: fixed; left: 16px; right: 16px; bottom: calc(100px + env(safe-area-inset-bottom)); display: flex; gap: 10px; z-index: 6; max-width: 528px; margin: 0 auto; }
.sel-bar button { flex: 1; height: 50px; border-radius: 14px; font-weight: 600; font-size: 15px; }

/* память */
.fact { display: flex; align-items: flex-start; gap: 10px; padding: 10px 4px 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--accent-text); }
.fact > svg { flex: none; margin-top: 2px; }
.fact span { flex: 1; color: var(--text); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.fact-x { width: 36px; height: 36px; margin: -8px 0; flex: none; border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 0; }
.fact-add { display: flex; gap: 8px; }
.fact-add input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--text); font-size: 15px; outline: none; }

/* личности */
.persona { display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid #2a262b; }
.persona.on { border-color: var(--accent); }
.persona .top { display: flex; gap: 12px; align-items: center; }
.persona .ava { width: 48px; height: 48px; border-radius: 24px; font-size: 26px; }
.persona .nm { flex: 1; font-size: 17px; font-weight: 600; }
.persona p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text-2); white-space: pre-line; }
.persona .row { display: flex; gap: 8px; }
.tag-on { display: flex; align-items: center; gap: 4px; padding: 5px 10px; border-radius: 12px; background: var(--accent-soft); color: #f08a7f; font-size: 12px; font-weight: 600; }
.btn-light { flex: 1; height: 44px; border-radius: 12px; background: var(--text); border: 0; color: var(--bg); font-weight: 600; font-size: 14px; }
.btn-outline { height: 44px; padding: 0 16px; border-radius: 12px; background: transparent; border: 1px solid #3a3438; color: var(--text-2); font-size: 14px; }
.btn-dashed { height: 56px; border-radius: 16px; border: 1.5px dashed #4a4246; background: transparent; color: #cfc8c2; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }

/* настройки */
.panel { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid #2a262b; }
.panel h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel .between, .between { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel .area { background: var(--bg); font-size: 14px; }
.panel .seg { background: var(--bg); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; }
.model { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 14px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.model.on { border-color: var(--accent); }
.model input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.model span { font-family: ui-monospace, monospace; font-size: 14px; font-weight: 600; word-break: break-all; }
.kv { display: flex; justify-content: space-between; align-items: center; min-height: 48px; font-size: 14.5px; }
.kv + .kv { border-top: 1px solid var(--line-soft); }
.dot { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.dot::before { content: ''; width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.row2 { display: flex; gap: 8px; }

/* нижнее меню */
.nav { position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); height: 64px; border-radius: 32px; background: rgba(28,26,30,.92); backdrop-filter: blur(10px); border: 1px solid var(--line); display: flex; align-items: center; justify-content: space-around; padding: 0 6px; z-index: 10; max-width: 528px; margin: 0 auto; }
.nav button { width: 54px; height: 44px; border-radius: 22px; display: flex; align-items: center; justify-content: center; color: var(--muted); background: transparent; border: 0; padding: 0; }
.nav button.on { background: var(--accent-soft); color: var(--accent-text); }
.nav .plus { width: 48px; height: 48px; border-radius: 24px; background: var(--accent); color: #fff; }
.nav .plus.on { background: var(--accent); color: #fff; box-shadow: 0 0 0 3px var(--surface-2), 0 0 0 5px var(--accent); }

/* окна снизу */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: rise .15s ease-out; }
.overlay .box { width: 100%; max-width: 560px; background: var(--surface); border-radius: 24px 24px 0 0; border-top: 1px solid var(--line); padding: 10px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; max-height: 88vh; overflow-y: auto; }
.grip { align-self: center; width: 40px; height: 4px; border-radius: 2px; background: #3a3438; flex: none; }
.overlay h3 { margin: 0; font-family: var(--serif); font-size: 26px; }
.overlay .field input, .overlay .field textarea { background: var(--bg); }
.act { height: 52px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); color: var(--text); font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 12px; padding: 0 16px; width: 100%; }
.act.danger { border-color: #3a2222; color: var(--accent-text); }

.toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; z-index: 50; max-width: 90vw; text-align: center; }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }
.card > .mono { align-items: flex-start; padding-top: 18%; }
