/**
 * Гадание на 3D Кубиках - Стили
 * Адаптировано под тему Gadanie.online
 */

/* =========================
   Контейнер плагина
========================= */
.dice-divination-container {
    width: 100%;
    max-width: var(--container, 1310px);
    margin: 0 auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: 'EB Garamond', 'Georgia', serif;
}

/* =========================
   Переключатель типа ответа (слайдер)
========================= */
.dice-answer-toggle {
    position: relative;
    display: inline-flex;
    background: var(--c-border, #e5e7eb);
    border-radius: 24px;
    padding: 4px;
    margin: 0 auto 1.5rem;
    justify-content: center;
    max-width: 100%;
}

.toggle-btn {
    font-family: var(--font-heading, "Inter", system-ui, sans-serif);
    font-size: 0.875rem;
    font-weight: var(--fw-medium, 500);
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    color: #6b7280;
    border-radius: 20px;
    cursor: pointer;
    transition: color 0.3s var(--ease-md, cubic-bezier(0.4, 0.0, 0.2, 1));
    position: relative;
    z-index: 2;
}

.toggle-btn.active {
    color: var(--c-button-text, #ffffff);
}

.toggle-btn:active {
    transform: scale(0.96);
    opacity: 0.85;
}

.toggle-btn:focus-visible {
    outline: 2px solid var(--c-primary, #b4975d);
    outline-offset: var(--focus-ring-offset, 2px);
}

/* Убираем стандартную подсветку iOS/Android */
.toggle-btn {
    -webkit-tap-highlight-color: transparent;
}

/* Анимированный фон слайдера */
.dice-answer-toggle::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: var(--c-primary, #b4975d);
    border-radius: 20px;
    transition: transform 0.3s var(--ease-md, cubic-bezier(0.4, 0.0, 0.2, 1));
    z-index: 1;
}

.dice-answer-toggle.full-active::before {
    transform: translateX(100%);
}

/* =========================
   Canvas контейнер для 3D
========================= */
.dice-canvas-container {
    width: 100%;
    height: 50vh;
    height: 50dvh; /* Dynamic viewport height для iOS */
    position: relative;
    margin-bottom: 1.5rem;
    border-radius: var(--radius, 12px);
    overflow: hidden;
    background: var(--c-bg, #edebe5);
    box-shadow: var(--shadow, 0 6px 18px rgba(0,0,0,.06));
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.dice-canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* WebGL Fallback */
.webgl-fallback {
    padding: 2rem;
    text-align: center;
    background: var(--surface-panel, #ffffff);
    border-radius: var(--radius, 12px);
    box-shadow: var(--shadow, 0 6px 18px rgba(0,0,0,.06));
    max-width: 500px;
    margin: 0 1rem;
}

.webgl-fallback-title {
    color: var(--c-text, #343444);
    font-size: 1.125rem;
    font-weight: var(--fw-semibold, 600);
    margin-bottom: 1rem;
    font-family: var(--font-heading, "Inter", system-ui, sans-serif);
}

.webgl-fallback-text {
    font-size: 0.9375rem;
    color: #6b7280;
    line-height: 1.6;
    font-family: var(--font-heading, "Inter", system-ui, sans-serif);
}

/* =========================
   Элементы управления
========================= */
.dice-controls {
    width: 100%;
    text-align: center;
    margin-bottom: 0;
    margin-top: 1rem;
}

.dice-roll-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 235px;
    height: 65px;
    margin: 10px auto 0;
    background-color: #f1e7d4;
    background-image: url('/wp-content/themes/gadanie-online/assets/images/knopka.webp');
    background-size: cover;
    background-position: center;
    color: #4a3828;
    font-size: 17px;
    font-weight: 400;
    font-family: 'EB Garamond', 'Georgia', serif;
    border: none;
    border-radius: 0;
    padding: 0 0 4px 0;
    outline: none;
    cursor: pointer;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: transform 0.2s ease, opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.dice-roll-button.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.dice-roll-button:hover {
    transform: translateY(-2px);
}

.dice-roll-button:active,
.dice-roll-button.dice-roll-button--active {
    background-image: url('/wp-content/themes/gadanie-online/assets/images/knopka-1.webp');
    transform: translateY(2px);
}

.dice-roll-button:focus-visible {
    outline: none;
}

/* =========================
   Результат
========================= */
.dice-result {
    font-family: 'EB Garamond', 'Georgia', serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--c-text, #343444);
    text-align: center;
    background: var(--surface-panel, #ffffff);
    padding: 1.25rem 2rem;
    border-radius: var(--radius, 12px);
    margin: 0 auto;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow, 0 6px 18px rgba(0,0,0,.06));
    opacity: 0;
    transform: translateY(10px);
    max-height: 0;
    overflow: hidden;
    box-sizing: border-box;
    transition: opacity 0.5s ease,
                transform 0.5s ease,
                max-height 0.5s ease,
                margin 0.5s ease;
}

.dice-result.show {
    opacity: 1;
    transform: translateY(0);
    max-height: 300px;
    margin: 1.5rem auto 0;
}

/* =========================
   Адаптивность для мобильных
========================= */
@media (max-width: 768px) {
    .dice-answer-toggle {
        margin-bottom: 1rem;
    }

    .toggle-btn {
        font-size: 0.8125rem;
        padding: 0.75rem 1rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .dice-canvas-container {
        height: 45vh;
        margin-bottom: 1rem;
        /* Fullscreen на мобильных - края экрана = стенки для кубиков */
        width: 100%;
        max-width: 100vw;
        margin-left: 0;
        margin-right: 0;
        border-radius: 0;
        box-shadow: none;
    }


    .dice-result.show {
        font-size: 1rem;
        padding: 1rem 1.25rem;
        margin-top: 1rem;
    }
}

@media (max-width: 480px) {
    .dice-canvas-container {
        height: 40vh;
        /* Fullscreen уже установлен в @media (max-width: 768px) */
    }

    .dice-result.show {
        padding: 0.875rem 1rem;
    }
}

/* =========================
   Очень узкие экраны (320px)
========================= */
@media (max-width: 360px) {
    .toggle-btn {
        padding: 0.75rem 0.75rem;
        font-size: 0.75rem;
    }

    .dice-result.show {
        padding: 0.875rem 0.75rem;
    }
}

/* =========================
   Ландшафтная ориентация на мобильных
========================= */
@media (max-width: 768px) and (orientation: landscape) {
    .dice-canvas-container {
        height: 60vh;
        max-height: 400px;
        /* Fullscreen уже установлен в @media (max-width: 768px) */
    }
}

/* =========================
   Поддержка prefers-reduced-motion
========================= */
@media (prefers-reduced-motion: reduce) {
    .dice-result {
        transition: opacity var(--tr-base, .25s);
        transform: none !important;
    }

    .dice-roll-button {
        transition: opacity var(--tr-base, .25s), background var(--tr-fast, .2s);
        transform: none !important;
    }
}

/* =========================
   Темная тема
========================= */
[data-theme="dark"] .dice-result {
    color: #FFFFFF;
    background: rgba(33, 33, 44, 0.95);
}

[data-theme="dark"] .dice-canvas-container {
    background: rgb(26, 32, 44);
    border: 1px solid #787070;
    box-shadow: 0 6px 18px rgba(0,0,0,.2);
}

[data-theme="dark"] .dice-answer-toggle {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .toggle-btn {
    color: rgba(255, 255, 255, 0.6);
}

[data-theme="dark"] .toggle-btn.active {
    color: #FFFFFF;
}

[data-theme="dark"] .webgl-fallback {
    background: rgba(33, 33, 44, 0.95);
}

[data-theme="dark"] .webgl-fallback-title {
    color: #FFFFFF;
}

[data-theme="dark"] .webgl-fallback-text {
    color: rgba(255, 255, 255, 0.7);
}
