/* ===== MAHJONG SOLITAIRE - GAME STYLES ===== */

/* ===== CSS VARIABLES (Dynamic Theme) ===== */
:root {
    --board-bg: #2C5F2D;
    --tile-bg: #F5E6D3;
    --tile-border: #8B7355;
    --tile-text: #2C1810;
    --tile-shadow: rgba(0, 0, 0, 0.3);
    --tile-selected: #FFD700;
    --tile-hint: #90EE90;
    --tile-matched: #98FB98;
    --primary-btn: #2C5F2D;
    --secondary-btn: #8B4513;
    --btn-text: #FFFFFF;
    --score-color: #FFD700;
    --bg-gradient-start: #1a3a1a;
    --bg-gradient-end: #2C5F2D;
}

/* ===== GLOBAL STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body {
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
    color: #FFFFFF;
}

/* ===== APP CONTAINER ===== */
#app {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* ===== SCREEN SYSTEM ===== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
}

.overlay-screen {
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1000;
}

.screen-content {
    width: 100%;
    max-width: 600px;
    margin: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* ===== TYPOGRAPHY ===== */
.game-title {
    font-size: 3rem;
    font-weight: 700;
    text-align: center;
    color: var(--score-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 0.5rem;
}

.game-subtitle {
    font-size: 1.2rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 1rem;
}

h2 {
    font-size: 2rem;
    color: var(--score-color);
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
}

h3 {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 0.5rem;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--primary-btn);
    color: var(--btn-text);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 120px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: var(--primary-btn);
}

.btn-secondary {
    background: var(--secondary-btn);
}

.btn-large {
    font-size: 1.3rem;
    padding: 16px 32px;
    min-width: 200px;
}

.btn-icon {
    font-size: 1.5em;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

/* ===== DIFFICULTY SELECTOR ===== */
.difficulty-selector,
.theme-selector {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.difficulty-options,
.theme-options {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.difficulty-btn,
.theme-btn {
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
    cursor: pointer;
    transition: all 0.2s ease;
}

.difficulty-btn:hover,
.theme-btn:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.2);
}

.difficulty-btn.active,
.theme-btn.active {
    border-color: var(--score-color);
    background: rgba(255, 215, 0, 0.2);
    color: var(--score-color);
}

.theme-btn {
    min-width: 80px;
    border-color: currentColor;
}

/* ===== GAME SCREEN ===== */
#game-screen {
    flex-direction: column;
    justify-content: space-between;
}

/* ===== TOP BAR ===== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.stats-group {
    display: flex;
    gap: 20px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--score-color);
}

.icon-btn {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ===== GAME BOARD ===== */
#game-board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
    position: relative;
    width: 100%;
    height: 100%;
}

#game-board {
    position: relative;
    transform-style: preserve-3d;
    perspective: 1000px;
    max-width: 100%;
    max-height: 100%;
}

/* ===== MAHJONG TILES ===== */
.tile {
    position: absolute;
    width: 50px;
    height: 66px;
    background: var(--tile-bg);
    border: 2px solid var(--tile-border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    box-shadow:
        2px 2px 4px var(--tile-shadow),
        inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.tile::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: 4px;
    bottom: 4px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, transparent 50%);
    border-radius: 6px;
    pointer-events: none;
}

.tile-symbol {
    position: relative;
    z-index: 1;
    color: var(--tile-text);
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}

.tile.selectable {
    cursor: pointer;
}

.tile.selectable:hover {
    transform: translateY(-4px);
    box-shadow:
        3px 5px 8px var(--tile-shadow),
        inset 0 0 0 1px rgba(255, 255, 255, 0.5),
        0 0 15px rgba(255, 215, 0, 0.3);
    border-color: var(--score-color);
}

.tile.selected {
    border: 3px solid var(--tile-selected);
    transform: translateY(-6px);
    box-shadow:
        4px 6px 12px var(--tile-shadow),
        0 0 20px rgba(255, 215, 0, 0.5);
}

.tile.hint {
    animation: hintPulse 1s ease-in-out;
    border-color: var(--tile-hint);
}

.tile.matched {
    animation: matchAnimation 0.4s ease-out forwards;
}

.tile.blocked {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== TILE ANIMATIONS ===== */
@keyframes hintPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(144, 238, 144, 0); }
    50% { transform: scale(1.1); box-shadow: 0 0 20px rgba(144, 238, 144, 0.8); }
}

@keyframes matchAnimation {
    0% { transform: scale(1) rotate(0deg); opacity: 1; }
    50% { transform: scale(1.2) rotate(10deg); opacity: 0.7; }
    100% { transform: scale(0) rotate(360deg); opacity: 0; }
}

@keyframes tileAppear {
    from {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    to {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.tile.appear {
    animation: tileAppear 0.3s ease-out;
}

/* ===== CONTROL BAR ===== */
.control-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.control-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.control-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.control-btn:active:not(:disabled) {
    transform: translateY(0);
}

.control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.control-btn .btn-icon {
    font-size: 1.8rem;
}

.control-btn .btn-label {
    font-size: 0.75rem;
}

.btn-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 24px;
    height: 24px;
    background: var(--score-color);
    color: #000;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ===== GAME OVER SCREEN ===== */
.final-stats {
    display: flex;
    gap: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin: 20px 0;
}

.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.final-stat-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.final-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--score-color);
}

/* ===== INSTRUCTIONS ===== */
.instructions {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px 0;
}

.instruction-item {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 16px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

.instruction-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.instruction-text h3 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.instruction-text p {
    font-size: 0.9rem;
    line-height: 1.5;
    opacity: 0.9;
}

/* ===== SETTINGS ===== */
.settings-group {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 0;
}

.setting-item label {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.setting-item label:hover {
    background: rgba(255, 255, 255, 0.15);
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.setting-item span {
    font-size: 1rem;
    flex: 1;
}

/* ===== PARTICLES ===== */
#particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.particle {
    position: absolute;
    font-size: 1.5rem;
    opacity: 1;
    animation: particleFly 0.6s ease-out forwards;
    pointer-events: none;
}

@keyframes particleFly {
    from {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }
    to {
        transform: translate(var(--tx), var(--ty)) scale(0);
        opacity: 0;
    }
}

/* ===== RESPONSIVE DESIGN ===== */

/* Small phones */
@media (max-width: 400px) {
    .game-title {
        font-size: 2rem;
    }

    .game-subtitle {
        font-size: 1rem;
    }

    .btn-large {
        font-size: 1.1rem;
        padding: 14px 28px;
    }

    .tile {
        width: 40px;
        height: 53px;
        font-size: 1.5rem;
    }

    .stats-group {
        gap: 12px;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .control-bar {
        gap: 8px;
        padding: 12px;
    }

    .control-btn {
        padding: 10px 12px;
        min-width: 70px;
    }

    .control-btn .btn-icon {
        font-size: 1.5rem;
    }

    .final-stats {
        gap: 15px;
        padding: 15px;
    }

    .final-stat-value {
        font-size: 1.5rem;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .top-bar {
        padding: 8px 12px;
    }

    .stat-value {
        font-size: 1rem;
    }

    .control-bar {
        padding: 10px;
    }

    .control-btn {
        padding: 8px 16px;
        min-width: 60px;
    }

    #game-board-container {
        padding: 10px;
    }

    .screen-content {
        padding: 15px;
        gap: 15px;
    }

    .game-title {
        font-size: 2rem;
    }
}

/* Tablets */
@media (min-width: 768px) {
    .tile {
        width: 60px;
        height: 80px;
        font-size: 2.5rem;
    }

    .game-title {
        font-size: 3.5rem;
    }

    .control-btn {
        min-width: 100px;
        padding: 14px 24px;
    }
}

/* Desktop */
@media (min-width: 1024px) {
    .tile {
        width: 70px;
        height: 93px;
        font-size: 3rem;
    }

    .screen-content {
        max-width: 700px;
    }

    .control-bar {
        gap: 16px;
    }
}

/* ===== ANIMATIONS DISABLED ===== */
.no-animations * {
    animation: none !important;
    transition: none !important;
}

/* ===== LOADING STATE ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--score-color);
}

.loading::after {
    content: '...';
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}
