/* ==========================================================================
   RESET & ROOT VARIABLES (JetBrains Mono & 15px Base)
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'JetBrains Mono', monospace !important;
    font-size: 15px;
}

:root {
    --bg-dark-core: #090d16;
    --bg-panel-surface: #111827;
    --bg-inner-terminal: #030712;
    --border-slate: #1f2937;
    --text-silver: #f3f4f6;
    --text-dim: #6b7280;
    --color-neon-blue: #3b82f6;
    --color-neon-emerald: #10b981;
    --color-neon-amethyst: #a855f7;
    --color-neon-amber: #f59e0b;
    --font-monospace: 'JetBrains Mono', monospace;
}

body {
    background-color: var(--bg-dark-core);
    color: var(--text-silver);
    padding: 12px;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ==========================================================================
   HEADER ARCHITECTURE
   ========================================================================== */
header {
    background: linear-gradient(135deg, #1e1b4b 0%, #030712 100%);
    border: 1px solid var(--border-slate);
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 15px;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

header h1 { 
    font-weight: 700; 
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    font-size: 20px !important;
}

.badge { 
    background: var(--color-neon-blue); 
    padding: 2px 6px; 
    border-radius: 4px; 
    margin-left: 6px;
    white-space: nowrap;
}

.developer-tag { 
    color: var(--color-neon-emerald); 
    word-break: break-all;
}

/* ==========================================================================
   MAIN GRID ARCHITECTURE
   ========================================================================== */
.tutor-grid {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 15px;
    align-items: stretch;
}

.panel-column {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
}

.panel-column.right-panel {
    height: 100%;
}

.panel-card {
    background-color: var(--bg-panel-surface);
    border: 1px solid var(--border-slate);
    border-radius: 10px;
    padding: 15px;
    min-width: 0;
}

.panel-card.spec-card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card-header {
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

/* ==========================================================================
   LEFT COLUMN COMPONENTS
   ========================================================================== */
.code-wrapper { 
    margin-bottom: 12px; 
    border-radius: 6px; 
    overflow: hidden; 
    border: 1px solid var(--border-slate); 
}

.CodeMirror { 
    height: 230px; 
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

.btn-primary { 
    background-color: var(--color-neon-blue); 
    color: white; 
    width: 100%; 
    margin-bottom: 12px; 
}
.btn-primary:hover { background-color: #2563eb; }

.navigation-cluster {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-inner-terminal);
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--border-slate);
    gap: 4px;
    overflow-x: auto;
}

.btn-nav { 
    background-color: #1f2937; 
    color: white; 
    border: 1px solid var(--border-slate); 
    padding: 6px 10px; 
    flex: 1;
    min-width: fit-content;
}
.btn-nav:hover:not(:disabled) { background-color: #374151; }
.btn-nav:disabled { opacity: 0.2; cursor: not-allowed; }

#stepCounter { 
    color: var(--color-neon-amber); 
    padding: 0 4px;
    white-space: nowrap;
}

.console-box {
    background-color: var(--bg-inner-terminal);
    border-left: 3px solid var(--color-neon-emerald);
    color: #10b981;
    padding: 10px;
    height: 120px; 
    overflow-y: auto;
    white-space: pre-wrap;
    border-radius: 4px;
}

/* ==========================================================================
   RIGHT COLUMN: PERFECT CONTAINER HEIGHT SYNC
   ========================================================================== */
.memory-grid-workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    background-color: var(--bg-inner-terminal);
    padding: 12px;
    border-radius: 8px;
    height: calc(230px + 120px + 182px); 
    max-height: calc(230px + 120px + 182px);
    min-height: 532px; 
    flex-grow: 1;
}

.memory-block {
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.memory-block h3 {
    color: var(--text-dim);
    text-align: center;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--border-slate);
    text-transform: uppercase;
    flex-shrink: 0;
}

#stackRoot, #heapRoot {
    width: 100%;
    height: 100%;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 6px;
    padding-bottom: 10px;
}

#stackRoot::-webkit-scrollbar, #heapRoot::-webkit-scrollbar { width: 6px; height: 6px; }
#stackRoot::-webkit-scrollbar-track, #heapRoot::-webkit-scrollbar-track { background: var(--bg-inner-terminal); }
#stackRoot::-webkit-scrollbar-thumb, #heapRoot::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
#stackRoot::-webkit-scrollbar-thumb:hover, #heapRoot::-webkit-scrollbar-thumb:hover { background: var(--color-neon-blue); }

/* ==========================================================================
   STACK MEMORY SCHEMATICS
   ========================================================================== */
.stack-memory-table {
    width: 100%;
    border-collapse: collapse;
    background-color: #111827;
    border: 1px solid #374151;
    min-width: 440px; 
}

.stack-memory-table th {
    background-color: #1f2937;
    color: #9ca3af;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid #374151;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stack-table-row { border-bottom: 1px solid #1f2937; }
.mem-addr-cell { color: #6b7280; padding: 8px 10px; font-weight: bold; }
.mem-name-cell { padding: 8px 10px; font-weight: bold; }
.primitive-ident { color: #10b981; }
.ref-ident { color: #f43f5e; }
.mem-type-cell { padding: 8px 10px; }

.badge-prim, .badge-ref { padding: 2px 4px; border-radius: 4px; white-space: nowrap; }
.badge-prim { background-color: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-ref { background-color: rgba(244, 63, 94, 0.15); color: #fb7185; }

.mem-val-cell { padding: 8px 10px; }
.prim-val-span { color: #f59e0b; font-weight: 500; word-break: break-all; }
.binary-subtext { color: #4b5563; margin-top: 2px; white-space: nowrap; }

/* ==========================================================================
   HEAP: PURPLE DOTTED OBJECT ALLOCATION NODE
   ========================================================================== */
.heap-alloc-node {
    background-color: #111827;
    border: 2px dashed var(--color-neon-amethyst); 
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 12px;
    min-width: 180px; 
}

.heap-node-addr { 
    color: var(--color-neon-amethyst); 
    font-weight: bold; 
    border-bottom: 1px solid var(--border-slate); 
    padding-bottom: 4px; 
    margin-bottom: 8px; 
}

.array-element-grid {
    display: flex;
    flex-wrap: wrap;       
    gap: 6px;              
    margin-top: 5px;
    background-color: var(--bg-dark-core);
    padding: 6px;
    border-radius: 4px;
    width: 100%;           
}

.array-cell {
    flex: 0 0 calc(25% - 5px); 
    min-width: 44px;           
    background: #1f2937;
    border: 1px solid #4b5563;
    text-align: center;
    border-radius: 3px;
    padding: 4px 2px;
}

.cell-idx { color: var(--text-dim); display: block; border-bottom: 1px solid #374151; padding-bottom: 1px; }
.cell-val { color: #22c55e; font-weight: bold; display: block; margin-top: 2px; }

/* ==========================================================================
   MISC STYLES
   ========================================================================== */
.pointer-link-tag {
    color: var(--color-neon-amethyst);
    font-weight: bold;
    background: rgba(168, 85, 247, 0.1);
    padding: 2px 5px;
    border-radius: 3px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    display: inline-block;
    white-space: nowrap;
}

.placeholder-msg { color: #374151; font-style: italic; text-align: center; padding-top: 30px; }
.active-code-line { background-color: rgba(234, 179, 8, 0.2) !important; border-left: 4px solid #f59e0b !important; }

/* ==========================================================================
   SMART FOOTER
   ========================================================================== */
.smart-footer {
    background: linear-gradient(135deg, #030712 0%, #111827 100%);
    border: 1px solid var(--border-slate);
    border-radius: 10px;
    padding: 14px 20px;
    margin-top: 20px;
    width: 100%;
}

.footer-container { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; }
.copyright-text { color: var(--text-dim); }
.brand-highlight { color: var(--color-neon-blue); font-weight: 600; }
.footer-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.footer-link { color: var(--text-silver); text-decoration: none; transition: color 0.2s ease; display: inline-flex; align-items: center; }
.footer-link:hover { color: var(--color-neon-amber); }
.footer-link-btn { background-color: #1f2937; text-decoration: none; border: 1px solid var(--border-slate); color: var(--text-silver); padding: 6px 12px; border-radius: 6px; transition: all 0.2s ease; display: inline-flex; align-items: center; }
.footer-link-btn:hover { background-color: var(--color-neon-blue); color: white; border-color: #2563eb; box-shadow: 0 0 10px rgba(59, 130, 246, 0.3); }

/* ==========================================================================
   RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 1024px) {
    .tutor-grid { grid-template-columns: 1fr; }
    .memory-grid-workspace { height: auto; max-height: none; min-height: 480px; }
}

@media (max-width: 640px) {
    .memory-grid-workspace { grid-template-columns: 1fr; height: auto; max-height: none; }
    .CodeMirror { height: 200px; }
    .smart-footer { padding: 15px; }
    .footer-container { flex-direction: column; text-align: center; gap: 12px; }
    .footer-right { justify-content: center; flex-direction: column; gap: 10px; width: 100%; }
    .footer-link, .footer-link-btn { width: 100%; justify-content: center; }
}

@media (max-width: 360px) {
    body { padding: 8px; }
    .panel-card { padding: 10px; }
}
