/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

/* Game Container */
.game-container {
    max-width: 800px;
    margin: 0 auto;
    padding: clamp(6px, 1vh, 10px) clamp(8px, 2vw, 16px);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}


/* Header Styles */
.game-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: clamp(10px, 1.5vw, 14px);
    margin: 0 auto clamp(8px, 1.5vh, 12px);
    width: 100%;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "title stats"
        "controls controls";
    align-items: center;
    gap: clamp(8px, 1.2vw, 12px);
}

.game-title {
    font-size: clamp(1.3rem, 2.5vw, 1.5rem);
    font-weight: 700;
    color: #2c3e50;
    margin: 0;
    grid-area: title;
}

.game-stats {
    display: flex;
    gap: clamp(10px, 2vw, 16px);
    flex-wrap: wrap;
    align-items: center;
    grid-area: stats;
    justify-self: end;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-weight: 600;
    color: #7f8c8d;
}

.stat-value {
    font-weight: 700;
    color: #2c3e50;
    font-size: clamp(0.9rem, 1.8vw, 1rem);
}

.game-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    grid-area: controls;
    align-items: center;
    justify-content: flex-start;
    margin-top: 2px;
}

/* Button Styles */
.btn {
    padding: clamp(6px, 1vw, 8px) clamp(10px, 1.5vw, 14px);
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: clamp(0.75rem, 1.5vw, 0.8rem);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(28px, 3vh, 32px);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    color: #2c3e50;
    border: 2px solid #e0e0e0;
}

.btn-secondary:hover {
    background: #f8f9fa;
    border-color: #667eea;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

/* Main Game Area */
.game-main {
    flex: 1;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    display: flex !important;
    flex-direction: column !important;
    gap: clamp(10px, 1.5vw, 16px);
    min-height: 0;
    max-height: calc(100vh - 120px);
}

/* Word Panel */
.word-panel {
    background: rgba(247, 248, 255, 0.95);
    border-radius: 12px;
    padding: clamp(10px, 1.5vw, 14px);
    box-shadow: 0 6px 24px rgba(34, 41, 74, 0.12);
    border: 1px solid rgba(102, 126, 234, 0.08);
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden;
    display: flex !important;
    flex-direction: column;
    gap: clamp(8px, 1.2vw, 10px);
    min-height: 0;
    flex-shrink: 0;
    box-sizing: border-box;
}

.word-panel-title {
    font-size: clamp(1rem, 2vw, 1.15rem);
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: clamp(8px, 1.2vw, 12px);
    text-align: center;
}

.word-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: clamp(6px, 1vw, 8px);
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
    min-height: 0;
    align-content: flex-start;
}

.word-item {
    padding: clamp(6px, 0.8vw, 8px) clamp(8px, 1.2vw, 10px);
    background: rgba(255, 255, 255, 0.8);
    border-radius: 6px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: clamp(0.75rem, 1.4vw, 0.85rem);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.word-item:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}

.word-item.found {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border-color: #27ae60;
    transform: scale(1.02);
}

.word-item.found::after {
    content: " ✓";
    font-weight: bold;
    font-size: 1.1rem;
    margin-left: 4px;
}

/* Game Grid Section */
.game-grid-section {
    display: flex !important;
    justify-content: center;
    align-items: center;
    width: 100% !important;
    max-width: 100% !important;
    flex: 1;
    min-height: 0;
    box-sizing: border-box;
}

.grid-container {
    background: #ffffff;
    border-radius: 12px;
    padding: clamp(10px, 1.5vw, 14px);
    box-shadow: 0 8px 24px rgba(34, 41, 74, 0.18);
    border: 1px solid rgba(102, 126, 234, 0.08);
    width: 100%;
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    overflow: hidden;
}

.word-grid {
    display: grid;
    gap: clamp(1px, 0.2vw, 2px);
    user-select: none;
    touch-action: none;
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 200px);
    margin: 0 auto;
    aspect-ratio: 1;
    box-sizing: border-box;
}

.grid-cell {
    width: 100%;
    min-width: 18px;
    aspect-ratio: 1;
    border: 1.5px solid transparent;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: clamp(0.7rem, 1.8vw, 0.85rem);
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.9);
    color: #2c3e50;
    position: relative;
}

.grid-cell:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.5);
    transform: scale(1.05);
}

.grid-cell.selected {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-color: #667eea;
    transform: scale(1.1);
    z-index: 2;
}

.grid-cell.found {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border-color: #27ae60;
    animation: foundPulse 0.6s ease;
}

.grid-cell.hint {
    animation: hintFlash 1s ease;
}

/* Grid Size Variations */
.word-grid.size-10 {
    grid-template-columns: repeat(10, 1fr);
}

.word-grid.size-12 {
    grid-template-columns: repeat(12, 1fr);
}

.word-grid.size-14 {
    grid-template-columns: repeat(14, 1fr);
}

/* Animations */
@keyframes foundPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes hintFlash {
    0% { background: rgba(255, 193, 7, 0.3); }
    50% { background: rgba(255, 193, 7, 0.8); }
    100% { background: rgba(255, 255, 255, 0.9); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s ease;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 15px;
    text-align: center;
}

.modal-message {
    text-align: center;
    color: #7f8c8d;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.modal-stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 25px;
    padding: 15px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 10px;
}

.modal-stat {
    text-align: center;
}

.modal-stat-label {
    display: block;
    font-weight: 600;
    color: #7f8c8d;
    margin-bottom: 5px;
}

.modal-stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: #2c3e50;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* Difficulty Options */
.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.difficulty-option {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
}

.difficulty-option:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.difficulty-option h3 {
    color: #2c3e50;
    margin-bottom: 5px;
    font-size: 1.2rem;
}

.difficulty-option p {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin: 0;
}

/* Category Options */
.category-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.category-option {
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.category-option:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.category-option h3 {
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 1.3rem;
}

.category-option p {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin: 0;
    line-height: 1.4;
}

/* Optimization for iframe up to 800px - main styles */
/* Game optimized for iframe width up to 800px */
@media (max-width: 800px) {
    .game-container {
        padding: clamp(6px, 1vh, 10px) clamp(8px, 2vw, 14px);
    }
    
    .game-header {
        padding: clamp(10px, 1.5vw, 12px);
        margin-bottom: clamp(8px, 1.2vh, 10px);
    }
    
    .game-main {
        max-height: calc(100vh - 110px);
    }
    
    .word-panel {
        width: 100% !important;
        max-width: 100% !important;
        max-height: clamp(100px, 15vh, 140px);
    }
    
    .word-list {
        max-height: clamp(80px, 12vh, 110px);
    }
    
    .word-grid {
        max-height: calc(100vh - 280px);
        max-width: min(100%, calc(100vh - 300px));
        /* Ensure the grid fits on laptop screen */
        width: min(100%, calc(100vh - 300px));
    }
    
    .grid-container {
        padding: clamp(8px, 1.2vw, 12px);
    }
}

/* Tablet & smaller adjustments - for iframe up to 800px */
@media (max-width: 750px) {
    .game-main {
        width: 100%;
        gap: clamp(10px, 2vw, 14px);
        max-height: none;
    }

    .word-panel {
        width: 100% !important;
        max-width: 100% !important;
        max-height: clamp(140px, 20vh, 180px);
        height: auto;
        overflow: visible;
    }
    
    .word-list {
        max-height: clamp(110px, 16vh, 150px);
        overflow-y: auto;
    }

    .game-grid-section {
        width: 100%;
        align-items: center;
        height: auto;
    }

    .grid-container {
        height: auto;
        max-height: calc(100vh - 320px);
    }
    
    .word-grid {
        max-height: calc(100vh - 350px);
    }

    .category-options {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

@media (max-width: 768px) {
    .game-container {
        padding: clamp(10px, 4vw, 16px);
    }

    .game-main {
        width: 100%;
    }
    
    .game-header {
        grid-template-columns: 1fr;
        grid-template-areas:
            "title"
            "stats"
            "controls";
        text-align: center;
        gap: 12px;
        padding: clamp(12px, 4vw, 18px);
        align-items: center;
    }
    
    .game-title {
        font-size: 1.3rem;
    }
    
    .game-stats {
        justify-content: center;
        justify-self: center;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }
    
    .stat-item {
        justify-content: center;
        padding: 6px 0;
        background: rgba(102, 126, 234, 0.08);
        border-radius: 10px;
    }
    
    .game-controls {
        justify-content: center;
        width: 100%;
        justify-self: stretch;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 9px;
    }
    
    .grid-cell {
        font-size: clamp(0.75rem, 2.6vw, 0.9rem);
    }
    
    .btn {
        min-height: 36px;
        font-size: 0.9rem;
    }

    .grid-container {
        padding: clamp(12px, 5vw, 18px);
        height: auto;
    }

    .word-panel {
        max-width: 100% !important;
        width: 100% !important;
        padding: clamp(12px, 5vw, 18px);
        height: auto;
    }

    .word-panel-title {
        font-size: 1.05rem;
    }

    .word-item {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .word-list {
        gap: 6px;
    }

    .modal-content {
        padding: 20px;
        margin: 20px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .category-options {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .category-option {
        padding: 15px;
    }
    
    .category-option h3 {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 1.2rem;
    }

    .game-stats {
        grid-template-columns: 1fr;
    }

    .stat-item {
        padding: 8px 0;
    }

    .game-controls {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 8px;
    }

    .btn {
        font-size: 0.85rem;
    }

    .grid-container,
    .word-panel {
        padding: clamp(10px, 6vw, 16px);
    }

    .word-grid {
        gap: 1px;
    }

    .word-item {
        font-size: 0.85rem;
    }
}

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

/* Focus styles for keyboard navigation */
.btn:focus,
.grid-cell:focus,
.difficulty-option:focus,
.category-option:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .grid-cell {
        border: 2px solid #000;
    }
    
    .grid-cell.selected {
        border-color: #000;
        background: #000;
        color: #fff;
    }
}

@media (hover: none) {
    .btn-primary:hover,
    .btn-secondary:hover,
    .grid-cell:hover,
    .difficulty-option:hover,
    .category-option:hover {
        transform: none;
    }
}
