/* PAR🇮🇹LE - Main Game Styles */

/* Prevent zoom on mobile */
* {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Reset zoom on page visibility change (iOS Safari fix) */
@supports (-webkit-touch-callout: none) {
    html {
        /* iOS Safari specific fix */
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* CSS Variables for theming */
:root {
    --color-correct: #538d4e;
    --color-present: #b59f3b;
    --color-absent: #3a3a3c;
    --color-bg: #121213;
    --color-surface: #1a1a1b;
    --color-border: #3a3a3c;
    --color-key: #818384;
}

/* Prevent pull-to-refresh and overscroll */
html,
body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height for mobile */
}

/* Ensure no unwanted scrolling on mobile */
body {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    /* Safe area for notched devices */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* High contrast mode */
.high-contrast {
    --color-correct: #85c0f9;
    --color-present: #f5793a;
}

/* ============================================
   3D CUBE TILE ANIMATION
   Each tile is a cube that rotates to reveal color
   ============================================ */

/* Container that holds the 3D perspective */
.tile-container {
    perspective: 300px;
    width: clamp(2.5rem, 13vw, 4.5rem);
    height: clamp(2.5rem, 13vw, 4.5rem);
    padding: 2px; /* Creates black gap between tiles */
}

/* The cube itself - maintains 3D space for children */
.tile-cube {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Each face of the cube */
.tile-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    font-size: clamp(1.25rem, 6vw, 2.25rem);
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* Front face - starts visible */
.tile-front {
    transform: rotateX(0deg) translateZ(calc(clamp(2.5rem, 13vw, 4.5rem) / 2));
}

/* Back face - rotated 90deg on X axis (top of cube) */
.tile-back {
    transform: rotateX(90deg) translateZ(calc(clamp(2.5rem, 13vw, 4.5rem) / 2));
}

/* Cube flip animation - rotate the whole cube */
.tile-cube.cube-flip {
    animation: cube-rotate 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* Already flipped state (for loaded games) */
.tile-cube.cube-flipped {
    transform: rotateX(-90deg);
}

@keyframes cube-rotate {
    0% {
        transform: rotateX(0deg);
    }
    100% {
        transform: rotateX(-90deg);
    }
}

/* Bounce animation when typing */
.tile-cube.cube-pop {
    animation: cube-pop 0.1s ease-out;
}

@keyframes cube-pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Flip delays - sequential reveal */
.tile-container:nth-child(1) .tile-cube.cube-flip {
    animation-delay: 0ms;
}

.tile-container:nth-child(2) .tile-cube.cube-flip {
    animation-delay: 200ms;
}

.tile-container:nth-child(3) .tile-cube.cube-flip {
    animation-delay: 400ms;
}

.tile-container:nth-child(4) .tile-cube.cube-flip {
    animation-delay: 600ms;
}

.tile-container:nth-child(5) .tile-cube.cube-flip {
    animation-delay: 800ms;
}

/* Tile state colors */
.tile-empty {
    border-color: var(--color-border);
    background-color: transparent;
}

.tile-filled {
    border-color: #565758;
    background-color: transparent;
}

.tile-correct {
    border-color: var(--color-correct);
    background-color: var(--color-correct);
}

.tile-present {
    border-color: var(--color-present);
    background-color: var(--color-present);
}

.tile-absent {
    border-color: var(--color-absent);
    background-color: var(--color-absent);
}

/* Keyboard key states */
.key-default {
    background-color: var(--color-key);
    color: white;
}

.key-default:hover {
    background-color: #a3a3a5;
}

.key-correct {
    background-color: var(--color-correct) !important;
    color: white;
}

.key-present {
    background-color: var(--color-present) !important;
    color: white;
}

.key-absent {
    background-color: #3a3a3c !important;
    color: white;
}

/* Key press effect */
.key:active {
    transform: scale(0.95);
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4a4a4c;
}

/* Modal backdrop blur */
.modal-backdrop {
    backdrop-filter: blur(4px);
}

/* Prevent text selection during gameplay */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Ensure consistent gap scaling */
#game-board {
    gap: clamp(0.35rem, 2vw, 0.6rem);
}

#game-board>div {
    gap: clamp(0.35rem, 2vw, 0.6rem);
}

/* Mobile optimizations */
@media (max-width: 380px) {
    .tile-container {
        width: clamp(2.25rem, 12vw, 3rem);
        height: clamp(2.25rem, 12vw, 3rem);
    }

    .tile-face {
        font-size: clamp(1rem, 5vw, 1.5rem);
    }

    .tile-front {
        transform: rotateX(0deg) translateZ(calc(clamp(2.25rem, 12vw, 3rem) / 2));
    }

    .tile-back {
        transform: rotateX(90deg) translateZ(calc(clamp(2.25rem, 12vw, 3rem) / 2));
    }

    .key {
        font-size: 0.7rem !important;
        min-height: 3rem;
    }
}

/* Very small screens (like iPhone SE) */
@media (max-width: 360px) {
    .tile-container {
        width: clamp(2rem, 11vw, 2.75rem);
        height: clamp(2rem, 11vw, 2.75rem);
    }

    .tile-face {
        font-size: clamp(0.875rem, 4.5vw, 1.25rem);
        border-width: 1.5px;
    }

    .tile-front {
        transform: rotateX(0deg) translateZ(calc(clamp(2rem, 11vw, 2.75rem) / 2));
    }

    .tile-back {
        transform: rotateX(90deg) translateZ(calc(clamp(2rem, 11vw, 2.75rem) / 2));
    }

    #game-board {
        gap: clamp(0.2rem, 1vw, 0.375rem);
    }

    #game-board>div {
        gap: clamp(0.2rem, 1vw, 0.375rem);
    }
}

/* Landscape mode adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    .tile-container {
        width: clamp(2rem, 8vh, 3.5rem);
        height: clamp(2rem, 8vh, 3.5rem);
    }

    .tile-face {
        font-size: clamp(1rem, 4vh, 1.75rem);
    }

    .tile-front {
        transform: rotateX(0deg) translateZ(calc(clamp(2rem, 8vh, 3.5rem) / 2));
    }

    .tile-back {
        transform: rotateX(90deg) translateZ(calc(clamp(2rem, 8vh, 3.5rem) / 2));
    }

    #game-board {
        gap: clamp(0.2rem, 1vh, 0.4rem);
    }

    #game-board>div {
        gap: clamp(0.2rem, 1vh, 0.4rem);
    }
}

/* Keyboard visual feedback */
.key-pressed {
    transform: scale(0.92);
    opacity: 0.8;
}

/* Distribution bar animation */
.distribution-bar {
    transition: width 0.5s ease-out;
}

/* Toast animation */
.toast-enter {
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px) translateX(-50%);
    }

    to {
        opacity: 1;
        transform: translateY(0) translateX(-50%);
    }
}

/* Italian flag gradient for special occasions */
.italian-gradient {
    background: linear-gradient(90deg,
            #009246 0%,
            #009246 33%,
            #ffffff 33%,
            #ffffff 66%,
            #ce2b37 66%,
            #ce2b37 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Pulse animation for countdown */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.countdown-pulse {
    animation: pulse 1s infinite;
}

/* ============================================
   LIVE FEED WIDGET
   Floating badge + dropdown panel
   ============================================ */

/* Floating Action Button - positioned top-right below header */
.live-feed-fab {
    position: fixed;
    top: 4rem;
    right: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, rgba(26, 26, 27, 0.95) 0%, rgba(18, 18, 19, 0.95) 100%);
    border: 1px solid rgba(83, 141, 78, 0.4);
    border-radius: 2rem;
    color: white;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    z-index: 40;
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.3),
        0 1px 3px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease;
    backdrop-filter: blur(12px);
}

.live-feed-fab:hover {
    transform: translateY(-1px);
    border-color: rgba(83, 141, 78, 0.6);
    box-shadow:
        0 6px 16px rgba(0, 0, 0, 0.35),
        0 2px 4px rgba(0, 0, 0, 0.2);
}

.live-feed-fab-active {
    background: rgba(83, 141, 78, 0.2);
    border-color: rgba(83, 141, 78, 0.6);
}

/* Live pulse indicator */
.live-feed-fab-pulse {
    width: 6px;
    height: 6px;
    background: #538d4e;
    border-radius: 50%;
    animation: fab-pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 6px rgba(83, 141, 78, 0.6);
}

@keyframes fab-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

.live-feed-fab-text {
    color: rgba(255, 255, 255, 0.9);
}

/* Unread count badge */
.live-feed-fab-badge {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    border-radius: 8px;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin-left: 0.125rem;
    box-shadow: 0 2px 6px rgba(231, 76, 60, 0.5);
    animation: badge-pulse 2s infinite;
}

@keyframes badge-pulse {
    0%, 100% {
        box-shadow: 0 2px 6px rgba(231, 76, 60, 0.5);
    }
    50% {
        box-shadow: 0 2px 12px rgba(231, 76, 60, 0.8);
    }
}

/* Feed Panel - positioned below the FAB */
.live-feed-panel {
    position: fixed;
    top: 4rem;
    right: 0.75rem;
    width: 300px;
    max-height: calc(100dvh - 6rem);
    background: linear-gradient(180deg, rgba(26, 26, 27, 0.98) 0%, rgba(18, 18, 19, 0.98) 100%);
    border: 1px solid rgba(83, 141, 78, 0.3);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.5),
        0 2px 10px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    z-index: 45;
}

/* Header */
.live-feed-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: linear-gradient(90deg, rgba(83, 141, 78, 0.15) 0%, transparent 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.live-feed-pulse {
    width: 8px;
    height: 8px;
    background: #538d4e;
    border-radius: 50%;
    animation: live-pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 8px rgba(83, 141, 78, 0.6);
}

@keyframes live-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(0.85);
    }
}

/* Feed Items Container */
.live-feed-items {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.live-feed-items::-webkit-scrollbar {
    width: 4px;
}

.live-feed-items::-webkit-scrollbar-track {
    background: transparent;
}

.live-feed-items::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* Empty state */
.live-feed-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
}

.live-feed-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: #538d4e;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 0.5rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Feed Item */
.live-feed-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.2s ease;
    animation: feed-item-enter 0.3s ease-out;
}

.live-feed-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.live-feed-item:last-child {
    border-bottom: none;
}

@keyframes feed-item-enter {
    from {
        opacity: 0;
        transform: translateX(10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Item header */
.live-feed-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    gap: 0.5rem;
}

.live-feed-username {
    font-size: 0.8125rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-feed-tournament {
    display: block;
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-feed-time {
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.35);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Item content */
.live-feed-item-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

/* Mini Grid - compact wordle visualization */
.mini-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mini-grid-row {
    display: flex;
    gap: 2px;
}

.mini-grid-cell {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    transition: transform 0.2s ease;
}

.live-feed-item:hover .mini-grid-cell {
    transform: scale(1.1);
}

/* Result badge */
.live-feed-result {
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 0.025em;
}

.live-feed-result-won {
    background: linear-gradient(135deg, rgba(83, 141, 78, 0.25) 0%, rgba(83, 141, 78, 0.15) 100%);
    color: #6aaa64;
    border: 1px solid rgba(83, 141, 78, 0.3);
}

.live-feed-result-lost {
    background: linear-gradient(135deg, rgba(58, 58, 60, 0.4) 0%, rgba(58, 58, 60, 0.2) 100%);
    color: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Mobile adjustments */
@media (max-width: 640px) {
    .live-feed-fab {
        top: 3.75rem;
        right: 0.5rem;
        padding: 0.4rem 0.625rem;
        font-size: 0.625rem;
    }

    .live-feed-panel {
        top: 3.75rem;
        width: calc(100vw - 1rem);
        right: 0.5rem;
        max-height: 50dvh;
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .live-feed-fab {
        top: 3.5rem;
    }

    .live-feed-panel {
        top: 3.5rem;
        width: calc(100vw - 1rem);
        right: 0.5rem;
    }

    .mini-grid-cell {
        width: 8px;
        height: 8px;
    }
}

/* Landscape mode */
@media (max-height: 600px) and (orientation: landscape) {
    .live-feed-fab {
        top: 3.5rem;
    }

    .live-feed-panel {
        top: 3.5rem;
        max-height: 70dvh;
    }
}