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

:root {
    --color-primary: #3b82f6;
    --color-primary-dark: #2563eb;
    --color-secondary: #10b981;
    --color-accent: #f59e0b;
    --color-coffee: #ffdd00;
    --color-coffee-dark: #e6c800;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-bg: #f9fafb;
    --color-white: #ffffff;
    --color-border: #e5e7eb;
    --color-korean-pink: #ff69b4;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 50%, #0ea5e9 100%);
    color: var(--color-white);
    padding: 4rem 0;
    text-align: center;
}

.hero-content {
    max-width: 800px;
    margin: 0 auto;
}

.hero h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: -0.025em;
}

.hero-subtitle {
    font-size: 1.25rem;
    opacity: 0.9;
    margin-bottom: 2rem;
}

.hero-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.875rem;
    opacity: 0.8;
    margin-top: 0.25rem;
}

/* Section Titles */
.section-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--color-text);
}

/* Collections Section */
.collections {
    padding: 4rem 0;
}

.collection-card {
    background: var(--color-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    margin-bottom: 2rem;
    border: 1px solid var(--color-border);
}

.collection-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.collection-icon {
    font-size: 2.5rem;
    width: 4rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: var(--radius-lg);
    flex-shrink: 0;
}

.collection-icon.korean-icon {
    font-family: 'Noto Sans KR', sans-serif;
    font-weight: 700;
    background: linear-gradient(135deg, #ffe4e6 0%, #fecdd3 100%);
    color: var(--color-korean-pink);
}

.collection-title-group {
    flex: 1;
    min-width: 200px;
}

.collection-title-group h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.25rem;
}

.collection-subtitle {
    color: var(--color-text-light);
    font-size: 1rem;
}

.collection-meta {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge-bidirectional {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-audio {
    background: #d1fae5;
    color: #047857;
}

.badge-examples {
    background: #fef3c7;
    color: #b45309;
}

.collection-description {
    color: var(--color-text);
    margin-bottom: 1.5rem;
    font-size: 1.0625rem;
}

.feature-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.feature-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-light);
    font-size: 0.9375rem;
}

.feature-list li::before {
    content: "✓";
    color: var(--color-secondary);
    font-weight: 700;
    flex-shrink: 0;
}

/* Preview Section */
.preview-section {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.preview-section h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 1rem;
}

.preview-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.preview-tab {
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    background: var(--color-white);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.preview-tab:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.preview-tab.active {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
}

.preview-cards {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Card wrapper showing front and back side by side */
.preview-card-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

@media (max-width: 768px) {
    .preview-card-wrapper {
        grid-template-columns: 1fr;
    }
}

.preview-card-side {
    display: flex;
    flex-direction: column;
}

/* Anki card container that holds the actual card with its CSS */
.anki-card-container {
    flex: 1;
    min-height: 150px;
    border-radius: var(--radius-md);
    overflow: hidden;
}

/* Override some Anki card styles for better preview display */
.anki-card-container .card {
    min-height: 150px;
    height: 100%;
    margin: 0;
}

/* Style for audio containers and buttons in modal */
.modal-card-content .audio-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 15px 0;
    text-align: center;
    position: relative;
    z-index: 1;
}

.modal-card-content button.replay-button {
    cursor: pointer;
    position: relative;
    z-index: 1;
    display: inline-block;
    padding: 12px 24px;
    background: linear-gradient(135deg, #ff69b4 0%, #ff1493 100%);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 8px rgba(255, 105, 180, 0.3);
    transition: all 0.3s ease;
    border: none;
    font-family: 'Noto Sans KR', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
}

.modal-card-content button.replay-button:hover {
    background: linear-gradient(135deg, #ff1493 0%, #c71585 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(255, 105, 180, 0.4);
}

.modal-card-content button.replay-button:active {
    transform: scale(0.95);
}

.modal-card-content button.replay-button::before {
    content: "🔊 ";
}

.preview-card {
    background: var(--color-white);
    border-radius: var(--radius-md);
    padding: 1rem;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.preview-card-front {
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed var(--color-border);
    margin-bottom: 0.75rem;
}

.preview-card-label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-light);
    margin-bottom: 0.25rem;
}

.preview-card-content {
    font-size: 1rem;
    color: var(--color-text);
}

.preview-card-content.korean {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--color-korean-pink);
}

.preview-card-romanization {
    font-size: 0.8125rem;
    color: var(--color-text-light);
    font-style: italic;
    margin-top: 0.25rem;
}

.preview-card-example {
    font-size: 0.875rem;
    color: var(--color-text-light);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dotted var(--color-border);
}

.preview-card-example .korean {
    font-family: 'Noto Sans KR', sans-serif;
    color: var(--color-text);
}

/* Letters Preview Specific */
.letters-preview .preview-card {
    text-align: center;
}

.letters-preview .preview-card-content.korean {
    font-size: 2.5rem;
    margin: 0.5rem 0;
}

.letters-preview .sample-word {
    font-size: 0.875rem;
    color: var(--color-text-light);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--color-border);
}

/* Collection Actions */
.collection-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.file-info {
    color: var(--color-text-light);
    font-size: 0.875rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-icon {
    width: 1.25rem;
    height: 1.25rem;
}

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

.btn-primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-coffee {
    background: var(--color-coffee);
    color: #000;
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

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

.coffee-icon {
    width: 1.5rem;
    height: 1.5rem;
}

/* Support Section */
.support-section {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: var(--radius-xl);
    padding: 3rem;
    text-align: center;
    margin: 2rem 0;
}

.support-content h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.support-content p {
    color: var(--color-text);
    margin-bottom: 1.5rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* Info Section */
.info-section {
    padding: 4rem 0 2rem;
}

.info-section h2 {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 2rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.info-card {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.info-icon {
    width: 3rem;
    height: 3rem;
    background: var(--color-primary);
    color: var(--color-white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 auto 1rem;
}

.info-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.info-card p {
    color: var(--color-text-light);
    font-size: 0.9375rem;
}

.info-card a {
    color: var(--color-primary);
    text-decoration: none;
}

.info-card a:hover {
    text-decoration: underline;
}

/* Footer */
.footer {
    background: var(--color-text);
    color: var(--color-white);
    padding: 2rem 0;
    text-align: center;
    margin-top: 4rem;
}

.footer p {
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.footer-links {
    opacity: 0.7;
    font-size: 0.875rem;
}

.footer-links a {
    color: var(--color-white);
    text-decoration: none;
}

.footer-links a:hover {
    text-decoration: underline;
}

.separator {
    margin: 0 0.5rem;
}

/* Preview Button */
.btn-preview {
    background: var(--color-secondary);
    color: var(--color-white);
    margin: 1rem 0;
}

.btn-preview:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    /* iOS Safari fix for 100vh */
    height: 100%;
    height: 100dvh;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--color-white);
    border-radius: var(--radius-xl);
    max-width: 1200px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    overflow: visible;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--color-text);
    z-index: 10;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: rotate(90deg);
}

.modal-header {
    padding: 2rem 3rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.modal-direction-tabs {
    display: flex;
    gap: 0.5rem;
}

.modal-direction-tab {
    padding: 0.5rem 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.modal-direction-tab:hover {
    background: var(--color-border);
}

.modal-direction-tab.active {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: var(--color-primary);
}

.modal-body {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 2rem 1rem;
    overflow-y: auto;
    min-height: 0;
}

.modal-card-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
    min-height: 400px;
}

.modal-card-wrapper {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 2rem;
    width: 100%;
    max-width: 1000px;
    align-items: stretch;
}

.modal-card-divider {
    width: 2px;
    background: linear-gradient(to bottom, transparent, var(--color-border) 20%, var(--color-border) 80%, transparent);
    align-self: stretch;
    min-height: 200px;
}

.modal-card-side {
    display: flex;
    flex-direction: column;
    min-height: 200px;
    height: 100%;
}

.modal-card-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-light);
    margin-bottom: 1rem;
    font-weight: 600;
    text-align: center;
}

.modal-card-content {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

/* Make Anki cards fill the modal properly and center content */
.modal-card-content .anki-card-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: stretch;
}

.modal-card-content .anki-card-container .card {
    min-height: 200px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    box-sizing: border-box;
}

.modal-nav {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.modal-nav svg {
    width: 1.5rem;
    height: 1.5rem;
}

.modal-nav:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.1);
}

.modal-nav:active {
    transform: scale(0.95);
}

.modal-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.modal-nav:disabled:hover {
    transform: none;
}

.modal-footer {
    padding: 1rem 2rem;
    border-top: 1px solid var(--color-border);
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.875rem;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal {
        align-items: flex-start;
        padding: 0;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .modal-header {
        padding: 1rem;
        flex-shrink: 0;
        padding-right: 3.5rem; /* Space for close button */
    }

    .modal-header h3 {
        font-size: 1.125rem;
        margin-bottom: 0.75rem;
    }

    .modal-direction-tabs {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-direction-tab {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }

    .modal-close {
        top: 0.75rem;
        right: 0.75rem;
        width: 2rem;
        height: 2rem;
        font-size: 1.25rem;
    }

    .modal-body {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 0;
        overflow: hidden;
        min-height: 0;
    }

    .modal-card-container {
        flex: 1;
        min-height: 0;
        padding: 0.5rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-card-wrapper {
        grid-template-columns: 1fr;
        gap: 1rem;
        align-items: start;
    }

    .modal-card-divider {
        display: none;
    }

    .modal-card-side {
        min-height: auto;
    }

    .modal-card-content .anki-card-container .card {
        min-height: auto;
    }

    /* Navigation buttons fixed at sides on mobile */
    .modal-nav {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: 2.5rem;
        height: 2.5rem;
        flex-shrink: 0;
        z-index: 10;
        background: rgba(255, 255, 255, 0.9);
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }

    .modal-nav-prev {
        left: 0.25rem;
    }

    .modal-nav-next {
        right: 0.25rem;
    }

    .modal-nav svg {
        width: 1.25rem;
        height: 1.25rem;
    }

    .modal-footer {
        flex-shrink: 0;
        padding: 0.75rem 1rem;
    }
}

/* Keyboard navigation hint */
.modal-footer::after {
    content: ' • Use ← → arrow keys to navigate';
    opacity: 0.6;
    font-size: 0.8125rem;
}

@media (max-width: 768px) {
    .modal-footer::after {
        display: none;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .hero {
        padding: 3rem 0;
    }

    .hero h1 {
        font-size: 1.875rem;
    }

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

    .hero-stats {
        gap: 2rem;
    }

    .stat-number {
        font-size: 2rem;
    }

    .collection-card {
        padding: 1.5rem;
    }

    .collection-header {
        flex-direction: column;
    }

    .collection-meta {
        margin-top: 0.5rem;
    }

    .preview-tabs {
        flex-direction: column;
    }

    .preview-tab {
        text-align: center;
    }

    .support-section {
        padding: 2rem 1.5rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 1rem;
    }

    .hero h1 {
        font-size: 1.5rem;
    }

    .collection-title-group h3 {
        font-size: 1.25rem;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .collection-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .file-info {
        text-align: center;
    }
}
