/* ==========================================================================
   editor-highlight-overlay.css

   Стили для overlay-подсветки синтаксиса в textarea редактора Intel 8085.

   Работает совместно с:
     - editor-highlighter.js (динамическая подсветка)
     - intel-8085-instruction-code-style.css (цвета классов подсветки)
     - editor-modal.css (базовые стили редактора)

   🎯 ВАЖНО: этот файл НЕ задаёт цвета классов (.instruction, .register и т.д.).
      Цвета приходят из intel-8085-instruction-code-style.css.

   Принцип работы:
     - textarea делается прозрачной (color: transparent)
     - под ней размещается <pre><code> с подсвеченным HTML
     - padding, font, line-height копируются из textarea в <pre> через JS,
       поэтому здесь их задавать НЕЛЬЗЯ — иначе каретка съедет.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Обёртка: содержит textarea и слой подсветки
   -------------------------------------------------------------------------- */

.editor-highlight-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

/* --------------------------------------------------------------------------
   Textarea внутри wrapper'а — растягивается на весь wrapper
   -------------------------------------------------------------------------- */

.editor-highlight-wrapper .editor-textarea {
    position: relative;
    z-index: 1;
    flex: 1;
    width: 100%;
    height: 100%;
    background: transparent !important;
    color: transparent !important;
    caret-color: transparent !important;   /* 🎯 скрываем нативную каретку */
    resize: none;
    border: none;
    outline: none;
    box-sizing: border-box;
}

body.light-theme .editor-highlight-wrapper .editor-textarea {
    caret-color: transparent !important;
}

/* Выделение текста — полупрозрачное, чтобы подсветка была видна */
.editor-highlight-wrapper .editor-textarea::selection {
    background-color: rgba(183, 255, 105, 0.25);
    color: transparent;
}

body.light-theme .editor-highlight-wrapper .editor-textarea::selection {
    background-color: rgba(72, 0, 150, 0.2);
    color: transparent;
}

/* Placeholder — прозрачный, чтобы не перекрывать подсветку */
.editor-highlight-wrapper .editor-textarea::placeholder {
    color: transparent;
}

/* --------------------------------------------------------------------------
   Слой подсветки (pre > code) — лежит под textarea

   🎯 НЕ задаём здесь font-size, line-height, padding, font-family —
      они приходят из JS (точная копия значений textarea).
      Иначе каретка съедет относительно текста.
   -------------------------------------------------------------------------- */

.editor-highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: auto;
    pointer-events: none;
    z-index: 0;
    background-color: transparent;
    border: none;
    box-sizing: border-box;
    color: inherit;

    /* Скрываем скроллбар — прокрутка управляется через textarea */
    scrollbar-width: none;
    -ms-overflow-style: none;

    /* Базовые настройки для <pre> — переопределяются JS */
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
}

.editor-highlight-layer::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* --------------------------------------------------------------------------
   Внутренний <code> — block, без собственных отступов и размеров
   -------------------------------------------------------------------------- */

.editor-highlight-content {
    display: block;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;

    /* Всё наследуется от pre — не переопределяем */
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    font-style: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;

    min-height: 100%;
}

/* --------------------------------------------------------------------------
   Адаптивность

   🎯 НЕ меняем font-size/padding у .editor-highlight-layer —
      эти значения копируются из textarea через JS.
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
    /* Пусто — всё синхронизировано через JS */
}

@media (max-width: 480px) {
    /* Пусто */
}

/* ==================== 🎯 КАРЕТКА-БЛОК ==================== */

/* Слой, содержащий блок-каретку. Лежит поверх textarea и подсветки,
   но НЕ перехватывает события мыши. */
.editor-block-caret-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 4;   /* выше подсветки (z=0), label-lines (z=2) и textarea (z=1) */
    overflow: hidden;
}

/* Сама каретка-блок */
.editor-block-caret {
    position: absolute;
    width: 1ch;                   /* ширина одного символа в ch */
    background-color: #B7FF69;    /* цвет каретки (тёмная тема) */
    border-radius: 2px;
    opacity: 0.85;
    /*transition: background-color 0.5s ease, left 0.05s ease, top 0.05s ease;*/
    pointer-events: none;
    will-change: left, top;
}

/* Невидимая каретка — когда textarea не в фокусе или не вставлена */
.editor-block-caret.hidden {
    display: none;
}

/* Пульсация (мигание) */
.editor-block-caret.blink {
    animation: block-caret-blink 1.06s step-end infinite;
}

@keyframes block-caret-blink {
    0%, 50%   { opacity: 0.85; }
    51%, 100% { opacity: 0; }
}

/* Светлая тема */
body.light-theme .editor-block-caret {
    background-color: #480096;
}

/* В режиме VIM NORMAL — каретка блока шире (визуально как в Vim) */
.editor-textarea.vim-normal-mode ~ .editor-block-caret-layer .editor-block-caret,
.editor-textarea.vim-visual-mode ~ .editor-block-caret-layer .editor-block-caret {
    width: 1ch;
    opacity: 1;
}

