/* Tensor Ranks Visualizer - Styles */
* { box-sizing: border-box; }
:root {
    --primary: #6366f1; /* Indigo for tensor primary highlight */
    --accent: #10b981;  /* Emerald for secondary */
    --accent-red: #ef4444; /* Rose for tertiary */
    --bg: #0f172a;
    --grid: rgba(255, 255, 255, 0.03);
}

body.math-lab-theme {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    background: var(--bg);
    color: white;
    overflow: hidden; touch-action: none;
    display: flex;
    flex-direction: column;
    font-family: 'Outfit', sans-serif;
}

#phet-stage {
    position: absolute; top: 0; left: 0;
    width: 1280px; height: 720px;
    background: var(--bg);
    display: flex; flex-direction: column;
    overflow: hidden; transform-origin: 0 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.4);
    touch-action: none;
}

#sim-app {
    flex: 1;
    display: flex;
    gap: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Main Visualizer Area */
.visualizer-panel {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    background: radial-gradient(var(--grid) 1px, transparent 1px);
    background-size: 40px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Tensor Container & Objects */
.tensor-container {
    perspective: 1200px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.tensor-object {
    display: flex;
    gap: 15px;
    transition: opacity 0.6s;
    opacity: 0;
    transform: scale(0.8);
    position: absolute;
    pointer-events: none;
    transform-style: preserve-3d;
}

.tensor-object.dragging {
    transition: none !important;
}

/* Visibility Control */
.tensor-container.rank-0 .scalar,
.tensor-container.rank-1 .vector,
.tensor-container.rank-2 .matrix,
.tensor-container.rank-3 .rank3 {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

/* Common Nodes */
.node {
    width: var(--node-size, 60px);
    height: var(--node-size, 60px);
    position: relative;
    transform-style: preserve-3d;
    transition: 0.3s;
    cursor: default;
    --thickness: calc(var(--node-size, 60px) / 2);
}

/* Face Base Styles */
.node [class^="face-"] {
    position: absolute;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono';
    font-weight: 700;
    color: white;
    box-sizing: border-box;
}

/* Front & Back Plates */
.node .face-front, .node .face-back {
    width: 100%;
    height: 100%;
}

.node .face-front { transform: translateZ(calc(var(--thickness) / 2)); background: #26334a; z-index: 2; border-color: rgba(255,255,255,0.4); }
.node .face-back  { transform: translateZ(calc(var(--thickness) / -2)) rotateY(180deg); background: #0f172a; }

/* Side Faces - Use slight overlap to kill gaps */
.node .face-left, .node .face-right {
    width: calc(var(--thickness) + 0.5px);
    height: 100%;
    left: calc(50% - (var(--thickness) / 2));
}

.node .face-right { transform: rotateY(90deg) translateZ(calc(var(--node-size, 60px) / 2)); background: #131c2e; }
.node .face-left  { transform: rotateY(-90deg) translateZ(calc(var(--node-size, 60px) / 2)); background: #131c2e; }

/* Horizontal Faces (Top & Bottom Lids) */
.node .face-top, .node .face-bottom {
    width: 100%;
    height: var(--thickness);
    top: calc(50% - (var(--thickness) / 2));
}

.node .face-top    { transform: rotateX(90deg) translateZ(calc(var(--node-size, 60px) / 2)); background: #334155; }
.node .face-bottom { transform: rotateX(-90deg) translateZ(calc(var(--node-size, 60px) / 2)); background: #080c14; }

/* Rank Specific Sizing via Variables */
.scalar .node { --node-size: 100px; font-size: 1.8rem; }
.rank3 .node, .custom .node { --node-size: 45px; font-size: 0.85rem; }

.node:hover .face-front {
    background: var(--primary);
    border-color: white;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}

.node:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    transform: translateY(-5px);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

/* Rank 0: Scalar */
.scalar .node {
    width: 100px;
    height: 100px;
    font-size: 2rem;
    background: radial-gradient(circle at 30% 30%, rgba(99, 102, 241, 0.3) 0%, rgba(0,0,0,0) 80%);
    border: 2px solid var(--primary);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.2);
}

/* Rank 1: Vector */
.vector {
    flex-direction: row;
    transform-style: preserve-3d;
}

/* Rank 2: Matrix */
.matrix {
    display: flex;
    flex-direction: column;
    transform-style: preserve-3d;
    gap: 15px;
}

.matrix .row {
    display: flex;
    gap: 15px;
    transform-style: preserve-3d;
}
.rank-selector::after {
    content: '🖱️ Drag anywhere to rotate';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: #475569;
    letter-spacing: 1px;
    text-transform: uppercase;
}
/* Rank 3: Order-3 Tensor */
.rank3 .slice {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: absolute;
    transform-style: preserve-3d;
    transform: translateZ(calc(var(--depth) * -80px));
}

.rank3 .row {
    display: flex;
    gap: 10px;
    transform-style: preserve-3d;
}

.rank3 .node {
    width: 50px;
    height: 50px;
}
.rank3 .face-front { 
    font-size: 0.9rem;
}

/* Switcher Controls */
.rank-selector {
    padding: 15px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    display: flex;
    gap: 10px;
    margin-bottom: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.rank-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-family: 'Outfit';
    font-weight: 700;
    transition: 0.3s;
    text-align: left;
}

.rank-btn small {
    display: block;
    font-weight: 400;
    font-size: 0.75rem;
    opacity: 0.6;
}

.rank-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.rank-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Sidebar Info Styles */
.info-sidebar {
    background: #1e293b;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    padding: 24px;
    width: 270px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
}

.theory-card h2 {
    font-size: 1.3rem;
    margin: 0 0 6px;
    background: linear-gradient(135deg, #818cf8, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle { color: #94a3b8; line-height: 1.4; font-size: 0.82rem; margin-top: 5px; }

.example-box, .notation-box {
    background: rgba(0, 0, 0, 0.2);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.example-box h5, .notation-box h5 {
    color: var(--primary);
    margin: 0 0 10px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.example-box ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.example-box li { color: #cbd5e1; font-size: 0.82rem; }

.notation-box code {
    font-family: 'JetBrains Mono';
    font-size: 1.1rem;
    color: white;
}

.insight-tips {
    margin-top: auto;
    background: rgba(99, 102, 241, 0.05);
    border: 1px dashed var(--primary);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.insight-tips i { font-size: 1.4rem; color: var(--primary); opacity: 0.8; }
.insight-tips p { margin: 0; font-size: 0.78rem; line-height: 1.4; color: #cbd5e1; }

/* Interactive Animation Steps */
.step-item {
    display: flex;
    gap: 10px;
    padding: 14px;
    background: rgba(0,0,0,0.15);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
}

.step-item.checked { border-color: rgba(99, 102, 241, 0.2); background: rgba(99, 102, 241, 0.05); }

.step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    flex-shrink: 0;
    font-size: 0.85rem;
}

.step-text h4 { margin: 0 0 3px; color: white; font-size: 0.9rem; }
.step-text p { margin: 0; color: #94a3b8; font-size: 0.78rem; line-height: 1.3; }

/* Custom Sidebar Workspace */
.input-area textarea {
    width: 100%;
    height: 120px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    color: #e2e8f0;
    font-family: 'JetBrains Mono';
    font-size: 0.85rem;
    resize: none;
    outline: none;
    transition: 0.3s;
    margin-top: 10px;
}

.input-area textarea:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.6);
}

.custom-workspace {
    margin-top: 10px;
    padding-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

/* Custom Tensor Visuals */
.tensor-container.rank-custom .custom {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

.custom {
    transform-style: preserve-3d;
}

.custom .slice {
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: absolute;
    transform-style: preserve-3d;
    transform: translateZ(calc(var(--depth) * -80px));
}

.custom .row {
    display: flex;
    gap: 10px;
    transform-style: preserve-3d;
}

.custom .node {
    width: 50px;
    height: 50px;
    font-size: 0.9rem;
    border-color: var(--accent);
}
