:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #ec4899;
    --accent: #14b8a6;
    
    --bg-gradient-start: #f8fafc;
    --bg-gradient-end: #e2e8f0;
    --bg-dark: #f1f5f9;
    --bg-panel: rgba(255, 255, 255, 0.85);
    --bg-card: rgba(255, 255, 255, 0.95);
    
    --text-main: #0f172a;
    --text-muted: #475569;
    
    --glass-border: rgba(0, 0, 0, 0.1);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e1b4b;
    --bg-dark: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --bg-card: rgba(30, 41, 59, 0.9);
    
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar Styling */
.sidebar {
    width: 300px;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 10;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    position: absolute;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--glass-border);
    background: linear-gradient(to right, rgba(99, 102, 241, 0.05), transparent);
}

.sidebar-header .icon-container {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    border-radius: 12px;
    flex-shrink: 0;
}

.sidebar-header .icon-container i {
    font-size: 1.4rem;
    color: #ffffff;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0.5px;
    color: var(--text-main);
    flex: 1;
}

.badge {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    color: #ffffff;
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(249, 115, 22, 0.3);
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

/* Custom Scrollbar for Sidebar */
.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}
.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-menu::-webkit-scrollbar-thumb {
    background: var(--primary-dark);
    border-radius: 10px;
}

/* Floating Action Buttons */
.floating-actions {
    position: fixed;
    bottom: 25px;
    right: 25px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 900;
}

.float-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--glass-border);
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.float-btn:hover {
    background: var(--primary);
    color: #ffffff;
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.3);
}

/* Menu Items */
.menu-group {
    margin-bottom: 1rem;
}

.menu-title {
    padding: 0.5rem 1.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--primary-light);
    font-weight: 700;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-list {
    list-style: none;
}

.menu-item {
    padding: 0.8rem 1.5rem 0.8rem 2.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    transition: var(--transition);
    border-left: 3px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-left-color: var(--primary-light);
}

.menu-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.2) 0%, transparent 100%);
    color: var(--text-main);
    border-left-color: var(--primary);
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;    /* Flex zincirini kapat — scroll container çalışsın */
    overflow: hidden; /* main-layout'un scroll'u devralmasını sağla */
}

.content-header {
    height: 70px;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 5;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#current-lesson-title {
    font-size: 1.3rem;
    font-weight: 600;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    outline: none;
    font-family: 'Outfit', sans-serif;
    border-radius: 8px;
    transition: var(--transition);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--primary);
    transform: scale(1.05);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0.6rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

/* Çizim modu aktifken butonu vurgula */
#btn-draw.active {
    background: linear-gradient(135deg, #7c3aed 0%, #4c1d95 100%);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.3), 0 0 0 2px rgba(124, 58, 237, 0.4);
    transform: translateY(0);
}

.btn-sidebar-link {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: 8px;
    transition: background 0.2s; /* Sadece renk değişimi, zıplama ve gölge yok */
}

.btn-sidebar-link:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    color: white;
    padding: 0.6rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

/* Content Area */
.main-layout {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0; /* Important for flex child scrolling */
}

.main-layout::-webkit-scrollbar {
    width: 6px;
}
.main-layout::-webkit-scrollbar-track {
    background: transparent;
}
.main-layout::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.3);
    border-radius: 10px;
}

.content-area {
    flex: 1;
    position: relative;
    background: var(--bg-dark);
    min-width: 0; /* Prevent flex overflow */
    min-height: 0; /* Important for vertical scrolling inside flex */
    overflow: hidden; /* iframe handles its own scroll on desktop */
}

#content-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* Ad Sidebar */
.ad-sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-left: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* İki bölge içeride yönetir */
}

/* Alt bölge: Sabit alan (Reklam vb.) */
.ad-zone {
    flex-shrink: 0;
    padding: 15px 15px 10px 15px;
    border-top: 1px solid var(--glass-border);
}

/* Üst bölge: Bilgi kartları — kalan alanı doldurur, gerekirse scroll */
.info-zone {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.info-zone::-webkit-scrollbar {
    width: 4px;
}
.info-zone::-webkit-scrollbar-track {
    background: transparent;
}
.info-zone::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.3);
    border-radius: 10px;
}

.ad-slot {
    width: 100%;
    height: auto;
    margin: 0 auto; /* Reklamı yatayda ortala (özellikle mobilde) */
    display: flex;
    align-items: center;
    justify-content: center;
}

.bty-ad-slot {
    width: 250px;
    height: 250px;
}

@media (max-width: 1300px) {
    .bty-ad-slot {
        width: 100%;
        height: 300px;
        max-width: 100%;
    }
}

/* Drawing Canvas */
#drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    cursor: crosshair;
    pointer-events: auto;
}

#drawing-tools {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 60;
    box-shadow: var(--glass-shadow);
    box-sizing: border-box; /* Padding taşmasını önle */
    max-width: calc(100vw - 40px); /* Ekrandan taşmasın */
    white-space: nowrap; /* İçerik alt satıra inmesin */
}

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

/* Tablet/Small Screen Responsiveness */
@media (max-width: 1300px) {
    /* Sayfanın kendisi (body) kaydirsın — en güvenilir yöntem */
    body {
        height: auto;
        min-height: 100vh;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
        flex-direction: row; /* Solda nav, sağda main-content */
    }

    .main-content {
        overflow: visible; /* İçerik taşabilsin, body scroll eder */
        min-height: 0;
    }

    .main-layout {
        flex-direction: column;
        overflow: visible; /* Body scroll eder, içeride scroll container gerekmez */
    }

    /* Başlık tek satırda, sığmazsa ... ile kesilir */
    #current-lesson-title {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    .header-left {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        gap: 0.4rem;
    }

    .content-header {
        gap: 0.75rem; /* Başlık ile sağ butonlar arası boşluk */
    }
    
    .content-area {
        flex-shrink: 0;
        width: 100%;
        overflow: visible;
    }

    #content-frame {
        position: static;
        width: 100%;
        height: auto;
    }
    
    .ad-sidebar {
        width: 100%;
        height: auto;
        flex-shrink: 0;
        border-left: none;
        border-top: 1px solid var(--glass-border);
        overflow: visible;
        flex-direction: column;
    }

    .ad-zone {
        padding: 15px;
        border-top: 1px solid var(--glass-border);
    }

    .info-zone {
        overflow: visible;
        padding: 15px;
    }

    /* Sol nav sidebar: body scroll edilirken yerinde kalsın */
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        flex-shrink: 0;
        align-self: flex-start;
    }
}

@media (max-width: 768px) {
    body {
        height: auto;
        overflow: visible;
        overflow-x: hidden;
    }

    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    .sidebar {
        position: fixed;
        width: 100%;
        height: 100%;
        z-index: 100;
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .main-content {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .content-header {
        position: sticky;
        top: 0;
        z-index: 50;
        background: var(--bg-panel);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid var(--glass-border);
        height: 70px;
        min-height: auto;
        padding: 0 0.5rem;
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }

    #content-frame {
        min-height: calc(100vh - 70px);
        /* Height will be set by JS for mobile, and overflow disabled inside iframe */
    }

    .header-left {
        width: auto;
        flex: 1;
        min-width: 0;
        gap: 0.5rem;
    }

    .header-right {
        width: auto;
        justify-content: flex-end;
        gap: 0.3rem;
    }

    #current-lesson-title {
        font-size: 0.95rem;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        white-space: normal;
        max-width: 100%;
        line-height: 1.1;
    }

    .btn-primary span, .btn-danger span {
        display: none;
    }

    .btn-primary, .btn-danger {
        width: 40px;
        height: 40px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }
    
    .btn-primary i, .btn-danger i {
        font-size: 1.1rem;
    }

    #btn-fullscreen {
        display: none !important;
    }

    #drawing-tools {
        width: auto;
        max-width: calc(100vw - 32px);
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        flex-wrap: nowrap;
        justify-content: center;
        padding: 8px 14px;
        gap: 10px;
    }
}
