@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Share+Tech+Mono&display=swap');

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #05070a;
    overflow: hidden;
    color: #e2e8f0;
    height: 100vh;
    font-family: 'Share Tech Mono', monospace;
}

/* СКАНИРАЩИ ЛИНИИ (ХОЛОГРАМА) */
.scanlines {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.25) 50%
    ), linear-gradient(
        90deg,
        rgba(255, 0, 0, 0.06),
        rgba(0, 255, 0, 0.02),
        rgba(0, 0, 255, 0.06)
    );
    background-size: 100% 4px, 6px 100%;
    z-index: 999;
    pointer-events: none;
    opacity: 0.4;
}

/* MAIN UI БЕКГРАУНД */
.ui {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    background: 
        radial-gradient(circle at center, rgba(34, 197, 94, 0.05) 0%, transparent 65%),
        linear-gradient(rgba(34, 197, 94, 0.01) 1px, transparent 1px) 0 0 / 40px 40px,
        linear-gradient(90deg, rgba(34, 197, 94, 0.01) 1px, transparent 1px) 0 0 / 40px 40px;
}

/* HUD ОБЩИ ПАНЕЛИ */
.hud-panel {
    position: absolute;
    padding: 10px 20px;
    background: rgba(34, 197, 94, 0.02);
    border: 1px solid rgba(34, 197, 94, 0.15);
    backdrop-filter: blur(5px);
    font-size: 13px;
    letter-spacing: 2px;
    color: #22c55e;
}

.system {
    top: 30px;
    left: 40px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 3px solid #22c55e;
}

.digital-clock {
    top: 82px;
    left: 40px;
    width: 168px;
    border-left: 3px solid #6ee7b7;
    color: #d6ffe9;
    font-family: 'Orbitron', sans-serif;
    font-size: 16px;
    letter-spacing: 3px;
    text-align: center;
    text-shadow: 0 0 14px rgba(110, 231, 183, 0.55);
}

.hud-stats {
    top: 30px;
    right: 40px;
    text-align: right;
    border-right: 3px solid #22c55e;
}

.matrix-text {
    color: #6ee7b7;
    font-size: 11px;
    margin-top: 3px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 10px #22c55e;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.4; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.1); box-shadow: 0 0 15px #22c55e; }
    100% { opacity: 0.4; transform: scale(0.9); }
}

/* DODO LOGO */
.logo {
    margin-top: 40px;
    font-family: 'Orbitron', sans-serif;
    font-size: 75px;
    font-weight: 900;
    letter-spacing: 30px;
    color: #22c55e;
    text-shadow: 0 0 20px rgba(34, 197, 94, 0.5), 0 0 40px rgba(34, 197, 94, 0.1);
    padding-left: 30px; /* За баланс на последната буква */
    user-select: none;
    z-index: 5;
}

/* HELLO TEXT */
.hello {
    margin-top: -5px;
    font-size: 14px;
    color: #6ee7b7;
    letter-spacing: 6px;
    text-transform: uppercase;
    opacity: 0.8;
    z-index: 5;
}

/* CORE WRAPPER (обвивка за THREE.JS + HUD RETICLE) */
.core-wrapper {
    position: relative;
    width: 500px;
    height: 500px;
    margin-top: -30px;
    z-index: 1;
}

/* CORE (THREEJS CONTAINER) */
#three-container {
    width: 100%;
    height: 100%;
    pointer-events: none;
    filter: drop-shadow(0 0 25px rgba(34, 197, 94, 0.3)) drop-shadow(0 0 55px rgba(34, 197, 94, 0.15));
}

/* HUD RETICLE - ВЪНШНА "TARGET LOCK" РАМКА ОКОЛО ЯДРОТО */
.reticle {
    position: absolute;
    top: 50%;
    left: 50%;
    pointer-events: none;
}

.reticle .ring {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.reticle .ring1 {
    width: 480px;
    height: 480px;
    border: 1px dashed rgba(34, 197, 94, 0.35);
    animation: reticleSpin 40s linear infinite;
}

.reticle .ring2 {
    width: 560px;
    height: 560px;
    border: 1px solid rgba(34, 197, 94, 0.15);
    animation: reticleSpin 60s linear infinite reverse;
}

@keyframes reticleSpin {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.reticle .tick {
    position: absolute;
    background: rgba(110, 231, 183, 0.6);
}

.reticle .tick-top, .reticle .tick-bottom {
    width: 2px;
    height: 14px;
    left: 50%;
    margin-left: -1px;
}
.reticle .tick-left, .reticle .tick-right {
    height: 2px;
    width: 14px;
    top: 50%;
    margin-top: -1px;
}
.reticle .tick-top { top: -7px; }
.reticle .tick-bottom { bottom: -7px; }
.reticle .tick-left { left: -7px; }
.reticle .tick-right { right: -7px; }

/* ЧАТ ОБВИВКА С ТЕХНОЛОГИЧНИ ЪГЛИ */
.chat-wrapper {
    position: absolute;
    left: 40px;
    bottom: 40px;
    width: 400px;
    height: calc(100vh - 180px);
    background: rgba(10, 12, 16, 0.6);
    border: 1px solid rgba(34, 197, 94, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 25px 10px 10px 10px;
}

.panel-label {
    position: absolute;
    top: -9px;
    left: 15px;
    background: #05070a;
    padding: 0 8px;
    font-size: 11px;
    color: #22c55e;
    letter-spacing: 2px;
}

/* Ъгълчета за HUD ефект */
.hud-corner {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 2px solid #22c55e;
}
.top-left { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.top-right { top: -1px; right: -1px; border-left: none; border-bottom: none; }
.bottom-left { bottom: -1px; left: -1px; border-right: none; border-top: none; }
.bottom-right { bottom: -1px; right: -1px; border-left: none; border-top: none; }

/* ЧАТ СЪОБЩЕНИЯ */
#chatMessages {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding-right: 5px;
}

#chatMessages::-webkit-scrollbar { width: 3px; }
#chatMessages::-webkit-scrollbar-thumb { background: rgba(34, 197, 94, 0.4); border-radius: 4px; }

.message {
    padding: 12px 16px;
    border-radius: 4px; /* Остри правоъгълни съобщения за сериозен терминален вид */
    max-width: 90%;
    line-height: 1.5;
    font-size: 14px;
    animation: slideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.user {
    align-self: flex-start;
    background: rgba(34, 197, 94, 0.04);
    border-left: 3px solid #22c55e;
    color: #6ee7b7;
}

.dodo {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.02);
    border-left: 3px solid rgba(255, 255, 255, 0.3);
    color: #e2e8f0;
}

/* КОНТРОЛИ (ИНПУТ И БУТОНИ) */
.controls {
    position: absolute;
    right: 40px;
    bottom: 40px;
    display: flex;
    gap: 12px;
    align-items: center;
    z-index: 10;
}

.controls input {
    width: 350px;
    height: 54px;
    padding: 0 20px;
    border-radius: 4px;
    background: rgba(10, 12, 16, 0.8);
    border: 1px solid rgba(34, 197, 94, 0.2);
    outline: none;
    color: #6ee7b7;
    font-family: 'Share Tech Mono', monospace;
    font-size: 15px;
    letter-spacing: 1px;
    backdrop-filter: blur(10px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.controls input:focus {
    border-color: #22c55e;
    width: 450px;
    box-shadow: 0 0 30px rgba(34, 197, 94, 0.15);
    background: rgba(34, 197, 94, 0.02);
}

#handBtn, #micBtn, #sendBtn {
    width: 54px;
    height: 54px;
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-radius: 4px;
    cursor: pointer;
    background: rgba(10, 12, 16, 0.8);
    color: #22c55e;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.3s;
}

#handBtn:hover, #micBtn:hover, #sendBtn:hover {
    background: rgba(34, 197, 94, 0.12);
    border-color: #22c55e;
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.4);
    color: #6ee7b7;
}

#sendBtn {
    font-size: 20px;
}

/* ЗАКЛЮЧЕНО СЪСТОЯНИЕ ПО ВРЕМЕ НА ОБРАБОТКА */
.controls input:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: rgba(10, 12, 16, 0.5);
}

#sendBtn:disabled {
    background: rgba(10, 12, 16, 0.5) !important;
    box-shadow: none !important;
}

/* МИКРОФОН - АКТИВНО СЛУШАНЕ */
#micBtn.listening {
    background: rgba(34, 197, 94, 0.25);
    border-color: #22c55e;
    color: #6ee7b7;
    animation: micListening 1s infinite;
}

#handBtn.active {
    background: rgba(110, 231, 183, 0.2);
    border-color: #6ee7b7;
    color: #d6ffe9;
    box-shadow: 0 0 22px rgba(110, 231, 183, 0.45);
}

.hand-control-panel {
    position: absolute;
    top: 96px;
    right: 40px;
    width: 190px;
    height: 142px;
    display: none;
    overflow: hidden;
    border: 1px solid rgba(110, 231, 183, 0.22);
    background: rgba(5, 7, 10, 0.62);
    box-shadow: inset 0 0 24px rgba(34, 197, 94, 0.08), 0 0 18px rgba(34, 197, 94, 0.12);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 12;
}

body.hand-control-active .hand-control-panel {
    display: block;
}

#handVideo,
#handCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

#handVideo {
    opacity: 0.42;
}

#handCanvas {
    opacity: 0.9;
}

.hand-readout {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 7px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(5, 7, 10, 0.68);
    border: 1px solid rgba(110, 231, 183, 0.18);
    color: #6ee7b7;
    font-size: 10px;
    letter-spacing: 2px;
}

#handCursor {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 28px;
    height: 28px;
    display: none;
    border: 2px solid rgba(214, 255, 233, 0.9);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 16px rgba(110, 231, 183, 0.75), inset 0 0 12px rgba(110, 231, 183, 0.28);
}

body.hand-control-active #handCursor {
    display: block;
}

#handCursor.grabbing {
    width: 34px;
    height: 34px;
    border-radius: 4px;
    border-color: #22c55e;
    box-shadow: 0 0 22px rgba(34, 197, 94, 0.9), inset 0 0 14px rgba(34, 197, 94, 0.35);
}

#handCursor.scrolling {
    border-color: #93c5fd;
    box-shadow: 0 0 22px rgba(147, 197, 253, 0.85), inset 0 0 14px rgba(147, 197, 253, 0.25);
}

@keyframes micListening {
    0% { box-shadow: 0 0 8px rgba(34, 197, 94, 0.4); transform: scale(1); }
    50% { box-shadow: 0 0 22px rgba(34, 197, 94, 0.9); transform: scale(1.06); }
    100% { box-shadow: 0 0 8px rgba(34, 197, 94, 0.4); transform: scale(1); }
}

/* TYPING / LOADING ИНДИКАТОР В ЧАТА */
.message.typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}

.message.typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6ee7b7;
    display: inline-block;
    animation: typingBounce 1.2s infinite ease-in-out;
}

.message.typing .dot1 { animation-delay: 0s; }
.message.typing .dot2 { animation-delay: 0.2s; }
.message.typing .dot3 { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* СТАТУС ДОЛУ ВДЯСНО */
#status {
    position: absolute;
    right: 45px;
    bottom: 105px;
    font-size: 11px;
    letter-spacing: 3px;
    color: #22c55e;
    opacity: 0.7;
    z-index: 10;
}

/* ==================== ТЕЛЕФОН И МАЛЪК ЕКРАН ====================
   Оригиналното оформление е с абсолютно позиционирани панели по фиксирани
   отстояния — на широк монитор е добре, на телефон всичко се качва едно
   върху друго. Тук същите елементи се подреждат вертикално един под друг. */
@media (max-width: 820px) {

    body {
        overflow-y: auto;
        -webkit-text-size-adjust: 100%;
    }

    .ui {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;               /* без това адресната лента на iOS реже дъното */
        padding: 0 12px calc(16px + env(safe-area-inset-bottom));
        gap: 14px;
    }

    /* Горните индикатори стават един ред, за да не се застъпват с логото. */
    .hud-panel {
        padding: 6px 10px;
        font-size: 10px;
        letter-spacing: 1px;
    }

    .system {
        top: calc(8px + env(safe-area-inset-top));
        left: 12px;
    }

    .digital-clock {
        top: calc(8px + env(safe-area-inset-top));
        left: auto;
        right: 12px;
        width: auto;
        font-size: 12px;
        letter-spacing: 1px;
    }

    .hud-stats {
        display: none;                    /* няма къде да се побере и не носи нищо */
    }

    .logo {
        margin-top: calc(52px + env(safe-area-inset-top));
        font-size: 38px;
        letter-spacing: 12px;
        padding-left: 12px;
    }

    .hello {
        font-size: 10px;
        letter-spacing: 3px;
        text-align: center;
    }

    .core-wrapper {
        width: min(78vw, 300px);
        height: min(78vw, 300px);
        margin-top: 0;
        flex-shrink: 0;
    }

    /* Чатът и полето за писане влизат в нормалния поток, под ядрото. */
    .chat-wrapper {
        position: static;
        width: 100%;
        height: auto;
        min-height: 180px;
        flex: 1 1 auto;
        padding: 22px 8px 8px 8px;
    }

    .controls {
        position: static;
        width: 100%;
        gap: 8px;
        flex-shrink: 0;
    }

    /* Полето заема останалото място; 16px шрифт спира автоматичното
       увеличаване на iOS при фокус. */
    .controls input,
    .controls input:focus {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        height: 48px;
        padding: 0 14px;
        font-size: 16px;
    }

    #handBtn, #micBtn, #sendBtn {
        width: 48px;
        height: 48px;
        flex-shrink: 0;
    }

    /* Ръчното управление иска камера и мишка — на телефон само пречи. */
    #handBtn,
    .hand-control-panel,
    #handCursor {
        display: none;
    }

    #status {
        position: static;
        align-self: flex-end;
        font-size: 10px;
        letter-spacing: 2px;
    }

    .scanlines {
        opacity: 0.35;                    /* по-четимо на малък екран */
    }
}
