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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8fafc;
}

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

/* Header */
.header {
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #2563eb;
}

.logo i {
    font-size: 2rem;
}

.nav-links {
    display: flex;
    gap: 2rem;
}

.nav-links a {
    text-decoration: none;
    color: #64748b;
    font-weight: 500;
    transition: color 0.3s ease;
}

.nav-links a:hover {
    color: #2563eb;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 4rem 0;
    text-align: center;
}

.hero-content h1 {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.2;
}

.hero-content p {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* Generator Section */
.generator-section {
    padding: 4rem 0;
    background: white;
}

.generator-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: start;
}

.generator-form {
    background: #f8fafc;
    border-radius: 12px;
    padding: 1.5rem;
}

.generator-form h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: #1e293b;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #374151;
}

.input-hint {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.25rem;
    margin-left: 0;
    font-style: italic;
}

.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    color: #1e293b;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

input[type="number"].form-select {
    -moz-appearance: textfield;
}

input[type="number"].form-select::-webkit-outer-spin-button,
input[type="number"].form-select::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-select:hover {
    border-color: #2563eb;
}

.form-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.range-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.range-control input[type="range"] {
    flex: 1;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.range-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: #2563eb;
    border-radius: 50%;
    cursor: pointer;
}

.range-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #2563eb;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#problems-display {
    font-weight: 600;
    color: #2563eb;
    min-width: 30px;
    text-align: center;
}

.generate-actions {
    margin-top: 2rem;
}

.print-tips {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #eff6ff;
    border-left: 4px solid #2563eb;
    border-radius: 6px;
}

.print-tips h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: #1e40af;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.print-tips ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.print-tips ul li {
    font-size: 0.85rem;
    color: #475569;
    margin-bottom: 0.25rem;
    padding-left: 1.25rem;
    position: relative;
}

.print-tips ul li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: #2563eb;
    font-weight: 600;
}

.generate-btn {
    width: 100%;
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(240, 147, 251, 0.3);
}

/* Preview Section */
.preview-section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

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

.preview-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1e293b;
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: #10b981;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.action-btn:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn-secondary {
    background: #2563eb;
}

.action-btn-secondary:hover {
    background: #1d4ed8;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* Print button gets special emphasis */
#print-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    font-size: 0.95rem;
    padding: 0.75rem 1.5rem;
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.2);
}

#print-btn:hover {
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.worksheet-preview {
    background: #f8fafc;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    transition: border-color 0.3s ease;
}

.worksheet-preview.has-worksheet {
    border-color: #10b981;
    background: white;
}

.worksheet-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 400px;
    color: #9ca3af;
    text-align: center;
}

.worksheet-placeholder i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.worksheet-placeholder p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.placeholder-hint {
    font-size: 0.875rem;
    opacity: 0.7;
}

/* Worksheet Styles */
.worksheet {
    font-family: 'Comic Neue', 'Inter', sans-serif;
    padding: 2rem;
    background: white;
    border-radius: 8px;
}

.worksheet-page {
    page-break-after: always;
}

.worksheet-page:last-child {
    page-break-after: auto;
}

.worksheet-header {
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e5e7eb;
}

.worksheet-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
    color: #1e293b;
}

.worksheet-meta {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.worksheet-type,
.worksheet-level {
    padding: 0.3rem 0.75rem;
    border-radius: 15px;
    font-weight: 600;
    font-size: 0.8rem;
}

.worksheet-body {
    margin-bottom: 1rem;
}

.problems-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.problem-item {
    padding: 0.4rem;
    border-radius: 6px;
    min-height: 2.5rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.problem-number {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1e293b;
    margin-right: 0.35rem;
    display: inline;
}

.problem-content {
    display: inline-block;
    vertical-align: top;
}

.problem-item:has(.problem-number) .problem-content {
    width: calc(100% - 2rem);
}

.problem-item:not(:has(.problem-number)) .problem-content {
    width: 100%;
}

.problem-question {
    font-size: 1.1rem;
    margin: 0;
    font-weight: 600;
    color: #1e293b;
    display: inline;
    line-height: 1.4;
}

.answer-space {
    display: inline-block;
    min-width: 50px;
    height: 1.2em;
    border-bottom: 2px solid #333;
    margin-left: 0.35rem;
    vertical-align: baseline;
}

/* Counting Aids Styles - Fixed size container */
.counting-aids {
    margin-bottom: 0.25rem;
    padding: 0.1rem 0.2rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.1rem;
    width: 100%;
    max-width: 100%;
    min-height: 1.2rem;
    max-height: 1.2rem;
    overflow: hidden;
    line-height: 1;
}

.counting-group {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.1rem;
    padding: 0.05rem;
}

.counting-group-division {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    justify-content: center;
    align-items: center;
}

.counting-subgroup {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.1rem;
    padding: 0.1rem;
    border: 1px dashed rgba(0, 0, 0, 0.2);
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.3);
}

.counting-object {
    font-size: 1em;
    line-height: 1;
    display: inline-block;
    user-select: none;
    margin: 0;
    flex-shrink: 0;
}

.counting-object.crossed-out {
    opacity: 0.5;
    position: relative;
}

.counting-object.crossed-out::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -10%;
    right: -10%;
    height: 2px;
    background: #ef4444;
    transform: rotate(-45deg);
    z-index: 1;
}

.counting-object.crossed-out::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -10%;
    right: -10%;
    height: 2px;
    background: #ef4444;
    transform: rotate(45deg);
    z-index: 1;
}

.counting-object.missing {
    opacity: 0.3;
    font-size: 0.65rem;
    font-weight: 700;
    color: #64748b;
}

.counting-operator {
    font-size: 1em;
    font-weight: 700;
    color: #1e293b;
    padding: 0 0.1rem;
    display: inline-flex;
    align-items: center;
    min-width: 0.75rem;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
}

.worksheet-footer {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.75rem;
    color: #64748b;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.worksheet-footer a {
    color: #2563eb;
    text-decoration: none;
    transition: color 0.3s ease;
}

.worksheet-footer a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

/* Template: Basic */
.template-basic .worksheet-header {
    border-bottom-color: #64748b;
}

.template-basic .worksheet-type,
.template-basic .worksheet-level {
    background: #f1f5f9;
    color: #475569;
}

.template-basic .problem-item {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
}

/* Template: Colourful */
.template-colourful .worksheet-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.5rem;
    border-radius: 6px;
    border-bottom: none;
    margin-bottom: 0.75rem;
}

.template-colourful .worksheet-title {
    color: white;
}

.template-colourful .worksheet-type,
.template-colourful .worksheet-level {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
}

.template-colourful .problem-item {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
}

.template-colourful .problem-question {
    color: white;
}

.template-colourful .problem-answer-line {
    border-bottom-color: white;
}

.template-colourful .problem-number {
    color: white;
}

/* Template: Flowers */
.template-flowers {
    background: linear-gradient(135deg, #ffeef8 0%, #fff0f5 100%);
    position: relative;
}

.template-flowers::before {
    content: '🌸';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2rem;
    opacity: 0.3;
}

.template-flowers .worksheet-header {
    border-bottom-color: #f8b4d9;
}

.template-flowers .worksheet-type,
.template-flowers .worksheet-level {
    background: #fce7f3;
    color: #be185d;
    border: 2px solid #f8b4d9;
}

.template-flowers .problem-item {
    background: #fdf2f8;
    border: 2px solid #fbcfe8;
    position: relative;
}

.template-flowers .problem-item::after {
    content: attr(data-emoji);
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1rem;
    opacity: 0.5;
}

.template-flowers .problem-question {
    color: #9f1239;
}

.template-flowers .problem-answer-line {
    border-bottom-color: #f472b6;
}

/* Template: Dinosaurs */
.template-dinosaurs {
    background: linear-gradient(135deg, #e0f2fe 0%, #dbeafe 100%);
    position: relative;
}

.template-dinosaurs::before {
    content: '🦕';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2rem;
    opacity: 0.3;
}

.template-dinosaurs .worksheet-header {
    border-bottom-color: #7dd3fc;
}

.template-dinosaurs .worksheet-type,
.template-dinosaurs .worksheet-level {
    background: #dbeafe;
    color: #1e40af;
    border: 2px solid #7dd3fc;
}

.template-dinosaurs .problem-item {
    background: #eff6ff;
    border: 2px solid #bfdbfe;
    position: relative;
}

.template-dinosaurs .problem-item::after {
    content: attr(data-emoji);
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1rem;
    opacity: 0.5;
}

.template-dinosaurs .problem-question {
    color: #1e3a8a;
}

.template-dinosaurs .problem-answer-line {
    border-bottom-color: #60a5fa;
}

/* Template: Rainbow */
.template-rainbow {
    background: linear-gradient(135deg, #fef3c7 0%, #fce7f3 25%, #e0e7ff 50%, #d1fae5 75%, #fef3c7 100%);
    position: relative;
}

.template-rainbow::before {
    content: '🌈';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2rem;
    opacity: 0.3;
}

.template-rainbow .worksheet-header {
    border-bottom-color: #f59e0b;
    background: linear-gradient(90deg, #ef4444 0%, #f59e0b 16.66%, #eab308 33.33%, #22c55e 50%, #3b82f6 66.66%, #8b5cf6 83.33%, #ec4899 100%);
    padding: 0.5rem;
    border-radius: 6px;
    margin-bottom: 0.75rem;
}

.template-rainbow .worksheet-title {
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.template-rainbow .worksheet-type,
.template-rainbow .worksheet-level {
    background: rgba(255, 255, 255, 0.9);
    color: #1e293b;
    border: 2px solid #f59e0b;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.template-rainbow .problem-item {
    background: linear-gradient(135deg, #fef3c7 0%, #fce7f3 50%, #e0e7ff 100%);
    border: 2px solid #f59e0b;
    position: relative;
}

.template-rainbow .problem-item::after {
    content: attr(data-emoji);
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1rem;
    opacity: 0.5;
}

.template-rainbow .problem-question {
    color: #1e293b;
}

.template-rainbow .problem-number {
    color: #8b5cf6;
}

.template-rainbow .problem-answer-line {
    border-bottom-color: #3b82f6;
}

.template-rainbow .worksheet-footer {
    color: #64748b;
    border-top-color: #f59e0b;
}

/* Template: Animals */
.template-animals {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    position: relative;
}

.template-animals::before {
    content: '🐾';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 2rem;
    opacity: 0.3;
}

.template-animals .worksheet-header {
    border-bottom-color: #86efac;
}

.template-animals .worksheet-type,
.template-animals .worksheet-level {
    background: #dcfce7;
    color: #166534;
    border: 2px solid #86efac;
}

.template-animals .problem-item {
    background: #f0fdf4;
    border: 2px solid #bbf7d0;
    position: relative;
}

.template-animals .problem-item::after {
    content: attr(data-emoji);
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1rem;
    opacity: 0.5;
}

.template-animals .problem-question {
    color: #15803d;
}

.template-animals .problem-answer-line {
    border-bottom-color: #4ade80;
}

/* Counting Aids Template Adjustments */
.template-colourful .counting-aids {
    background: rgba(255, 255, 255, 0.2);
}

.template-rainbow .counting-aids {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid #f59e0b;
}

.template-rainbow .counting-operator {
    color: #8b5cf6;
    font-weight: 700;
}

.template-rainbow .counting-subgroup {
    border-color: #3b82f6;
    background: rgba(255, 255, 255, 0.5);
}

/* Features Section */
.features {
    padding: 4rem 0;
    background: #f8fafc;
}

.features h2 {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 3rem;
    color: #1e293b;
}

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

.feature-card {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.feature-card i {
    font-size: 3rem;
    color: #f5576c;
    margin-bottom: 1rem;
}

.feature-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #1e293b;
}

.feature-card p {
    color: #64748b;
    line-height: 1.6;
}

/* Footer */
.footer {
    background: #1e293b;
    color: white;
    padding: 3rem 0 1rem;
}

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

.footer-section h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #f1f5f9;
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 0.5rem;
}

.footer-section ul li a {
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-section ul li a:hover {
    color: #f1f5f9;
}

.footer-section p {
    color: #94a3b8;
    line-height: 1.6;
}

.footer-bottom {
    border-top: 1px solid #334155;
    padding-top: 1rem;
    text-align: center;
    color: #94a3b8;
}

.footer-bottom a {
    color: #94a3b8;
    text-decoration: none;
}

.footer-bottom a:hover {
    color: #f1f5f9;
}

/* Responsive Design */
@media (max-width: 768px) {
    .nav-links {
        display: none;
    }
    
    .hero-content h1 {
        font-size: 2.5rem;
    }
    
    .hero-content p {
        font-size: 1.1rem;
    }
    
    .generator-container {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .problems-grid {
        grid-template-columns: 1fr;
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
    
    .footer-content {
        grid-template-columns: 1fr;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 15px;
    }
    
    .hero {
        padding: 2rem 0;
    }
    
    .hero-content h1 {
        font-size: 2rem;
    }
    
    .generator-section {
        padding: 2rem 0;
    }
    
    .features {
        padding: 2rem 0;
    }
    
    .features h2 {
        font-size: 2rem;
    }
    
    .preview-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .preview-actions {
        justify-content: center;
    }
}

/* Print Styles - For direct printing from page */
@media print {
    @page {
        size: A4;
        margin: 1.5cm;
    }
    
    .counting-aids {
        max-height: none !important;
        overflow: visible !important;
        min-height: auto !important;
    }
    
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    .counting-object.crossed-out {
        opacity: 0.5 !important;
        position: relative !important;
    }
    
    .counting-object.crossed-out::before {
        content: '' !important;
        position: absolute !important;
        top: 50% !important;
        left: -10% !important;
        right: -10% !important;
        height: 2px !important;
        background: #ef4444 !important;
        transform: rotate(-45deg) !important;
        z-index: 1 !important;
    }
    
    .counting-object.crossed-out::after {
        content: '' !important;
        position: absolute !important;
        top: 50% !important;
        left: -10% !important;
        right: -10% !important;
        height: 2px !important;
        background: #ef4444 !important;
        transform: rotate(45deg) !important;
        z-index: 1 !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .header,
    .generator-form,
    .preview-header,
    .preview-actions,
    .features,
    .footer,
    .hero {
        display: none !important;
    }
    
    .worksheet-preview {
        border: none !important;
        padding: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        background: white !important;
    }
    
    .worksheet {
        page-break-inside: avoid;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .worksheet-header {
        page-break-after: avoid;
    }
    
    .problem-item {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    
    .worksheet-footer {
        page-break-before: avoid;
    }
    
    /* Ensure proper spacing for print */
    .problems-grid {
        gap: 1cm !important;
    }
    
    .problem-item {
        min-height: 2.5cm !important;
    }
}

