/* Fixed font reference - version 1.1 */
@font-face {
    font-family: 'ThisCafe';
    src: url('./fonts/this_cafe.ttf') format('truetype');
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
    position: relative;
}

/* Prevent any element from causing horizontal scroll */
* {
    max-width: 100vw;
}

img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* 🌐 Language Selector */
#language-selector {
    position: fixed;
    top: 10px;
    right: 15px;
    z-index: 1000;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#language-selector label {
    font-size: 0.95rem;
    font-weight: bold;
    color: #333;
    margin: 0;
    cursor: pointer;
}

#language-selector select {
    padding: 6px 10px;
    font-size: 0.9rem;
    border: 2px solid #009688;
    border-radius: 6px;
    background-color: white;
    color: #333;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

#language-selector select:hover {
    border-color: #00796b;
}

#language-selector select:focus {
    outline: none;
    border-color: #004d40;
    box-shadow: 0 0 5px rgba(0, 150, 136, 0.3);
}

body {
    font-family: 'This Cafe', sans-serif;
    background: linear-gradient(rgba(249, 249, 249, 0.95), rgba(249, 249, 249, 0.95)), 
                url('./images/background.jpg') center/cover no-repeat fixed;
    text-align: center;
    margin: 0;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
}

h1 {
    font-size: 2.5rem;
    margin-top: 15px;
    margin-bottom: 5px;
    color: #222;
    text-shadow: 1px 1px 2px #999;
    letter-spacing: 1px;
    text-align: center;
}

h2 {
    font-size: 1.4rem;
    margin-top: 0;
    margin-bottom: 15px;
    color: #444;
    text-shadow: 0.5px 0.5px 1px #bbb;
    text-align: center;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
    width: 100%;
    max-width: 100vw;
    padding: 0 10px;
}

#solver-controls {
    justify-content: center !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
    margin: 0 auto !important;
    width: 100% !important;
}

#solver-controls[style*="display: block"],
#solver-controls[style*="display: flex"] {
    display: flex !important;
}

#play-controls {
    justify-content: center !important;
    align-items: center !important;
    flex-wrap: wrap !important;
}

#play-controls[style*="display: block"],
#play-controls[style*="display: flex"] {
    display: flex !important;
}

button {
    font-family: inherit;
    font-size: 1rem;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background-color: #009688;
    color: white;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: background-color 0.3s ease, transform 0.2s ease;
    position: relative;
    display: inline-block;
}

/* 🎮 Special styling for mode toggle */
#interactive-toggle {
    background-color: #4caf50;
    font-weight: bold;
}

/* 🎮 Mode selection buttons */
#play-mode-btn, #solver-mode-btn {
    font-size: 1.1rem;
    padding: 12px 20px;
    font-weight: bold;
    margin: 0 5px;
}

#play-mode-btn {
    background-color: #4caf50;
}

#solver-mode-btn {
    background-color: #2196f3;
}

button:hover {
    background-color: #2196f3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* 🎯 Difficulty buttons */
.difficulty-btn {
    margin: 3px;
    padding: 12px 16px;
    font-size: 0.9rem;
    border-radius: 10px;
    min-width: 100px;
    transition: all 0.3s ease;
}

.difficulty-btn:hover {
    transform: scale(1.05);
}

#easy-btn { background-color: #4caf50; }
#easy-btn:hover { background-color: #45a049; }

#medium-btn { background-color: #ff9800; }
#medium-btn:hover { background-color: #f57c00; }

#hard-btn { background-color: #f44336; }
#hard-btn:hover { background-color: #d32f2f; }

#time-trial-btn { background-color: #9c27b0; }
#time-trial-btn:hover { background-color: #7b1fa2; }

button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* ❓ Tutorial button styling */
#tutorial-btn {
    background-color: #673ab7 !important;
    font-size: 0.9rem !important;
    padding: 10px 14px !important;
    border-radius: 8px !important;
    margin-left: 10px !important;
    margin-right: 0 !important;
    color: white !important;
    align-self: center;
}

#tutorial-btn:hover {
    background-color: #5e35b1 !important;
}

#puzzle-board {
    display: grid;
    gap: 8px;
    margin-bottom: 20px;
    width: 100%;
    max-width: 350px;
    grid-template-columns: repeat(auto-fit, minmax(55px, 1fr));
    padding: 0 10px;
    margin-left: auto;
    margin-right: auto;
}

.tile {
    background-color: #fffbf0;
    border: 2px solid #ccc;
    border-radius: 12px;
    font-size: 1.4rem;
    font-weight: bold;
    color: #333;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    width: 100%;
    transition: background 0.3s ease, transform 0.2s;
    -moz-appearance: textfield; /* Firefox: remove number arrows */
    cursor: pointer; /* 🎮 Show it's clickable */
}

/* 🎮 Interactive hover effect */
.tile:hover {
    background-color: #e8f5e8;
    transform: scale(1.05);
    border-color: #4caf50;
}

/* 🎮 Clickable tile effect */
.tile.clickable {
    background-color: #f0f8ff;
    border-color: #2196f3;
    animation: pulse 1.5s infinite;
}

/* 🎯 Moveable tiles with arrows */
.tile.moveable {
    background-color: #e8f5e8 !important;
    border-color: #4caf50 !important;
    cursor: pointer !important;
    animation: breathe 2s ease-in-out infinite;
}

/* 🌬️ Breathing animation for moveable tiles */
@keyframes breathe {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 0 5px rgba(76, 175, 80, 0.3);
    }
    50% { 
        transform: scale(1.02);
        box-shadow: 0 0 15px rgba(76, 175, 80, 0.6);
    }
}

/* 🏹 Arrow indicators */
.arrow-indicator {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.8rem;
    color: #4caf50;
    font-weight: bold;
    pointer-events: none;
    text-shadow: 0 0 2px white;
}

/* 💡 Hint highlight - Enhanced animations */
.tile.hint-highlight {
    background-color: #fff3e0 !important;
    border-color: #ff9800 !important;
    animation: hintGlow 1s ease-in-out infinite alternate;
}

.tile.hint-pulse {
    animation: hintPulse 0.8s ease-in-out infinite alternate;
}

.tile.hint-glow {
    animation: hintGlow 1s ease-in-out infinite alternate;
}

/* Combined animation for ultimate attention */
.tile.hint-highlight.hint-pulse.hint-glow {
    background-color: #fff3e0 !important;
    border-color: #ff4444 !important;
    animation: hintCombined 0.6s ease-in-out infinite alternate;
}

@keyframes hintGlow {
    from { box-shadow: 0 0 5px #ff9800; }
    to { box-shadow: 0 0 15px #ff9800, 0 0 25px #ff9800; }
}

@keyframes hintPulse {
    from { 
        transform: scale(1);
        background-color: #fff3e0;
    }
    to { 
        transform: scale(1.05);
        background-color: #ffeb3b;
    }
}

@keyframes hintCombined {
    from { 
        transform: scale(1);
        background-color: #fff3e0;
        box-shadow: 0 0 5px #ff4444;
        border-color: #ff4444;
    }
    to { 
        transform: scale(1.1);
        background-color: #ffeb3b;
        box-shadow: 0 0 20px #ff4444, 0 0 30px #ff4444;
        border-color: #ff0000;
    }
}

@keyframes hintArrowPulse {
    from { 
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
    to { 
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 1;
    }
}

/* 💡 Hint button styling */
#hint-btn {
    background-color: #ff9800;
}

#hint-btn:hover {
    background-color: #f57c00;
}

@keyframes hintPop {
    from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.4); }
    70% { box-shadow: 0 0 0 8px rgba(33, 150, 243, 0); }
    100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0); }
}

/* ⌨️ Keyboard hint animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Chrome/Safari: remove number arrows */
.tile::-webkit-outer-spin-button,
.tile::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.tile:focus {
    outline: 2px solid #009688;
    background-color: #e0f7fa;
}

/* ❌ Invalid input styling */
.tile.invalid {
    background-color: #ffebee !important;
    border-color: #f44336 !important;
    animation: shake 0.5s ease-in-out;
}

/* 🎯 Next moveable tiles - Shows which tiles CAN move next (with smooth pulse) */
.tile.next-moveable {
    background-color: #fff9c4 !important;
    border-color: #f57f17 !important;
    animation: nextMoveablePulse 0.8s ease-in-out infinite;
    position: relative;
}

/* Arrow indicator showing direction of movement */
.move-arrow {
    position: absolute;
    font-size: 1.2rem;
    font-weight: bold;
    color: #f57f17;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 249, 196, 0.9);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
    z-index: 10;
    animation: arrowPulse 0.8s ease-in-out infinite;
}

@keyframes nextMoveablePulse {
    0% {
        background-color: #fff9c4;
        box-shadow: 0 0 5px rgba(245, 127, 23, 0.6);
        transform: scale(1);
    }
    50% {
        background-color: #ffeb3b;
        box-shadow: 0 0 15px rgba(245, 127, 23, 0.9);
        transform: scale(1.02);
    }
    100% {
        background-color: #fff9c4;
        box-shadow: 0 0 5px rgba(245, 127, 23, 0.6);
        transform: scale(1);
    }
}

@keyframes arrowPulse {
    0% {
        opacity: 0.7;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.15);
    }
    100% {
        opacity: 0.7;
        transform: scale(1);
    }
}


/* Arrows for PREVIOUS and NEXT */
#prev-btn::before {
    content: "← ";
}
#next-btn::after {
    content: " →";
}

#brain-loader {
    display: none;
    margin: 20px auto;
    width: 60px;
}

#move-counter {
    margin-top: 10px;
    font-size: 1.2rem;
    font-weight: bold;
    color: #444;
}

#step-counter {
    display: none;
    font-size: 1.2rem;
    font-weight: bold;
    color: #444;
    margin-top: 15px;
}

/* 🎉 Puzzle Solved Popup */
#solved-popup {
    display: none;
    position: fixed;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    background: #fff9c4;
    color: #222;
    padding: 15px 30px;
    border: 2px solid #fbc02d;
    border-radius: 12px;
    font-size: 1.6rem;
    font-weight: bold;
    box-shadow: 0 0 25px 8px rgba(255, 235, 59, 0.6);
    animation: glow 1.5s ease-in-out forwards;
    z-index: 9999;
}

@keyframes glow {
    0%   { opacity: 0; transform: translateX(-50%) scale(0.8); }
    40%  { opacity: 1; transform: translateX(-50%) scale(1.05); }
    100% { opacity: 0; transform: translateX(-50%) scale(1); }
}

/* Desktop - ensure language selector is visible */
@media (min-width: 769px) {
    #language-selector {
        display: flex !important;
        position: fixed !important;
        top: 10px !important;
        right: 15px !important;
    }
}

/* Mobile & Tablet Optimization */
@media (max-width: 768px) {
    html {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }
    
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
        position: relative !important;
    }
    
    body {
        padding: 10px 5px !important;
        width: 100% !important;
    }
    
    /* Prevent any element from overflowing */
    * {
        max-width: 100% !important;
    }
    
    /* Exception for viewport-based elements */
    #puzzle-board, .controls, h1, h2 {
        max-width: 100vw !important;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 5px;
        padding: 0 10px;
        word-wrap: break-word;
    }

    h2 {
        font-size: 1.1rem;
        margin-bottom: 10px;
        padding: 0 10px;
    }
    }

    h2 {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }

    /* Touch-friendly buttons */
    button {
        font-size: 0.95rem !important;
        padding: 10px 14px !important;
        min-height: 44px !important;
        max-width: calc(50vw - 20px) !important;
        word-wrap: break-word !important;
    }

    /* Larger puzzle board on mobile */
    #puzzle-board {
        max-width: 350px !important;
        width: 100% !important;
        gap: 5px !important;
        padding: 0 !important;
        margin: 10px auto !important;
        box-sizing: border-box !important;
    }

    /* Bigger tiles with better readability */
    .tile {
        font-size: 1.8rem;
        border-radius: 10px;
        border-width: 2px;
    }

    .controls {
        gap: 8px !important;
        margin-bottom: 15px !important;
        flex-wrap: wrap !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0 5px !important;
        box-sizing: border-box !important;
    }

    /* Stats display optimization */
    #stats {
        font-size: 1rem;
        margin-bottom: 15px;
    }

    /* Language selector - reposition to avoid overlapping branding */
    #language-selector {
        position: static !important;
        display: inline-flex !important;
        font-size: 0.8rem;
        padding: 6px 10px;
        margin-bottom: 10px;
        width: fit-content;
        margin-left: auto;
        margin-right: auto;
        max-width: 90vw;
        top: auto !important;
        right: auto !important;
    }

    #language-selector label {
        font-size: 0.8rem;
        white-space: nowrap;
    }

    #lang-dropdown {
        font-size: 0.8rem;
        padding: 4px 8px;
        max-width: 150px;
    }
}

/* Large phones (iPhone 14 Pro Max, Samsung S23 Ultra, etc.) */
@media (min-width: 400px) and (max-width: 768px) {
    #puzzle-board {
        max-width: 350px;
    }

    .tile {
        font-size: 2rem;
    }

    h1 {
        font-size: 2.6rem;
    }
}

/* Small phones optimization */
@media (max-width: 375px) {
    h1 {
        font-size: 1.9rem;
    }

    h2 {
        font-size: 1.1rem;
    }

    .tile {
        font-size: 1.6rem;
    }

    button {
        font-size: 0.95rem;
        padding: 10px 14px;
    }

    #puzzle-board {
        gap: 5px;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 5px 10px;
    }

    h1 {
        font-size: 1.8rem;
        margin-bottom: 5px;
    }

    h2 {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    #puzzle-board {
        max-width: 350px;
    }

    .controls {
        margin-bottom: 10px;
    }
}
/* Fix for alert/confirm dialogs and tutorial on mobile */
@media (max-width: 768px) {
    /* SweetAlert2 modal fixes for mobile */
    .swal2-popup {
        width: 90vw !important;
        max-width: 90vw !important;
        padding: 15px !important;
        font-size: 0.9rem !important;
    }
    
    .swal2-html-container {
        max-height: 60vh !important;
        overflow-y: auto !important;
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
    }
    
    .swal2-title {
        font-size: 1.3rem !important;
        padding: 10px 5px !important;
    }
    
    .swal2-html-container ul {
        margin-left: 15px !important;
        font-size: 0.8rem !important;
    }
    
    .swal2-html-container p {
        font-size: 0.85rem !important;
        margin: 8px 0 !important;
    }
    
    /* Prevent body scroll when modal is open */
    body.swal2-shown {
        overflow: hidden !important;
    }
}

/* Footer */
#page-footer {
    width: 100%;
    text-align: center;
    padding: 20px 15px;
    margin-top: 50px;
    font-family: Arial, sans-serif;
    color: #000;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.9);
}

#page-footer p {
    margin: 3px 0;
    font-size: 14px;
    font-weight: bold;
}

#page-footer p:first-child {
    font-weight: bold;
    font-size: 16px;
}

#page-footer p:last-child {
    font-style: italic;
    font-weight: bold;
}