:root {
    --bg: #eef1f3;
    --panel: #f5f7f9;
    --card: #ffffff;
    --mint: #33c0a4;
    --mint-dark: #1fa78d;
    --ink: #253045;
    --muted: #556070;
    --line: #dce2e8;
    --danger: #ef7070;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
    background: radial-gradient(circle at 20% 0%, #f7fbfd 0%, var(--bg) 60%);
    color: var(--ink);
    height: 100dvh;
    overflow: hidden;
}

.hidden { display: none !important; }

/* Авторизация */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(170deg, #f8fcff 0%, #edf4f8 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.auth-box {
    background: var(--card);
    padding: 30px;
    border-radius: 28px;
    box-shadow: 0 20px 45px rgba(24, 40, 65, 0.08);
    width: min(92vw, 390px);
    text-align: center;
    max-height: 95dvh;
    overflow-y: auto;
}

.auth-logo img { width: 74px; border-radius: 18px; margin-bottom: 16px; }
#auth-title { margin-bottom: 20px; font-size: 26px; color: var(--ink); }

.auth-box input {
    width: 100%;
    padding: 13px 14px;
    margin-bottom: 14px;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.25s;
}

.auth-box input:focus { border-color: var(--mint); }

.primary-btn {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, var(--mint) 0%, #31b69a 100%);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.error-msg { color: #de4d4d; margin-bottom: 14px; font-size: 14px; min-height: 20px; }
#auth-switch-text { margin-top: 16px; font-size: 14px; color: #7a8495; }
#switch-auth-mode { color: #3c7de9; cursor: pointer; font-weight: 700; }

/* Основной лейаут */
.app-container {
    display: flex;
    height: 100dvh;
    width: 100vw;
    position: relative;
}

.sidebar {
    width: 320px;
    background: #f6f8fa;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    z-index: 1200;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--line);
    text-align: center;
    position: relative;
}

.sidebar-close {
    position: absolute;
    top: 18px;
    right: 16px;
    border: none;
    background: transparent;
    color: #3d82ea;
    font-size: 30px;
    cursor: pointer;
    line-height: 1;
}

#new-chat-btn {
    width: 100%;
    padding: 16px 12px;
    background: linear-gradient(135deg, #38c2a6 0%, #32b79d 100%);
    color: #fff;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    font-weight: 700;
    font-size: 16px;
    margin-top: 14px;
}

.chat-history-list { flex: 1; overflow-y: auto; padding: 14px; }

.lang-switcher {
    margin-top: 12px;
    display: flex;
    justify-content: center;
    gap: 8px;
}

.lang-btn {
    border: 1px solid #cfd8e1;
    background: #ffffff;
    color: #4d5a6d;
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-btn.active {
    border-color: #35bfa2;
    background: #e8f8f4;
    color: #19927a;
}

.chat-history-item {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: 12px 14px;
    margin-bottom: 8px;
    border-radius: 12px;
    cursor: pointer;
    color: #4e5969;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.chat-history-item:hover { background: #e7eef4; transform: translateX(2px); }
.chat-history-item.active { background: #d9f2ec; color: #0f8873; font-weight: 600; }

.chat-history-item .chat-title {
    font-size: 13px;
    font-weight: 700;
    color: #344256;
}

.chat-history-item .chat-preview {
    font-size: 12px;
    color: #6c7788;
    margin-top: 3px;
}

.sidebar-footer { padding: 14px 20px 20px; border-top: 1px solid var(--line); }

.profile-btn {
    width: 100%;
    padding: 13px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 600;
    color: #455064;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(25, 32, 44, 0.42);
    z-index: 1150;
}

/* Дашборд */
.dashboard-panel {
    background: #d9ecea;
    border-radius: 26px;
    padding: 18px;
    margin: 14px 0 0;
    border: 1px solid #d0e6e1;
    text-align: left;
    color: #415164;
}

.user-plan { font-size: 14px; }
.user-plan span { font-weight: 800; color: var(--mint-dark); }
.user-level { margin-top: 6px; font-size: 18px; font-weight: 700; }
.user-xp { margin-top: 6px; display: flex; justify-content: space-between; color: #59697f; }
.progress-bar-bg {
    width: 100%;
    height: 9px;
    background: #edf2f6;
    border-radius: 999px;
    margin-top: 8px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3dc6aa 0%, #6ad9c0 100%);
    transition: width 0.45s ease;
}

/* Основной контент */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #f5f7f9 0%, #f1f3f5 100%);
    position: relative;
}

.chat-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 88px;
}

.header-title { font-family: "Sora", "Manrope", sans-serif; font-weight: 700; font-size: 19px; letter-spacing: 0; color: #273144; }

.action-buttons-container { display: flex; gap: 10px; }

.action-btn {
    padding: 10px 18px;
    border-radius: 999px;
    border: 2px solid #d2d8df;
    background: #f7f8fa;
    cursor: pointer;
    font-weight: 600;
    font-size: 16px;
    color: #546173;
}

.feature-btn {
    border-color: #b2dfd4;
    color: #188f79;
    background: #edf9f6;
}

/* Сообщения */
.chat-container { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

.welcome-screen {
    position: absolute;
    top: 44%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #8e99a9;
    width: min(90vw, 680px);
}

.welcome-screen img {
    width: 114px;
    border-radius: 28px;
    box-shadow: 0 12px 30px rgba(21, 45, 69, 0.12);
    margin-bottom: 20px;
}

.welcome-screen h1 { font-size: clamp(36px, 5vw, 54px); color: #232e42; margin-bottom: 10px; }
.welcome-screen p { font-size: clamp(18px, 2.2vw, 28px); line-height: 1.45; color: #57647a; }

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    max-width: min(760px, 88%);
    padding: 16px 18px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.55;
    animation: fadeIn 0.25s ease;
}

.msg-ai pre,
.msg-ai code,
.msg-ai p,
.msg-ai li,
.msg-ai div {
    max-width: 100%;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.msg-ai pre {
    white-space: pre-wrap;
    background: #f5f8fb;
    border: 1px solid #e2e8ef;
    padding: 10px;
    border-radius: 10px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #6b7688;
    font-weight: 600;
}

.typing-label {
    margin-right: 4px;
}

.loading-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6fcfbc;
    animation: typingDot 1s infinite ease-in-out;
}

.loading-dots .dot:nth-child(3) { animation-delay: 0.15s; }
.loading-dots .dot:nth-child(4) { animation-delay: 0.3s; }

@keyframes typingDot {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
    40% { transform: translateY(-5px); opacity: 1; }
}

.msg-user {
    background: #dff4ef;
    color: #123f35;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

.msg-ai {
    background: #fff;
    border: 1px solid #e3e8ee;
    color: #273144;
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 4px 16px rgba(29, 47, 68, 0.04);
}

/* Ввод */
.input-area {
    padding: 12px 20px 18px;
    background: rgba(245, 247, 249, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(6px);
}

#image-preview-container { display: inline-block; position: relative; margin-bottom: 10px; }
#image-preview { height: 60px; border-radius: 12px; border: 2px solid #5fcab4; }

#remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #e45555;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 21px;
    height: 21px;
    cursor: pointer;
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: #e6eaee;
    border-radius: 34px;
    padding: 10px 12px;
    min-height: 74px;
}

#user-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0 12px;
    font-size: 16px;
    color: #39445a;
    outline: none;
}

#user-input::placeholder { color: #96a0af; }

#send-btn,
#attach-btn {
    background: transparent;
    border: none;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    cursor: pointer;
    color: #566377;
    display: grid;
    place-items: center;
}

#send-btn {
    background: linear-gradient(135deg, #38c5a8 0%, #2fb79d 100%);
    color: #fff;
    box-shadow: 0 8px 20px rgba(41, 179, 151, 0.35);
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

#send-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 20px rgba(41, 179, 151, 0.45); }

.msg-image { max-width: 100%; border-radius: 14px; margin-top: 8px; }

/* Модалки */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 28, 40, 0.45);
    z-index: 5000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #fff;
    width: min(640px, 92vw);
    border-radius: 26px;
    padding: 28px;
    position: relative;
    text-align: center;
    box-shadow: 0 18px 50px rgba(12, 25, 39, 0.22);
    animation: modalIn 0.24s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.close-modal {
    position: absolute;
    top: 12px;
    right: 18px;
    font-size: 30px;
    cursor: pointer;
    color: #9ca5b2;
}

.avatar-circle {
    width: 92px;
    height: 92px;
    background: #d7dde6;
    border-radius: 50%;
    margin: 6px auto 12px;
}

.logout-btn-large {
    width: 100%;
    padding: 14px;
    margin-top: 24px;
    background: #ffe8e8;
    color: #d84c4c;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 700;
}

/* Профиль */
.profile-content {
    background: linear-gradient(180deg, #d7ece9 0%, #cce7e4 100%);
    text-align: left;
}

.profile-content h2 {
    text-align: center;
    font-size: 40px;
    margin: 10px 0 8px;
    color: #243146;
}

#profile-email { text-align: center; color: #68768b; margin-bottom: 24px; font-size: 20px; }

.profile-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 48px;
}

.profile-settings-btn {
    border: none;
    background: transparent;
    font-size: 30px;
    color: #556174;
    cursor: pointer;
}

.plan-switch {
    background: #fff;
    border-radius: 24px;
    padding: 10px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    color: #8791a1;
    font-weight: 700;
    font-size: 16px;
}

.plan-active {
    background: linear-gradient(135deg, #34bf9f 0%, #2bb394 100%);
    color: #fff;
    text-align: center;
    border-radius: 18px;
    padding: 12px 10px;
}

.plan-divider {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c9d2de;
    justify-self: center;
}

.profile-cards { display: grid; gap: 14px; margin-top: 20px; }

.profile-card-item {
    background: #fff;
    border-radius: 18px;
    padding: 20px;
    font-size: 20px;
    font-weight: 600;
    color: #303d52;
}

.promo-code-block {
    margin-top: 16px;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #d7e7e3;
}

.promo-code-block label {
    display: block;
    font-weight: 700;
    font-size: 14px;
    color: #3f4b5f;
    margin-bottom: 8px;
}

.promo-code-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

#promo-code-input {
    border: 1px solid #cfd9e3;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
}

#apply-promo-btn {
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #38c5a8 0%, #2fb79d 100%);
    color: #fff;
    font-weight: 700;
    padding: 10px 14px;
    cursor: pointer;
}

.promo-status {
    margin-top: 8px;
    font-size: 13px;
    color: #2e6f61;
}

.profile-card-item.clickable {
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.profile-card-item.clickable:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(25, 42, 62, 0.08);
}

.ai-settings-content {
    max-width: 520px;
    text-align: left;
}

.ai-settings-content h2 {
    margin-bottom: 16px;
}

.setting-group {
    margin-bottom: 14px;
}

.setting-group label {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: #445165;
    margin-bottom: 7px;
}

.setting-group select,
.setting-group input[type="range"] {
    width: 100%;
}

.setting-group select {
    border: 1px solid #cfd8e1;
    border-radius: 12px;
    padding: 10px;
    background: #fff;
}

.setting-hint {
    margin-top: 6px;
    font-size: 13px;
    color: #6a778b;
}

/* Квиз + флешкарты */
.quiz-content,
.flashcard-content {
    max-width: 740px;
    width: 92vw;
    text-align: left;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 12px;
}

.modal-header h2 { font-size: 26px; color: #273347; }

.regen-btn {
    border: 1px solid var(--line);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    color: #4e5a6e;
    background: #fff;
}

.quiz-option {
    display: block;
    width: 100%;
    padding: 14px 18px;
    margin: 10px 0;
    background: #fff;
    border: 2px solid #d6dbe2;
    border-radius: 16px;
    cursor: pointer;
    text-align: left;
    font-size: 16px;
    color: #3f4c5f;
}

.quiz-option.correct { background: #e8f7ef; border-color: #53c389; color: #196640; }
.quiz-option.wrong { background: #fce9e9; border-color: #eb7f7f; color: #7a2626; }
.quiz-footer { margin-top: 20px; text-align: center; }

.flashcard-scene { width: 100%; height: 300px; perspective: 1000px; margin: 20px 0; }

.flashcard-card {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    cursor: pointer;
}

.flashcard-card.is-flipped { transform: rotateY(180deg); }

.flashcard-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    border-radius: 24px;
    box-shadow: 0 8px 24px rgba(22, 38, 59, 0.08);
    font-size: 18px;
    text-align: center;
    line-height: 1.35;
}

.flashcard-front { background: #fff; color: #273144; }
.flashcard-back { transform: rotateY(180deg); background: #edf6f4; color: #273144; }

.flashcard-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
}

.fc-btn {
    padding: 14px 18px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
}

.fc-btn.danger { background: var(--danger); }
.fc-btn.success { background: #32be9f; }
#fc-counter { font-weight: 600; color: #69788d; font-size: 20px; text-align: center; }

/* Глазик пароля */
.password-wrapper { position: relative; width: 100%; margin-bottom: 14px; }
.password-wrapper input { margin-bottom: 0 !important; padding-right: 40px; }

.toggle-password {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    user-select: none;
    opacity: 0.65;
}

.toggle-password:hover { opacity: 1; }

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #33c0a4;
    color: #fff;
    padding: 12px 22px;
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(18, 48, 45, 0.2);
    z-index: 10000;
    font-weight: 700;
    transition: opacity 0.3s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

/* Мобильный интерфейс из референса */
.mobile-only { display: none; }

@media (max-width: 1024px) {
    .header-title { font-size: 18px; }
    .message { max-width: 92%; }
}

@media (max-width: 768px) {
    .app-container { overflow: hidden; }

    .mobile-only { display: block; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(82vw, 430px);
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 10px 0 30px rgba(20, 31, 45, 0.15);
    }

    .sidebar.open { transform: translateX(0); }

    .main-content { width: 100%; }

    .chat-header {
        min-height: 92px;
        justify-content: center;
        position: relative;
    }

    #mobile-menu-btn {
        position: absolute;
        left: 16px;
        border: none;
        background: transparent;
        color: #2f3b4f;
        font-size: 32px;
        line-height: 1;
        cursor: pointer;
    }

    .header-title { font-size: 20px; font-family: "Sora", "Manrope", sans-serif; }

    .action-buttons-container {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 74px);
        display: flex;
        justify-content: flex-start;
        gap: 8px;
        overflow-x: auto;
        padding: 0 2px 2px;
        z-index: 1100;
        scrollbar-width: none;
    }
    .action-buttons-container::-webkit-scrollbar { display: none; }

    .action-btn {
        min-height: auto;
        flex: 0 0 auto;
        padding: 6px 12px;
        font-size: 12px;
        font-weight: 500;
        border-width: 2px;
        border-radius: 16px;
        background: #f8fafb;
    }

    .feature-btn { background: #f8fafb; border-color: #ccd4dd; color: #4f5b6f; }

    #mode-oko-btn {
        border-color: #49c9af;
        background: #e7f8f4;
        color: #1f9d85;
    }

    .chat-box { padding: 14px 15px 170px; }
    .message { font-size: 14px; padding: 12px 14px; }

    .msg-ai table {
        display: block;
        width: max-content;
        max-width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }

    .welcome-screen {
        top: 43%;
        width: calc(100vw - 34px);
    }

    .welcome-screen img {
        width: 160px;
        border-radius: 36px;
    }

    .welcome-screen h1 { font-size: clamp(34px, 9vw, 44px); }
    .welcome-screen p { font-size: clamp(16px, 5vw, 24px); }

    .chat-history-item .chat-title { font-size: 15px; }
    .chat-history-item .chat-preview { font-size: 13px; }

    .input-area {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1090;
        padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
        background: rgba(245, 247, 249, 0.94);
    }

    .input-wrapper {
        min-height: 56px;
        border-radius: 22px;
        padding: 5px 8px;
    }

    #user-input {
        font-size: 16px;
        line-height: 1.35;
        padding: 0 8px;
    }

    #send-btn, #attach-btn {
        width: 38px;
        height: 38px;
    }

    #send-btn svg,
    #attach-btn svg {
        width: 18px;
        height: 18px;
    }

    .modal { align-items: stretch; }

    .profile-content,
    .quiz-content,
    .flashcard-content {
        width: 100vw;
        max-width: none;
        height: 100dvh;
        border-radius: 0;
        padding: 22px 16px calc(env(safe-area-inset-bottom, 0px) + 22px);
        overflow-y: auto;
    }

    .profile-content h2,
    #fc-counter,
    .modal-header h2 {
        font-size: clamp(24px, 6vw, 34px);
    }

    .profile-card-item { font-size: clamp(18px, 4.6vw, 24px); }

    .quiz-option,
    .fc-btn {
        font-size: clamp(16px, 4.3vw, 22px);
    }

    .flashcard-scene { height: 420px; }

    .flashcard-controls {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    #fc-counter { order: -1; }
}
