/* ===========================================================================
   RedoSchool — экранное управление (touch.js). Слой лежит над canvas и под загрузчиком/входом.
   Вёрстка рассчитана на горизонтальный экран телефона; вертикальный закрывает просьба повернуть.
   Копия файла лежит в обоих шаблонах и обязана совпадать байт в байт.
   =========================================================================== */

.rs-tc {
    /* Всё полупрозрачное: слой лежит над игрой и не должен её закрывать. Палец поднимает яркость. */
    --rs-tc-ink: rgba(12, 18, 51, 0.34);
    --rs-tc-ink-strong: rgba(12, 18, 51, 0.46);
    --rs-tc-line: rgba(234, 241, 255, 0.4);
    --rs-tc-rest: 0.7;
    --rs-tc-accent: var(--rs-orange, #ff7a1a);
    --rs-tc-accent-hi: var(--rs-orange-hi, #ffb04a);
    --rs-tc-edge: 14px;

    position: fixed;
    inset: 0;
    z-index: 10;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    pointer-events: none;
    font-family: var(--rs-font-text, system-ui, sans-serif);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
}

.rs-tc[hidden] {
    display: none;
}

/* Поверхность ловит всё, что не кнопка: джойстик, взгляд или указатель мыши. */
.rs-tc-surface {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    touch-action: none;
}

/* ------------------------------------------------------------------ джойстик */
.rs-tc-stick {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease-out;
}

.rs-tc-stick.is-on {
    opacity: 1;
}

.rs-tc-stick-base {
    position: absolute;
    left: -58px;
    top: -58px;
    width: 116px;
    height: 116px;
    border-radius: 50%;
    background: var(--rs-tc-ink);
    border: 2px solid var(--rs-tc-line);
}

.rs-tc-stick-knob {
    position: absolute;
    left: -26px;
    top: -26px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, var(--rs-tc-accent-hi), var(--rs-tc-accent));
    border: 2px solid rgba(255, 255, 255, 0.6);
    opacity: 0.8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------------- кнопки */
.rs-tc-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 2px solid var(--rs-tc-line);
    background: var(--rs-tc-ink);
    color: var(--rs-fg, #eaf1ff);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    opacity: var(--rs-tc-rest);
    pointer-events: auto;
    touch-action: none;
    cursor: pointer;
    transition: transform 0.08s ease-out, opacity 0.12s ease-out, background-color 0.12s ease-out,
        border-color 0.12s ease-out;
}

.rs-tc-btn:focus {
    outline: none;
}

.rs-tc-btn.is-down {
    transform: scale(0.92);
    opacity: 1;
    background: var(--rs-tc-accent);
    border-color: var(--rs-tc-accent-hi);
}

.rs-tc-btn.is-on {
    opacity: 0.95;
    background: var(--rs-tc-accent);
    border-color: var(--rs-tc-accent-hi);
}

.rs-tc-ico {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
}

.rs-tc-ico svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.rs-tc-top {
    position: absolute;
    left: var(--rs-tc-edge);
    right: var(--rs-tc-edge);
    top: 10px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.rs-tc-group {
    display: flex;
    gap: 8px;
    pointer-events: none;
}

/* Только значки: все кнопки — круги, подписей нет. */
.rs-tc-small {
    width: 44px;
    height: 44px;
    border-radius: 50%;
}

.rs-tc-small .rs-tc-ico svg {
    width: 22px;
    height: 22px;
}

.rs-tc-round {
    position: absolute;
    border-radius: 50%;
}

/* Кластер действий целиком в 160 × 150 у правого нижнего угла: ни одна кнопка не выходит за его границу. */
.rs-tc-actions {
    position: absolute;
    right: var(--rs-tc-edge);
    bottom: 12px;
    width: 160px;
    height: 150px;
    pointer-events: none;
}

.rs-tc-action {
    right: 0;
    bottom: 0;
    width: 84px;
    height: 84px;
    background: var(--rs-tc-ink-strong);
    border-color: var(--rs-tc-accent-hi);
}

.rs-tc-action .rs-tc-ico svg {
    width: 34px;
    height: 34px;
}

.rs-tc-jump {
    right: 94px;
    bottom: 6px;
    width: 62px;
    height: 62px;
}

.rs-tc-jump .rs-tc-ico svg {
    width: 26px;
    height: 26px;
}

.rs-tc-run {
    right: 72px;
    bottom: 84px;
    width: 52px;
    height: 52px;
}

.rs-tc-interact {
    right: 6px;
    bottom: 94px;
    width: 56px;
    height: 56px;
}

.rs-tc-interact .rs-tc-ico {
    font-size: 26px;
}

/* Не в игре, а в панели (чат брифинга, редактор кода, карта курса): слой почти исчезает. Остаются «Меню»
   (выйти), «Экран» и — только пока мир просит — «Использ.» (E, тир). Все кнопки ещё бледнее, чем в игре, и
   жмутся к краям: середина экрана и экранная клавиатура свободны. Прокрутка — двумя пальцами, без кнопок. */
.rs-tc.is-pointer {
    --rs-tc-rest: 0.4;
}

.rs-tc.is-pointer .rs-tc-play-only {
    display: none;
}

/* «Использ.» — только когда мир её просит. */
.rs-tc:not(.has-interact) .rs-tc-interact {
    display: none;
}

.rs-tc.is-pointer .rs-tc-interact {
    bottom: 6px;
}

.rs-tc-btn[hidden] {
    display: none;
}

/* ------------------------------------------------------------- ввод текста */
/* Настоящее поле браузера над экранной клавиатурой: Unity (UI Toolkit) само клавиатуру не открывает.
   Положение по высоте выставляет touch.js по видимой области; кнопки жмутся к полю, а не к краям. */
.rs-tc-text {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--rs-tc-line);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    background: rgba(12, 18, 51, 0.94);
    pointer-events: auto;
    touch-action: manipulation;
}

.rs-tc-text[hidden] {
    display: none;
}

.rs-tc-text-field {
    flex: 1 1 auto;
    min-width: 0;
}

.rs-tc-text-input {
    display: block;
    width: 100%;
    max-height: 96px;
    margin: 0;
    padding: 10px 12px;
    box-sizing: border-box;
    border: 1px solid var(--rs-tc-line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--rs-fg, #eaf1ff);
    font: inherit;
    font-size: 16px; /* меньше 16px iOS увеличивает страницу при фокусе */
    line-height: 1.3;
    resize: none;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}

.rs-tc-text-input:focus {
    border-color: var(--rs-tc-accent-hi);
}

.rs-tc-text .rs-tc-btn {
    flex: 0 0 auto;
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Пока набирается текст, кнопки действий не нужны и не должны лежать над панелью. */
.rs-tc.has-text .rs-tc-actions {
    visibility: hidden;
}

/* ------------------------------------------------------------ «поверните экран» */
.rs-tc-rotate {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px;
    background: rgba(12, 18, 51, 0.97);
    color: var(--rs-fg, #eaf1ff);
    text-align: center;
    pointer-events: auto;
    touch-action: none;
}

.rs-tc-rotate-text {
    margin: 0;
    max-width: 18em;
    font-family: var(--rs-font-display, system-ui, sans-serif);
    font-size: 22px;
    line-height: 1.25;
}

.rs-tc-rotate-phone {
    width: 44px;
    height: 76px;
    border: 3px solid var(--rs-tc-accent-hi);
    border-radius: 10px;
    animation: rs-tc-turn 2.2s ease-in-out infinite;
}

@keyframes rs-tc-turn {
    0%, 25% { transform: rotate(0deg); }
    65%, 100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) {
    .rs-tc-rotate {
        display: flex;
    }

    .rs-tc-top,
    .rs-tc-actions,
    .rs-tc-text {
        visibility: hidden;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rs-tc-rotate-phone {
        animation: none;
        transform: rotate(-90deg);
    }

    .rs-tc-btn,
    .rs-tc-stick {
        transition: none;
    }
}

/* Совсем низкий экран (телефон в горизонтали с панелями браузера): кластер уменьшается к углу. */
@media (max-height: 340px) {
    .rs-tc-actions {
        transform: scale(0.84);
        transform-origin: right bottom;
    }

    .rs-tc-small {
        width: 40px;
        height: 40px;
    }
}
