/* readQ - Global Styles */

:root {
    /* Light theme colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-tertiary: #adb5bd;
    --border-color: #dee2e6;
    --shadow: rgba(0, 0, 0, 0.1);

    /* Brand colors */
    --primary: #9b59b6;
    --primary-hover: #8e44ad;
    --secondary: #3498db;
    --success: #2ecc71;
    --warning: #f39c12;
    --danger: #e74c3c;
    --info: #16a085;

    /* Level colors (dessert theme) */
    --level-1: #f9e4d4;
    --level-2: #f4d5c6;
    --level-3: #d4b5a5;
    --level-4: #c5a38e;
    --level-5: #b89076;
    --level-6: #a67c5e;
    --level-7: #936845;
    --level-8: #7d5638;
    --level-9: #6a442b;
    --level-10: #583620;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans TC", sans-serif;
    --font-serif: "Noto Serif TC", Georgia, serif;
    --font-mono: "SF Mono", Monaco, Menlo, monospace;

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

    /* Border radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    --radius-full: 9999px;

    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #404040;
    --text-primary: #f8f9fa;
    --text-secondary: #adb5bd;
    --text-tertiary: #6c757d;
    --border-color: #404040;
    --shadow: rgba(0, 0, 0, 0.3);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: var(--space-md);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: var(--space-md);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-hover);
}

/* Container */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
}

.container-fluid {
    width: 100%;
    padding: 0 var(--space-lg);
}

/* Navigation */
.navbar {
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-md) 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px var(--shadow);
}

.navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.navbar-nav {
    display: flex;
    gap: var(--space-lg);
    list-style: none;
    align-items: center;
}

.navbar-nav a {
    color: var(--text-primary);
    font-weight: 500;
}

.navbar-nav a:hover {
    color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

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

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

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

.btn-secondary:hover {
    background-color: #2980b9;
    color: white;
}

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

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

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

.btn-sm {
    padding: var(--space-xs) var(--space-md);
    font-size: 0.875rem;
}

.btn-lg {
    padding: var(--space-md) var(--space-xl);
    font-size: 1.125rem;
}

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

/* Cards */
.card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: 0 2px 8px var(--shadow);
    transition: var(--transition);
}

.card:hover {
    box-shadow: 0 4px 16px var(--shadow);
    transform: translateY(-2px);
}

.card-header {
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.card-body {
    margin-bottom: var(--space-md);
}

.card-footer {
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

/* Grid */
.grid {
    display: grid;
    gap: var(--space-lg);
}

.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
    .grid-cols-2, .grid-cols-3, .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* 在手機上調整網格間距，讓雙欄更緊湊 */
    .grid {
        gap: var(--space-md);
    }

    /* 調整卡片內的字體大小，讓內容更適合雙欄顯示 */
    .grid .card h3 {
        font-size: 1.1rem;
    }

    .grid .card .text-secondary {
        font-size: 0.8rem;
    }

    .grid .card .badge {
        font-size: 0.7rem;
        padding: 0.15rem 0.4rem;
    }
}

/* 針對非常小的手機螢幕（如 iPhone SE）做額外優化 */
@media (max-width: 375px) {
    .container {
        padding: 0 var(--space-sm);
    }

    .grid {
        gap: var(--space-sm);
    }

    .grid .card {
        padding: var(--space-md);
    }

    .grid .card h3 {
        font-size: 1rem;
        margin-bottom: var(--space-sm);
    }

    .grid .card .btn {
        padding: var(--space-sm) var(--space-md);
        font-size: 0.875rem;
    }
}

/* Form */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.1);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
}

/* Badge */
.badge {
    display: inline-block;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
}

.badge-primary { background-color: var(--primary); color: white; }
.badge-success { background-color: var(--success); color: white; }
.badge-warning { background-color: var(--warning); color: white; }
.badge-danger { background-color: var(--danger); color: white; }
.badge-info { background-color: var(--info); color: white; }

/* Alert */
.alert {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
}

.alert-success {
    background-color: rgba(46, 204, 113, 0.1);
    border: 1px solid var(--success);
    color: var(--success);
}

.alert-error {
    background-color: rgba(231, 76, 60, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.alert-info {
    background-color: rgba(52, 152, 219, 0.1);
    border: 1px solid var(--secondary);
    color: var(--secondary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: var(--space-lg);
}

.modal-content {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--space-md);
    justify-content: flex-end;
}

/* Progress bar */
.progress {
    width: 100%;
    height: 12px;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary);
    transition: width 0.5s ease;
    border-radius: var(--radius-full);
}

/* Story content specific */
.story-content {
    font-family: var(--font-serif);
    font-size: 1.125rem;
    line-height: 2;
    max-width: 800px;
    margin: 0 auto;
}

.story-content p {
    margin-bottom: var(--space-xl);
    text-align: justify;
}

.ruby-text {
    cursor: help;
    position: relative;
}

.ruby-text ruby {
    ruby-position: over;
}

.ruby-text rt {
    font-size: 0.6em;
    color: var(--text-secondary);
}

.idiom-highlight {
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.idiom-highlight:hover {
    color: var(--primary-hover);
}

/* Level indicator */
.level-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    font-weight: 600;
}

.level-icon {
    width: 24px;
    height: 24px;
}

/* ReadQ chart */
.chart-container {
    position: relative;
    height: 300px;
    margin: var(--space-lg) 0;
}

/* Utilities */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.hidden { display: none !important; }
.visible { display: block !important; }

/* Loading spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Theme toggle */
.theme-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.theme-toggle:hover {
    background-color: var(--bg-tertiary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: var(--space-md);
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px var(--shadow);
}

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

.modal-header h3 {
    margin: 0;
    color: var(--primary);
    font-size: 1.5rem;
}

.modal-body {
    padding: var(--space-lg);
}

.modal-body strong {
    color: var(--text-primary);
    display: block;
    margin-bottom: var(--space-xs);
}

.modal-body p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* Series Group Styles */
.series-group {
    margin-bottom: var(--space-xl);
}

.series-header {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 3px solid #4FC3F7;
    padding: var(--space-lg) var(--space-xl);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.series-header:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(79, 195, 247, 0.4);
    border-color: #29B6F6;
}

.series-header.expanded {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom-color: transparent;
}

.series-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex: 1;
    min-width: 0;
}

.series-icon {
    font-size: 2rem;
}

.series-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.series-count {
    background: #4FC3F7;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    font-weight: 500;
}

.expand-btn {
    background: transparent;
    border: 2px solid #4FC3F7;
    color: #4FC3F7;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s ease;
    flex-shrink: 0;
    white-space: nowrap;
}

.expand-btn:hover {
    background: #4FC3F7;
    color: white;
}

.series-content {
    background: var(--bg-secondary);
    padding: var(--space-lg) var(--space-xl);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border: 3px solid #4FC3F7;
    border-top: none;
}

/* Ad Placeholder */
.ad-placeholder {
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Responsive */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .navbar-nav {
        gap: var(--space-md);
    }

    .container {
        padding: 0 var(--space-md);
    }

    .story-content {
        font-size: 1rem;
    }

    /* Series header mobile optimization */
    .series-header {
        padding: var(--space-md);
        gap: var(--space-sm);
    }

    .series-info {
        /* Keep horizontal layout on mobile */
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-xs);
    }

    .series-title {
        font-size: 1rem;
    }

    .series-icon {
        font-size: 1.5rem;
    }

    .series-count {
        font-size: 0.75rem;
        padding: 0.2rem 0.5rem;
    }

    .series-level {
        font-size: 0.75rem;
        padding: 0.2rem 0.5rem;
    }

    .expand-btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.6rem;
    }

    .series-content {
        padding: var(--space-md);
    }
}
