/* ===========================
   CSS CUSTOM PROPERTIES
   =========================== */
:root {
    /* Jungle green foundation */
    --color-bg-primary: #1f5210;
    --color-bg-secondary: #286615;
    --color-bg-tertiary: #31781a;

    /* Karuba temple gold accents */
    --color-accent-primary: #c98b10;
    --color-accent-secondary: #e8aa28;

    /* Text colors */
    --color-text-primary: #f0e8d0;
    --color-text-secondary: #c8b890;
    --color-text-muted: #7a6a4a;

    /* Shadows and effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.45);
    --shadow-glow: 0 0 20px rgba(201, 139, 16, 0.4);

    /* Spacing scale */
    --space-xs: 0.5rem;
    --space-sm: 1rem;
    --space-md: 1.5rem;
    --space-lg: 2rem;
    --space-xl: 3rem;

    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ===========================
   GLOBAL RESET & BASE
   =========================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari fix */
    overflow-x: hidden;
    touch-action: manipulation; /* Disable double-tap zoom */
}

/* ===========================
   LAYOUT
   =========================== */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: var(--space-md);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.app-header {
    text-align: center;
    padding: var(--space-md);
    border: 2px solid var(--color-accent-primary);
    border-radius: var(--radius-lg);
    background: var(--color-bg-secondary);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.app-header h1 {
    font-size: clamp(1.25rem, 5.5vw, 2rem);
    font-weight: 700;
    margin-bottom: 0.1rem;
    white-space: nowrap;
}

.app-header h1 span {
    font-family: 'Almendra', serif;
    font-size: clamp(1.5rem, 7.5vw, 2.75rem);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.author {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-sm);
    font-style: italic;
}

.deck-status {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
}

.remaining-count {
    font-size: 3rem;
    font-weight: 800;
    color: var(--color-accent-primary);
    line-height: 1;
}

.deck-label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.controls {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
    flex-wrap: wrap;
}

.tile-history {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding-bottom: 0;
}

.app-footer {
    margin-top: -1rem;
    padding-top: var(--space-xs);
    border-top: 1px solid var(--color-bg-tertiary);
    text-align: center;
}

.disclaimer {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    max-width: 500px;
    margin: 0 auto;
}

/* ===========================
   COMPONENTS - BUTTONS
   =========================== */
.btn {
    /* Touch-friendly sizing */
    min-height: 56px;
    min-width: 140px;
    padding: var(--space-sm) var(--space-md);

    /* Visual design */
    border: none;
    border-radius: var(--radius-md);
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    font-size: 1.125rem;
    font-weight: 600;
    font-family: inherit;

    /* Interaction */
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);

    /* Flexbox for icon + text */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);

    /* Remove default button styles */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: scale(0.96);
    transition: transform var(--transition-fast);
}

.btn:focus-visible {
    outline: 3px solid var(--color-accent-secondary);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.btn-primary:hover {
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}


.btn-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.btn-text {
    line-height: 1;
}

.btn.pulse {
    animation: pulse 2s infinite;
}

/* ===========================
   COMPONENTS - TILES
   =========================== */
.tile {
    /* Card appearance */
    background: var(--color-bg-secondary);
    border: 2px solid var(--color-bg-tertiary);
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-md);
    box-shadow: var(--shadow-sm);
    position: relative;

    /* Layout */
    display: flex;
    align-items: center;
    justify-content: center;

    /* Responsive sizing */
    min-height: 56px;

    /* Animation preparation */
    opacity: 0;
    transform: translateY(-20px);
    animation: tileEnter var(--transition-slow) forwards;

    /* Transition for exit */
    transition: all 300ms ease;
}

.tile-number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-accent-primary);
    width: 4rem;
    text-align: center;
    background: var(--color-bg-tertiary);
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    line-height: 1;
}

.tile-order {
    position: absolute;
    top: 0.66rem;
    right: 0.5rem;
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--color-text-secondary);
    line-height: 1;
}

.tile.exiting {
    animation: tileExit 300ms forwards;
}

/* ===========================
   ANIMATIONS
   =========================== */
@keyframes tileEnter {
    0% {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    60% {
        transform: translateY(5px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes tileExit {
    0% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateX(100px) scale(0.8);
    }
}

@keyframes pulse {
    0%, 100% {
        box-shadow: var(--shadow-md), 0 0 0 0 rgba(201, 139, 16, 0.7);
    }
    50% {
        box-shadow: var(--shadow-md), 0 0 0 10px rgba(201, 139, 16, 0);
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    10%, 30%, 50%, 70%, 90% {
        transform: translateX(-5px);
    }
    20%, 40%, 60%, 80% {
        transform: translateX(5px);
    }
}

/* ===========================
   RESPONSIVE DESIGN
   =========================== */
@media (min-width: 768px) {
    .app-container {
        padding: var(--space-xl);
        gap: var(--space-xl);
    }

    .app-header h1 span {
        font-size: 3.5rem;
    }

    .remaining-count {
        font-size: 4rem;
    }

    .controls {
        gap: var(--space-lg);
    }

    .btn {
        min-width: 160px;
        font-size: 1.25rem;
    }

    .tile {
        padding: var(--space-sm) var(--space-lg);
        min-height: 60px;
    }

    .tile-number {
        font-size: 2.75rem;
        width: 4.5rem;
    }

}

@media (min-width: 1024px) {
    .app-container {
        max-width: 800px;
    }

    .tile-history {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
    }
}

/* ===========================
   ACCESSIBILITY
   =========================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 3px solid var(--color-accent-secondary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    .tile {
        border-width: 3px;
    }
}
