:root {
    --bg: #0b0b0f; --panel: #17171e; --panel-light: #22222a; --accent: #8a2be2; --text: #ffffff; --text-muted: #888; --border: #2a2a35;
    --btn-bg: #ffffff; --btn-text: #000000; 
}
body.light-theme {
    --bg: #f5f5f7; --panel: #ffffff; --panel-light: #e5e5ea; --text: #000000; --text-muted: #666666; --border: #d1d1d6;
    --btn-bg: #000000; --btn-text: #ffffff; 
}

* { 
    box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    transition: background-color 0.3s, color 0.3s, border-color 0.3s; 
    -webkit-tap-highlight-color: transparent; 
    user-select: none; 
}
input, textarea, .msg, .history-item { user-select: text; }

body { background-color: var(--bg); color: var(--text); height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; padding-bottom: env(safe-area-inset-bottom); }

svg { display: block; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }

em, i { font-style: italic; color: var(--text-muted); }

.header { background: var(--panel); padding: 15px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); flex-shrink: 0; z-index: 10; }
.logo { font-weight: 800; font-size: 18px; letter-spacing: 1px; }
.logo span { color: var(--text); }
.balance { background: var(--panel-light); color: var(--text); padding: 6px 12px; border-radius: 20px; font-size: 14px; font-weight: bold; border: 1px solid var(--border); display: flex; align-items: center; gap: 6px; }
.token-svg { width: 16px; height: 16px; stroke: var(--text); fill: var(--text); stroke-width: 1; }

.custom-select { position: relative; user-select: none; }
.custom-select-trigger { background: var(--panel-light); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 60px; }
.custom-select-trigger:hover { background: var(--border); }
.custom-options { position: absolute; top: 100%; right: 0; margin-top: 5px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); min-width: 100%; z-index: 50; opacity: 0; visibility: hidden; transform: translateY(-10px); transition: all 0.3s ease; overflow: hidden; }
.custom-options.open { opacity: 1; visibility: visible; transform: translateY(0); }
.custom-option { padding: 10px 15px; font-size: 13px; cursor: pointer; transition: background 0.2s; white-space: nowrap; }
.custom-option:hover { background: var(--panel-light); }

#main-content { flex: 1; overflow-y: auto; position: relative; }
.screen { display: none; padding: 15px; padding-bottom: 80px; animation: fadeIn 0.2s ease-out; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.main-tabs { display: flex; gap: 10px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.mtab { color: var(--text-muted); font-weight: 600; cursor: pointer; font-size: 15px; padding: 5px 0; position: relative; }
.mtab.active { color: var(--text); }
.mtab.active::after { content: ''; position: absolute; bottom: -11px; left: 0; width: 100%; height: 2px; background: var(--text); }

.search-wrapper { position: relative; margin-bottom: 20px; }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-bar { width: 100%; padding: 14px 18px 14px 45px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 15px; outline: none; }
.search-bar:focus { border-color: var(--text); }

.btn-create-large { display: flex; align-items: center; background-color: var(--panel); color: var(--text); padding: 16px 24px; border-radius: 30px; font-weight: 600; font-size: 16px; cursor: pointer; border: 1px solid var(--border); width: 100%; margin-bottom: 20px; gap: 12px; }
.btn-create-large:hover { background-color: var(--panel-light); }

.char-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.char-card { background: var(--panel); border-radius: 16px; overflow: hidden; border: 1px solid var(--border); cursor: pointer; transition: transform 0.1s; }
.char-card:active { transform: scale(0.97); }
.card-img { height: 140px; background: var(--panel-light) center/cover; display: flex; align-items: center; justify-content: center; }
.card-info { padding: 12px; }
.card-name { font-weight: bold; font-size: 15px; margin-bottom: 4px; }
.card-desc { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.create-header { font-size: 20px; font-weight: bold; margin-bottom: 15px; }
.toggle-container { display: flex; position: relative; background: var(--panel); border-radius: 12px; padding: 5px; margin-bottom: 25px; border: 1px solid var(--border); }
.toggle-bg { position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc(50% - 5px); background: var(--btn-bg); border-radius: 8px; transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1); z-index: 1; }
.toggle-bg.universe, .toggle-bg.os-bg.active { transform: translateX(100%); }
.toggle-btn { flex: 1; text-align: center; padding: 10px; font-size: 14px; font-weight: 600; color: var(--text-muted); cursor: pointer; z-index: 2; transition: color 0.3s; }
.toggle-btn.active { color: var(--btn-text); }

.form-container { position: relative; overflow: visible; }
.form-wrapper { display: none; }
.form-wrapper.active { display: block; }
.anim-explode-out { animation: explodeOut 0.4s cubic-bezier(0.1, 0.8, 0.2, 1) forwards; pointer-events: none; }
.anim-suck-in { animation: suckIn 0.4s cubic-bezier(0.1, 0.8, 0.2, 1) forwards; }
@keyframes explodeOut { 0% { transform: scale(1); opacity: 1; } 30% { transform: scale(1.05); opacity: 1; } 100% { transform: scale(1.5) translateY(-30px); opacity: 0; filter: blur(12px); } }
@keyframes suckIn { 0% { transform: scale(0.7) translateY(30px); opacity: 0; filter: blur(12px); } 100% { transform: scale(1); opacity: 1; filter: blur(0); } }

.input-group { margin-bottom: 15px; }
.input-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.input-field { width: 100%; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; outline: none; }
textarea.input-field { resize: vertical; min-height: 80px; }
.input-field:focus { border-color: var(--text); }

.file-input-wrapper { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.file-input-wrapper input[type="file"] { background: var(--panel); border: 1px dashed var(--border); padding: 10px; border-radius: 8px; color: var(--text-muted); font-size: 13px; cursor: pointer; }
.file-input-wrapper input[type="file"]::file-selector-button { background: var(--panel-light); color: var(--text); border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; margin-right: 10px; font-weight: 500; }

.avatar-drop-zone { border: 2px dashed var(--border); border-radius: 12px; cursor: pointer; position: relative; overflow: hidden; background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; width: 160px; height: 160px; margin: 0 auto 15px auto; color: var(--text-muted); }
.avatar-drop-zone:hover, .avatar-drop-zone.dragover { border-color: var(--text); color: var(--text); }
.avatar-drop-zone .drop-text { font-size: 12px; text-align: center; margin-top: 10px; }
.avatar-drop-zone input[type="file"] { display: none; }
.avatar-preview { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; display: none; z-index: 1; }

.btn { background: var(--btn-bg); color: var(--btn-text); border: none; padding: 14px; border-radius: 10px; width: 100%; font-weight: bold; font-size: 15px; cursor: pointer; margin-top: 10px; display: flex; justify-content: center; align-items: center; gap: 8px;}
.btn.secondary { background: var(--panel-light); color: var(--text); }
.btn-group { display: flex; gap: 10px; margin-top: 20px; }

.theme-switcher-container { position: absolute; top: 15px; right: 15px; display: flex; align-items: center; gap: 8px; }
.profile-top { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 20px; margin-top: 30px; }
.avatar-circle { width: 60px; height: 60px; background: var(--panel-light); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); overflow: hidden; }
.avatar-circle.large { width: 90px; height: 90px; margin-bottom: 10px; }
.avatar-circle img { width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-size: 20px; font-weight: bold; display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 5px; }
.edit-nick-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; }
.profile-stats { color: var(--text-muted); font-size: 13px; margin-bottom: 15px; }
.settings-btn { width: auto; padding: 8px 20px; border-radius: 20px; font-size: 14px; background: var(--panel-light); color: var(--text); border: 1px solid var(--border); }

.profile-tabs { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); margin-bottom: 15px; overflow-x: auto; }
.ptab { padding: 10px 15px; color: var(--text-muted); font-weight: 600; cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; }
.ptab.active { color: var(--text); border-bottom-color: var(--text); }
.ptab-content { display: none; }
.ptab-content.active { display: block; animation: fadeIn 0.2s; }

.like-dislike-btns { display: flex; gap: 15px; align-items: center; }
.like-dislike-btns button { background: none; border: none; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; justify-content: center; padding: 5px; transition: color 0.2s, transform 0.1s; }
.like-dislike-btns button:hover { color: var(--text); }
.like-dislike-btns button:active { transform: scale(0.9); }
.like-dislike-btns svg { width: 20px; height: 20px; }

.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.shop-square-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 15px; display: flex; flex-direction: column; justify-content: space-between; aspect-ratio: 1 / 1; }
.shop-square-title { font-weight: bold; font-size: 14px; margin-bottom: 5px; color: var(--text); }
.shop-square-price { font-weight: bold; font-size: 15px; color: var(--text-muted); margin-bottom: auto; }
.shop-square-card .btn { padding: 8px; font-size: 13px; margin-top: 10px; }

/* ИСПРАВЛЕНО: OVERFLOW HIDDEN РЕШАЕТ ПРОБЛЕМУ С ПУСТЫМ ЭКРАНОМ */
#screen-chat { 
    padding: 0; display: flex; flex-direction: column; height: 100%; 
    position: absolute; top: 0; left: 0; right: 0; bottom: 0; 
    background: var(--bg); z-index: 5; overflow: hidden; 
}
.chat-header { background: var(--panel); padding: 15px; display: flex; align-items: center; border-bottom: 1px solid var(--border); justify-content: space-between; }
.back-btn, .menu-btn { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; padding: 5px; display: flex; align-items: center; }
.chat-title { font-weight: bold; font-size: 17px; flex: 1; text-align: center; }

.chat-header-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background-color: var(--panel-light);
    background-size: cover; background-position: center;
    margin-right: 10px;
    border: 1px solid var(--border);
}

/* ИСПРАВЛЕННЫЕ ПАНЕЛИ */
.chat-side-menu { 
    position: absolute; top: 0; right: 0; bottom: 0; width: 85%; max-width: 320px; 
    background: var(--panel); z-index: 20; border-left: 1px solid var(--border); 
    padding: 20px; display: flex; flex-direction: column; gap: 15px; 
    transform: translateX(100%); transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1); 
    box-shadow: -5px 0 15px rgba(0,0,0,0.2); overflow-y: auto;
}
.chat-side-menu.open { transform: translateX(0); }

.history-overlay {
    position: absolute; top: 0; right: 0; bottom: 0; width: 85%; max-width: 320px;
    background: var(--panel); z-index: 30; border-left: 1px solid var(--border);
    padding: 20px; display: flex; flex-direction: column; gap: 15px;
    transform: translateX(100%); transition: transform 0.9s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -5px 0 15px rgba(0,0,0,0.2); overflow-y: auto;
}
.history-overlay.open { transform: translateX(0); }

.history-list-full { display: flex; flex-direction: column; gap: 10px; overflow-y: visible; padding-bottom: 20px; }
.history-item { 
    background: var(--panel-light); padding: 15px; border-radius: 10px; cursor: pointer; 
    border: 1px solid transparent; display: flex; justify-content: space-between; align-items: center;
    position: relative; z-index: 1;
}
.history-item:hover { border-color: var(--border); }
.history-item.active { border-color: var(--accent); z-index: 2; }

.pinned-icon { display: inline-flex; vertical-align: middle; margin-right: 5px; color: var(--text-muted); }
.pinned-icon svg { width: 14px; height: 14px; fill: currentColor; }

.chat-options-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 5px; display: flex; align-items: center; justify-content: center; }
.chat-options-btn:hover { color: var(--text); }
.chat-options-menu {
    position: absolute; right: 0px; top: 40px; background: var(--panel); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.4); display: none; flex-direction: column; min-width: 160px; z-index: 100; 
}
.chat-options-menu.open { display: flex; }
.chat-options-menu button { background: none; border: none; color: var(--text); padding: 12px 15px; text-align: left; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.chat-options-menu button:last-child { border-bottom: none; }
.chat-options-menu button:hover { background: var(--panel-light); }

.side-menu-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding-bottom: 15px; border-bottom: 1px solid var(--border); }
.side-menu-title { font-weight: bold; font-size: 18px; }
.close-menu-btn { background: var(--panel-light); border: none; color: var(--text); cursor: pointer; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
.close-menu-btn:hover { background: var(--border); }

.menu-section h4 { font-size: 14px; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; margin-top: 15px; }
.style-desc { font-size: 11px; color: var(--text-muted); margin-top: 5px; }

.settings-toggle-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; }
.settings-info { flex: 1; padding-right: 15px; }
.settings-title { font-weight: bold; font-size: 15px; margin-bottom: 4px; }
.settings-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .4s; border-radius: 26px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--btn-bg); }
input:checked + .slider:before { transform: translateX(20px); background-color: var(--bg); }

.warning-box { background: rgba(255, 193, 7, 0.08); border: 1px solid rgba(255, 193, 7, 0.3); border-radius: 8px; padding: 12px; margin-top: 10px; display: none; }
.warning-box.active { display: block; }
.warning-text { color: #ffc107; font-size: 12px; line-height: 1.4; display: flex; gap: 8px; align-items: flex-start; }

.chat-messages { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.msg-wrapper { display: flex; flex-direction: column; max-width: 85%; margin-bottom: 5px; }
.msg-wrapper.user { align-self: flex-end; align-items: flex-end; }
.msg-wrapper.ai { align-self: flex-start; align-items: flex-start; }
.msg { padding: 12px 16px; border-radius: 16px; font-size: 14px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.msg.ai { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.user { background: var(--btn-bg); color: var(--btn-text); border-bottom-right-radius: 4px; }
.msg.typing { color: var(--text-muted); font-style: italic; }

.msg-actions { display: flex; gap: 10px; margin-top: 5px; opacity: 0.5; transition: opacity 0.2s; }
.msg-wrapper:hover .msg-actions { opacity: 1; }
.msg-actions button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 2px 5px; }
.msg-actions button:hover { color: var(--text); }

.chat-input-area { padding: 12px 15px; background: var(--panel); border-top: 1px solid var(--border); display: flex; gap: 10px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); align-items: center;}
.chat-input { flex: 1; padding: 12px 16px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 15px; outline: none; }
.send-btn { background: var(--btn-bg); color: var(--btn-text); border: none; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

.bottom-nav { background: var(--panel); display: flex; justify-content: space-around; align-items: center; border-top: 1px solid var(--border); position: absolute; bottom: 0; left: 0; right: 0; padding: 10px 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 10; }
.nav-item { display: flex; flex-direction: column; align-items: center; color: var(--text-muted); font-size: 11px; cursor: pointer; transition: color 0.2s; gap: 4px; }
.nav-item.active { color: var(--text); }

.list-container { margin-top: 20px; background: var(--panel); border-radius: 16px; border: 1px solid var(--border); overflow: hidden; }
.list-item { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-size: 14px; }
.list-item:active { background: var(--panel-light); }
.list-item-left { display: flex; align-items: center; gap: 12px; color: var(--text); }
.list-item-arrow { color: var(--text-muted); font-weight: bold; }

.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 100; opacity: 1; transition: opacity 0.3s; }
.modal-overlay.hidden { display: none !important; opacity: 0; }
.modal-box { background: var(--panel); border-radius: 16px; padding: 25px; width: 85%; max-width: 350px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); border: 1px solid var(--border); }
.modal-title { font-size: 18px; font-weight: bold; margin-bottom: 10px; color: var(--text); }
.modal-message { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.4; }
.modal-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.modal-actions .btn { margin-top: 0; padding: 10px 15px; font-size: 14px; width: auto; }

.hidden { display: none !important; }
body { top: 0 !important; }
.skiptranslate iframe { display: none !important; }
#goog-gt-tt { display: none !important; }
.goo