* {
    box-sizing: border-box;
}

body {
    margin: 0;
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: #121826;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#main-section {
    position: relative;
    margin-left: 24vw;
    margin-right: 24vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin 0.3s ease;
}

#main-section.left-collapsed {
    margin-left: 60px;
}

#game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 25px;
    overflow: hidden;
    position: relative;
}

canvas {
    border-radius: 10px;
    border: 1px solid #2d3748;
    display: block;
    max-width: 100%;
    max-height: 100%;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    color: #60a5fa;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin: 0;
}

.panel-header {
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, #1a1f2e 0%, #0f1419 100%);
    padding: 24px 25px;
    border-bottom: 1px solid #2d3748;
    z-index: 100;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    transition: padding 0.3s ease;
}

#information-panel.collapsed .panel-header {
    padding: 12px 8px;
    border-bottom: none;
}

.panel-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #60a5fa;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.panel-header h1 {
    margin: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.controls {
    display: flex;
    gap: 10px;
}

.side-panel {
    position: fixed;
    top: 0;
    width: 24vw;
    height: 100vh;
    background: linear-gradient(180deg, #0a0e1a 0%, #151923 100%);
    color: #e8eaf0;
    overflow: hidden;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
}

#information-panel {
    left: 0;
    border-right: 1px solid #2d3748;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    transition: width 0.3s ease;
}

#simulation-panel {
    right: 0;
    border-left: 1px solid #2d3748;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
}

#information-panel.collapsed {
    width: 60px;
}

#information-panel.collapsed .header-content {
    flex-direction: column;
    align-items: center;
}

#information-panel.collapsed .panel-header h2 {
    display: none;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease;
}

#information-panel.collapsed .panel-content {
    display: none;
}

.controllers-wrapper {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.controller-group {
    flex: 0 1 auto;
    padding: 20px 15px;
    min-width: 110px;
}

.movement-controllers-grid,
.arrow-controllers-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.movement-controllers-grid .controller-item:nth-child(1),
.arrow-controllers-grid .controller-item:nth-child(1) {
    grid-column: 2;
}

.movement-controllers-grid .controller-item:nth-child(2),
.arrow-controllers-grid .controller-item:nth-child(2) {
    grid-column: 1;
    grid-row: 2;
}

.movement-controllers-grid .controller-item:nth-child(3),
.arrow-controllers-grid .controller-item:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
}

.movement-controllers-grid .controller-item:nth-child(4),
.arrow-controllers-grid .controller-item:nth-child(4) {
    grid-column: 3;
    grid-row: 2;
}

.controller-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.controller-item .control-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
}

.space-button-container {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

.space-btn {
    min-width: 150px;
    width: 90%;
    max-width: 260px;
    height: 38px;
    font-size: 12px;
}

.collapse-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.collapse-icon {
    display: inline-block;
    transition: transform 0.3s ease;
    font-size: 14px;
}

#information-panel.collapsed .collapse-icon {
    transform: rotate(180deg);
}

.control-btn {
    background: linear-gradient(135deg, #1e3a5f 0%, #1a2332 100%);
    border-radius: 8px;
    padding: 12px 16px;
    border: 1px solid #2d3748;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 13px;
}

.control-btn:hover {
    background: linear-gradient(180deg, #3d4758 0%, #2a3038 100%);
    border-color: #60a5fa;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.2);
}

.control-btn:active {
    transform: translateY(0);
}

.patient-info {
    padding: 25px;
    background: #0f1419;
    border-bottom: 1px solid #2d3748;
}

.patient-info h3 {
    margin: 0 0 16px 0;
    font-size: 14px;
    font-weight: 600;
    color: #60a5fa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.patient-info p {
    margin: 0 0 12px 0;
    font-size: 13px;
    line-height: 1.6;
    color: #cbd5e0;
}

.patient-info p:last-child {
    margin-bottom: 0;
}

.patient-info strong {
    color: #a0aec0;
}

.patient-card {
    background: linear-gradient(135deg, #1e3a5f 0%, #1a2332 100%);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid #2d3748;
}

.patient-card h3 {
    margin: 0 0 12px 0;
    font-size: 16px;
    color: #60a5fa;
    font-weight: 600;
}

.patient-details {
    display: grid;
    gap: 8px;
}

.detail-row {
    display: flex;
    align-items: center;
    font-size: 13px;
    line-height: 1.5;
}

.detail-label {
    color: #a0aec0;
    min-width: 120px;
    font-weight: 500;
}

.detail-value {
    color: #e8eaf0;
    flex: 1;
}

.timeline-container {
    padding: 25px;
    flex: 1;
}

.timeline-step {
    position: relative;
    padding: 16px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #1a202c 0%, #0f1419 100%);
    border-radius: 10px;
    border-left: 3px solid #4a5568;
    transition: all 0.3s ease;
    cursor: pointer;
}

.timeline-step:hover {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    transform: translateX(-4px);
}

.timeline-step.current {
    border-left-color: #10b981;
    background: linear-gradient(135deg, #064e3b 0%, #022c22 100%);
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.3);
    transform: translateX(-4px) scale(1.02);
}

.timeline-step.completed {
    opacity: 0.4;
    border-left-color: #4a5568;
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.step-number {
    background: #2d3748;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    color: #a0aec0;
    letter-spacing: 0.5px;
}

.timeline-step.current .step-number {
    background: #10b981;
    color: white;
}

.step-agent {
    font-size: 15px;
    font-weight: 700;
    color: #60a5fa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timeline-step.current .step-agent {
    color: #34d399;
}

.step-content {
    font-size: 13px;
    line-height: 1.6;
    color: #cbd5e0;
}

.step-content p {
    margin: 0;
}

.step-decision {
    margin-top: 10px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    font-size: 12px;
    border-left: 2px solid #3b82f6;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.step-decision strong {
    color: #60a5fa;
}

.timeline-step.current .step-decision {
    border-left-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.timeline-step.completed .step-decision {
    border-left-color: #4a5568;
}

#simulation-panel::-webkit-scrollbar,
.panel-content::-webkit-scrollbar {
    width: 6px;
}

#simulation-panel::-webkit-scrollbar-track,
.panel-content::-webkit-scrollbar-track {
    background: #0a0e1a;
}

#simulation-panel::-webkit-scrollbar-thumb,
.panel-content::-webkit-scrollbar-thumb {
    background: #2d3748;
    border-radius: 3px;
}

#simulation-panel::-webkit-scrollbar-thumb:hover,
.panel-content::-webkit-scrollbar-thumb:hover {
    background: #4a5568;
}

/* Patient Selector Styles */
.patient-selector {
    background: #0f1419;
    border-bottom: 1px solid #2d3748;
    padding: 12px 16px;
}

.selector-header {
    font-size: 11px;
    font-weight: 600;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.patient-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.patient-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: linear-gradient(135deg, #1a202c 0%, #0f1419 100%);
    border: 1px solid #2d3748;
    border-radius: 6px;
    font-size: 12px;
    color: #cbd5e0;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.patient-chip:hover {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    border-color: #4a5568;
    transform: translateY(-1px);
}

.patient-chip.selected {
    background: linear-gradient(135deg, #1e3a5f 0%, #1a2332 100%);
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

.patient-chip-active {
    border-color: #10b981;
}

.patient-chip-active .chip-icon {
    color: #10b981;
}

.patient-chip-waiting .chip-icon {
    color: #f59e0b;
}

.patient-chip-completed {
    opacity: 0.6;
}

.patient-chip-completed .chip-icon {
    color: #6b7280;
}

.chip-icon {
    font-size: 10px;
    line-height: 1;
}

.chip-name {
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1920px) {
    .side-panel {
        width: 22vw;
    }

    #main-section {
        margin-left: 22vw;
        margin-right: 22vw;
    }

    #main-section.left-collapsed {
        margin-left: 60px;
    }

    #information-panel.collapsed {
        width: 60px;
    }

    .controllers-wrapper {
        gap: 14px;
    }

    .controller-group {
        min-width: 105px;
    }
}

@media (max-width: 1600px) {
    .side-panel {
        width: 20vw;
    }

    #main-section {
        margin-left: 20vw;
        margin-right: 20vw;
    }

    #main-section.left-collapsed {
        margin-left: 60px;
    }

    #information-panel.collapsed {
        width: 60px;
    }

    .controllers-wrapper {
        gap: 12px;
    }

    .controller-group {
        min-width: 100px;
        padding: 18px 12px;
    }
}

@media (max-width: 1440px) {
    h1 {
        font-size: 20px;
    }

    .panel-header {
        padding: 16px 20px;
    }

    .control-btn {
        padding: 10px 14px;
        font-size: 12px;
    }

    .controller-group {
        min-width: 95px;
        padding: 16px 10px;
    }

    .movement-controllers-grid,
    .arrow-controllers-grid {
        gap: 6px;
    }

    .controller-item .control-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .controllers-wrapper {
        gap: 10px;
    }
}

@media (max-width: 900px) {

    /* Hide the information panel, but keep timeline panel visible on the right */
    #information-panel {
        display: none !important;
    }

    #simulation-panel {
        position: fixed;
        right: 0;
        top: 0;
        width: 34vw;
        /* About 1/3 of mobile landscape for timeline */
        min-width: 110px;
        max-width: 40vw;
        height: 100vh;
        z-index: 10000;
        font-size: 0.86em;
        overflow-y: auto;
        padding: 0;
        border-left: 1px solid #22304a;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.11);
        background: linear-gradient(180deg, #131c2a 0%, #182033 100%);
    }

    #main-section {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100vw !important;
        flex-direction: row;
        height: 100vh !important;
    }

    #main-section>.panel-header {
        display: none !important;
    }

    #game-container {
        width: 66vw !important;
        /* Take all but the timeline's right width */
        min-width: 0;
        max-width: 100vw;
        height: 100vh !important;
        padding: 0 !important;
        display: flex;
        align-items: center;
        justify-content: flex-start;
    }

    canvas {
        max-width: 100% !important;
        max-height: 100vh !important;
        object-fit: contain;
    }

    .panel-header,
    .panel-header h1,
    .controls {
        font-size: 0.85em !important;
        padding: 8px 10px !important;
    }

    .timeline-step,
    .timeline-container,
    .patient-info {
        font-size: 0.87em !important;
        padding: 12px !important;
        margin: 0 0 7px 0 !important;
    }

    .timeline-step.current {
        box-shadow: 0 2px 7px rgba(40, 200, 180, .07);
    }
}