/* --- Base Theme Variables --- */
:root {
    --bg-main: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --border-color: rgba(0, 0, 0, 0.1);
    
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    
    --accent-primary: #00B5AC; /* Custom Hex */
    --accent-secondary: #00e0d6; /* Custom lighter teal */
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    
    --sidebar-width: 320px;
    --navbar-height: 70px;
    --radius-lg: 16px;
    --radius-md: 10px;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.05);
}

body.dark-theme {
    --bg-main: #0f1016; /* Deep dark blue/black */
    --bg-secondary: #161821;
    --bg-glass: rgba(22, 24, 33, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --accent-primary: #00B5AC;
    --accent-secondary: #00e0d6;
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* --- Global Reset & Typography --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body.dsa-page {
    background-color: var(--bg-main);
    color: var(--text-primary);
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow: hidden; /* Stop page scrolling, manage inside panels */
}

/* Typography Highlights */
.highlight {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* --- Navbar --- */
.navbar {
    height: var(--navbar-height);
    background-color: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
}

@media (max-width: 600px) {
    .navbar {
        padding: 0 0.8rem;
    }
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 1.5rem;
    font-weight: 700;
}
.logo-icon-img {
    height: 38px;
    width: 38px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid var(--accent-primary);
    animation: bounce 2s infinite ease-in-out;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.theme-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

.theme-btn:hover {
    background: var(--border-color);
    transform: rotate(15deg) scale(1.1);
}

/* Toggle icon logic */
body.dark-theme .dark-icon { display: none; }
body.dark-theme .light-icon { display: block; }
body:not(.dark-theme) .dark-icon { display: block; }
body:not(.dark-theme) .light-icon { display: none; }

.user-avatar {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid var(--accent-primary);
    background: linear-gradient(135deg, rgba(22, 24, 33, 0.8), rgba(0, 181, 172, 0.4));
    font-size: 1.5rem;
    box-shadow: 0 0 15px rgba(0, 181, 172, 0.4);
    cursor: pointer;
    transition: all 0.3s ease;
}

.user-avatar:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 0 25px rgba(0, 181, 172, 0.8);
}

/* --- App Container --- */
.app-container {
    display: flex;
    height: calc(100dvh - var(--navbar-height));
    margin-top: var(--navbar-height);
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}
.sidebar-content::-webkit-scrollbar {
    width: 6px;
}
.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.sidebar-footer {
    padding: 1.2rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    margin-top: auto;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.sidebar-footer img {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    object-fit: cover;
    border: 2px solid var(--accent-primary);
}

/* Tree Structure styling */
.chapter-wrapper, .subchapter-wrapper {
    margin-bottom: 0.5rem;
}

.tree-node {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    font-weight: 600;
    color: var(--text-secondary);
}

.tree-node:hover {
    background-color: rgba(0, 181, 172, 0.15);
    color: var(--accent-primary);
}

.tree-node i {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.tree-node.expanded > i {
    transform: rotate(90deg);
}

.tree-children {
    display: none;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
    border-left: 1px solid var(--border-color);
    margin-left: 1.25rem;
}

.tree-node.expanded + .tree-children {
    display: block;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.problem-node {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    margin-bottom: 0.3rem;
}

.problem-node::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--text-secondary);
}

.problem-node:hover {
    background-color: rgba(0, 181, 172, 0.15);
    color: var(--accent-primary);
    transform: translateX(4px);
}

.problem-node.active {
    background: var(--accent-gradient);
    color: white;
}
.problem-node.active::before {
    background-color: white;
}


/* --- Main Content Area --- */
.content-area {
    flex: 1;
    position: relative;
    padding: 2rem;
    padding-bottom: 4rem;
    overflow-y: auto;
}
.content-area::-webkit-scrollbar {
    width: 8px;
}
.content-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.hidden {
    display: none !important;
}

/* Welcome State */
.welcome-state {
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.welcome-card {
    text-align: center;
    padding: 4rem;
}

.welcome-card h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.welcome-card p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.floating-icons {
    display: flex;
    justify-content: center;
    gap: 2rem;
    color: var(--accent-primary);
}

.floating-icons i:nth-child(1) { animation: float 3s ease-in-out infinite; }
.floating-icons i:nth-child(2) { animation: float 3s ease-in-out infinite 1s; }
.floating-icons i:nth-child(3) { animation: float 3s ease-in-out infinite 2s; }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

/* Problem State */
.problem-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.problem-header h2 {
    font-size: 1.8rem;
    line-height: 1.2;
    word-wrap: break-word;
    max-width: 75%;
}

.difficulty-badge {
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.difficulty-badge.easy {
    background-color: rgba(74, 222, 128, 0.2);
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.4);
}

.difficulty-badge.medium {
    background-color: rgba(234, 179, 8, 0.2);
    color: #eab308;
    border-color: rgba(234, 179, 8, 0.4);
}

.difficulty-badge.hard {
    background-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.4);
}

/* Glass Card Reusable */
.glass-card {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

/* Segments Tabs */
.segment-tabs {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.segment-tabs::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome, Safari and Opera */
}

.tab-btn {
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-lg);
    border: none;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--border-color);
    white-space: nowrap;
    flex-shrink: 0;
}

.tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--accent-gradient);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
}

/* Segment Contents */
.segment-content-container {
    padding: 2rem;
    min-height: 400px;
    position: relative;
    overflow: hidden;
}

.segment-pane {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}

.segment-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.segment-pane h3 {
    margin-bottom: 1rem;
    font-size: 1.4rem;
    color: var(--accent-secondary);
}

.segment-pane p {
    line-height: 1.6;
    margin-bottom: 1rem;
}

.sub-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Explanation styling */
.cool-list {
    list-style: none;
    margin-top: 1rem;
}
.cool-list li {
    padding: 0.8rem;
    background: rgba(139, 92, 246, 0.05);
    border-left: 3px solid var(--accent-primary);
    margin-bottom: 0.5rem;
    border-radius: 0 8px 8px 0;
}

/* --- Hand Cricket Game UI --- */
.hc-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.2rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transition: transform 0.2s, background 0.2s;
    border: 2px solid var(--accent-primary);
}
.hc-btn:hover {
    transform: translateY(-4px) scale(1.1);
    background: var(--accent-primary);
    color: white;
}
.score-box {
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    border-radius: 12px;
    min-width: 120px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.05), var(--shadow-soft);
    border: 1px solid var(--border-color);
}

/* Code styling */
#pane-code {
    background: #1e1e1e;
    border-radius: var(--radius-md);
    overflow: hidden;
    color: #d4d4d4;
}

.code-header {
    background: #2d2d2d;
    padding: 0.6rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: #9cdcfe;
}

.code-lang-tabs {
    display: flex;
    gap: 0.5rem;
}

.code-lang-btn {
    background: transparent;
    border: none;
    color: #858585;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.code-lang-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.code-lang-btn:active {
    transform: translateY(0) scale(0.95);
}

.code-lang-btn.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--accent-secondary);
}

.code-lang-year {
    margin-left: 0.35rem;
    font-size: 0.65rem;
    opacity: 0.6;
    vertical-align: super;
}

.btn-copy {
    background: none;
    border: none;
    color: #858585;
    cursor: pointer;
    transition: color 0.2s;
}
.btn-copy:hover { color: #ffffff; }

#code-block {
    display: block; /* <code> is inline by default, so overflow-x would be ignored */
    padding: 1.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    line-height: 1.5;
    overflow-x: auto;
    margin: 0;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

#code-block::-webkit-scrollbar {
    height: 8px;
}

#code-block::-webkit-scrollbar-track {
    background: transparent;
}

#code-block::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    cursor: pointer;
}

#code-block::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Screenshots styling */
.ss-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}
.ss-img {
    width: 100%;
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    transition: transform 0.3s;
    cursor: pointer;
}
.ss-img:hover {
    transform: scale(1.05);
    border-color: var(--accent-primary);
}

/* Homework styling */
.homework-card {
    background: rgba(6, 182, 212, 0.1);
    border: 1px dashed var(--accent-secondary);
    padding: 2rem;
    border-radius: var(--radius-md);
    text-align: center;
    margin-top: 1.5rem;
}
.homework-icon {
    font-size: 3rem;
    color: var(--accent-secondary);
    margin-bottom: 1rem;
}

/* Funfact styling */
.funfact-wrapper {
    text-align: center;
    padding: 3rem 1rem;
}
.funfact-emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 1rem;
    animation: wiggle 2s infinite ease-in-out;
}
@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

/* --- Floating Feather Animation --- */
.floating-feather {
    position: fixed;
    bottom: -50px;
    pointer-events: none;
    z-index: 1000;
}

@keyframes floatUp {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(-110dvh) rotate(360deg); opacity: 0; }
}

/* --- Responsive Media Queries --- */
.hidden-lg {
    display: none;
}

@media (max-width: 900px) {
    .hidden-lg {
        display: flex;
        background: transparent;
        border: 1px solid var(--border-color);
        width: 40px;
        height: 40px;
        border-radius: 8px;
        color: var(--text-primary);
        cursor: pointer;
        justify-content: center;
        align-items: center;
        font-size: 1.2rem;
        transition: all 0.3s;
    }
    
    .menu-btn:hover {
        background: var(--border-color);
    }
    
    .sidebar {
        position: fixed;
        left: -100%;
        top: var(--navbar-height);
        height: calc(100dvh - var(--navbar-height));
        z-index: 50;
        transition: left 0.3s ease;
        box-shadow: 4px 0 15px rgba(0,0,0,0.5);
    }
    
    .sidebar.show {
        left: 0;
    }

    .content-area {
        padding: 1rem;
        padding-bottom: 3rem;
    }
    
    .welcome-card h1 {
        font-size: 2rem;
    }
    
    .segment-tabs {
        justify-content: flex-start;
        flex-wrap: wrap;
        overflow-x: visible;
    }
    
    .tab-btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 600px) {
    .logo-text {
        font-size: 1.1rem;
    }
    
    .nav-actions {
        gap: 0.8rem;
    }

    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
    }
    
    .problem-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8rem;
    }

    .problem-header h2 {
        font-size: 1.3rem;
        max-width: 100%;
    }
    
    .segment-content-container {
        padding: 1rem;
    }

    .code-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .code-lang-tabs {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .code-lang-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    #pane-code {
        border-radius: 8px;
        overflow: hidden;
    }

    #code-block {
        font-size: 0.75rem;
        padding: 1rem 0.75rem;
        line-height: 1.6;
        overflow-x: auto;
        white-space: pre;
        word-break: normal;
        -webkit-overflow-scrolling: touch;
    }

    pre {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .hc-btn {
        width: 42px;
        height: 42px;
        font-size: 1rem;
    }

    /* Fixed RPS Game Overflow for mobile */
    .score-box {
        padding: 0.8rem 1rem;
        min-width: 80px;
    }
    #rps-player-hand, #rps-comp-hand {
        font-size: 2rem !important;
    }
    #rps-player-score, #rps-comp-score {
        font-size: 1.5rem !important;
    }
}

/* --- Pattern Output Block (LeetCode style) --- */
.pattern-output {
    background: #1a1a2e;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent-primary);
    border-radius: 8px;
    padding: 1rem 1.2rem;
    margin-top: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.8;
    color: #a8ff78;
    white-space: pre;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

body:not(.dark-theme) .pattern-output {
    background: #f0fdf4;
    color: #166534;
    border-left-color: #22c55e;
}

/* --- LeetCode Styling --- */
.leetcode-io-card {
    background: rgba(139, 92, 246, 0.05);
    border-left: 3px solid var(--accent-secondary);
    border-radius: 0 8px 8px 0;
    padding: 1.2rem;
    margin-top: 1.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
}

.leetcode-io-card p {
    margin-bottom: 0.8rem;
}
.leetcode-io-card p:last-child {
    margin-bottom: 0;
}
.leetcode-io-card strong {
    color: var(--text-primary);
    font-weight: 700;
}

.constraints-list {
    list-style: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}
.constraints-list li {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
}
body:not(.dark-theme) .constraints-list li {
    background: rgba(0, 0, 0, 0.05);
}
