/* ── PhET Scaling Base ───────────────────────────────────── */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* PhET Stage — scalable container */
#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    overflow-y: auto;
    background: #1e293b;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#bgCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.sim-page {
    background: #1e293b;
    height: 100%;
    width: 100%;
    padding-top: 0 !important;
    font-family: 'Outfit', sans-serif;
    display: flex;
    flex-direction: column;
}

nav {
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.sim-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
    flex: 1;
    min-height: 0;
}

.sim-box {
    background: #f8fafc;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
}

/* Header */
.sim-header {
    background: #1e40af;
    padding: 1rem;
    text-align: center;
}

.sim-header h1 {
    color: white;
    font-size: 1.8rem;
    margin: 0;
    font-weight: 700;
}

.sim-header .highlight {
    color: #fbbf24;
}

/* Toolbar */
.sim-toolbar {
    background: white;
    padding: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.tool-group label {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.95rem;
}

.custom-select {
    position: relative;
}

.custom-select select {
    appearance: none;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 0.5rem 2.5rem 0.5rem 1rem;
    font-weight: 600;
    cursor: pointer;
    color: #1e293b;
    outline: none;
}

.custom-select i {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #64748b;
    font-size: 0.8rem;
}

.button-group {
    display: flex;
    gap: 0.8rem;
}

.btn-start, .btn-reset {
    padding: 0.6rem 2.5rem;
    border-radius: 6px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn-start {
    background: linear-gradient(to bottom, #4ade80, #22c55e);
    color: white;
    box-shadow: 0 4px 0 #16a34a;
}

.btn-start:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.btn-start:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #16a34a;
}

.btn-reset {
    background: linear-gradient(to bottom, #f87171, #ef4444);
    color: white;
    box-shadow: 0 4px 0 #dc2626;
}

.btn-reset:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.btn-reset:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #dc2626;
}

/* Speed Slider */
.speed-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    width: 151px;
}

.speed-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 800;
    color: #1e293b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.range-container {
    position: relative;
    height: 12px;
    display: flex;
    align-items: center;
}

#speed-slider {
    width: 100%;
    appearance: none;
    background: transparent;
    z-index: 2;
    cursor: pointer;
}

#speed-slider::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    background: #0ea5e9;
    border: 2px solid white;
    border-radius: 50%;
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
}

.range-track {
    position: absolute;
    width: 100%;
    height: 8px;
    background: linear-gradient(to right, #0ea5e9, #f59e0b, #ef4444);
    border-radius: 10px;
    z-index: 1;
}

/* Content Area */
.sim-content {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1.5rem;
    background: white;
}

.grid-column {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.grid-wrapper {
    background: white;
    border: 1px solid #e2e8f0;
    padding: 0.5rem;
    border-radius: 8px;
}

.node-grid {
    display: grid;
    /* Columns set via grid-template-columns in JS */
    gap: 1px;
    background: #e2e8f0;
    border: 1px solid #e2e8f0;
}

.node {
    aspect-ratio: 1;
    background: white;
    cursor: pointer;
    transition: background 0.1s;
    position: relative;
}

.node:hover {
    background: #f1f5f9;
}

.node.start {
    background: #22c55e !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node.start::after {
    content: "Start";
    font-size: 8px;
    color: white;
    font-weight: 800;
}

.node.end {
    background: #ef4444 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node.end::after {
    content: "End";
    font-size: 8px;
    color: white;
    font-weight: 800;
}

.node.wall {
    background: #1e293b !important;
    animation: wallAnim 0.3s forwards;
}

@keyframes wallAnim {
    from { transform: scale(0.3); }
    to { transform: scale(1); }
}

.node.explored {
    background: #0ea5e9;
    animation: exploredAnim 0.5s ease-out forwards;
}

@keyframes exploredAnim {
    0% { transform: scale(0.3); background: #a5f3fc; border-radius: 100%; }
    50% { background: #22d3ee; }
    100% { transform: scale(1); background: #0ea5e9; }
}

.node.path {
    background: #fbbf24;
    animation: pathAnim 0.5s ease-out forwards;
}

@keyframes pathAnim {
    0% { transform: scale(0.6); background: #fef08a; }
    100% { transform: scale(1); background: #fbbf24; }
}

/* Legend */
.legend {
    display: flex;
    gap: 1.5rem;
    padding: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #1e293b;
}

.node-icon {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.node-icon.start { background: #22c55e; }
.node-icon.end { background: #ef4444; }
.node-icon.wall { background: #1e293b; }
.node-icon.explored { background: #0ea5e9; }
.node-icon.path { background: #fbbf24; }

/* Stats Column */
.stats-column {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.stats-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1.2rem;
}

.stats-card header {
    font-weight: 800;
    font-size: 1.1rem;
    color: #1e293b;
    margin-bottom: 1rem;
}

.stats-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.stats-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    background: #f8fafc;
}

.item-info {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-weight: 700;
    font-size: 0.95rem;
    color: #334155;
}

.item-info i {
    font-size: 1.1rem;
}

.icon-now { color: #0ea5e9; }
.icon-end { color: #ef4444; }
.icon-wall { color: #1e293b; }
.icon-explored { color: #0ea5e9; }
.icon-path { color: #fbbf24; }

.val {
    font-weight: 800;
    font-size: 1rem;
    color: #1e293b;
}

.stat-path-row {
    background: #fffbeb !important;
}

/* Secondary Stats */
.stats-secondary {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.detail-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    background: #f1f5f9;
    border-radius: 8px;
    border: 1px dashed #cbd5e1;
}

.detail-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #64748b;
    font-weight: 700;
    font-size: 0.85rem;
}

.detail-label i {
    color: #0ea5e9;
}

.detail-val {
    color: #1e293b;
    font-weight: 800;
    font-size: 1rem;
}

.educational-insights {
    background: #eff6ff !important;
    border: 1px solid #bfdbfe !important;
}

#algo-description {
    font-size: 0.8rem;
    color: #1e3a8a;
    line-height: 1.4;
    font-weight: 500;
    margin-bottom: 0.8rem;
    font-style: italic;
}

.pseudo-code-box {
    background: #1e293b;
    border-radius: 6px;
    padding: 1rem;
    font-family: 'Space Grotesk', monospace;
    font-size: 0.75rem;
    color: #38bdf8;
    line-height: 1.6;
}

.pseudo-code-box .highlight-line {
    color: white;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    padding: 0 4px;
}

/* Node Labels for Advanced Mode */
.node .cost-label {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 7px;
    font-weight: 700;
    color: rgba(0,0,0,0.4);
    pointer-events: none;
    z-index: 5;
}

.node.explored .cost-label {
    color: rgba(255,255,255,0.6);
}

.node.path .cost-label {
    color: rgba(0,0,0,0.6);
}

.node.start .cost-label, .node.end .cost-label {
    display: none;
}

@media (max-width: 950px) {
    .sim-content {
        grid-template-columns: 1fr;
    }
    .sim-toolbar {
        flex-wrap: wrap;
    }
}
