/* ================================================================
   PHOTOSYNTHESIS SIMULATOR — PhET-Style Scale-to-Fit Layout
   Desktop view is the "true" design. On mobile the entire
   #phet-stage is scaled down via JS transform: scale() to fit
   the screen — identical to how PhET simulations work.
   ================================================================ */

/* --- Root viewport: always fills the real screen exactly --- */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #020617;
    font-family: 'Outfit', sans-serif;
    overscroll-behavior: none;
    touch-action: none; /* Disable browser defaults for panning */
}

/* ----------------------------------------------------------------
   #phet-stage  — The fixed-size "design canvas"
   JS sets its width/height and transform: scale() dynamically.
   Think of it like a 1280×720 TV inside whatever-size room.
   ---------------------------------------------------------------- */
#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 1280px;
    height: 720px;
    background: #020617;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: 0 0; /* Updated for custom pan/zoom math */
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    touch-action: none;
}

/* ----------------------------------------------------------------
   Everything inside #phet-stage uses the SAME px values as desktop.
   Nothing below changes on mobile — JS handles the zoom.
   ---------------------------------------------------------------- */

nav {
    position: relative !important;
    background: rgba(15, 23, 42, 0.95) !important;
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    height: 60px; /* Slimmer nav */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    flex-shrink: 0;
    z-index: 100; /* Higher z-index */
    white-space: nowrap; /* Prevent wrapping from hiding content */
}

.algoviz-page {
    background-color: #020617;
    color: #f8fafc;
    overflow: hidden;
    height: 100vh;
}

#bgCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1; /* Stay in background but above some underlying body color if needed */
    background: radial-gradient(circle at top right, #0f172a 0%, #020617 100%);
}

#sim-app {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

.algoviz-page nav {
    background: rgba(15, 23, 42, 0.9) !important;
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.algoviz-page .logo a {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
}

.algoviz-page .nav-right .btn-back:hover {
    color: #06b6d4 !important;
}

/* Container & Layout */
.sim-container {
    flex: 1;
    display: grid;
    grid-template-columns: 260px 1fr 300px; /* Slimmer sidebars */
    width: 100%;
    overflow: hidden;
}

/* Sidebar Styles */
.algo-sidebar,
.code-panel {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(10px);
    padding: 1rem; /* Reduced padding */
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    gap: 0.75rem; /* Tighter gaps between sections */
    overflow: hidden; /* No scrollbars as requested */
}

.code-panel {
    border-right: none;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
}

.section-title {
    font-size: 0.65rem; /* Even smaller */
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #94a3b8;
    margin-bottom: 0.5rem; /* Tighter */
    font-weight: 700;
    opacity: 0.8;
}

.control-group {
    margin-bottom: 0.5rem; /* Reduced from 1.5rem */
}

.control-group label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    color: #94a3b8;
}

input[type="range"] {
    width: 100%;
    accent-color: #06b6d4;
    cursor: pointer;
}

.val-display {
    display: block;
    text-align: right;
    font-family: 'Space Grotesk', monospace;
    font-size: 0.85rem;
    color: #06b6d4;
    margin-top: 0.15rem;
}

/* Action Buttons */
.btn-action {
    width: 100%;
    padding: 0.8rem;
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.2);
    color: #06b6d4;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-action:hover {
    background: rgba(6, 182, 212, 0.2);
    border-color: #06b6d4;
    transform: translateY(-2px);
}

.algo-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem; /* Tight list */
}

.algo-btn {
    padding: 0.6rem 0.8rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.algo-btn:hover {
    background: rgba(255, 255, 255, 0.03);
    color: white;
}

.algo-btn.active {
    background: linear-gradient(90deg, rgba(6, 182, 212, 0.2), transparent);
    border-left: 3px solid #06b6d4;
    color: white;
    padding-left: 1.25rem;
}

/* Analysis Box */
.complexity-box {
    background: #020617;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.comp-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}

.comp-row:last-child {
    margin-bottom: 0;
}

.value.cyan {
    color: #06b6d4;
}

.value.pink {
    color: #ec4899;
}

.stats-box {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.stat-item {
    background: rgba(255, 255, 255, 0.02);
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 0.25rem;
}

.stat-val {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1rem;
}

/* Visualization Area */
.viz-area {
    padding: 1rem 1.5rem; /* Reduced padding */
    display: flex;
    flex-direction: column;
    gap: 1rem; /* Reduced gap from 2rem */
    overflow: hidden; /* Prevent internal section from growing and causing scrollbars on the parent */
}

.viz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.viz-header h2 {
    font-size: 2rem;
    letter-spacing: -1px;
}

.status-indicator {
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-indicator.sorting {
    background: rgba(251, 191, 36, 0.1);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.2);
}

.main-canvas-container {
    flex: 1;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 2rem;
    gap: 2px;
    position: relative;
    overflow: hidden;
}

/* Bar Animation */
.bar {
    background: #1e293b;
    border-radius: 2px 2px 0 0;
    transition: height 0.1s ease, background-color 0.2s;
    width: 100%;
}

.bar.comparing {
    background: #06b6d4 !important;
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.5);
    z-index: 2;
}

.bar.swapping {
    background: #ec4899 !important;
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.5);
    z-index: 2;
}

.bar.sorted {
    background: #10b981 !important;
}

/* Playback Controls */
.playback-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.btn-playback {
    padding: 1rem 2.5rem;
    border-radius: 12px;
    font-weight: 700;
    font-family: 'Space Grotesk', sans-serif;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-playback.play {
    background: #06b6d4;
    color: white;
    border: none;
    box-shadow: 0 4px 20px rgba(6, 182, 212, 0.4);
}

.btn-playback.play:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(6, 182, 212, 0.5);
    background: #0891b2;
}

.btn-playback.pause {
    background: #f43f5e;
}

.btn-playback.secondary {
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-playback.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Code Viewer */
.code-viewer {
    background: #020617;
    border-radius: 12px;
    padding: 1rem;
    font-family: 'Space Grotesk', monospace;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    flex: 1;
}

.code-line {
    padding: 0.25rem 0.5rem;
    color: #64748b;
    border-left: 2px solid transparent;
}

.code-line.active {
    background: rgba(6, 182, 212, 0.1);
    color: #06b6d4;
    border-left-color: #06b6d4;
}

.description-box h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: white;
}

.description-box p {
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.5;
}

/* Footer Legend */
.viz-footer {
    position: static;
    width: 100%;
    padding: 0.75rem 0; /* Tighter padding */
    background: transparent;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 10;
    margin-top: auto;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 600;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.primary {
    background: #06b6d4;
}

.dot.accent {
    background: #ec4899;
}

.dot.success {
    background: #10b981;
}
