/**
 * Emoji Match Rush - Mobile-First Game Styles
 *
 * @file        styles.css
 * @author      Mike Fairbrother <mike@fairbrother.me>
 * @copyright   2024-2026 Mike Fairbrother. All rights reserved.
 * @license     PROPRIETARY - No rights to copy, modify, distribute, or reuse
 *              any part of this code without explicit written permission from the author.
 */

:root {
    --bg-dark: #0f0c29;
    --bg-mid: #1a1640;
    --text-primary: #fff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --accent: #ffd93d;
    --accent-glow: rgba(255, 217, 61, 0.4);
    --danger: #ff4757;
    --success: #2ed573;
    --fire-a: #ff6b6b;
    --fire-b: #ff9f43;
    --cell-bg: rgba(255, 255, 255, 0.06);
    --cell-radius: 6px;
    --transition-fast: 150ms;
    --transition-normal: 300ms;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

/* ---- App container ---- */
#app {
    position: relative;
    width: 100%;
    max-width: 420px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    overflow: hidden;
    background: linear-gradient(170deg, #1a1640 0%, #0f0c29 40%, #1e1245 100%);
}

/* ---- Screen system ---- */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}
.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}
.screen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    padding: 40px 24px;
    text-align: center;
    overflow-y: auto;
}

/* ---- Menu Screen ---- */
.game-logo {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    justify-content: center;
}
.logo-emoji {
    font-size: 40px;
    animation: logo-bounce 2s ease-in-out infinite;
}
.logo-emoji:nth-child(1) { animation-delay: 0s; }
.logo-emoji:nth-child(2) { animation-delay: 0.15s; }
.logo-emoji:nth-child(3) { animation-delay: 0.3s; }

@keyframes logo-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.1); }
}

.game-title {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    background: linear-gradient(135deg, #fff 0%, #ffd93d 50%, #ff6b6b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}
.game-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}
.menu-best {
    font-size: 18px;
    color: var(--accent);
    margin-bottom: 24px;
    font-weight: 600;
}

.settings-row {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    justify-content: center;
}
.pause-settings {
    margin-top: 20px;
}

/* ---- Footer ---- */
.game-footer {
    margin-top: 16px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.5px;
    font-weight: 500;
    flex-shrink: 0;
}
.game-footer a {
    color: inherit;
    text-decoration: none;
}
.game-footer a:hover {
    text-decoration: underline;
}

/* ---- Buttons ---- */
.btn {
    display: block;
    width: 220px;
    padding: 16px 32px;
    border: none;
    border-radius: 16px;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    letter-spacing: 0.5px;
    font-family: inherit;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
    background: linear-gradient(135deg, #ffd93d, #ff9f43);
    color: #1a1640;
    box-shadow: 0 4px 20px rgba(255, 217, 61, 0.3);
}
.btn-primary:active { box-shadow: 0 2px 10px rgba(255, 217, 61, 0.2); }
.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    margin-top: 12px;
    font-size: 16px;
    padding: 12px 32px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }
.icon-btn-sm {
    width: 30px;
    height: 30px;
    font-size: 14px;
}
.icon-btn.off {
    opacity: 0.4;
}

/* ---- Game Header ---- */
#screen-game { display: flex; flex-direction: column; }

#game-header {
    display: flex;
    align-items: center;
    padding: 10px 12px 6px;
    gap: 8px;
    min-height: 52px;
}
.stat {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.stat-right { align-items: flex-end; }
.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.stat-value {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}

/* ---- Combo bar ---- */
#combo-bar {
    text-align: center;
    padding: 2px 0 4px;
    min-height: 22px;
    transition: opacity 0.2s;
}
#combo-bar.hidden { display: none !important; }
#combo-text {
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-glow);
    animation: combo-pop 0.3s ease-out;
}
@keyframes combo-pop {
    0% { transform: scale(0.5); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ---- Board ---- */
#board-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 4px 8px 0;
    position: relative;
    overflow: hidden;
    min-height: 0;
}
#board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 3px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 6px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3);
    aspect-ratio: 1;
    width: 100%;
    max-width: 380px;
    max-height: calc(100% - 4px);
    position: relative;
}

/* ---- Emoji Cells ---- */
.cell {
    background: var(--cell-bg);
    border-radius: var(--cell-radius);
    aspect-ratio: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 4.5vw, 32px);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
    overflow: hidden;
    line-height: 1;
}
.cell:active {
    transform: scale(0.92);
}
.cell.selected {
    background: rgba(255, 217, 61, 0.15);
    box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent-glow);
    transform: scale(1.08);
    z-index: 2;
}
.cell.hint {
    animation: hint-pulse 0.8s ease-in-out infinite;
}
@keyframes hint-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 217, 61, 0); }
    50% { box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.4); }
}

/* Special tile indicators */
.cell .special-indicator {
    position: absolute;
    bottom: 1px;
    right: 1px;
    font-size: 10px;
    line-height: 1;
    pointer-events: none;
    filter: drop-shadow(0 0 2px rgba(0,0,0,0.5));
}

/* Match clear animation */
.cell.clearing {
    animation: cell-clear 0.35s ease-out forwards;
    pointer-events: none;
}
@keyframes cell-clear {
    0%   { transform: scale(1);   opacity: 1; }
    40%  { transform: scale(1.3); opacity: 0.8; }
    100% { transform: scale(0);   opacity: 0; }
}

/* Fall animation */
.cell.falling {
    transition: none;
    animation: cell-fall var(--fall-duration, 0.25s) ease-in forwards;
}
@keyframes cell-fall {
    from { transform: translateY(var(--fall-from, -50px)); opacity: 0.7; }
    to   { transform: translateY(0); opacity: 1; }
}

/* Spawn (new from top) */
.cell.spawning {
    animation: cell-spawn 0.3s ease-out forwards;
}
@keyframes cell-spawn {
    0%   { transform: scale(0.3) translateY(-20px); opacity: 0; }
    60%  { transform: scale(1.1) translateY(0); }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* Swap animation */
.cell.swapping {
    transition: transform 0.2s ease-in-out;
    z-index: 5;
}

/* Invalid swap shake */
.cell.invalid-swap {
    animation: shake-cell 0.3s ease-out;
}
@keyframes shake-cell {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* Special tile glow */
.cell.special-bomb {
    background: rgba(255, 107, 107, 0.15);
}
.cell.special-area {
    background: rgba(160, 94, 234, 0.15);
}
.cell.special-rainbow {
    background: rgba(255, 217, 61, 0.15);
    animation: rainbow-glow 2s ease-in-out infinite;
}
@keyframes rainbow-glow {
    0%, 100% { box-shadow: 0 0 6px rgba(255, 107, 107, 0.3); }
    33% { box-shadow: 0 0 6px rgba(46, 213, 115, 0.3); }
    66% { box-shadow: 0 0 6px rgba(95, 124, 255, 0.3); }
}

/* ---- Level Bar ---- */
#level-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 12px;
    flex-shrink: 0;
}
.level-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}
.level-progress {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}
.level-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--fire-b));
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* ---- Score Popup ---- */
.score-popup {
    position: absolute;
    font-size: 16px;
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 20;
    animation: score-float 0.9s ease-out forwards;
    white-space: nowrap;
    transform: translateX(-50%);
}
.score-popup.big-combo {
    font-size: 22px;
    color: var(--fire-a);
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}
@keyframes score-float {
    0%   { transform: translateX(-50%) translateY(0) scale(0.5); opacity: 0; }
    20%  { transform: translateX(-50%) translateY(-10px) scale(1.1); opacity: 1; }
    100% { transform: translateX(-50%) translateY(-60px) scale(0.9); opacity: 0; }
}

/* ---- Particles ---- */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}
.particle {
    position: fixed;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: particle-fly 0.65s ease-out forwards;
    z-index: 200;
}
@keyframes particle-fly {
    0%   { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* Screen shake */
.shake { animation: shake 0.3s ease-out; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px); }
    40% { transform: translateX(3px); }
    60% { transform: translateX(-2px); }
    80% { transform: translateX(1px); }
}

/* ---- Game Over Screen ---- */
.gameover-title {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 8px;
}
#new-best-badge {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    background: rgba(255, 217, 61, 0.15);
    padding: 6px 20px;
    border-radius: 20px;
    margin-bottom: 16px;
    animation: badge-pop 0.5s ease-out;
}
@keyframes badge-pop {
    0%  { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}
.hidden { display: none !important; }

.final-score-block, .final-best-block { margin-bottom: 6px; }
.final-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.final-value {
    font-size: 52px;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.final-value-small {
    font-size: 26px;
    color: var(--text-secondary);
}
.final-stats {
    display: flex;
    gap: 20px;
    margin: 20px 0 16px;
    flex-wrap: wrap;
    justify-content: center;
}
.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.final-stat-num {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.final-stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}
.motivation-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--fire-a);
    margin-bottom: 20px;
    animation: badge-pop 0.5s ease-out 0.3s both;
}

/* ---- Back to Games ---- */
.back-to-games-inline {
    display: inline-block;
    color: rgba(255, 255, 255, 0.35);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 10px;
    margin-bottom: 12px;
    transition: color 150ms, background 150ms;
}
.back-to-games-inline:active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
.gameover-back {
    margin-top: 12px;
    margin-bottom: 0;
}

/* ---- Overlays ---- */
.game-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.game-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.overlay-title {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 20px;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 20px;
}
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: linear-gradient(170deg, #1e1650, #150f35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 28px 24px;
    max-width: 360px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.25s ease;
}
.modal-overlay.active .modal-content {
    transform: scale(1);
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 20px;
}
.help-section {
    margin-bottom: 14px;
    text-align: left;
}
.help-emoji-row {
    font-size: 28px;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 4px;
}
.help-text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.help-text strong {
    color: var(--text-primary);
}

/* ---- Responsive ---- */
@media (min-width: 421px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: #080620;
    }
    #app {
        border-radius: 24px;
        box-shadow: 0 0 60px rgba(30, 20, 80, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.05);
        max-height: 900px;
    }
}

@supports (padding-top: env(safe-area-inset-top)) {
    #game-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
}
