/* ============================================================================
 * WRAITH CAPTCHA WIDGET — Phase 4: Mobile-Adaptive
 * Drag-версия: адаптируется под desktop/mobile через CSS-переменные
 * ============================================================================ */

.wc-captcha {
    /* CSS-переменные — JS их переопределяет под профиль */
    --wc-canvas-width:  400px;
    --wc-canvas-height: 200px;
    --wc-piece-size:    50px;

    display: inline-block;
    user-select: none;
    -webkit-user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    line-height: 1.4;
    max-width: 100%;
    box-sizing: border-box;
}

.wc-captcha *,
.wc-captcha *::before,
.wc-captcha *::after {
    box-sizing: border-box;
}

/* ---------- ОБЁРТКА КАРТИНОК ---------- */
.wc-captcha__canvas {
    position: relative;
    width: var(--wc-canvas-width);
    max-width: 100%;
    /* ВАЖНО: border вынесен на wrapper, чтобы не смещать piece */
    border: 1px solid #d0d7de;
    border-radius: 6px;
    overflow: hidden;
    background: #f6f8fa;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    /* Минимальная высота чтобы loader красиво отображался */
    min-height: 80px;
}

.wc-captcha__canvas.is-loading::before {
    content: "";
    position: absolute;
    inset: 0;
    background: #f6f8fa url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'><circle cx='12' cy='12' r='10' stroke='%23999' stroke-width='2' fill='none' stroke-dasharray='40' stroke-dashoffset='20'><animateTransform attributeName='transform' type='rotate' from='0 12 12' to='360 12 12' dur='1s' repeatCount='indefinite'/></circle></svg>") center/24px no-repeat;
    z-index: 5;
}

.wc-captcha__bg {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    -webkit-user-drag: none;
    /* ВАЖНО: убираем любые отступы у картинки */
    margin: 0;
    padding: 0;
    vertical-align: top;  /* убирает baseline gap */
}

/* ---------- КУСОЧЕК ПАЗЛА ---------- */
.wc-captcha__piece {
    position: absolute;
    top: 0;
    left: 0;
    /* Размер через CSS-переменную — адаптируется под профиль */
    width: var(--wc-piece-size);
    height: var(--wc-piece-size);
    cursor: grab;
    touch-action: none;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
    transition: filter 0.15s ease;
    -webkit-user-drag: none;
    z-index: 3;
    /* ВАЖНО: убираем отступы */
    margin: 0;
    padding: 0;
    display: block;
}

/* Увеличенный hit-area на touch-устройствах для удобства пальца */
@media (hover: none) and (pointer: coarse) {
    .wc-captcha__piece::after {
        content: "";
        position: absolute;
        /* +8px со всех сторон = пальцу легче попасть */
        inset: -8px;
        /* Невидимая зона, но захватывает тачи */
    }
}

.wc-captcha__piece:active,
.wc-captcha__piece.is-dragging {
    cursor: grabbing;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

/* ---------- СТАТУС (успех/ошибка) ---------- */
.wc-captcha__canvas.is-success {
    border-color: #28a745;
    box-shadow: 0 0 0 3px rgba(40, 167, 69, 0.15);
}

.wc-captcha__canvas.is-error {
    border-color: #dc3545;
    animation: wc-shake 0.4s;
}

@keyframes wc-shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-6px); }
    75%      { transform: translateX(6px); }
}

/* ---------- ПАНЕЛЬ УПРАВЛЕНИЯ ---------- */
.wc-captcha__panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    padding: 6px 10px;
    background: #f6f8fa;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    min-height: 32px;
}

.wc-captcha__hint {
    color: #57606a;
    flex: 1;
    font-size: 13px;
}

.wc-captcha__hint.is-success { color: #1a7f37; font-weight: 500; }
.wc-captcha__hint.is-error   { color: #cf222e; font-weight: 500; }

.wc-captcha__refresh {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    color: #57606a;
    font-size: 16px;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
    /* Увеличенная touch-зона для кнопки обновления */
    min-width: 32px;
    min-height: 32px;
}

.wc-captcha__refresh:hover {
    background: #eaeef2;
    color: #24292f;
}

.wc-captcha__refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------- СКРЫТЫЙ TOKEN ---------- */
.wc-captcha__token {
    display: none;
}

/* ============================================================================
 * АДАПТИВ ДЛЯ МОБИЛЬНЫХ
 * JS добавляет класс .wc-captcha--mobile при детекте touch-устройства
 * ============================================================================ */

.wc-captcha--mobile {
    /* Мобильный профиль: меньше canvas и piece */
    --wc-canvas-width:  320px;
    --wc-canvas-height: 180px;
    --wc-piece-size:    42px;

    /* На мобильном — растягиваем на всю доступную ширину */
    display: block;
    width: 100%;
}

.wc-captcha--mobile .wc-captcha__canvas {
    width: 100%;
}

.wc-captcha--mobile .wc-captcha__hint {
    font-size: 12px;
}

/* Дополнительный fallback для совсем узких экранов */
@media (max-width: 360px) {
    .wc-captcha {
        --wc-piece-size: 38px;
    }
}