/* CSS Custom Properties for consistent theming */
:root {
    --primary-color: #7868E6;
    --primary-light: #B8B5FF;
    --secondary-color: #EDEEF7;
    --accent-blue: #E4FBFF;
    --accent-pink: #FFB4B4;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-light: #999999;
    --white: #ffffff;
    --shadow: 0 2px 10px rgba(120, 104, 230, 0.1);
    --shadow-hover: 0 4px 20px rgba(120, 104, 230, 0.2);
    --border-radius: 12px;
    --transition: all 0.3s ease;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Dark theme overrides */
.theme-dark {
    --primary-color: #A69CFF;
    --primary-light: #7C6EEB;
    --secondary-color: #1F2230;
    --accent-blue: #1C2A37;
    --accent-pink: #6E5066;
    --text-primary: #ECECF1;
    --text-secondary: #C5C6CC;
    --text-light: #9DA3AE;
    --white: #141826;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.6);
}

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

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--accent-blue) 100%);
    min-height: 100vh;
    /* Paper texture effect */
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(120, 104, 230, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 180, 180, 0.05) 0%, transparent 50%);
}

.theme-dark body {
    background: linear-gradient(135deg, #10131C 0%, #0B0F18 100%);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    color: var(--white);
    padding: 2rem 0;
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="paper" patternUnits="userSpaceOnUse" width="100" height="100"><rect width="100" height="100" fill="none"/><circle cx="25" cy="25" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="75" cy="75" r="1" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23paper)"/></svg>') repeat;
    opacity: 0.3;
}

.header__title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    z-index: 1;
}

.header__icon {
    font-size: 3rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.header__icon img {
    height: 40px;
    width: auto;
}

.header__subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    position: relative;
    z-index: 1;
}

/* Ensure theme toggle sits above header decoration */
#theme-toggle,
#theme-label {
    position: relative;
    z-index: 1;
}

/* Compact theme switch - top right */
.theme-switch {
    position: absolute;
    top: 12px;
    right: 12px;
    text-align: center;
    z-index: 2;
}
.theme-toggle-btn {
    background: var(--white);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
}
.theme-toggle-btn:hover {
    background: var(--primary-color);
    color: var(--white);
}
.theme-toggle-label {
    font-size: 0.75rem;
    margin-top: 0.25rem;
    opacity: 0.9;
}

/* Main Content */
.main {
    padding-bottom: 4rem;
}

/* Search Section */
.search-section {
    margin-bottom: 3rem;
}

.search-container {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    max-width: 600px;
    margin: 0 auto;
}

.search-label {
    display: block;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.search-input-container {
    position: relative;
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--secondary-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--white);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(120, 104, 230, 0.1);
}

.search-clear {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 50%;
    transition: var(--transition);
    display: none;
}

.search-clear:hover {
    background: var(--secondary-color);
    color: var(--text-primary);
}

.search-clear.show {
    display: block;
}

.search-help {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

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

/* Age Categories */
.age-categories {
    margin-bottom: 3rem;
}

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

.age-category {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    text-align: center;
}

.age-category:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-light);
}

.age-category.active {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--white) 100%);
}

.age-category__icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

.age-category__title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.age-category__description {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

.favorites-toggle {
    background: var(--white);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

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

.favorites-toggle.active {
    background: var(--primary-color);
    color: var(--white);
}

.patterns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.pattern-card {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    transition: var(--transition);
    border-left: 4px solid var(--primary-color);
}

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

.pattern-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.pattern-card__title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.pattern-card__age {
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--secondary-color);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
}

.favorite-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    padding: 0.25rem;
    border-radius: 50%;
}

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

.favorite-btn.active {
    color: var(--primary-color);
}

.pattern-card__content {
    margin-bottom: 1rem;
}

.pattern-card__description {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.pattern-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.pattern-detail {
    text-align: center;
    padding: 1rem;
    background: var(--secondary-color);
    border-radius: var(--border-radius);
}

.pattern-detail__label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    font-weight: 600;
}

.pattern-detail__value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
}

/* Problems Section */
.problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
}

.problem-card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
}

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

.problem-card__header {
    background: linear-gradient(135deg, var(--accent-pink) 0%, var(--primary-light) 100%);
    padding: 1.5rem;
    color: var(--white);
    position: relative;
}

.problem-card__icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* increase size of icon badges in problem headers */
.problem-card__header .icon-badge {
    width: 64px;
    height: 64px;
}

/* Monochrome icon styling */
.icon {
    display: inline-flex;
    vertical-align: middle;
    color: var(--primary-color);
}
.icon svg {
    display: block;
}

/* Icon badge for better legibility */
.icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--secondary-color);
    color: var(--primary-color);
    box-shadow: inset 0 0 0 2px var(--primary-light);
}

/* Improve contrast on header icon */
.header__icon .icon svg,
.header__icon svg {
    color: var(--white);
    stroke: var(--white);
}

/* Ensure problem card header icons remain clear on gradient */
.problem-card__header .icon-badge {
    background: rgba(255, 255, 255, 0.25);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6);
    color: #fff;
}

.problem-card__title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.problem-card__problem {
    font-size: 0.9rem;
    opacity: 0.9;
}

.problem-card__body {
    padding: 1.5rem;
}

.problem-card__solution-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.solution-steps {
    list-style: none;
    counter-reset: step-counter;
}

.solution-steps li {
    counter-increment: step-counter;
    margin-bottom: 0.75rem;
    padding-left: 2rem;
    position: relative;
    line-height: 1.5;
}

.solution-steps li::before {
    content: counter(step-counter);
    position: absolute;
    left: 0;
    top: 0;
    background: var(--primary-color);
    color: var(--white);
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.problem-card__footer {
    padding: 1rem 1.5rem;
    background: var(--secondary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.problem-card__age-tag {
    background: var(--primary-color);
    color: var(--white);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 3rem;
    display: none;
}

.loading.show {
    display: block;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--secondary-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    display: none;
}

.empty-state.show {
    display: block;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    max-width: 400px;
    margin: 0 auto;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--white);
    border: 1px solid var(--secondary-color);
    border-radius: var(--border-radius);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow);
    min-width: 300px;
    animation: slideIn 0.3s ease;
    position: relative;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.info {
    border-left: 4px solid var(--primary-color);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Footer */
.footer {
    background: var(--primary-color);
    color: var(--white);
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 4rem;
    font-size: 0.8rem;
    line-height: 1.5;
}

.footer-text {
    font-size: 0.9rem;
    opacity: 0.9;
}


.footer__links p,
.footer__disclaimer,
.footer p {
  margin: 0.5rem 0;
}

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

.mb-3 {
    margin-bottom: 1rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}


/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    .header__title {
        font-size: 2rem;
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }
    
    .header__icon {
        font-size: 2.5rem;
    }
    
    .header__icon img {
        height: 36px;
    }
    
    .search-container {
        padding: 1.5rem;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
    
    .age-grid {
        grid-template-columns: 1fr;
    }
    
    .patterns-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .patterns-grid {
        grid-template-columns: 1fr;
    }
    
    .problems-grid {
        grid-template-columns: 1fr;
    }
    
    .pattern-details {
        grid-template-columns: 1fr;
    }
    
    .toast-container {
        left: 20px;
        right: 20px;
    }
    
    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 1.5rem 0;
    }
    
    .header__title {
        font-size: 1.8rem;
    }
    
    .header__icon img {
        height: 32px;
    }
    
    .search-container {
        padding: 1rem;
    }
    
    .age-category {
        padding: 1.5rem;
    }
    
    .pattern-card {
        padding: 1.5rem;
    }
    
    .problem-card__header {
        padding: 1rem;
    }
    
    .problem-card__body {
        padding: 1rem;
    }
    
    .toast-container {
        top: 10px;
        left: 10px;
        right: 10px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.4);
    }
    
    .search-input:focus {
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3);
    }
}

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

/* Print styles */
@media print {
    .header,
    .search-section,
    .favorites-toggle,
    .favorite-btn,
    .toast-container {
        display: none !important;
    }
    
    .pattern-card,
    .problem-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
