* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #fff;
    overflow: hidden;
}

/* Header */
.header {
    background: #3d9ed9;
    color: #fff;
    padding: 20px;
    height: 107px;
    display: flex;
    align-items: center;
}

.header h1 {
    font-size: 45px;
    font-weight: 400;
    margin: 0;
}

/* Main Layout */
.main-container {
    display: flex;
    height: calc(100vh - 107px);
    position: relative;
    padding: 20px;
    gap: 20px;
    background: #f5f5f5;
}

/* Map Container */
.map-container {
    flex: 1;
    background: #fff;
    position: relative;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.map-header {
    background: #fff;
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    font-size: 18px;
    font-weight: 500;
    color: #333;
}
/* Controls */
.controls-bar { display:flex; align-items:center; gap:14px; flex-wrap:wrap; }
.controls-bar label { font-size:14px; font-weight:500; color:#333; display:flex; align-items:center; gap:6px; }
.controls-group { display:flex; align-items:center; gap:12px; }
.atlas-select, .atlas-button {
    appearance:none;
    border:1px solid #3d9ed9;
    background:#fff;
    color:#1c4d66;
    padding:6px 10px;
    border-radius:6px;
    font-size:14px;
    cursor:pointer;
    transition:background .2s, box-shadow .2s;
}
.atlas-select:hover { background:#f0f8fd; }
.atlas-select:focus, .atlas-button:focus { outline:none; box-shadow:0 0 0 2px rgba(61,158,217,.3); }
.atlas-button { background:#3d9ed9; color:#fff; font-weight:500; }
.atlas-button:hover { background:#348bc0; }
.atlas-button:active { background:#2d78a7; }
.controls-spacer { flex:1; }
/* Legend */
#legend-container { 
    position: absolute; 
    bottom: 10px; 
    right: 10px; 
    background: #ffffff; 
    border: 1.5px solid #3d9ed9; 
    border-radius: 8px; 
    padding: 10px 14px; 
    font-size: 12px; 
    color: #333; 
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.legend-scale-bar { 
    height: 12px; 
    width: 180px; 
    background: #e0e0e0; 
    border-radius: 6px; 
    margin-bottom: 8px; 
    transition: background 0.3s; 
    border: 1px solid #d0d0d0;
}
.legend-labels { 
    display: flex; 
    justify-content: space-between; 
    font-size: 11px; 
    color: #555;
    font-weight: 500;
}

.map-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#escher-map {
    width: 100%;
    height: 100%;
}

/* Override Escher's default full-screen behavior */
#escher-map svg {
    max-width: 100%;
    max-height: 100%;
}

/* Sidebar */
.sidebar {
    width: 315px;
    background: #fff;
    overflow-y: auto;
    padding: 20px 10px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.tissue-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 0 10px;
}

.circulation-card {
    grid-column: 1 / -1;
    width: 100%;
    height: 120px;
    background: rgba(62, 158, 217, 0.5);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 15px;
}

.circulation-card:hover {
    background: rgba(62, 158, 217, 0.7);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.circulation-card.active {
    background: rgba(62, 158, 217, 0.9);
    box-shadow: 0 4px 12px rgba(62, 158, 217, 0.5);
}

.circulation-icon {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.circulation-text {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tissue-card {
    width: 100%;
    height: 103px;
    background: rgba(62, 158, 217, 0.5);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.tissue-card:hover {
    background: rgba(62, 158, 217, 0.7);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.tissue-card.active {
    background: rgba(62, 158, 217, 0.9);
    box-shadow: 0 4px 12px rgba(62, 158, 217, 0.5);
}

.tissue-icon {
    width: 54px;
    height: 51px;
    margin-bottom: 8px;
    object-fit: contain;
}

.tissue-icon-emoji {
    width: 54px;
    height: 51px;
    margin-bottom: 8px;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tissue-name {
    font-size: 20px;
    font-weight: 500;
    color: #333;
    line-height: 1.2;
}

.tissue-subname {
    font-size: 12px;
    color: #555;
    margin-top: 2px;
}

/* Loading indicator */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    color: #3d9ed9;
}

/* Circulation Diagram Styles */
#circulation-container {
    width: 100%;
    height: 100%;
    position: relative;
    background: #fafafa;
    display: flex;
    flex-direction: column;
}

.circulation-diagram-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #fafafa;
}

.circulation-zoom-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 10;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    background: #fff;
    border: 1px solid #3d9ed9;
    border-radius: 6px;
    color: #3d9ed9;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.zoom-btn:hover {
    background: #3d9ed9;
    color: #fff;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.circulation-svg {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

.circulation-svg:active {
    cursor: grabbing;
}

.organ-block {
    transition: opacity 0.2s;
}

.organ-block:hover {
    opacity: 0.8;
}

.capillary-block {
    transition: opacity 0.2s;
}

.capillary-block:hover {
    opacity: 0.8;
}

.organ-label {
    pointer-events: none;
    user-select: none;
}

.capillary-label {
    pointer-events: none;
    user-select: none;
}

.transporter-arrow {
    opacity: 0.9;
    transition: opacity 0.2s;
}

.transporter-arrow:hover {
    opacity: 1;
}

.transporter-arrow-line {
    cursor: pointer;
    transition: opacity 0.2s, stroke-width 0.2s;
}

.transporter-arrow-line:hover {
    opacity: 1;
}

.blood-flow-arrow {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.blood-flow-arrow:hover {
    opacity: 0.8;
}

.blood-flow-arrow line {
    cursor: pointer;
    transition: opacity 0.2s;
}

.blood-flow-arrow line:hover {
    opacity: 1;
}

.kidney-excretion-arrow {
    opacity: 0.9;
    transition: opacity 0.2s;
}

.kidney-excretion-arrow line {
    cursor: pointer;
    transition: opacity 0.2s;
}

.kidney-excretion-arrow line:hover {
    opacity: 0.7;
}

.blood-flow-in-label text,
.blood-flow-out-label text {
    cursor: pointer;
    transition: opacity 0.2s, font-size 0.2s;
}

.blood-flow-in-label text:hover,
.blood-flow-out-label text:hover {
    opacity: 0.8;
    font-size: 10px;
}

.flux-label {
    font-weight: 600;
    pointer-events: none;
    user-select: none;
}

.persistent-tooltip {
    animation: fadeIn 0.2s ease-in;
    filter: drop-shadow(0 2px 8px rgba(61, 158, 217, 0.2));
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.circulation-legend {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #ffffff;
    border: 1.5px solid #3d9ed9;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 12px;
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    line-height: 1.6;
}

#metabolite-container {
    display: inline-flex !important;
}

/* Removed tooltip styles to start fresh */

/* Responsive adjustments */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        padding: 10px;
    }

    .sidebar {
        width: 100%;
        max-height: none;
    }

    .tissue-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .circulation-card {
        height: 100px;
    }

    .circulation-icon {
        width: 60px;
        height: 60px;
    }

    .tissue-card {
        height: 90px;
    }

    .header h1 {
        font-size: 28px;
    }

    .map-container {
        min-height: 400px;
    }
}
