/* Worksheet Generator Styles */

/* Generator Section */

/* Worksheet Types Grid */
.worksheet-types-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.worksheet-type-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.worksheet-type-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    border-color: #4CAF50;
}

.worksheet-type-card .type-icon {
    font-size: 48px;
    margin-bottom: 15px;
    line-height: 1;
}

.worksheet-type-card h3 {
    margin: 10px 0;
    color: #333;
    font-size: 1.2rem;
}

/* Button Styles */
.btn {
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
}

.btn-secondary {
    background: #f5f5f5;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-large {
    padding: 15px 40px;
    font-size: 18px;
    width: 100%;
}

/* Preview Container */
.generator-preview-container {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
    margin-top: 30px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

.preview-header h2 {
    color: #333;
    font-size: 24px;
    margin: 0;
}

.preview-actions {
    display: flex;
    gap: 15px;
}

.preview-content {
    background: #f9f9f9;
    padding: 30px;
    border-radius: 8px;
    min-height: 400px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow: auto;
}

.preview-content .worksheet {
    width: 210mm !important;
    height: 330mm !important;
}

/* Worksheet Styles - Fixed A4 Size */
.worksheet {
    background: white;
    padding: 8mm 12mm;
    width: 210mm !important;
    height: 330mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    min-height: 330mm !important;
    max-height: 330mm !important;
    margin: 0 auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    display: flex !important;
    flex-direction: column !important;
    position: relative;
}

/* Header Layout - Side by Side */
.worksheet-top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    border-bottom: 2px solid #4CAF50;
    margin-bottom: 10px;
    padding-bottom: 5px;
    flex-shrink: 0;
}

.worksheet-logo {
    text-align: left;
    margin: 0;
    padding: 0;
    border: none;
    flex-shrink: 0;
}

.worksheet-logo img {
    max-width: 300px;
    height: 50px;
    width: auto;
    object-fit: contain;
    display: block !important;
    margin: 0;
}

.worksheet-header {
    text-align: right;
    margin: 0;
    padding: 0;
    border: none;
    flex-grow: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.worksheet-header h2 {
    color: #333;
    font-size: 24px;
    /* Slightly larger title */
    margin: 0;
    font-weight: 700;
    line-height: 1.2;
    text-align: right;
}

.student-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.student-info span {
    padding: 5px 15px;
    background: #f5f5f5;
    border-radius: 4px;
    font-weight: 600;
}

/* Tracing Grid - Full Page Coverage */
.tracing-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    flex: 1;
    min-height: 0;
}

.tracing-column {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px 5px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
}

.tracing-letter-large,
.tracing-number-large {
    font-size: 42px;
    font-weight: bold;
    text-align: center;
    color: #4CAF50;
    margin-bottom: 5px;
    font-family: 'Arial', sans-serif;
    line-height: 1;
    flex-shrink: 0;
}

.tracing-lines {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.tracing-line {
    font-size: 24px;
    color: #ddd;
    text-align: center;
    padding: 2px;
    border-bottom: 1px dashed #ccc;
    font-weight: bold;
    line-height: 1;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Math Problems Grid */
.math-problems-grid {
    display: grid;
    gap: 15px;
    flex: 1;
    align-content: start;
}

.math-problem {
    border: 2px solid;
    border-radius: 10px;
    padding: 15px 20px;
    text-align: center;
    transition: transform 0.2s ease;
}

.math-problem:hover {
    transform: scale(1.02);
}

.problem-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    font-size: 28px;
    font-weight: bold;
}

.problem-content .number {
    color: #333;
    font-size: 32px;
}

.problem-content .operator {
    font-size: 36px;
    color: #4CAF50;
}

.problem-content .equals {
    color: #333;
    font-size: 32px;
}

.problem-content .answer-box {
    border-bottom: 2px solid #333;
    min-width: 80px;
    display: inline-block;
}

/* Vertical Math Problem Styles */
.math-problem.vertical {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 17px;
    background: transparent !important;
    border: none !important;
}

.vertical-problem-container {
    display: inline-block;
    text-align: right;
    font-family: Arial, Helvetica, sans-serif;
    /* Clean sans-serif font */
    font-size: 36px;
    font-weight: bold;
    color: #333;
    position: relative;
    line-height: 1.4;
    min-width: 120px;
}

.vertical-problem-container .number-row {
    display: block;
    padding-right: 15px;
}

.vertical-problem-container .operator-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    border-bottom: 3px solid #333;
    padding-bottom: 10px;
    margin-bottom: 10px;
    position: relative;
}

.vertical-problem-container .operator {
    position: absolute;
    left: 0;
    font-size: 36px;
}

.vertical-problem-container .operator-row .number {
    padding-right: 15px;
}

.vertical-problem-container .answer-row {
    height: 45px;
}

.problem-number {
    position: absolute;
    top: 5px;
    left: 15px;
    font-size: 16px;
    color: #666;
    font-weight: normal;
    font-family: Arial, Helvetica, sans-serif;
}

/* Drawing Container */
.drawing-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.color-picker-section {
    background: #f5f5f5;
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.color-picker-section label {
    font-weight: 600;
    color: #333;
}

.color-picker-section input[type="color"] {
    width: 80px;
    height: 40px;
    border: 2px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
}

.quick-colors {
    display: flex;
    gap: 10px;
}

.quick-color-btn {
    width: 40px;
    height: 40px;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-color-btn:hover {
    transform: scale(1.1);
}

.quick-color-btn.active {
    border-color: #2196F3;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
}

.btn-clear,
.btn-clear-step {
    padding: 8px 20px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s ease;
}

.btn-clear:hover,
.btn-clear-step:hover {
    background: #d32f2f;
}

canvas {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    display: block;
    margin: 0 auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Steps Grid */
.steps-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.step-item {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 15px;
    background: #fafafa;
    text-align: center;
}

.step-number {
    font-weight: bold;
    color: #4CAF50;
    font-size: 18px;
    margin-bottom: 10px;
}

.step-guide {
    margin-bottom: 15px;
    padding: 10px;
    background: white;
    border-radius: 8px;
}

.step-guide svg {
    display: block;
    margin: 0 auto;
}

.step-canvas {
    margin: 15px auto 10px;
}

/* Dot to Dot */
.dot-to-dot-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 0;
}

.dot-to-dot-wrapper {
    position: relative;
    display: inline-block;
    margin-top: 20px;
}

.dot-to-dot-wrapper svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.dot-to-dot-wrapper canvas {
    position: relative;
    background: transparent !important;
}

/* Shapes & Colors */
.shapes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.shape-item {
    text-align: center;
    padding: 20px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: #fafafa;
}

.shape-display {
    width: 80px;
    height: 80px;
    margin: 0 auto 15px;
    border-radius: 8px;
}

.shape-display.circle {
    border-radius: 50%;
}

.shape-display.triangle {
    width: 0;
    height: 0;
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-bottom: 80px solid;
    background: none !important;
    margin-left: auto;
    margin-right: auto;
}

.shape-label {
    font-weight: 600;
    color: #333;
    font-size: 16px;
}

/* Word Search & Matching */
.word-list {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

.word-list h3 {
    color: #4CAF50;
    margin-bottom: 15px;
}

.word-list ul {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.word-list li {
    background: white;
    padding: 10px;
    border-radius: 5px;
    text-align: center;
    font-weight: 600;
}

.word-search-grid {
    background: white;
    padding: 30px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    text-align: center;
    min-height: 300px;
}

.matching-pairs {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 30px;
}

.matching-pair {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
}

.match-item {
    padding: 15px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
    font-size: 18px;
}

.match-line {
    color: #ccc;
    font-size: 24px;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .worksheet-types-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }

    .steps-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .worksheet-types-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }

    .customization-panel,
    .generator-preview-container {
        padding: 20px;
    }

    .panel-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .preview-actions {
        width: 100%;
        flex-direction: column;
    }

    .preview-actions .btn {
        width: 100%;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .tracing-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .math-problems-grid {
        grid-template-columns: 1fr !important;
    }

    .steps-grid {
        grid-template-columns: 1fr;
    }

    .worksheet {
        padding: 20px;
    }

    .color-picker-section {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 480px) {
    .worksheet-type-card {
        padding: 20px 15px;
    }

    .worksheet-type-card .type-icon {
        font-size: 36px;
    }

    .worksheet-type-card h3 {
        font-size: 16px;
    }

    .worksheet-header h2 {
        font-size: 22px;
    }

    .tracing-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tracing-letter-large,
    .tracing-number-large {
        font-size: 32px;
    }

    .tracing-line {
        font-size: 18px;
    }

    .student-info {
        flex-direction: column;
        gap: 10px;
    }
}

/* Generator Workspace (Two Column Layout) */
.generator-workspace {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.preview-column {
    flex: 1.3;
    /* Reduced width */
    background: #f0f2f5;
    padding: 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.config-column {
    flex: 1;
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 20px;
    min-width: 300px;
}

.preview-header-actions {
    margin-bottom: 10px;
}

.workspace-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.download-actions {
    display: flex;
    gap: 10px;
}

.download-actions .btn {
    flex: 1;
}

.btn-full {
    width: 100%;
    text-align: center;
    padding: 12px;
    font-size: 16px;
}

.btn-info {
    background: #2196F3;
    color: white;
}

.btn-info:hover {
    background: #1976D2;
}

/* Hide original preview container styles that conflict */
.generator-preview-container {
    margin-top: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
}

.customization-panel {
    display: block !important;
    /* Always show inside config column */
}

.panel-header h2 {
    font-size: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.panel-header .btn {
    display: none;
    /* Hide back button in panel header */
}

/* Responsive */
@media (max-width: 900px) {
    .generator-workspace {
        flex-direction: column-reverse;
    }

    .config-column {
        width: 100%;
        position: static;
    }

    .preview-column {
        width: 100%;
    }
}

/* Compact Layout Adjustments */
.config-column {
    padding: 15px !important;
    /* Reduced padding */
}

/* Improved Content Scaling & Layout */
.preview-content {
    background: white;
    padding: 10px !important;
    min-height: 732px !important;
    /* User requested height */
    overflow: hidden !important;
    align-items: flex-start !important;
    position: relative;
    display: flex;
    justify-content: center;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    margin: 0 auto;
}

.worksheet {
    transform-origin: top center;
    /* Ensure scaling happens from top */
}

.preview-content .worksheet {
    transform: scale(0.6);
    /* Slightly smaller scale */
    transform-origin: top center;
    margin-top: 0 !important;
    margin-bottom: -40% !important;
    /* Adjust negative margin based on scale */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    /* Ensure width is respected before scaling */
    width: 210mm !important;
    min-width: 210mm !important;
}

/* Ensure container allows centering */
.generator-preview-container {
    display: flex;
    justify-content: center;
}

/* Answer Key Styles */
.answer-value {
    color: #d32f2f;
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Marker Felt', sans-serif;
    font-weight: bold;
}

.placeholder {
    display: inline;
}

/* PDF Specific Styles - Applied only during PDF generation */
.pdf-mode .vertical-problem-container .operator-row {
    /* Adjust padding-bottom to move the line UP (smaller value) or DOWN (larger value) relative to the number */
    padding-bottom: 15px !important;
    /* Adjust margin-bottom to move the answer UP (smaller value) or DOWN (larger value) relative to the line */
    margin-bottom: 10px !important;
    border-bottom: 2px solid #333 !important;
}

.pdf-mode .vertical-problem-container {
    font-size: 28px;
}

.pdf-mode .math-problem {
    padding: 20px;
}

.pdf-mode .vertical-problem-container .answer-row {
    padding-top: 0;
}

.answer-row {
    line-height: 0.6;
    width: 105px;
}

.pdf-mode .answer-row {
    width: 105px;
    line-height: 0.3;
}

/* PDF Footer Styles */
.pdf-footer {
    position: absolute;
    bottom: 15px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 14px;
    color: #333;
    font-family: Arial, sans-serif;
    line-height: 1.4;
}

.pdf-footer p {
    margin: 2px 0;
}