:root {
    --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(90, 37, 114, 0.2);
    --primary: #5a2572;
    --primary-hover: #4a1d5e;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --text-main: #1e293b;
    --text-muted: #475569;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #e2e8f0;
    color: #1e293b;
    font-family: var(--font-body);
    overflow-y: auto;
    padding: 20px;
}

h1, h2, h3, h4 {
    font-family: var(--font-heading);
    font-weight: 600;
}

/* --- GAMIFICATION PLAYER BAR --- */
.player-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid var(--primary);
    border-radius: 12px;
    padding: 15px 25px;
    margin-bottom: 30px;
    box-shadow: 0 8px 15px rgba(0,0,0,0.1);
    flex-wrap: wrap;
    gap: 20px;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.player-avatar {
    width: 60px; height: 60px;
    background: linear-gradient(135deg, #fbbf24, #f59e0b); /* Nova's Yellow */
    border-radius: 50%; border: 3px solid #1e293b;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; font-weight: bold; color: white;
    font-family: var(--font-heading);
    box-shadow: 0 4px 10px rgba(245, 158, 11, 0.4);
}

.player-details {
    display: flex;
    flex-direction: column;
}
.player-name {
    font-size: 24px; font-weight: 800; color: #1e293b;
    letter-spacing: 1px;
}
.player-title {
    font-size: 14px; font-weight: 600; color: var(--primary);
    text-transform: uppercase; background: rgba(90, 37, 114, 0.1);
    padding: 2px 8px; border-radius: 4px; margin-top: 4px;
    display: inline-block;
}

.player-xp-container {
    flex: 1; min-width: 250px; max-width: 400px;
}

.xp-labels {
    display: flex; justify-content: space-between;
    font-weight: 800; font-size: 14px; margin-bottom: 8px;
    color: #1e293b;
}

.xp-bar-bg {
    width: 100%; height: 20px; background: #cbd5e1;
    border-radius: 10px; border: 2px solid #1e293b;
    overflow: hidden;
}

.xp-bar-fill {
    height: 100%; background: linear-gradient(90deg, #009bdc, #10b981);
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.level-up-anim {
    animation: bounce 0.5s ease 3;
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* --- COMIC PANEL STATS OVERLAY --- */
.panel-stats {
    position: absolute;
    bottom: 0px; 
    left: 0px;
    width: 100%;
    padding: 10px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    color: #fff;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    justify-content: center;
    gap: 10px;
    opacity: 0;
    transition: opacity 0.5s ease;
    border-top: 2px solid #009bdc;
    z-index: 20;
}
.comic-panel.completed .panel-stats {
    opacity: 1;
}

.panel-stats span {
    color: #10b981;
}

/* --- COMIC PAGE LAYOUT --- */
.comic-page {
    max-width: 1000px;
    margin: 0 auto;
    background: #ffffff;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    border: 4px solid #0f172a;
    border-radius: 4px;
}

.comic-header {
    text-align: center;
    margin-bottom: 40px;
    font-family: 'Bangers', cursive;
}

.comic-header h1 {
    font-size: 72px;
    text-transform: uppercase;
    letter-spacing: 3px;
    margin: 0;
    color: #0f172a;
    text-shadow: 4px 4px 0 var(--primary);
    line-height: 1.1;
}
.comic-header p {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.comic-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-gap: 30px;
    margin-bottom: 20px;
}

.comic-grid .comic-panel:nth-child(3) {
    grid-column: span 2;
    aspect-ratio: 21/9;
}
.comic-panel {
    position: relative;
    border: 5px solid #0f172a;
    background: #000;
    overflow: visible; /* Ensure Badges can stick out */
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    aspect-ratio: 16/9;
}

/* Fix inner overflow for images while retaining outer overflow for badges */
.panel-img-container {
    width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0;
}

.panel-img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: filter 0.3s ease;
}

.comic-panel:hover {
    transform: scale(1.02);
    box-shadow: 8px 8px 0 rgba(0,0,0,0.8);
    z-index: 10;
}

/* Locked Panels */
.comic-panel.locked {
    cursor: not-allowed;
}

.comic-panel.locked .panel-img-container img {
    filter: grayscale(100%) brightness(40%);
}

.comic-panel.locked:hover {
    transform: none;
    box-shadow: none;
}

.panel-lock-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 64px;
    opacity: 0.8;
}

.panel-caption {
    position: absolute;
    bottom: 0; 
    left: 0; 
    width: 100%;
    background: rgba(15, 23, 42, 0.95);
    color: white;
    padding: 12px;
    font-family: var(--font-heading);
    border-top: 3px solid #0f172a;
    transform: translateY(100%);
    transition: transform 0.3s;
    font-size: 14px;
}

.comic-panel:not(.locked):hover .panel-caption,
.comic-panel.completed .panel-caption {
    transform: translateY(0);
}

.status-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 24px;
    background: white;
    border-radius: 50%;
    width: 32px; height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid #0f172a;
}

/* --- TOAST MESSAGES --- */
#toast-container {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    border-left: 5px solid var(--danger);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    font-size: 16px;
    font-family: var(--font-body);
    animation: slideDownToast 0.3s ease-out forwards;
}

@keyframes slideDownToast {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast.fade-out { animation: slideUpToast 0.3s ease-in forwards; }
@keyframes slideUpToast {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}

/* --- MODAL OVERLAY (Hacking Terminal) --- */
#modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(46, 38, 114, 0.7);
    backdrop-filter: blur(8px);
    z-index: 50;
    display: none; 
    justify-content: center;
    align-items: center;
    padding: 15px;
}
#modal-overlay.active {
    display: flex;
    animation: fadeInModal 0.3s ease;
}

@keyframes fadeInModal {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.glass-panel {
    background: var(--bg-gradient);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 24px;
    color: var(--text-main);
}

.app-container {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 24px;
    width: 95vw;
    max-width: 1400px;
    height: 85vh;
    position: relative;
    border: 2px solid var(--primary);
    overflow: visible;
}

.btn-close {
    position: absolute;
    top: -20px; right: -20px;
    background: var(--danger);
    color: white;
    border: 2px solid #0f172a;
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.5);
    transition: transform 0.2s, background 0.2s;
    z-index: 60;
}
.btn-close:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.main-content {
    display: flex; flex-direction: column; gap: 24px; height: 100%;
}

.customer-section {
    display: flex; flex-direction: column; gap: 16px; flex: 0 0 auto;
    background: var(--glass-bg);
}

.customer-header {
    display: flex; align-items: center; gap: 16px;
    padding-bottom: 16px; border-bottom: 1px solid var(--glass-border);
}

.customer-avatar {
    width: 48px; height: 48px; border-radius: 50%;
    background: linear-gradient(135deg, #5a2572, #2e2672);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 800; border: 2px solid var(--primary);
    color: white;
}

.customer-message {
    font-style: italic; color: var(--text-muted); font-size: 15px; line-height: 1.5;
}

.original-text {
    background: rgba(0, 155, 220, 0.1);
    padding: 16px; border-radius: 12px;
    border-left: 4px solid var(--primary);
    font-size: 15px; line-height: 1.6;
    user-select: text;
}

.original-text strong {
    display: block; margin-bottom: 8px; color: var(--primary);
}

.editor-section {
    flex: 1; display: flex; flex-direction: column; gap: 16px; min-height: 0;
    background: var(--glass-bg);
}

.editor-header {
    display: flex; justify-content: space-between; align-items: center;
}

.btn {
    padding: 8px 16px; border-radius: 8px; border: none;
    font-family: var(--font-body); font-weight: 600; cursor: pointer;
    transition: all 0.3s ease; font-size: 14px;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: scale(1.05); }
.btn-success { background: var(--success); color: white; box-shadow: 0 0 15px rgba(16, 185, 129, 0.4); animation: pulse 2s infinite; }
.btn-success:hover { background: var(--success-hover); transform: scale(1.05); }

.hidden { display: none !important; }

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

#editor {
    flex: 1; width: 100%;
    background: #ffffff;
    border: 2px solid var(--glass-border); border-radius: 12px;
    padding: 16px; color: var(--text-main);
    font-family: var(--font-body); font-size: 16px; line-height: 1.6;
    resize: none; outline: none; transition: border-color 0.3s ease;
}
#editor:focus { border-color: var(--primary); }

.analysis-panel {
    display: flex; flex-direction: column; gap: 24px; overflow-y: auto; height: 100%;
    background: var(--glass-bg);
}

.progress-section h3, .rules-section h3 {
    font-size: 18px; margin-bottom: 16px; color: var(--text-muted);
}

.progress-bar-container {
    width: 100%; height: 24px; background: rgba(0, 0, 0, 0.1);
    border-radius: 12px; overflow: hidden; position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.progress-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #ef4444 0%, #eab308 50%, #10b981 100%);
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; align-items: center; justify-content: flex-end;
    padding-right: 12px; font-size: 12px; font-weight: bold; color: white;
}

.rules-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }

.rule-item {
    background: #ffffff;
    border: 1px solid var(--glass-border);
    padding: 12px 16px; border-radius: 10px; display: flex; align-items: flex-start; gap: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.rule-item.violated { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.1); }
.rule-item.passed { border-color: rgba(16, 185, 129, 0.5); background: rgba(16, 185, 129, 0.1); }

.rule-icon { font-size: 18px; margin-top: 2px; }
.rule-content h4 { font-size: 14px; margin-bottom: 4px; color: var(--text-main); }
.rule-content p { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.2); border-radius: 10px; }

/* === RESPONSIVE DESIGN === */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr 300px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    .comic-page {
        padding: 15px;
        border-width: 2px;
    }
    .comic-header h1 {
        font-size: 38px;
    }
    .comic-header p {
        font-size: 16px;
    }

    /* Player Bar Scaling */
    .player-bar {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 15px;
        gap: 15px;
    }
    .player-xp-container {
        width: 100%;
        max-width: 100%;
        min-width: unset;
    }

    /* Panel Scaling */
    .comic-grid {
        grid-template-columns: 1fr;
        grid-gap: 20px;
    }
    .comic-grid .comic-panel:nth-child(3) {
        grid-column: span 1;
        aspect-ratio: 16/9;
    }
    .panel-caption {
        font-size: 12px;
        padding: 8px;
    }
    .panel-badge {
        width: 45px; height: 45px;
        font-size: 22px;
        bottom: 5px; right: 5px;
    }
    .status-icon {
        width: 28px; height: 28px;
        font-size: 16px;
    }
    .panel-lock-icon {
        font-size: 40px;
    }

    /* Modal Layout (Scrolling Stack) */
    .app-container {
        display: flex;
        flex-direction: column;
        height: 95vh;
        width: 95vw;
        padding: 15px;
        overflow-y: auto;
        gap: 15px;
    }
    .main-content {
        flex: 0 0 auto;
        height: auto;
    }
    .editor-section {
        min-height: 250px; /* Keep editor usable */
    }
    .analysis-panel {
        flex: 0 0 auto;
        height: auto;
        overflow-y: visible;
    }
    
    .btn-close {
        top: 2px; right: 2px;
        padding: 8px 12px;
        font-size: 12px;
    }
    .editor-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    .editor-header button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .comic-header h1 {
        font-size: 32px;
    }
    .player-name {
        font-size: 20px;
    }
    .player-avatar {
        width: 45px; height: 45px; font-size: 20px;
    }
    .toast {
        width: 90vw;
        font-size: 14px;
        padding: 12px 16px;
    }
    .customer-header {
        flex-direction: column;
        text-align: center;
    }
    .editor-section, .original-text {
        padding: 12px;
    }
}

/* =============================================
   === LIMES INTEGRATION STYLES ================
   ============================================= */

/* --- Editor Header Layout --- */
.editor-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* --- LIMES Server Status Indicator --- */
.limes-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: default;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    transition: background 0.3s ease;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
    animation: statusPulse 2s infinite;
}

.status-dot.disconnected {
    background: #94a3b8;
    box-shadow: none;
}

.status-label {
    font-family: var(--font-body);
}

@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(16, 185, 129, 0.4); }
    50% { box-shadow: 0 0 10px rgba(16, 185, 129, 0.8); }
}

/* --- LIMES Section in Sidebar --- */
.limes-section {
    border-top: 2px solid rgba(90, 37, 114, 0.15);
    padding-top: 20px;
    margin-top: 4px;
}

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

.limes-section-header h3 {
    font-size: 16px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}

.limes-badge {
    background: linear-gradient(135deg, #5a2572, #9333ea);
    color: white;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.limes-toggle-btn {
    background: none;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.limes-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* --- Complexity Score --- */
.limes-complexity-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 10px;
    margin-bottom: 12px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.complexity-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.complexity-value {
    font-size: 20px;
    font-weight: 800;
    font-family: var(--font-heading);
    color: var(--text-muted);
    transition: color 0.3s ease;
}
.complexity-value.low {
    color: var(--success);
}
.complexity-value.medium {
    color: #eab308;
}
.complexity-value.high {
    color: var(--danger);
}

/* --- Barriers Panel --- */
.limes-barriers-panel {
    max-height: 400px;
    overflow-y: auto;
    transition: max-height 0.4s ease, opacity 0.3s ease;
}
.limes-barriers-panel.collapsed {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
}

.limes-barriers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.limes-barrier-item {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.limes-barrier-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(90, 37, 114, 0.12);
}

.barrier-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.barrier-category {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(90, 37, 114, 0.1);
    color: var(--primary);
    white-space: nowrap;
}

/* Category-specific colors */
.barrier-category.hohes-sprachliches-niveau {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}
.barrier-category.komplexe-verb-konstruktion {
    background: rgba(234, 179, 8, 0.15);
    color: #a16207;
}
.barrier-category.verneinung {
    background: rgba(249, 115, 22, 0.12);
    color: #c2410c;
}
.barrier-category.satzbau {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
}
.barrier-category.informationsstruktur {
    background: rgba(6, 182, 212, 0.1);
    color: #0891b2;
}
.barrier-category.komposita {
    background: rgba(168, 85, 247, 0.1);
    color: #7c3aed;
}
.barrier-category.wortwahl {
    background: rgba(236, 72, 153, 0.1);
    color: #db2777;
}

.barrier-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
}

.barrier-description {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 6px;
}

.barrier-affected {
    margin-bottom: 6px;
}

.barrier-affected code {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 3px 8px;
    border-radius: 5px;
    font-size: 12px;
    color: #dc2626;
    font-family: 'Courier New', monospace;
    display: inline-block;
    word-break: break-word;
}

.barrier-suggestion {
    font-size: 12px;
    color: var(--success);
    font-weight: 500;
    padding: 6px 10px;
    background: rgba(16, 185, 129, 0.06);
    border-radius: 6px;
    border-left: 3px solid var(--success);
    line-height: 1.4;
}

/* --- Empty State --- */
.limes-empty {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-muted);
}
.limes-empty-icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
}
.limes-empty p {
    font-size: 13px;
    line-height: 1.5;
}

/* --- Responsive LIMES --- */
@media (max-width: 768px) {
    .limes-status {
        order: -1;
        width: 100%;
        justify-content: center;
    }
    .editor-header-right {
        width: 100%;
        flex-direction: column;
    }
    .editor-header-right .btn {
        width: 100%;
    }
    .limes-barriers-panel {
        max-height: 250px;
    }
}
