/* ==========================================================================
 * SYNTAX CORE: 100% KARMA-HUB MONOCHROME BRUTALISM
 * VERSION: 3.5 (SYMMETRY ALIGNED)
 * ========================================================================== */

:root {
    --bg-base: #000000;
    --bg-surface: #0a0a0a;
    --bg-elevated: #121212;

    --border-dim: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    --border-strong: #ffffff;

    --text-main: #ffffff;
    --text-muted: #777777;
    --text-dim: #444444;

    /* Идеальные плавные кривые (Fluid Spring) из оригинала */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

html, body {
    height: 100dvh;
    width: 100vw;
    position: fixed;
    overflow: hidden;
    overscroll-behavior-y: none;
    background: var(--bg-base);
    color: var(--text-main);
    font-family: 'Inter', -apple-system, sans-serif;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
 * 1. БАЗА И ЦИФРОВОЙ ШУМ
 * -------------------------------------------------------------------------- */

.app-container {
    height: 100dvh;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.safe-area-top {
    width: 100%;
    flex-shrink: 0;
    height: var(--tg-content-safe-area-inset-top, env(safe-area-inset-top, 40px));
    background: var(--bg-surface);
}

/* --------------------------------------------------------------------------
 * 2. PRELOADER (ЭКРАН ЗАГРУЗКИ)
 * -------------------------------------------------------------------------- */
.preloader {
    position: fixed;
    inset: 0;
    background: var(--bg-base);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s var(--ease-out-expo), visibility 0.5s;
    opacity: 0;
    visibility: hidden;
}
.preloader.active {
    opacity: 1;
    visibility: visible;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border-dim);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 24px;
}
.preloader-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    letter-spacing: 3px;
    color: var(--text-muted);
    text-transform: uppercase;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
 * 3. HEADER (СИНХРОНИЗАЦИЯ С КАРМОЙ)
 * -------------------------------------------------------------------------- */
.karma-header {
    padding: 25px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 1px solid var(--border-dim);
    background: var(--bg-surface);
    text-align: center;
}

.user-badge {
    padding: 6px 16px;
    border: 1px solid var(--border-light);
    border-radius: 30px;
    margin-bottom: 25px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.greeting-text {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

.karma-display {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 10px;
    justify-content: center;
    width: 100%;
}

.syntax-logo {
    font-size: clamp(60px, 18vw, 85px);
    font-weight: 900;
    letter-spacing: -3px;
    line-height: 1;
    color: #fff;
    text-shadow: 0 0 30px rgba(255,255,255,0.15);
}

.sub-text {
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 8px;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* --------------------------------------------------------------------------
 * 4. MAIN CONTENT & SMART TEXTAREA
 * -------------------------------------------------------------------------- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    overflow-y: auto;
}

.section-title {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 2px;
    padding: 25px 20px 10px;
    text-transform: uppercase;
}

.textarea-wrapper {
    padding: 0 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

/* Оформление поля ввода в стиле Karma-модалов */
.smart-textarea {
    width: 100%;
    flex: 1;
    padding: 18px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    color: var(--text-main);
    font-size: 15px;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.6;
    resize: none;
    transition: 0.3s var(--ease-out-expo);
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
    border-style: solid;
}

.smart-textarea:focus {
    border-color: var(--border-strong);
    background: #000;
    box-shadow: 0 0 20px rgba(255,255,255,0.05);
}

.smart-textarea::placeholder {
    color: var(--text-dim);
}

/* Скроллбар */
.smart-textarea::-webkit-scrollbar { width: 4px; }
.smart-textarea::-webkit-scrollbar-track { background: transparent; }
.smart-textarea::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

/* --------------------------------------------------------------------------
 * 5. ACTION PANEL & BUTTONS (КНОПКИ 1:1)
 * -------------------------------------------------------------------------- */
.action-panel {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(0deg, var(--bg-base) 0%, transparent 100%);
    margin-bottom: env(safe-area-inset-bottom, 20px);
}

/* Белая кнопка (btn-submit из Кармы) */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 18px;
    background: #fff;
    color: #000;
    font-weight: 800;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s var(--ease-spring), background 0.2s;
    box-shadow: 0 10px 30px rgba(255,255,255,0.1);
}

.btn-primary:active {
    transform: scale(0.96);
    background: #d0d0d0;
}

/* Прозрачная кнопка (btn-cancel из Кармы) */
.btn-secondary {
    width: 100%;
    padding: 16px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.btn-secondary:active {
    background: rgba(255,255,255,0.05);
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}

.btn-icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.5;
}

/* Анимация пульсации для главной кнопки */
.pulse-btn {
    animation: forge-pulse 2s infinite;
}

@keyframes forge-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }
    70% { box-shadow: 0 0 0 12px rgba(255, 255, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.file-status-badge {
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin-bottom: 5px;
    text-transform: uppercase;
}

/* ==========================================================================
 * EXPAND MODULE (FULLSCREEN EDITOR)
 * ========================================================================== */

/* Кнопка развертывания: Strict Monochrome */
.textarea-wrapper {
    position: relative; /* Обязательно для позиционирования иконки */
}

button#btn-expand.expand-toggle {
    all: unset !important;
    box-sizing: border-box !important;
    position: absolute !important;
    top: 18px !important;    /* Чуть ниже верхнего края */
    right: 35px !important;  /* Слева от возможного скроллбара */
    z-index: 99 !important;
    width: 24px !important;
    height: 24px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: none !important; /* Без фона */
    border: none !important;
    color: #ffffff !important;   /* Белые стрелочки */
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s var(--ease-spring) !important;
}

button#btn-expand.expand-toggle:hover,
button#btn-expand.expand-toggle:active {
    opacity: 1 !important;
    transform: scale(1.1) !important;
}

button#btn-expand.expand-toggle svg {
    width: 20px !important;
    height: 20px !important;
    stroke: currentColor !important;
    fill: none !important;
    stroke-width: 2.5px !important;
}

/* Фикс для textarea, чтобы текст не залезал под иконку */
.smart-textarea {
    padding-right: 50px !important;
}

/* * МАГИЯ ФЛЕКСОВ:
 * Когда body получает класс .editor-expanded, приложение перестраивается
 * так, чтобы поле ввода заняло ВСЁ пустое место, прижав кнопки к низу.
 */
body.editor-expanded .app-container {
    display: flex;
    flex-direction: column;
    height: 100dvh; /* Строго 100% высоты видимого экрана */
}

body.editor-expanded .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.editor-expanded .input-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Важно: разрешаем блоку сжиматься/растягиваться */
}

body.editor-expanded .textarea-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 16px; /* Отступ от поля ввода до кнопок */
}

body.editor-expanded .smart-textarea {
    flex: 1;
    height: 100% !important; /* Отключаем фиксированную высоту */
    resize: none;
}