:root {
    --bg-dark: #0a0a0a;
    --nav-bg: #121212;
    --panel-bg: #1a1a1a;
    --accent-green: #00ff88;
    --accent-blue: #00e5ff;
    --text-primary: #f0f0f0;
    --text-muted: #888888;
    --line-highlight: rgba(0, 255, 136, 0.15);
    --border: #2a2a2a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100%;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

#app { 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    width: 100%; 
}

main { 
    flex: 1; 
    overflow: hidden; 
    position: relative;
    display: flex;
    flex-direction: column;
}

.view { 
    flex: 1; 
    display: none; 
    flex-direction: column; 
    overflow-y: auto; 
    -webkit-overflow-scrolling: touch;
    width: 100%;
    padding-bottom: 72px; /* Matches bottom-nav height */
    overscroll-behavior-y: contain;
}
.view:not(.hidden) { display: flex; }
.hidden { display: none !important; }

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(6, 1fr); /* Force 6 equal rows */
    gap: 10px;
    padding: 12px;
    flex: 1;
    min-height: calc(100vh - 64px - 72px);
    box-sizing: border-box;
}

.cat-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.cat-card:active { transform: scale(0.95); background: #222; }

.cat-icon { 
    width: 28px; 
    height: 28px; 
    color: var(--accent-green); 
    margin-bottom: 8px;
    flex-shrink: 0;
}
.cat-icon svg { width: 100%; height: 100%; }
.cat-name { 
    font-weight: 600; 
    font-size: 0.85rem; 
    color: var(--text-primary); 
    letter-spacing: -0.01em; 
    line-height: 1.2;
}

/* Headers */
.top-bar, .list-header, .panel-header {
    height: 64px;
    background: var(--nav-bg);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: auto 1fr auto; /* Rigid 3-column layout */
    align-items: center;
    padding: 0 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    gap: 12px;
}

.back-btn-wrapper {
    display: contents; /* Children (Icon and Title) will behave like grid items */
}

.back-icon-circle {
    grid-column: 1;
    width: 34px;
    height: 34px;
    background: var(--panel-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-green);
    border: 1px solid var(--border);
    font-size: 1.1rem;
}

.top-main-title {
    grid-column: 2;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent-green);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* Enable truncation */
}

.controls {
    grid-column: 3;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-self: end;
}

/* Lab View */
#view-lab { overflow: hidden; padding-bottom: 0; }
.lab-container { display: flex; flex-direction: column; height: 100%; width: 100%; }
.editor-panel { display: flex; flex-direction: column; height: 45%; background: #000; border-bottom: 1px solid var(--border); }

.code-viewer { 
    flex: 1; 
    padding: 16px; 
    overflow-y: auto; 
    font-family: 'JetBrains Mono', monospace; 
    font-size: 0.9rem; /* Restored size */
    line-height: 1.5; 
    color: #d0d0d0; 
}


.code-line { display: flex; border-left: 2px solid transparent; white-space: pre; }
.code-line.active { background: rgba(0, 255, 136, 0.1); border-left-color: var(--accent-green); }
.line-num { width: 28px; color: #444; margin-right: 16px; text-align: right; user-select: none; font-size: 0.75rem; }

/* Syntax Highlighting */
.code-keyword { color: #ff79c6; font-weight: bold; }
.code-header { color: #8be9fd; }
.code-string { color: #f1fa8c; }
.code-comment { color: #6272a4; font-style: italic; }
.code-number { color: #bd93f9; }
.code-type { color: #50fa7b; }
.code-func { color: #8be9fd; }

.debug-panel { flex: 1; padding: 16px; background: var(--bg-dark); overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.variable-watch table { width: 100%; border-collapse: collapse; font-family: 'JetBrains Mono', monospace; }
.variable-watch th, td { border: 1px solid var(--border); padding: 8px; text-align: left; font-size: 0.75rem; }
.variable-watch th { color: var(--text-muted); font-weight: 500; }
.variable-watch td { color: var(--accent-blue); }

.explanation-box { background: var(--panel-bg); padding: 14px; border-radius: 10px; border-left: 4px solid var(--accent-blue); font-size: 0.85rem; line-height: 1.5; color: #ccc; }
#graphic-output { background: #000; border: 1px solid var(--border); border-radius: 12px; height: 200px; width: 100%; display: flex; align-items: center; justify-content: center; margin-bottom: 15px; overflow: hidden; }
#graphic-output svg { max-width: 90%; max-height: 90%; }
.terminal { background: #000; padding: 14px; border-radius: 10px; font-family: 'JetBrains Mono', monospace; color: var(--accent-green); min-height: 64px; font-size: 0.8rem; border: 1px solid #111; white-space: pre-wrap; }

/* List Styles */
.list-container { padding: 12px; }
.list-item {
    background: var(--panel-bg);
    margin-bottom: 8px;
    padding: 14px 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}
.list-item:active { background: #222; }
.list-item-icon { width: 24px; height: 24px; color: var(--accent-green); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.list-item-icon svg { width: 100%; height: 100%; }
.list-item-content { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.list-item .title { font-weight: 500; font-size: 0.9rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .subtitle { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em; }
.list-item .arrow { color: var(--text-muted); font-size: 0.8rem; margin-left: 12px; flex-shrink: 0; }

/* Quiz */
.quiz-container { padding: 16px; width: 100%; max-width: 600px; margin: 0 auto; flex: 1; }
.quiz-stats { display: flex; justify-content: space-between; margin-bottom: 16px; font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.quiz-card { background: var(--panel-bg); padding: 24px; border-radius: 20px; border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.quiz-question { margin-bottom: 24px; font-weight: 600; line-height: 1.5; font-size: 1.05rem; white-space: pre-wrap; color: #fff; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-btn { padding: 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-dark); color: var(--text-primary); text-align: left; cursor: pointer; font-size: 0.9rem; font-weight: 500; transition: all 0.2s; }
.quiz-btn:active { background: #111; transform: scale(0.98); }
.quiz-btn.correct { background: var(--accent-green) !important; color: var(--bg-dark) !important; border-color: var(--accent-green) !important; font-weight: 700; }
.quiz-btn.wrong { background: #ff4757 !important; color: white !important; border-color: #ff4757 !important; }
.btn-cancel-quiz { margin-top: 24px; width: 100%; background: transparent; border: 1.5px solid var(--border); color: var(--text-muted); padding: 12px; border-radius: 12px; font-size: 0.85rem; font-weight: 600; cursor: pointer; text-transform: uppercase; letter-spacing: 0.05em; }

/* Search */
#view-search { overflow: hidden; padding-bottom: 0; }
.search-container { padding: 16px 16px 0; width: 100%; height: 100%; display: flex; flex-direction: column; gap: 12px; }
#search-input { width: 100%; padding: 14px 20px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel-bg); color: white; outline: none; font-size: 0.95rem; font-weight: 500; flex-shrink: 0; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
#search-input:focus { border-color: var(--accent-green); }
#search-results { flex: 1; overflow-y: auto; overscroll-behavior-y: contain; padding: 4px 0 120px; }

/* About */
.about-container { padding: 16px; width: 100%; max-width: 600px; margin: 0 auto; flex: 1; }
.about-card { background: var(--panel-bg); padding: 24px; border-radius: 20px; border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.dev-info { text-align: center; margin-bottom: 30px; }
.dev-avatar { width: 64px; height: 64px; background: var(--accent-green); color: var(--bg-dark); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 800; margin: 0 auto 15px; }
.dev-info h3 { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 5px; }
.dev-info h2 { font-size: 1.4rem; color: #fff; font-weight: 700; }
.about-section { margin-bottom: 25px; }
.about-section h4 { color: var(--accent-green); font-size: 0.9rem; margin-bottom: 8px; text-transform: uppercase; }
.about-section p { color: var(--text-muted); font-size: 0.85rem; line-height: 1.6; }

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 72px;
    background: rgba(18, 18, 18, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 9999;
}
.bottom-nav.disabled { pointer-events: none; opacity: 0.4; filter: grayscale(1); }
.nav-item { background: none; border: none; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; font-size: 0.7rem; cursor: pointer; flex: 1; height: 100%; justify-content: center; font-weight: 600; }
.nav-item .icon { width: 24px; height: 24px; margin-bottom: 4px; opacity: 0.7; display: flex; align-items: center; justify-content: center; }
.nav-item .icon svg { width: 100%; height: 100%; }
.nav-item.active { color: var(--accent-green); }
.nav-item.active .icon { opacity: 1; }

/* Utilities */
.btn-primary { width: 100%; padding: 14px; background: var(--accent-green); border: none; color: var(--bg-dark); border-radius: 12px; cursor: pointer; font-weight: 700; font-size: 0.95rem; }
.btn-primary:active { transform: scale(0.98); }
.control-btn { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; margin-left: 12px; cursor: pointer; }
.control-btn.accent { color: var(--accent-green); font-weight: 700; font-size: 0.9rem; border: 1.5px solid var(--accent-green); padding: 4px 12px; border-radius: 8px; }
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.9); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { background: var(--nav-bg); width: 90%; max-width: 400px; border-radius: 20px; border: 1px solid var(--border); padding: 25px; text-align: center; }
.close-btn { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
#toast { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel-bg); color: var(--accent-green); padding: 12px 24px; border-radius: 30px; border: 1px solid var(--accent-green); font-size: 0.85rem; font-weight: 600; z-index: 10000; opacity: 0; visibility: hidden; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); box-shadow: 0 4px 20px rgba(0,0,0,0.5); white-space: nowrap; }
#toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
