/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light theme colors (default) */
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --text-color: #333;
    --card-bg: white;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --border-color: #ddd;
    --placeholder-bg: linear-gradient(45deg, #f0f0f0, #e0e0e0);
    --info-bg: #f5f5f5;
    --history-bg: #fff3e0;
    --primary-color: #1976d2;
    --secondary-color: #ff7043;
    --success-color: #4caf50;
    --error-color: #f44336;
}

/* Only apply system dark theme if no manual theme is set */
:root:not([data-theme]) {
    @media (prefers-color-scheme: dark) {
        --bg-gradient: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
        --text-color: #e2e8f0;
        --card-bg: #2d3748;
        --card-shadow: rgba(0, 0, 0, 0.3);
        --border-color: #4a5568;
        --placeholder-bg: linear-gradient(45deg, #4a5568, #2d3748);
        --info-bg: #1a202c;
        --history-bg: #2d3748;
        --primary-color: #63b3ed;
        --secondary-color: #ed8936;
        --success-color: #68d391;
        --error-color: #fc8181;
    }
}

/* Manual dark theme override */
[data-theme="dark"] {
    --bg-gradient: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    --text-color: #e2e8f0;
    --card-bg: #2d3748;
    --card-shadow: rgba(0, 0, 0, 0.3);
    --border-color: #4a5568;
    --placeholder-bg: linear-gradient(45deg, #4a5568, #2d3748);
    --info-bg: #1a202c;
    --history-bg: #2d3748;
    --primary-color: #63b3ed;
    --secondary-color: #ed8936;
    --success-color: #68d391;
    --error-color: #fc8181;
}

/* Manual light theme override */
[data-theme="light"] {
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --text-color: #333;
    --card-bg: white;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --border-color: #ddd;
    --placeholder-bg: linear-gradient(45deg, #f0f0f0, #e0e0e0);
    --info-bg: #f5f5f5;
    --history-bg: #fff3e0;
    --primary-color: #1976d2;
    --secondary-color: #ff7043;
    --success-color: #4caf50;
    --error-color: #f44336;
}

/* Icon styling for SVG images */
.icon {
    width: 24px;
    height: 24px;
    display: inline-block;
    vertical-align: middle;
    fill: currentColor;
}

/* Icon color adjustments based on context and theme */
/* Title header icons - white on gradient background */
.title .icon {
    filter: brightness(0) invert(1);
}

/* Card placeholder and history empty icons - dark on white background */
.card-placeholder .icon,
.history-empty .icon {
    filter: brightness(0) invert(0.2);
}

/* Button icons - white on colored backgrounds */
.btn-primary .icon,
.btn-secondary .icon {
    filter: brightness(0) invert(1);
}

/* Outline button icons - match theme text color */
.btn-outline .icon {
    filter: brightness(0) invert(0.2);
}

/* Reshuffle history icon - match secondary color */
.history-item .reshuffle-icon {
    filter: brightness(0) saturate(100%) invert(0.5) sepia(1) saturate(5)
        hue-rotate(15deg);
}

/* Dark theme adjustments */
[data-theme="dark"] .card-placeholder .icon,
[data-theme="dark"] .history-empty .icon {
    filter: brightness(0) invert(0.8);
}

[data-theme="dark"] .btn-outline .icon {
    filter: brightness(0) invert(0.8);
}

/* System dark theme adjustments */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .card-placeholder .icon,
    :root:not([data-theme]) .history-empty .icon {
        filter: brightness(0) invert(0.8);
    }

    :root:not([data-theme]) .btn-outline .icon {
        filter: brightness(0) invert(0.8);
    }
}

/* Theme toggle styling */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#theme-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 12px 16px;
    border: none;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    min-width: 180px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-direction: column;
}

#theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#theme-toggle-btn:active {
    transform: translateY(0);
}

.theme-icon {
    font-size: 18px;
    display: flex;
    align-items: center;
}

.theme-text {
    font-size: 12px;
    font-weight: 600;
}

.theme-current {
    font-size: 10px;
    opacity: 0.8;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    margin-bottom: 2px;
}

.theme-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Theme-specific button styling */
[data-theme="dark"] #theme-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] #theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

[data-theme="light"] #theme-toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.3);
}

[data-theme="light"] #theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

body {
    font-family: "Roboto", sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-color);
    line-height: 1.6;
    transition:
        all 0.3s ease,
        background 0.3s ease,
        color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    flex-wrap: wrap;
}

.title {
    color: white;
    font-size: 2.5rem;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.title .icon {
    width: 2.5rem;
    height: 2.5rem;
}

.theme-toggle {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Main Content */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 2rem;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 8px 32px var(--card-shadow);
    margin-bottom: 2rem;
}

/* Deck Selection */
.deck-selection {
    grid-column: 1 / -1;
    margin-bottom: 1rem;
}

.deck-selection h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-weight: 500;
}

.deck-options {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
}

.deck-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.deck-option input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary-color);
}

.deck-option label {
    cursor: pointer;
    font-weight: 500;
}

.deck-settings {
    padding: 1rem;
    background: var(--info-bg);
    border-radius: 8px;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary-color);
}

.setting-item label {
    cursor: pointer;
}

/* Card Display */
.card-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.current-card {
    width: 200px;
    height: 280px;
    margin-bottom: 1rem;
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.card-placeholder {
    width: 100%;
    height: 100%;
    background: white !important; /* Always white background for card placeholder */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666 !important; /* Fixed color for placeholder text */
    border: 2px dashed #ddd !important; /* Fixed border color */
    border-radius: 12px;
}

.card-placeholder .icon {
    width: 3rem;
    height: 3rem;
    margin-bottom: 0.5rem;
}

.card-image-container {
    width: 100%;
    height: 100%;
    background: white !important; /* Always white background for cards */
    border-radius: 12px;
    overflow: hidden;
}

.card-image-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white !important; /* Always white background for card images */
    border-radius: 8px;
}

.card-info h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.card-info p {
    color: var(--text-color);
    opacity: 0.8;
    font-size: 0.9rem;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.primary-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-height: 48px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
}

.btn-primary:hover {
    background: var(--primary-color);
    filter: brightness(0.9);
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
    box-shadow: 0 2px 8px rgba(255, 112, 67, 0.3);
}

.btn-secondary:hover {
    background: var(--secondary-color);
    filter: brightness(0.9);
    box-shadow: 0 4px 12px rgba(255, 112, 67, 0.4);
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

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

.deck-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--info-bg);
    border-radius: 8px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-color);
    opacity: 0.8;
}

.info-item .icon {
    width: 1.2rem;
    height: 1.2rem;
    color: var(--primary-color);
}

/* History */
.history {
    grid-column: 1 / -1;
    margin-top: 1rem;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.history-header h2 {
    color: var(--primary-color);
    font-weight: 500;
}

.history-empty {
    text-align: center;
    color: var(--text-color);
    opacity: 0.6;
    padding: 2rem;
}

.history-empty .icon {
    width: 3rem;
    height: 3rem;
    display: block;
    margin: 0 auto 0.5rem auto;
}

.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    background: white !important; /* Always white background for history items */
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
    box-shadow: 0 2px 8px var(--card-shadow);
    border-left: 4px solid var(--primary-color);
    transition: transform 0.2s ease;
}

.history-item:hover {
    transform: translateY(-2px);
}

.history-item.reshuffle {
    border-left-color: var(--secondary-color);
    background: var(--history-bg);
}

.history-item .card-mini {
    width: 60px;
    height: 84px;
    margin: 0 auto 0.5rem;
    border-radius: 4px;
    overflow: hidden;
    background: white !important; /* Always white background for card thumbnails */
    box-shadow: 0 1px 4px var(--card-shadow);
}

.history-item .card-mini img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: white !important; /* Always white background for card mini images */
    border-radius: 2px;
}

.history-item .card-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: #333 !important; /* Fixed color for card names in history */
    margin-bottom: 0.25rem;
}

.history-item .card-time {
    font-size: 0.7rem;
    color: #666 !important; /* Fixed color for card time in history */
    opacity: 0.7;
}

.history-item .reshuffle-icon {
    width: 2rem;
    height: 2rem;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

/* Footer */
.footer {
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    padding: 1rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .title {
        font-size: 2rem;
    }

    .title .icon {
        width: 2rem;
        height: 2rem;
    }

    .main-content {
        grid-template-columns: 1fr;
        padding: 1.5rem;
        gap: 1.5rem;
    }

    .deck-options {
        flex-direction: column;
        gap: 1rem;
    }

    .current-card {
        width: 160px;
        height: 224px;
    }

    .primary-controls {
        width: 100%;
    }

    .deck-info {
        order: -1;
    }

    .history-list {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .history-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .header {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
        justify-content: center;
    }

    .theme-toggle {
        order: -1;
        margin-bottom: 1rem;
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 1.5rem;
        flex-direction: column;
        gap: 0.25rem;
        text-align: center;
    }

    .header {
        text-align: center;
    }

    .main-content {
        padding: 1rem;
    }

    .current-card {
        width: 140px;
        height: 196px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .history-list {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
}

/* Animations */
@keyframes cardDraw {
    0% {
        transform: scale(0.8) rotateY(180deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.05) rotateY(90deg);
        opacity: 0.5;
    }
    100% {
        transform: scale(1) rotateY(0deg);
        opacity: 1;
    }
}

.card-draw-animation {
    animation: cardDraw 0.6s ease-out;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.pulse-animation {
    animation: pulse 0.3s ease-out;
}

/* Scrollbar Styling */
.history-list::-webkit-scrollbar {
    width: 8px;
}

.history-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
    filter: brightness(0.9);
}

/* Focus states for accessibility */
.btn:focus,
input:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        background: #000;
        color: #fff;
    }

    .btn-secondary {
        background: #333;
        color: #fff;
    }

    .card-placeholder {
        border-color: #000;
        color: #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
