:root {
    --bg: #030305;
    --glass: rgba(15, 17, 26, 0.7);
    --glass-bright: rgba(255, 255, 255, 0.03);
    --border: rgba(255, 255, 255, 0.08);
    --accent-physics: #60a5fa;
    --accent-maths: #f472b6;
    --accent-biology: #4ade80;
    --accent-chemistry: #f59e0b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
}

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
}

/* Neural Background */
.neural-bg {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, #1e293b 0%, #030305 100%);
    z-index: -1;
}

.neural-overlay {
    position: fixed;
    inset: 0;
    background: url('https://www.transparenttextures.com/patterns/carbon-fibre.png');
    opacity: 0.05;
    z-index: -1;
    pointer-events: none;
}

/* Hide global elements */
#chat-widget-container,
header,
footer {
    display: none !important;
}

.app-viewport {
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 0;
    box-sizing: border-box;
}

/* STEM CONTAINER */
.stem-container {
    width: 100%;
    height: 100%;
    background: var(--glass);
    backdrop-filter: blur(40px);
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: none;
    --scrollbar-color: var(--accent-physics);
}

/* SUBJECT TABS */
.subject-tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    padding: 12px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 16px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid transparent;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    letter-spacing: 0.5px;
    opacity: 0.6;
}

.tab i {
    font-size: 1.2rem;
}

.tab.active {
    opacity: 1;
    background: var(--glass-bright);
    border-color: var(--border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.tab[data-subject="physics"].active {
    color: var(--accent-physics);
    border-bottom: 2px solid var(--accent-physics);
}

.tab[data-subject="maths"].active {
    color: var(--accent-maths);
    border-bottom: 2px solid var(--accent-maths);
}

.tab[data-subject="biology"].active {
    color: var(--accent-biology);
    border-bottom: 2px solid var(--accent-biology);
}

.tab[data-subject="chemistry"].active {
    color: var(--accent-chemistry);
    border-bottom: 2px solid var(--accent-chemistry);
}

.tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.02);
    opacity: 0.8;
}

/* MAIN CONTENT SPLIT */
.main-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    flex: 1;
    overflow: hidden;
}

/* SIDEBAR (Chat) */
.sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

/* SCROLLBAR */
.chat-history::-webkit-scrollbar {
    width: 8px;
}

.chat-history::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.chat-history::-webkit-scrollbar-thumb {
    background: var(--scrollbar-color, rgba(255, 255, 255, 0.15));
    border-radius: 10px;
    min-height: 40px;
}

.chat-history::-webkit-scrollbar-thumb:hover {
    filter: brightness(1.4);
}

.message {
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    line-height: 1.6;
    max-width: 90%;
    animation: fadeIn 0.5s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background: var(--glass-bright);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-secondary);
    border-bottom-left-radius: 4px;
}

.message.thought {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    border: 1px dashed var(--border);
    color: #64748b;
    background: transparent;
    position: relative;
    max-height: 4.5rem;
    overflow: hidden;
    transition: all 0.3s ease;
    padding-top: 35px;
    cursor: pointer;
}

.message.thought.expanded {
    max-height: 2000px;
    background: rgba(255, 255, 255, 0.02);
}

.thought-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 8px 18px;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    letter-spacing: 1px;
}

.thought-toggle-icon {
    font-size: 0.7rem;
    transition: transform 0.3s;
}

.message.thought.expanded .thought-toggle-icon {
    transform: rotate(180deg);
}

/* INPUT AREA - Persistent 22% height */
.input-area {
    height: 22vh;
    min-height: 120px;
    flex-shrink: 0;
    padding: 16px 20px;
    background: linear-gradient(to top, rgba(3, 3, 5, 0.98) 70%, rgba(3, 3, 5, 0.85) 100%);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

/* SCROLL TO BOTTOM FAB */
.scroll-to-bottom {
    position: absolute;
    bottom: calc(20vh + 20px);
    left: 50%;
    transform: translateX(-50%) scale(0);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(15, 17, 26, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 25;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.scroll-to-bottom.visible {
    transform: translateX(-50%) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.scroll-to-bottom:hover {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(30, 34, 52, 0.9);
    transform: translateX(-50%) scale(1.1);
}

.input-box {
    flex: 1;
    display: flex;
    align-items: flex-end;
    /* Align button to bottom */
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 16px;
    gap: 10px;
    transition: all 0.3s;
}

.input-box:focus-within {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
}

textarea {
    flex: 1;
    height: 100% !important;
    background: transparent;
    border: none;
    color: #fff;
    resize: none;
    outline: none;
    font-family: 'Inter', sans-serif;
    line-height: 1.5;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px 0;
    max-height: 150px;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* VISUALIZATION PANEL */
.viz-panel {
    position: relative;
    background: #000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* TOOL PALETTE */
.tool-palette {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 64px;
    background: var(--glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    z-index: 150;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.tool-item {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2rem;
    position: relative;
}

.tool-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    transform: translateY(-2px);
}

.tool-item.active {
    background: var(--accent-physics);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
}

.tool-tip {
    position: absolute;
    right: 60px;
    background: #000;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.tool-item:hover .tool-tip {
    opacity: 1;
}

#canvas-container {
    flex: 1;
    width: 100%;
    height: 100%;
}

.viz-overlay {
    position: absolute;
    top: 32px;
    left: 32px;
    pointer-events: none;
    z-index: 10;
}

.viz-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 2.2rem;
    margin: 0;
    letter-spacing: -1px;
    text-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

.viz-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #333;
}

.status-dot.active {
    background: #10b981;
    box-shadow: 0 0 15px #10b981;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.2);
    }
}

/* HUD CONTROLS */
.measurement-label {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: var(--accent-physics);
    padding: 4px 10px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 160;
    border: 1px solid var(--accent-physics);
    box-shadow: 0 0 15px rgba(96, 165, 250, 0.3);
    display: none;
    white-space: nowrap;
}

/* STOPWATCH OVERLAY */
.stopwatch-overlay {
    position: absolute;
    top: 80px;
    left: 20px;
    background: var(--glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 150;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    width: 140px;
}

.stopwatch-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    color: #fff;
}

.stopwatch-controls {
    display: flex;
    gap: 6px;
}

.sw-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.sw-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.hud-controls {
    position: absolute;
    bottom: 32px;
    right: 32px;
    display: flex;
    gap: 12px;
    z-index: 10;
}

.hud-btn {
    background: rgba(15, 17, 26, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 14px;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-btn:hover {
    background: var(--glass-bright);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-4px);
}

/* LOADER */
.neural-loader {
    position: absolute;
    inset: 0;
    background: rgba(3, 3, 5, 0.9);
    backdrop-filter: blur(10px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 3px solid rgba(255, 255, 255, 0.05);
    border-top-color: var(--accent-physics);
    border-radius: 50%;
    animation: spin 1s infinite cubic-bezier(0.5, 0, 0.5, 1);
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.loader-text {
    margin-top: 24px;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 3px;
    color: var(--text-primary);
    text-transform: uppercase;
    animation: pulse 2s infinite;
}
