/* ==================================================
   RESPONSIVE DESIGN - ALL DEVICES
   Mobile • Tablet • Desktop • iOS • Android
================================================== */

/* Prevent zoom issues on iOS */
html {
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* Better box sizing */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ===============================
   BODY
================================= */
body {
    font-family: Arial, sans-serif;

    display: flex;
    justify-content: center;
    align-items: center;

    min-height: 100dvh;

    background: #f0f2f5;

    margin: 0;
    padding: 15px;

    /* Smooth font rendering */
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ===============================
   MAIN CONTAINER
================================= */
.container {
    width: 100%;

    /* Responsive max width */
    max-width: 520px;
    text-align: center;
    padding: clamp(16px, 4vw, 28px);
    background: white;
    border-radius: 18px;

    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

/* ===============================
   TITLE
================================= */
h1 {
    color: white;
    background: linear-gradient(135deg, #6a0dad, #8a2be2);
    padding: clamp(12px, 3vw, 16px);
    border-radius: 14px;
    margin-top: 0;
    margin-bottom: 16px;

    /* Responsive font */
    font-size: clamp(1.5rem, 5vw, 2.2rem);

    line-height: 1.2;
}

/* ===============================
   GAME MODE TEXT
================================= */
.gamemode {
    color: #6a0dad;
    font-weight: 700;
    font-size: clamp(15px, 4vw, 18px);
    margin-bottom: 15px;
}

/* ===============================
   STATUS TEXT
================================= */
#status {
    margin: 15px 0;
    font-size: clamp(1rem, 4vw, 1.4rem);
    font-weight: bold;
    line-height: 1.3;
}

/* ===============================
   BOARD
================================= */
.board {
    display: grid;

    /* Responsive cells */
    grid-template-columns: repeat(3, minmax(75px, 1fr));
    gap: clamp(6px, 2vw, 10px);
    width: 100%;
    max-width: 360px;
    margin: 20px auto;
}

/* ===============================
   GAME CELLS
================================= */
.cell {
    /* Perfect square */
    aspect-ratio: 1 / 1;
    width: 100%;
    border: none;
    border-radius: 14px;
    background: #6a0dad;
    color: white;

    /* Responsive symbol size */
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition:
        transform .15s ease,
        box-shadow .15s ease;

    /* Better touch response */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Hover only on desktop devices */
@media (hover: hover) {
    .cell:hover {
        transform: scale(1.05);
        box-shadow: 0 0 15px rgba(106, 13, 173, .4);
    }
}

/* Press effect */
.cell:active {
    transform: scale(.96);
}

/* Taken cells */
.cell.taken {
    cursor: not-allowed;
}

/* ===============================
   CONTROLS
================================= */
.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

/* ===============================
   BUTTONS
================================= */
button {
    background: linear-gradient(135deg, #6a0dad, #8a2be2);
    border: none;
    border-radius: 12px;
    color: white;
    padding: 12px 18px;
    font-size: clamp(14px, 3vw, 16px);
    font-weight: 700;
    cursor: pointer;
    transition: all .25s ease;
    box-shadow: 0 4px 12px rgba(106, 13, 173, 0.25);
    min-height: 48px;

    /* Prevent text selection */
    user-select: none;

    /* Better mobile tap */
    -webkit-tap-highlight-color: transparent;
}

/* Hover effect for desktop */
@media (hover: hover) {
    button:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(106, 13, 173, 0.35);
    }
}

/* Press animation */
button:active {
    transform: scale(.96);
}

/* Sound + Reset buttons */
#soundToggle,
#resetBtn {
    min-width: 140px;
}

/* ===============================
   BACK BUTTON
================================= */
.btn-back-inline {
    display: inline-block;
    margin-top: 12px;
    color: #666;
    font-size: clamp(13px, 3vw, 15px);
    text-decoration: none;
}

/* Hover only for desktop */
@media (hover: hover) {
    .btn-back-inline:hover {
        color: #6a0dad;
    }
}

/* ===============================
   POPUP OVERLAY
================================= */
.popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 9999;
}

/* ===============================
   POPUP BOX
================================= */
.popup-content {
    width: 100%;
    max-width: 340px;
    background: #fff;
    padding: clamp(20px, 5vw, 30px);
    border-radius: 18px;
    text-align: center;
    animation: popupZoom .35s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
}

/* Popup message */
#popupMessage {
    font-size: clamp(1.3rem, 5vw, 2rem);
    font-weight: 700;
    color: #6a0dad;
    line-height: 1.3;
}

/* ===============================
   POPUP ANIMATION
================================= */
@keyframes popupZoom {
    from {
        transform: scale(.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===============================
   IOS INSTALL BANNER
================================= */
#iosInstallBanner {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: white;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.2);
    padding: 12px 15px;
    z-index: 9999;
    animation: slideUp 0.4s ease;
}

/* Banner content */
.ios-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: clamp(13px, 3vw, 14px);
}

/* Install button */
#iosInstallBanner button {
    background: purple;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
}

/* Slide animation */
@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* ===============================
   WINNER EFFECT
================================= */
.winner {
    box-shadow: 0 0 20px #ffd700;
    animation:
        winnerGlow 0.8s infinite alternate,
        winnerPulse 0.6s infinite;
}

/* Pulse animation */
@keyframes winnerPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }
}

/* Glow animation */
@keyframes winnerGlow {
    from {
        box-shadow: 0 0 10px #ffd700;
    }

    to {
        box-shadow: 0 0 25px #ffd700;
    }
}

/* ===============================
   CONFETTI
================================= */
#confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 9998;
}

.confetti {
    position: absolute;
    top: -20px;
    border-radius: 3px;
    animation: confettiFall linear forwards;
    will-change: transform;
}

/* Falling confetti animation */
@keyframes confettiFall {
    from {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    to {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

/* ==================================================
   SMALL MOBILE DEVICES
   (320px - 480px)
================================================== */
@media (max-width: 480px) {

    body {
        padding: 10px;
    }

    .container {
        padding: 16px;
        border-radius: 16px;
    }

    .controls {
        flex-direction: column;
        align-items: center;
    }

    button,
    #soundToggle,
    #resetBtn {
        width: 100%;
        max-width: 260px;
    }

    .ios-content {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ==================================================
   TABLET DEVICES
   (481px - 768px)
================================================== */
@media (min-width: 481px) and (max-width: 768px) {

    .container {
        max-width: 600px;
    }

    .board {
        max-width: 420px;
    }
}

/* ==================================================
   LARGE DESKTOP SCREENS
================================================== */
@media (min-width: 1200px) {

    .container {
        max-width: 560px;
    }

    .board {
        max-width: 400px;
    }
}

/* ==================================================
   LANDSCAPE MOBILE FIX
================================================== */
@media (max-height: 500px) and (orientation: landscape) {

    body {
        padding: 10px;
    }

    .container {
        padding: 14px;
    }

    h1 {
        margin-bottom: 10px;
    }

    .board {
        max-width: 280px;
        gap: 6px;
    }

    .controls {
        margin-top: 10px;
    }
}
/* ==================================================
   TABLET DEVICES
   iPads • Android Tablets • Foldables
================================================== */
@media (min-width: 481px) and (max-width: 1024px) {

    body {
        padding: 24px;
    }

    .container {
        /* Wider layout for tablets */
        max-width: 1020px;
        padding: 28px;
        border-radius: 22px;
    }

    h1 {
        font-size: 2.4rem;
        padding: 18px;
    }

    #status {
        font-size: 1.5rem;
        margin: 18px 0;
    }

    .gamemode {
        font-size: 20px;
    }

    .board {
        /* Bigger board on tablets */
        max-width: 520px;
        gap: 12px;
        margin: 28px auto;
    }

    .cell {
        border-radius: 18px;

        /* Larger symbols */
        font-size: 4rem;
    }

    .controls {
        gap: 16px;
        margin-top: 22px;

        /* Keep buttons in row */
        flex-direction: row;
    }

    button,
    #soundToggle,
    #resetBtn {
        min-width: 170px;
        min-height: 56px;
        font-size: 17px;
        border-radius: 14px;
    }

    .btn-back-inline {
        font-size: 16px;
        margin-top: 16px;
    }

    .popup-content {
        max-width: 420px;
        padding: 34px;
    }

    #popupMessage {
        font-size: 2.2rem;
    }
}