/* === VARIABLEN === */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --success: #22c55e;
    --success-light: #dcfce7;
    --error: #ef4444;
    --error-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --header-purple: #7c3aed;
}

/* === GRUNDEINSTELLUNGEN === */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    line-height: 1.6;
}

/* === HEADER === */
.worksheet-header {
    background: linear-gradient(135deg, var(--header-purple) 0%, var(--primary) 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.subject-tag {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
}

.worksheet-header h1 {
    margin: 0;
    font-size: 1.4em;
    font-weight: 600;
}

.header-logo {
    height: 45px;
    width: auto;
}

.worksheet-number {
    background: white;
    color: var(--header-purple);
    padding: 8px 15px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.1em;
}

/* === TAB NAVIGATION === */
.tab-navigation {
    display: flex;
    background: white;
    padding: 10px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    justify-content: center;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: 2px solid transparent;
    border-radius: 10px;
    background: var(--bg);
    color: var(--text-muted);
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-dark);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.tab-icon {
    font-size: 1.2em;
}

/* === MAIN CONTENT === */
.worksheet-content {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === COLLAPSIBLE SECTIONS === */
.collapsible-section {
    background: white;
    border-radius: var(--radius);
    margin-bottom: 15px;
    box-shadow: 0 2px 8px var(--shadow);
    overflow: hidden;
}

.collapse-toggle {
    width: 100%;
    padding: 15px 20px;
    background: white;
    border: none;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.05em;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: background 0.2s;
}

.collapse-toggle:hover {
    background: var(--bg);
}

.toggle-icon {
    transition: transform 0.3s ease;
    font-size: 0.8em;
    color: var(--text-muted);
}

.collapse-toggle.open .toggle-icon {
    transform: rotate(90deg);
}

.collapse-content {
    display: none;
    padding: 0 20px 20px;
}

.collapse-content.open {
    display: block;
}

/* === INSTRUCTION GRID === */
.instruction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.instruction-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.instruction-icon {
    font-size: 1.5em;
    flex-shrink: 0;
}

.instruction-text {
    font-size: 0.95em;
}

/* === PDF VIEWER === */
.pdf-container {
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.pdf-viewer {
    width: 100%;
    height: 70vh;
    min-height: 500px;
    border: none;
}

/* === SUMMARY BOX === */
.summary-box {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 15px;
    border-left: 4px solid var(--warning);
}

.summary-box h3 {
    margin: 0 0 12px 0;
    color: #92400e;
}

.summary-box ul {
    margin: 0;
    padding-left: 20px;
}

.summary-box li {
    margin-bottom: 8px;
    color: #78350f;
}

/* === PROGRESS BAR === */
.progress-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px var(--shadow);
}

.progress-bar {
    flex: 1;
    height: 12px;
    background: var(--bg);
    border-radius: 6px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--success), #4ade80);
    border-radius: 6px;
    transition: width 0.5s ease;
}

.progress-text {
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* === EXERCISE CARDS === */
.exercise-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px var(--shadow);
    border: 2px solid transparent;
    transition: border-color 0.3s;
}

.exercise-card.completed {
    border-color: var(--success);
}

.exercise-card.wrong {
    border-color: var(--error);
}

.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.exercise-number {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
}

.exercise-type {
    color: var(--text-muted);
    font-size: 0.85em;
}

.exercise-card h3 {
    margin: 0 0 10px 0;
    font-size: 1.15em;
}

.exercise-instruction {
    color: var(--text-muted);
    font-size: 0.95em;
    margin-bottom: 15px;
}

.exercise-hint {
    background: var(--warning-light);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 0.9em;
    color: #92400e;
}

.exercise-feedback {
    margin-top: 15px;
    padding: 12px 15px;
    border-radius: 8px;
    display: none;
    font-weight: 500;
}

.exercise-feedback.success {
    display: block;
    background: var(--success-light);
    color: #166534;
}

.exercise-feedback.error {
    display: block;
    background: var(--error-light);
    color: #991b1b;
}

/* === TAP-TAP === */
.tap-tap-container {
    display: flex;
    gap: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.tap-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 140px;
}

.tap-item {
    padding: 12px 20px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    user-select: none;
    -webkit-user-select: none;
}

.tap-item:hover {
    border-color: var(--primary);
    background: white;
}

.tap-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
}

.tap-item.matched {
    border-color: var(--success);
    background: var(--success-light);
    color: #166534;
    cursor: default;
    pointer-events: none;
}

.tap-item.wrong {
    border-color: var(--error);
    background: var(--error-light);
    animation: shake 0.4s ease;
}

/* === CLOZE (Lückentext) === */
.cloze-container {
    background: var(--bg);
    padding: 20px;
    border-radius: 8px;
}

.cloze-text {
    font-size: 1.05em;
    line-height: 2.2;
    margin-bottom: 10px;
}

.cloze-select {
    padding: 6px 12px;
    font-size: 1em;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    min-width: 150px;
}

.cloze-select:focus {
    outline: none;
    border-color: var(--primary);
}

.cloze-select.correct {
    border-color: var(--success);
    background: var(--success-light);
}

.cloze-select.incorrect {
    border-color: var(--error);
    background: var(--error-light);
}

/* === MULTIPLE CHOICE === */
.mc-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mc-options.single .mc-option {
    text-align: left;
    padding: 15px 20px;
}

.mc-option {
    padding: 12px 20px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.mc-option:hover:not(.selected):not(.correct):not(.incorrect) {
    border-color: var(--primary);
    background: white;
}

.mc-option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.mc-option.correct {
    border-color: var(--success);
    background: var(--success-light);
    color: #166534;
}

.mc-option.incorrect {
    border-color: var(--error);
    background: var(--error-light);
    color: #991b1b;
}

/* === SUMMARY BOX (in collapsible) === */
.summary-section {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid var(--warning);
}

.summary-section .collapse-toggle {
    background: transparent;
}

.summary-section .collapse-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.summary-box-content {
    padding: 5px 0;
}

.summary-box-content ul {
    margin: 0;
    padding-left: 20px;
}

.summary-box-content li {
    margin-bottom: 8px;
    color: #78350f;
}

/* === SORT-TAP (Tap-basiertes Sortieren) === */
.sort-tap-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.sort-tap-source {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.sort-tap-item {
    padding: 12px 24px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    user-select: none;
    -webkit-user-select: none;
}

.sort-tap-item:hover {
    border-color: var(--primary);
    background: white;
}

.sort-tap-item.used {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.sort-tap-result {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.sort-slot {
    width: 100px;
    padding: 12px;
    background: white;
    border: 2px dashed var(--border);
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.sort-slot.filled {
    border-style: solid;
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
}

.sort-slot.correct {
    border-color: var(--success);
    background: var(--success-light);
    color: #166534;
}

.sort-slot.incorrect {
    border-color: var(--error);
    background: var(--error-light);
    color: #991b1b;
}

.reset-btn {
    padding: 10px 20px;
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95em;
    cursor: pointer;
    margin-top: 15px;
    margin-left: 10px;
}

.reset-btn:hover {
    background: white;
    border-color: var(--text-muted);
}

/* === SORTABLE (legacy, kann entfernt werden) === */
.sortable-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 300px;
    margin: 0 auto;
}

.sortable-item {
    padding: 12px 20px;
    background: white;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    text-align: center;
    font-weight: 500;
    user-select: none;
    -webkit-user-select: none;
}

.sortable-item:active {
    cursor: grabbing;
}

.sortable-item.dragging {
    opacity: 0.5;
    border-color: var(--primary);
}

.sortable-item.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

.sortable-item.correct-position {
    border-color: var(--success);
    background: var(--success-light);
}

.sortable-item.wrong-position {
    border-color: var(--error);
    background: var(--error-light);
}

/* === BUTTONS === */
.check-btn, .btn-primary {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 15px;
}

.check-btn:hover, .btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* === RESULT BOX === */
.result-box {
    display: none;
    background: linear-gradient(135deg, var(--success-light) 0%, #bbf7d0 100%);
    border-radius: var(--radius);
    padding: 30px;
    text-align: center;
    margin-top: 20px;
    border: 2px solid var(--success);
}

.result-box.show {
    display: block;
}

.result-box h3 {
    margin: 0 0 10px 0;
    color: #166534;
}

/* === TUTOR SECTION === */
.tutor-task-container {
    background: white;
    border-radius: var(--radius);
    padding: 15px 20px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px var(--shadow);
}

.tutor-task-header {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.task-label {
    font-weight: 600;
    color: var(--text);
}

.task-select {
    flex: 1;
    min-width: 200px;
    padding: 12px 15px;
    font-size: 1.05em;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
    cursor: pointer;
}

.task-select:focus {
    outline: none;
    border-color: var(--primary);
}

.tutor-task-description {
    margin-top: 10px;
    padding: 12px 15px;
    background: var(--bg);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.95em;
}

/* === TUTOR CONTAINER === */
.tutor-container {
    background: white;
    border-radius: var(--radius);
    padding: 15px;
    box-shadow: 0 2px 8px var(--shadow);
}

.toolbox {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
    margin-bottom: 15px;
    justify-content: center;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.tool-group label {
    font-size: 0.85em;
    color: var(--text-muted);
}

.tool {
    padding: 10px 14px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95em;
}

.tool:hover:not(.active):not(:disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.tool.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

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

#clear-button {
    background: var(--error-light);
    border-color: var(--error);
    color: var(--error);
}

#clear-button:hover {
    background: var(--error);
    color: white;
}

/* === TUTOR MAIN LAYOUT - MOBILE FIRST (GROSS!) === */
.tutor-main {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.canvas-container {
    position: relative;
    width: 100%;
}

#drawing-canvas {
    display: block;
    width: 100%;
    height: auto;
    min-height: 55vh; /* Mehr als halber Bildschirm */
    background: white;
    border: 2px solid var(--border);
    border-radius: 8px;
    touch-action: none;
    cursor: crosshair;
}

#chat-container {
    display: flex;
    flex-direction: column;
    min-height: 450px;
    height: 55vh; /* Mehr als halber Bildschirm */
    max-height: 600px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

#chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #fafafa;
}

.message {
    margin-bottom: 12px;
    padding: 14px 18px;
    border-radius: 16px;
    max-width: 90%;
    line-height: 1.6;
    font-size: 1.05em;
}

.ai-message {
    background: #eef1f5;
    color: var(--text);
    float: left;
    clear: both;
}

.user-message {
    background: var(--primary);
    color: white;
    float: right;
    clear: both;
}

.chat-input {
    display: flex;
    padding: 12px;
    gap: 10px;
    background: white;
    border-top: 1px solid var(--border);
}

#question-input {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1.05em;
}

#question-input:focus {
    outline: none;
    border-color: var(--primary);
}

#send-button {
    padding: 14px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1.05em;
    cursor: pointer;
    min-width: 100px;
}

#send-button:hover {
    background: var(--primary-dark);
}

#send-button:disabled {
    background: var(--primary-light);
    cursor: wait;
}

/* === FOOTER === */
.worksheet-footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
    font-size: 0.9em;
    border-top: 1px solid var(--border);
    margin-top: 30px;
    background: var(--bg);
}

.footer-logo {
    margin-bottom: 15px;
}

.wk-logo {
    height: 80px;
    width: auto;
    opacity: 0.9;
    transition: opacity 0.3s ease;
}

.wk-logo:hover {
    opacity: 1;
}

/* === ANIMATIONS === */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* === RESPONSIVE - TABLET (iPad) === */
@media (min-width: 768px) {
    .tutor-main {
        flex-direction: row;
        align-items: stretch;
        min-height: 70vh; /* Mindestens 70% Bildschirmhöhe */
    }
    
    .canvas-container {
        flex: 3;
        min-width: 0;
    }
    
    #drawing-canvas {
        min-height: 550px;
        height: 68vh; /* Fast 70% Bildschirmhöhe */
        max-height: 800px;
    }
    
    #chat-container {
        flex: 2;
        height: auto;
        min-height: 550px;
        max-height: none;
    }
    
    .message {
        font-size: 1.1em;
        padding: 16px 20px;
    }
    
    #question-input {
        font-size: 1.15em;
        padding: 18px;
        min-height: 60px;
    }
    
    #send-button {
        font-size: 1.15em;
        padding: 18px 30px;
        min-height: 60px;
    }
}

/* === RESPONSIVE - DESKTOP === */
@media (min-width: 1100px) {
    .worksheet-content {
        max-width: 1600px; /* Breiterer Container */
    }
    
    .tutor-main {
        gap: 20px;
        min-height: 75vh;
    }
    
    .canvas-container {
        flex: 2;
    }
    
    #drawing-canvas {
        min-height: 600px;
        height: 72vh; /* Noch größer auf Desktop */
    }
    
    #chat-container {
        flex: 1;
        min-width: 450px;
        max-width: 550px;
    }
}

/* === RESPONSIVE - MOBILE === */
@media (max-width: 600px) {
    .worksheet-header h1 {
        font-size: 1.1em;
    }
    
    .tab-btn {
        padding: 10px 15px;
        font-size: 0.9em;
    }
    
    .tab-label {
        display: none;
    }
    
    .tab-icon {
        font-size: 1.4em;
    }
    
    .tap-tap-container {
        flex-direction: column;
        align-items: center;
    }
    
    .tap-column {
        width: 100%;
        max-width: 200px;
    }
    
    .pdf-viewer {
        height: 50vh;
        min-height: 350px;
    }
    
    .exercise-card {
        padding: 15px;
    }
}

/* === DYNAMIC TEXT INPUT === */
.dynamic-text-input {
    position: absolute;
    border: 2px dashed var(--primary);
    font-family: sans-serif;
    padding: 4px;
    z-index: 100;
    outline: none;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
}
