/* CSS Reset & Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Card Colors - customizable */
    --card-red: #d40000;
    --card-black: #000000;
    --card-back-primary: #1e3a5f;
    --card-back-secondary: #c9a227;

    /* Table Backgrounds */
    --table-green: #1a5f2a;
    --table-blue: #1a3f5f;
    --table-red: #5f1a1a;
    --table-wood: #8b5a2b;
    --table-dark: #1a1a1a;

    /* Current Theme */
    --table-bg: var(--table-green);
    --table-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");

    /* UI Colors */
    --ui-primary: #c9a227;
    --ui-secondary: #ffffff;
    --ui-bg: rgba(0, 0, 0, 0.7);
    --ui-hover: rgba(255, 255, 255, 0.1);
    --ui-active: rgba(255, 255, 255, 0.2);
    --ui-border: rgba(255, 255, 255, 0.2);

    /* Typography */
    --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-display: Georgia, 'Times New Roman', serif;

    /* Card Dimensions */
    --card-width: 100px;
    --card-height: 140px;
    --card-radius: 8px;
    --card-gap: 15px;
    --stack-offset: 25px;
    --cascade-offset: 30px;

    /* Animation Speed */
    --anim-speed: 0.3s;

    /* Z-indices */
    --z-cards: 1;
    --z-dragging: 1000;
    --z-header: 100;
    --z-panel: 500;
    --z-modal: 600;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background: var(--table-bg);
    color: white;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-image: var(--table-pattern);
    background-color: var(--table-bg);
}

/* Screen Management */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    z-index: 1;
}

.screen.active {
    display: flex;
    z-index: 10;
}

#menu-screen.active {
    z-index: 100;
}

/* Loading Screen */
#loading-screen {
    justify-content: center;
    align-items: center;
    background: var(--table-bg);
    z-index: 9999;
}

.loading-content {
    text-align: center;
}

.loading-cards {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

.loading-card {
    width: 40px;
    height: 56px;
    background: linear-gradient(135deg, var(--card-back-primary), var(--card-back-secondary));
    border-radius: 4px;
    animation: loadingBounce 0.6s ease-in-out infinite;
}

.loading-card:nth-child(2) { animation-delay: 0.1s; }
.loading-card:nth-child(3) { animation-delay: 0.2s; }
.loading-card:nth-child(4) { animation-delay: 0.3s; }

@keyframes loadingBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

/* Landing Page */
#landing-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 50%, #0a0a1a 100%);
    z-index: 10000;
    overflow: hidden;
}

#landing-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(201, 162, 39, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(201, 162, 39, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.landing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 20px;
    max-width: 100%;
    max-height: 100%;
    animation: fadeIn 1s ease-out;
}

.landing-image-wrapper {
    position: relative;
    max-width: 90vw;
    max-height: 60vh;
    animation: floatImage 6s ease-in-out infinite;
}

.landing-hero-image {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
    border-radius: 16px;
    box-shadow:
        0 0 60px rgba(201, 162, 39, 0.3),
        0 0 120px rgba(201, 162, 39, 0.2),
        0 20px 60px rgba(0, 0, 0, 0.5);
}

@keyframes floatImage {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.enter-games-btn {
    position: relative;
    padding: 18px 60px;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(135deg, #c9a227 0%, #f4d675 50%, #c9a227 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    overflow: hidden;
    box-shadow:
        0 4px 20px rgba(201, 162, 39, 0.4),
        0 0 40px rgba(201, 162, 39, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    animation: pulseGlow 2s ease-in-out infinite;
}

.enter-games-btn:hover {
    transform: scale(1.05);
    box-shadow:
        0 6px 30px rgba(201, 162, 39, 0.6),
        0 0 60px rgba(201, 162, 39, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.enter-games-btn:active {
    transform: scale(0.98);
}

.enter-games-btn .btn-text {
    position: relative;
    z-index: 2;
}

.enter-games-btn .btn-sparkle {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: sparkleMove 3s ease-in-out infinite;
}

@keyframes sparkleMove {
    0% { left: -100%; }
    50%, 100% { left: 100%; }
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow:
            0 4px 20px rgba(201, 162, 39, 0.4),
            0 0 40px rgba(201, 162, 39, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow:
            0 4px 30px rgba(201, 162, 39, 0.6),
            0 0 60px rgba(201, 162, 39, 0.4),
            inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
}

/* Floating particles for landing page */
.landing-container::before,
.landing-container::after {
    content: '✦';
    position: absolute;
    font-size: 20px;
    color: rgba(201, 162, 39, 0.6);
    animation: floatParticle 4s ease-in-out infinite;
}

.landing-container::before {
    top: 20%;
    left: 10%;
    animation-delay: 0s;
}

.landing-container::after {
    bottom: 20%;
    right: 10%;
    animation-delay: 2s;
}

@keyframes floatParticle {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
        opacity: 0.6;
    }
    50% {
        transform: translateY(-20px) rotate(180deg);
        opacity: 1;
    }
}

/* Responsive landing page */
@media (max-width: 768px) {
    .enter-games-btn {
        padding: 14px 40px;
        font-size: 1.2rem;
    }

    .landing-image-wrapper {
        max-height: 50vh;
    }

    .landing-hero-image {
        max-height: 50vh;
    }
}

/* Game Screen Layout */
#game-screen {
    flex-direction: column;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--ui-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: var(--z-header);
    border-bottom: 1px solid var(--ui-border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-app-icon {
    width: 45px;
    height: 45px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    object-fit: cover;
}

.header-btn {
    min-width: 44px;
    height: 44px;
    border: none;
    background: var(--ui-hover);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--anim-speed);
    color: white;
    font-size: 16px;
    gap: 5px;
    padding: 0 12px;
}

.header-btn.labeled {
    flex-direction: column;
    padding: 6px 10px;
    height: auto;
    min-height: 50px;
    gap: 2px;
}

.header-btn .btn-icon {
    font-size: 18px;
    line-height: 1;
}

.header-btn .btn-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.9;
}

.header-btn:hover {
    background: var(--ui-active);
}

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

.header-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.game-info {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}

.game-info span {
    padding: 5px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
}

#current-game-name {
    font-weight: bold;
    color: var(--ui-primary);
    background: rgba(201, 162, 39, 0.2);
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* Icon Styles using CSS */
.menu-icon::before { content: '☰'; }
.undo-icon::before { content: '↩'; }
.hint-icon::before { content: '💡'; font-size: 16px; }
.new-game-icon::before { content: '🔄'; font-size: 16px; }
.settings-icon::before { content: '⚙'; }
.stats-icon::before { content: '📊'; }

/* Game Table */
.game-table {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Card Slot (empty placeholder) */
.card-slot {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: var(--card-radius);
    background: rgba(0, 0, 0, 0.1);
    position: relative;
}

.card-slot.highlight {
    border-color: var(--ui-primary);
    box-shadow: 0 0 15px rgba(201, 162, 39, 0.5);
}

/* Pile containers */
.pile {
    position: relative;
    width: var(--card-width);
    min-height: var(--card-height);
}

/* Tableau (cascading piles) */
.tableau-pile {
    min-height: calc(var(--card-height) + 200px);
}

.tableau-pile .card {
    position: absolute;
    left: 0;
}

/* Foundation piles */
.foundation-pile .card {
    position: absolute;
    left: 0;
    top: 0;
}

/* Stock pile */
.stock-pile {
    cursor: pointer;
}

.stock-pile.empty {
    cursor: pointer;
}

.stock-pile.empty::after {
    content: '↻';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 40px;
    color: rgba(255, 255, 255, 0.5);
}

/* Waste pile */
.waste-pile .card {
    position: absolute;
    left: 0;
    top: 0;
}

/* Panels (Settings & Stats) */
.panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 100%;
    max-width: 400px;
    height: 100%;
    background: var(--ui-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: var(--z-panel);
    transition: right var(--anim-speed) ease;
    overflow-y: auto;
}

.panel.active {
    right: 0;
}

.panel-content {
    padding: 20px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--ui-border);
}

.panel-header h2 {
    font-size: 24px;
    font-weight: 600;
}

.close-panel-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: white;
    font-size: 28px;
    cursor: pointer;
    border-radius: 50%;
    transition: background var(--anim-speed);
}

.close-panel-btn:hover {
    background: var(--ui-hover);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: var(--z-modal);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(145deg, #2a2a2a, #1a1a1a);
    border-radius: 16px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--ui-border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    margin-bottom: 20px;
    color: var(--ui-primary);
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

.modal-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all var(--anim-speed);
    background: var(--ui-hover);
    color: white;
}

.modal-btn.primary {
    background: var(--ui-primary);
    color: #000;
    font-weight: bold;
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* Help Modal */
.help-content {
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.help-content .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--ui-border);
    margin-bottom: 15px;
}

.help-content .close-modal-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: white;
    font-size: 24px;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.help-content .close-modal-btn:hover {
    background: var(--ui-hover);
}

.help-body {
    flex: 1;
    overflow-y: auto;
    text-align: left;
    padding-right: 10px;
}

.help-body h3 {
    color: var(--ui-primary);
    margin: 20px 0 10px 0;
    font-size: 16px;
}

.help-body h3:first-child {
    margin-top: 0;
}

.help-body p {
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.6;
    margin-bottom: 10px;
}

.help-body ul {
    margin: 10px 0;
    padding-left: 20px;
}

.help-body li {
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.6;
    margin-bottom: 8px;
}

.help-body .tip {
    background: rgba(201, 162, 39, 0.15);
    border-left: 3px solid var(--ui-primary);
    padding: 10px 15px;
    margin: 15px 0;
    border-radius: 0 8px 8px 0;
}

.help-body .tip strong {
    color: var(--ui-primary);
}

.modal-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--ui-border);
    text-align: center;
}

/* Win Modal */
.win-content {
    background: linear-gradient(145deg, #2a4a2a, #1a3a1a);
    border: 2px solid var(--ui-primary);
}

.win-content h2 {
    font-size: 32px;
    margin-bottom: 10px;
}

.win-message {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 25px;
}

.win-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 25px;
}

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

.win-stat .label {
    display: block;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
    margin-bottom: 5px;
}

.win-stat .value {
    display: block;
    font-size: 28px;
    font-weight: bold;
    color: var(--ui-primary);
}

.win-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.win-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all var(--anim-speed);
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.win-btn.primary {
    background: var(--ui-primary);
    color: #000;
    font-weight: bold;
}

.win-btn:hover {
    transform: translateY(-2px);
}

/* Overlay for panels */
.panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-panel) - 1);
    display: none;
}

.panel-overlay.active {
    display: block;
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --card-width: 65px;
        --card-height: 91px;
        --card-gap: 8px;
        --stack-offset: 18px;
        --cascade-offset: 22px;
    }

    .game-header {
        padding: 8px 10px;
        flex-wrap: wrap;
    }

    .header-btn.labeled {
        padding: 4px 8px;
        min-height: 44px;
    }

    .header-btn .btn-label {
        font-size: 9px;
    }

    .header-btn .btn-icon {
        font-size: 16px;
    }

    .header-actions {
        gap: 5px;
    }

    .game-info {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 8px;
        gap: 8px;
        font-size: 12px;
    }

    .game-info span {
        padding: 3px 8px;
    }

    .panel {
        max-width: 100%;
    }

    .help-content {
        max-height: 90vh;
        margin: 10px;
    }
}

@media (max-width: 480px) {
    :root {
        --card-width: 50px;
        --card-height: 70px;
        --stack-offset: 15px;
        --cascade-offset: 18px;
    }

    .game-table {
        padding: 10px 5px;
    }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    :root {
        --card-width: 55px;
        --card-height: 77px;
    }

    .game-header {
        padding: 5px 15px;
    }

    .game-table {
        padding: 10px;
    }
}

/* Large screens */
@media (min-width: 1200px) {
    :root {
        --card-width: 120px;
        --card-height: 168px;
        --card-gap: 20px;
        --stack-offset: 30px;
        --cascade-offset: 35px;
    }
}

/* Touch-friendly sizing */
@media (hover: none) and (pointer: coarse) {
    .header-btn {
        width: 48px;
        height: 48px;
    }
}

/* Table Background Themes */
body.bg-green-felt {
    --table-bg: #1a5f2a;
    background-color: #1a5f2a;
}

body.bg-blue-felt {
    --table-bg: #1a3f5f;
    background-color: #1a3f5f;
}

body.bg-red-felt {
    --table-bg: #5f1a1a;
    background-color: #5f1a1a;
}

body.bg-wood {
    --table-bg: #8b5a2b;
    background-color: #8b5a2b;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='0.1'%3E%3Cpath d='M0 0h100v2H0zM0 20h100v1H0zM0 40h100v2H0zM0 60h100v1H0zM0 80h100v2H0z'/%3E%3C/g%3E%3C/svg%3E");
}

body.bg-dark {
    --table-bg: #1a1a1a;
    background-color: #1a1a1a;
    background-image: none;
}

/* Print styles - hide everything for print */
@media print {
    body {
        display: none;
    }
}
