/**
 * Bento Grid Design System
 * Экспертное сообщество ЕВМ
 *
 * Включает:
 * - Bento Grid layout utilities
 * - Reveal-анимации (IntersectionObserver)
 * - Micro-interactions (hover, focus, active)
 * - Smooth scroll behavior
 * - Glassmorphism эффекты
 */

/* ========================================
   1. ГЛОБАЛЬНЫЕ НАСТРОЙКИ
   ======================================== */

html {
    scroll-behavior: smooth;
}

:root {
    --bg-page: #f7f8f9;
    --bg-card: #ffffff;
    --bg-card-alt: #d5dde7;
    --accent-purple: #831f88;
    --accent-blue: #3272a9;
    --accent-magenta: #782683;
    --text-primary: #1c2542;
    --text-secondary: #868fb0;
    --border-color: rgba(134, 143, 176, 0.3);
    --shadow-color: rgba(28, 37, 66, 0.08);
}

.dark {
    --bg-page: #0a0e1a;
    --bg-card: #151b2e;
    --bg-card-alt: #1e2a45;
    --accent-purple: #9d4edd;
    --accent-blue: #4a90d9;
    --accent-magenta: #b85cb3;
    --text-primary: #ffffff;
    --text-secondary: #a8bdd9;
    --border-color: rgba(168, 189, 217, 0.12);
    --shadow-color: rgba(0, 0, 0, 0.4);
}

html.lenis,
html.lenis body {
    height: auto;
}

.lenis.lenis-smooth {
    scroll-behavior: auto !important;
}

.lenis.lenis-smooth [data-lenis-prevent] {
    overscroll-behavior: contain;
}

.lenis.lenis-stopped {
    overflow: hidden;
}

.lenis.lenis-scrolling iframe {
    pointer-events: none;
}

/* ========================================
   2. BENTO GRID
   ======================================== */

.bento-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(1, 1fr);
}

@media (min-width: 640px) {
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }
}

@media (min-width: 1024px) {
    .bento-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.5rem;
    }
}

@media (min-width: 1280px) {
    .bento-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Bento item sizes */
.bento-item {
    position: relative;
    border-radius: 1.25rem;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.bento-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px -12px var(--shadow-color);
}

.dark .bento-item:hover {
    box-shadow: 0 12px 40px -12px var(--shadow-color);
}

.bento-item-sm {
    grid-column: span 1;
    grid-row: span 1;
}

.bento-item-md {
    grid-column: span 1;
    grid-row: span 1;
}

@media (min-width: 1024px) {
    .bento-item-md {
        grid-column: span 2;
    }
}

.bento-item-lg {
    grid-column: span 1;
    grid-row: span 1;
}

@media (min-width: 1024px) {
    .bento-item-lg {
        grid-column: span 2;
        grid-row: span 2;
    }
}

.bento-item-xl {
    grid-column: span 1;
    grid-row: span 1;
}

@media (min-width: 1024px) {
    .bento-item-xl {
        grid-column: span 3;
    }
}

@media (min-width: 1280px) {
    .bento-item-xl {
        grid-column: span 4;
    }
}

/* ========================================
   3. BENTO CARD
   ======================================== */

.bento-card {
    position: relative;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 1.25rem;
    padding: 1.5rem;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.dark .bento-card {
    background: linear-gradient(160deg, #151b2e 0%, #1a2240 50%, #151b2e 100%);
    border-color: var(--border-color);
}

.dark .card-title {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.bento-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 1.25rem;
    padding: 1px;
    background: linear-gradient(135deg, rgba(255,255,255,0.4), rgba(255,255,255,0));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.dark .bento-card::before {
    background: linear-gradient(135deg, rgba(168, 189, 217, 0.12), rgba(168, 189, 217, 0));
}

.bento-card:hover::before {
    opacity: 1;
}

.bento-card:hover {
    transform: translateY(-4px) scale(1.005);
    box-shadow: 0 20px 50px -15px var(--shadow-color);
    border-color: var(--border-color);
}

.dark .bento-card:hover {
    box-shadow: 0 20px 50px -15px var(--shadow-color);
    border-color: rgba(168, 189, 217, 0.25);
}

.bento-card-glow {
    position: relative;
    overflow: hidden;
}

.bento-card-glow::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, rgba(10, 207, 254, 0.08), transparent 60%);
    opacity: 0;
    transition: opacity 0.6s ease;
    pointer-events: none;
}

.bento-card-glow:hover::after {
    opacity: 1;
}

/* ========================================
   4. REVEAL-АНИМАЦИИ
   ======================================== */

.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

.reveal-delay-1 { transition-delay: 0.1s; }
.reveal-delay-2 { transition-delay: 0.2s; }
.reveal-delay-3 { transition-delay: 0.3s; }
.reveal-delay-4 { transition-delay: 0.4s; }
.reveal-delay-5 { transition-delay: 0.5s; }
.reveal-delay-6 { transition-delay: 0.6s; }

.reveal-left {
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal-left.revealed {
    opacity: 1;
    transform: translateX(0);
}

.reveal-right {
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal-right.revealed {
    opacity: 1;
    transform: translateX(0);
}

.reveal-scale {
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal-scale.revealed {
    opacity: 1;
    transform: scale(1);
}

.reveal-blur {
    opacity: 0;
    filter: blur(8px);
    transition: opacity 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                filter 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal-blur.revealed {
    opacity: 1;
    filter: blur(0);
}

/* Stagger children */
.reveal-group > * {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.reveal-group.revealed > *:nth-child(1) { transition-delay: 0.05s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(2) { transition-delay: 0.1s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(3) { transition-delay: 0.15s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(4) { transition-delay: 0.2s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(5) { transition-delay: 0.25s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(6) { transition-delay: 0.3s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(7) { transition-delay: 0.35s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(8) { transition-delay: 0.4s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(9) { transition-delay: 0.45s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(10) { transition-delay: 0.5s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(11) { transition-delay: 0.55s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(12) { transition-delay: 0.6s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(13) { transition-delay: 0.65s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(14) { transition-delay: 0.7s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(15) { transition-delay: 0.75s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(16) { transition-delay: 0.8s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(17) { transition-delay: 0.85s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(18) { transition-delay: 0.9s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(19) { transition-delay: 0.95s; opacity: 1; transform: translateY(0); }
.reveal-group.revealed > *:nth-child(20) { transition-delay: 1.0s; opacity: 1; transform: translateY(0); }
/* Fallback для всех остальных элементов (если больше 20) */
.reveal-group.revealed > *:nth-child(n+21) { transition-delay: 1.0s; opacity: 1; transform: translateY(0); }

/* ========================================
   5. MICRO-INTERACTIONS
   ======================================== */

/* Magnetic hover effect for buttons */
.btn-magnetic {
    position: relative;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Ripple effect */
.btn-ripple {
    position: relative;
    overflow: hidden;
}

.btn-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s ease, height 0.6s ease, opacity 0.6s ease;
    opacity: 0;
    pointer-events: none;
}

.btn-ripple:active::after {
    width: 300%;
    height: 300%;
    opacity: 1;
    transition: width 0.3s ease, height 0.3s ease, opacity 0.3s ease;
}

/* Link underline animation */
.link-underline {
    position: relative;
    display: inline-block;
}

.link-underline::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 1.5px;
    background: currentColor;
    transition: width 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.link-underline:hover::after {
    width: 100%;
}

/* Icon bounce on hover */
.icon-bounce {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.group:hover .icon-bounce,
.icon-bounce-trigger:hover .icon-bounce {
    transform: scale(1.15) rotate(-4deg);
}

/* Shimmer loading effect */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.shimmer {
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.1) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
}

/* Floating animation */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
}

.float-animation {
    animation: float 4s ease-in-out infinite;
}

/* Pulse glow */
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(131, 31, 136, 0.3); }
    50% { box-shadow: 0 0 20px 4px rgba(131, 31, 136, 0.1); }
}

.pulse-glow {
    animation: pulse-glow 3s ease-in-out infinite;
}

/* ========================================
   6. GLASSMORPHISM
   ======================================== */

.glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.dark .glass {
    background: rgba(21, 27, 46, 0.7);
    border-color: rgba(168, 189, 217, 0.1);
}

.glass-strong {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

.dark .glass-strong {
    background: rgba(21, 27, 46, 0.9);
    border-color: rgba(168, 189, 217, 0.15);
}

/* ========================================
   7. MODAL BENTO
   ======================================== */

.bento-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.bento-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.35s ease;
}

.bento-modal.active .bento-modal-overlay {
    opacity: 1;
}

.bento-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    box-shadow: 0 25px 60px -15px var(--shadow-color);
    max-width: 90vw;
    max-height: calc(85vh - 1rem);
    max-height: calc(85dvh - 1rem);
    min-height: 0;
    overflow: hidden;
    margin: 0.5rem;
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.35s ease;
}

@media (max-width: 767px) {
    .bento-modal-content {
        width: 100%;
        max-height: calc(85dvh - 0.5rem);
        margin: 0.25rem;
    }
}

.dark .bento-modal-content {
    background: rgba(10, 14, 26, 0.95);
    border-color: var(--border-color);
}

.bento-modal.active .bento-modal-content {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* ========================================
   8. SCROLLBAR STYLING
   ======================================== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(134, 143, 176, 0.4);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(134, 143, 176, 0.6);
}

.dark ::-webkit-scrollbar-thumb {
    background: rgba(168, 189, 217, 0.3);
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(168, 189, 217, 0.5);
}

/* ========================================
   9. TYPOGRAPHY ENHANCEMENTS
   ======================================== */

.text-gradient {
    background: linear-gradient(135deg, #831f88 0%, #3272a9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dark .text-gradient {
    background: linear-gradient(135deg, #9d4edd 0%, #4a90d9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ========================================
   10. IMAGE HOVER EFFECTS
   ======================================== */

.img-zoom {
    overflow: hidden;
}

.img-zoom img {
    transition: transform 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.img-zoom:hover img {
    transform: scale(1.05);
}

/* ========================================
   11. FORM ENHANCEMENTS
   ======================================== */

.bento-input,
.bento-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.bento-card select,
.bento-card textarea {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(229, 231, 235, 0.8);
    border-radius: 0.875rem;
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-size: 0.875rem;
    width: 100%;
}

.dark .bento-input,
.dark .bento-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.dark .bento-card select,
.dark .bento-card textarea {
    background: rgba(21, 27, 46, 0.5);
    border-color: rgba(45, 49, 80, 0.6);
    color: #e5e7eb;
}

.bento-input:focus,
.bento-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
.bento-card select:focus,
.bento-card textarea:focus {
    outline: none;
    border-color: #831f88;
    box-shadow: 0 0 0 3px rgba(131, 31, 136, 0.15);
    background: rgba(255, 255, 255, 0.9);
}

.dark .bento-input:focus,
.dark .bento-card input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
.dark .bento-card select:focus,
.dark .bento-card textarea:focus {
    background: rgba(21, 27, 46, 0.8);
    box-shadow: 0 0 0 3px rgba(131, 31, 136, 0.1);
}

/* ========================================
   12. NOTIFICATION TOAST BENTO
   ======================================== */

.bento-toast {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.2);
    z-index: 100;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.4s ease;
}

.bento-toast.show {
    transform: translateX(0);
    opacity: 1;
}

/* ========================================
   13. PAGE TRANSITION
   ======================================== */

.page-transition {
    animation: pageIn 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes pageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   14. REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }

    .reveal,
    .reveal-left,
    .reveal-right,
    .reveal-scale,
    .reveal-blur {
        opacity: 1;
        transform: none;
        filter: none;
    }
}
