/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

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

/* Worksheet Selection Screen */
.worksheet-selection {
    background: white;
    border-radius: 15px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    margin-top: 20px;
}

.worksheet-selection header {
    text-align: center;
    margin-bottom: 40px;
}

.worksheet-selection h1 {
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 10px;
}

.worksheet-selection p {
    font-size: 1.2rem;
    color: #7f8c8d;
}

.worksheets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.worksheet-card {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    padding: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    text-decoration: none;
    display: block;
    color: inherit;
}

.worksheet-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
    text-decoration: none;
    color: inherit;
}

.worksheet-card h3 {
    font-size: 1.4rem;
    color: #2c3e50;
    margin-bottom: 10px;
}

.worksheet-card p {
    color: #6c757d;
    margin-bottom: 15px;
    line-height: 1.5;
}









.selection-footer {
    text-align: center;
    color: #6c757d;
    font-style: italic;
}

/* Section headings on the homepage (Worksheets / Playground) */
.section-heading {
    font-size: 1.3rem;
    color: #495057;
    font-weight: 600;
    margin: 30px 0 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e9ecef;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ── Scratchpad ──────────────────────────────────────────────── */

/* Settings toolbar below the header */
.scratchpad-settings {
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.settings-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-divider {
    width: 1px;
    height: 24px;
    background: #dee2e6;
    flex-shrink: 0;
}

.settings-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
}

.settings-label-suffix {
    color: #6c757d;
    font-weight: 400;
}

.settings-toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.settings-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #667eea;
}

.height-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

.height-btn {
    width: 26px;
    height: 26px;
    border: 1px solid #ced4da;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #495057;
    transition: background 0.15s;
}

.height-btn:hover {
    background: #e9ecef;
}

.height-input {
    width: 48px;
    padding: 3px 6px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85rem;
    text-align: center;
    color: #495057;
}

.height-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Inputs configuration panel */
.inputs-config {
    background: #f1f3f5;
    border-bottom: 1px solid #dee2e6;
    padding: 14px 24px;
}

.inputs-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.inputs-config-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.add-input-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.add-input-btn:hover {
    background: #5a6fd8;
}

.inputs-config-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-config-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.input-config-name {
    width: 120px;
    padding: 5px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    color: #2d3748;
}

.input-config-type {
    padding: 5px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
    color: #495057;
}

.input-config-placeholder {
    flex: 1;
    min-width: 120px;
    padding: 5px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #495057;
}

.input-config-name:focus,
.input-config-type:focus,
.input-config-placeholder:focus {
    outline: none;
    border-color: #667eea;
}

.remove-input-btn {
    background: none;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    color: #6c757d;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.remove-input-btn:hover {
    background: #fee2e2;
    border-color: #f87171;
    color: #dc2626;
}

/* Wrapper around the code section in the scratchpad */
.scratchpad-body {
    padding: 20px;
}

/* Worksheet Interface */
.worksheet-interface {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.worksheet-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.back-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    white-space: nowrap;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.start-over-btn {
    background: #6c757d;
    border: 2px solid #6c757d;
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
    white-space: nowrap;
}

.start-over-btn:hover {
    background: #5a6268;
    border-color: #5a6268;
    box-shadow: 0 4px 8px rgba(108, 117, 125, 0.4);
    transform: translateY(-1px);
}

.worksheet-info h1 {
    font-size: 1.8rem;
    margin-bottom: 5px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.worksheet-info p {
    opacity: 0.9;
    font-size: 1rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
}



/* Progress Bar */
.progress-container {
    background: #f8f9fa;
    padding: 15px 30px;
    border-bottom: 1px solid #e9ecef;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #28a745, #20c997);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    text-align: center;
    color: #6c757d;
    font-size: 0.9rem;
}

/* Problem Navigation */
.problem-nav {
    background: white;
    padding: 15px 30px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.nav-btn:hover {
    background: #5a6fd8;
}

.nav-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

#problem-counter {
    font-weight: 600;
    color: #495057;
}

/* Problems Container */
.problems-container {
    background: white;
    border-radius: 12px;
    margin: 20px 0;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

/* Problem Container */
.problem-container {
    padding: 30px;
    border-bottom: 1px solid #e9ecef;
}

.problem-container:last-child {
    border-bottom: none;
}

.problem-container:nth-child(even) {
    background: #f8f9fa;
}

/* Concept Card */
.concept-card {
    padding: 30px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border-left: 6px solid #f59e0b;
}

.concept-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.concept-icon {
    font-size: 2.2rem;
    line-height: 1;
}

.concept-header h3 {
    margin: 0;
    font-size: 1.4rem;
    color: #78350f;
    font-weight: 700;
}

.concept-body p {
    color: #451a03;
    margin-bottom: 14px;
    font-size: 1rem;
    line-height: 1.7;
}

.concept-body code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
}

.concept-examples {
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid #fcd34d;
    border-radius: 10px;
    padding: 18px 20px;
    margin: 18px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.concept-example {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 0.95rem;
}

.example-input {
    background: #dbeafe;
    color: #1e3a5f;
    padding: 5px 12px;
    border-radius: 6px;
    white-space: nowrap;
}

.example-arrow {
    color: #9ca3af;
    font-size: 1.1rem;
    font-weight: bold;
}

.example-code {
    color: #374151;
    white-space: nowrap;
}

.example-code code {
    background: #f3f4f6;
    padding: 3px 8px;
    border-radius: 4px;
}

.example-output {
    background: #dcfce7;
    color: #14532d;
    padding: 5px 12px;
    border-radius: 6px;
    white-space: nowrap;
}

.concept-footer {
    font-style: italic;
    color: #78350f;
    margin-top: 14px;
    font-size: 0.95rem;
    margin-bottom: 0;
}

.bracket-print {
    color: #2563eb;
    font-weight: 700;
}

.bracket-math {
    color: #dc2626;
    font-weight: 700;
}

.problem-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.problem-header h2 {
    color: #2c3e50;
    font-size: 1.6rem;
}

.problem-meta {
    display: flex;
    gap: 10px;
}



/* Problem Content */
.problem-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

@media (max-width: 768px) {
    .problem-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

.explanation {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 12px;
    border-left: 4px solid #667eea;
}

.explanation h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.explanation p {
    margin-bottom: 15px;
    line-height: 1.6;
}

.problem-content-text {
    margin-bottom: 15px;
    line-height: 1.6;
}


.task-box {
    background: #e3f2fd;
    border: 1px solid #bbdefb;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
}

.task-box h4 {
    color: #1976d2;
    margin-bottom: 8px;
}

/* Code Section */
.code-section {
    background: #2d3748;
    border-radius: 12px;
    overflow: hidden;
}

.code-header {
    background: #1a202c;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.code-header h4 {
    color: white;
    margin: 0;
}

.code-controls {
    display: flex;
    gap: 10px;
}

.hint-btn, .run-btn, .reset-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.reset-btn {
    background: #6c757d;
    color: white;
}

.reset-btn:hover {
    background: #5a6268;
}

.hint-btn {
    background: #ffc107;
    color: #212529;
}

.hint-btn:hover {
    background: #e0a800;
}

.run-btn {
    background: #28a745;
    color: white;
}

.run-btn:hover {
    background: #218838;
}

/* CodeMirror Customization */
.CodeMirror {
    font-size: 14px;
    border: none;
    min-height: 70px;
}

/* Input Section */
.input-section {
    background: #f8f9fa;
    border-top: 1px solid #e2e8f0;
    padding: 20px;
}

.input-fields {
    display: flex;
    flex-direction: row;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.input-field {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.input-field label {
    color: #4a5568;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: nowrap;
}

.problem-input {
    padding: 8px 10px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    background: white;
    width: 80px;
    text-align: center;
}

.problem-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.problem-input::placeholder {
    color: #a0aec0;
}

/* Responsive design for input fields */
@media (max-width: 768px) {
    .input-fields {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .input-field {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .problem-input {
        width: 100%;
        text-align: left;
    }
}

/* Choice Input System */
.choice-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    margin-top: 10px;
}

.choice-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 60px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.choice-btn:hover {
    background: #5a67d8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.choice-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.choice-btn.selected {
    background: #28a745;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

/* Responsive design for choice buttons */
@media (max-width: 768px) {
    .choice-buttons {
        justify-content: flex-start;
        gap: 8px;
    }
    
    .choice-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
        min-width: 50px;
    }
}

/* Run Code Button */
.run-btn {
    background: #28a745;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 100px;
}

.run-btn:hover {
    background: #218838;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

/* Output */
.output-section {
    background: #ffffff;
    border-radius: 0 0 12px 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.output-header {
    background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    color: white;
    padding: 12px 20px;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.output-header span::before {
    content: "▶";
    font-size: 0.8rem;
    opacity: 0.8;
    margin-right: 8px;
}

.output {
    background: #fafbfc;
    color: #2d3748;
    padding: 20px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    min-height: 120px;
    max-height: 400px; /* 20 lines * 20px line height */
    white-space: pre-wrap;
    border: none;
    position: relative;
    overflow-x: auto;
    overflow-y: auto;
}

.output:empty::before {
    content: "Output will appear here when you run your code...";
    color: #a0aec0;
    font-style: italic;
}

.output.error {
    border-left: 4px solid #f56565;
}

.output.success {
    border-left: 4px solid #48bb78;
}

.output.running {
    border-left: 4px solid #4299e1;
}

/* Enhanced output content styling */
.output-content {
    margin-bottom: 15px;
}

.output-empty {
    color: #999;
    font-style: italic;
}

.output-message {
    margin-top: 15px;
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.output-message.success {
    background: #c6f6d5;
    color: #22543d;
    border: 1px solid #9ae6b4;
}

.output-message.error {
    background: #fed7d7;
    color: #742a2a;
    border: 1px solid #feb2b2;
}

.output-message.running {
    background: #bee3f8;
    color: #2a4365;
    border: 1px solid #90cdf4;
}





/* Output animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.output:not(:empty) {
    animation: fadeIn 0.3s ease-out;
}

/* Loading animation for running state */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.output.running::after {
    content: "Running...";
    position: absolute;
    top: 10px;
    right: 10px;
    color: #4a5568;
    font-style: italic;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: 1;
}

/* Truncation indicator */
.output-truncated {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 10px;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.output-truncated::before {
    content: "⚠️";
    font-size: 14px;
}

/* ===========================
   Canvas System Styles
   =========================== */

/* Canvas container - responsive sizing */
.canvas-container {
    width: 100%;
    max-width: 550px;
    margin: 0 auto 20px auto;
}

/* Grid wrapper for canvas + labels */
.canvas-grid-wrapper {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: 1fr auto;
    gap: 5px;
    width: fit-content;
    margin: 0 auto;
}

/* Canvas element */
canvas {
    grid-column: 2;
    grid-row: 1;
    border: 2px solid #667eea;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    image-rendering: pixelated;  /* Crisp pixels for GRID100 */
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    background: white;
}

/* GRID3 specific styling - larger cells */
canvas.grid3 {
    max-width: 360px;
}

/* GRID100 specific styling - smaller cells */
canvas.grid100 {
    max-width: 500px;
}

/* Y-axis labels - left column */
.canvas-labels-y {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    padding-right: 5px;
}

.canvas-labels-y span {
    font-size: 14px;
    font-weight: 500;
    color: #4a5568;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* X-axis labels - bottom row */
.canvas-labels-x {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    justify-content: space-around;
    padding-top: 5px;
    width: 100%;
}

.canvas-labels-x span {
    font-size: 14px;
    font-weight: 500;
    color: #4a5568;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

/* Spacer for grid alignment */
.canvas-label-spacer {
    grid-column: 1;
    grid-row: 2;
}

/* Scrollable text output container (separate from canvas) */
.output-text-scroll {
    max-height: 300px;
    overflow-y: auto;
    overflow-x: auto;
}

/* Output text container */
.output-text {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Remove scroll from main output when it has structure */
.output {
    overflow: visible;
    max-height: none;
}

/* Responsive canvas */
@media (max-width: 768px) {
    .canvas-container {
        max-width: 90vw;
    }

    canvas.grid3 {
        max-width: 270px;  /* 90px per cell x 3 */
    }

    canvas.grid100 {
        max-width: 400px;  /* 4px per cell x 100 */
    }

    .canvas-labels-x span,
    .canvas-labels-y span {
        font-size: 12px;
    }

    .canvas-labels-y {
        left: -25px;
    }
}

/* Mobile extra small screens */
@media (max-width: 480px) {
    canvas.grid3 {
        max-width: 240px;  /* 80px per cell x 3 */
    }

    canvas.grid100 {
        max-width: 320px;  /* 3.2px per cell x 100 */
    }
}

/* ===========================
   End Canvas System Styles
   =========================== */

/* Responsive output */
@media (max-width: 768px) {
    .output {
        font-size: 12px;
        padding: 15px;
        min-height: 100px;
    }
    
    .output-header {
        padding: 10px 15px;
        font-size: 0.8rem;
    }
}

/* Modals */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    position: relative;
    text-align: center;
}

.close {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #6c757d;
}

.close:hover {
    color: #495057;
}

.modal h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.5rem;
}

.completion-stats {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
}

.completion-stats p {
    margin: 5px 0;
    font-weight: 600;
}

.completion-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.btn:hover {
    background: #5a6fd8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .worksheet-selection {
        padding: 20px;
    }
    
    .worksheets-grid {
        grid-template-columns: 1fr;
    }
    
    .problem-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .worksheet-header {
        flex-direction: column;
        text-align: center;
    }
    
    .problem-header {
        flex-direction: column;
        text-align: center;
    }
    
    .completion-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
}

/* Code styling */
code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: #2c3e50;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    max-width: 400px;
    width: 90%;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.loading-content h2 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.loading-content p {
    color: #6c757d;
    font-size: 1rem;
}

/* Scroll Hint */
.scroll-hint {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 15px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: none;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.scroll-hint.animate {
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

.scroll-arrow {
    font-size: 1.5rem;
    font-weight: bold;
}

.scroll-text {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Success/Error states */
.success-message {
    background: #d4edda;
    color: #155724;
    padding: 10px;
    border-radius: 6px;
    margin: 10px 0;
    border: 1px solid #c3e6cb;
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 10px;
    border-radius: 6px;
    margin: 10px 0;
    border: 1px solid #f5c6cb;
}

/* Development Banner */
.dev-banner {
    background: linear-gradient(135deg, #ff6b6b, #ffa500);
    color: white;
    text-align: center;
    padding: 12px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 2px 10px rgba(255, 107, 107, 0.3);
    position: relative;
    z-index: 100;
}

.dev-banner span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* When trace mode hides the output content, square off and remove shadow */
.output-section.trace-active {
    border-radius: 0;
    box-shadow: none;
}

/* Seamlessly connect trace player to the output header above it */
.output-section.trace-active + #trace-player {
    margin-top: 0;
    border-top: none;
    border-radius: 0 0 8px 8px;
}

/* ── Trace Player ──────────────────────────────────────────────────────────── */

.trace-player {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin-top: 12px;
    overflow: hidden;
    background: #fff;
}

.trace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
}

.trace-step-count {
    color: #6c757d;
    font-weight: normal;
    font-size: 0.8rem;
}

.trace-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 7px 10px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    flex-wrap: wrap;
}

.trace-btn {
    padding: 3px 9px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
}

.trace-btn:hover:not(:disabled) {
    background: #e9ecef;
}

.trace-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.trace-play-btn {
    background: #667eea;
    color: white;
    border-color: #667eea;
    font-weight: 600;
}

.trace-play-btn:hover:not(:disabled) {
    background: #5a6fd6;
    border-color: #5a6fd6;
}

.trace-slider {
    flex: 1;
    min-width: 80px;
    accent-color: #667eea;
}

.trace-speed {
    padding: 3px 5px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.8rem;
    background: white;
}

.trace-vars-panel,
.trace-output-panel {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
}

.trace-output-panel,
.trace-full-output-panel {
    border-bottom: none;
}

.trace-full-output-panel {
    border-top: 1px solid #e9ecef;
    background: #fafbfc;
}

.trace-panel-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #6c757d;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.trace-vars {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    min-height: 24px;
}

.trace-empty {
    color: #adb5bd;
    font-size: 0.82rem;
    font-style: italic;
}

.trace-ann {
    display: inline-flex;
    align-items: center;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: monospace;
}

.trace-ann-done   { background: #fef3c7; border: 1px solid #f59e0b; color: #92400e; }
.trace-ann-assign { background: #d1fae5; border: 1px solid #34d399; color: #065f46; }
.trace-ann-true   { background: #d1fae5; border: 1px solid #34d399; color: #065f46; }
.trace-ann-false  { background: #fee2e2; border: 1px solid #f87171; color: #991b1b; }
.trace-ann-print  { background: #ede9fe; border: 1px solid #a78bfa; color: #4c1d95; gap: 4px; }
.trace-ann-print-val { font-weight: 700; color: #6d28d9; }
.trace-ann-if     { background: #e0f2fe; border: 1px solid #38bdf8; color: #0c4a6e; }
.trace-ann-eval   { background: #fef9c3; border: 1px solid #facc15; color: #713f12; gap: 4px; }
.trace-ann-eval-val { font-weight: 700; color: #a16207; }

.trace-for-ctx {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 4px;
    padding: 2px 8px;
    font-family: monospace;
    font-size: 0.82rem;
}

.trace-for-kw {
    color: #7c3aed;
    font-weight: 700;
}

.trace-for-target {
    color: #667eea;
    font-weight: 700;
}

.trace-for-iter {
    color: #2c3e50;
}

.trace-for-iter-items {
    font-family: monospace;
    color: #2c3e50;
}

.trace-iter-sep {
    color: #9ca3af;
}

.trace-iter-item {
    transition: all 0.15s;
}

.trace-iter-item.consumed {
    text-decoration: line-through;
    color: #9ca3af;
}

.trace-iter-item.current {
    background: rgba(102, 126, 234, 0.15);
    border-radius: 2px;
    padding: 0 2px;
    font-weight: 700;
    color: #4338ca;
}

.trace-var-row {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #f8f9fa;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 2px 8px;
    font-family: monospace;
    font-size: 0.82rem;
    transition: background 0.15s, border-color 0.15s;
}

.trace-var-row.trace-var-changed {
    background: #fff3cd;
    border-color: #ffc107;
}

.trace-var-name {
    color: #667eea;
    font-weight: 700;
}

.trace-var-eq {
    color: #9ca3af;
}

.trace-var-value {
    color: #2c3e50;
}

.trace-output-content {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    white-space: pre-wrap;
    color: #2c3e50;
    background: #f8f9fa;
    border-radius: 4px;
    padding: 6px 8px;
}

/* Sliding overlay for current trace step (background) */
.trace-line-overlay {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    background: rgba(102, 126, 234, 0.12);
    border-top: 1px solid rgba(102, 126, 234, 0.25);
    border-bottom: 1px solid rgba(102, 126, 234, 0.25);
    pointer-events: none;
    z-index: 1;
    will-change: top;
}

.trace-current-line-gutter {
    background: rgba(102, 126, 234, 0.35) !important;
    color: white !important;
}

/* Embedded Trace Card (worksheet) */
.trace-card {
    padding: 24px 30px;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8eeff 100%);
    border-left: 6px solid #667eea;
}

.trace-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.trace-card-icon {
    font-size: 1.4rem;
    line-height: 1;
    color: #667eea;
}

.trace-card-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #3730a3;
    font-weight: 700;
}

.trace-card-instruction {
    margin: 0 0 12px 0;
    font-size: 0.9rem;
    color: #6b7280;
    font-style: italic;
}

.trace-card-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.trace-card-footer .trace-step-count {
    font-family: monospace;
    font-size: 0.82rem;
    color: #4338ca;
    padding: 0 2px;
}

.trace-card-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    border: 1px solid #c7d2fe;
}

.trace-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.trace-btn:hover:not(:disabled) {
    background: #4f46e5;
}

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

.trace-btn-play {
    margin-left: 4px;
    min-width: 74px;
}

.trace-slider {
    flex: 1;
    accent-color: #667eea;
}

/* 3-column layout: code | variables | output */
.trace-card-layout {
    display: flex;
    gap: 0;
    align-items: flex-start;
    width: 100%;
}

/* Column 1: code editor — width set by JS to fit content, never grows beyond that */
.trace-card-editor-wrap {
    flex: 0 0 auto;
    min-width: 215px;
    border-radius: 6px 0 0 6px;
    overflow: hidden;
    border: 1px solid #c7d2fe;
}

/* Column 2: variables — fills remaining space; height grows via JS ratchet, never shrinks */
.trace-card-vars-col {
    flex: 3 0 130px;
    min-width: 130px;
    padding: 8px 12px;
    border: 1px solid #c7d2fe;
    border-left: none;
}

.trace-card-vars-col .trace-vars {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Column 3: output — fills remaining space; height grows via JS ratchet, never shrinks */
.trace-card-output-col {
    flex: 2 0 100px;
    min-width: 100px;
    padding: 8px 12px;
    border: 1px solid #c7d2fe;
    border-left: none;
    border-radius: 0 6px 6px 0;
    min-height: 60px;
}

