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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    margin: 0;
    padding: 0;
}

/* Side Navigation */
.side-nav {
    width: 250px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    backdrop-filter: blur(10px);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    padding: 30px 0;
    z-index: 1000;
}

.nav-header {
    padding: 0 30px 30px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.nav-header h2 {
    color: white;
    font-size: 1.8em;
}

.nav-menu {
    list-style: none;
    padding: 20px 0;
}

.nav-menu li {
    margin: 5px 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 30px;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.8);
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-link.active {
    background: rgba(255, 255, 255, 0.2);
    border-left-color: white;
    color: white;
}

/* .nav-icon {
    font-size: 1.5em;
} */

.nav-text {
    font-size: 1em;
    font-weight: 500;
}

/* Main Content Area */
.main-content {
    margin-left: 250px;
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    height: 100vh;
}

/* Page Containers */
.page {
    display: none;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    width: 100%;
    margin: 0;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

h1 {
    color: #333;
    font-size: 2.5em;
    margin-bottom: 10px;
}

.subtitle {
    color: #666;
    font-size: 1.1em;
}

main {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.canvas-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

#canvas {
    border: 3px solid #667eea;
    border-radius: 10px;
    cursor: crosshair;
    background: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    width: 100%;
    height: auto;
}

.controls {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 15px 30px;
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover {
    background: #d0d0d0;
    transform: translateY(-2px);
}

.results-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.result {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    color: white;
}

/* Tabs */
.tabs-container {
    width: 100%;
}

.tabs-header {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
    flex: 1;
    padding: 12px 20px;
    background: #f0f0f0;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
    border-radius: 8px 8px 0 0;
}

.tab-btn:hover {
    background: #e8e8e8;
    color: #333;
}

.tab-btn.active {
    background: white;
    color: #667eea;
    border-bottom-color: #667eea;
}

.tabs-content {
    width: 100%;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-pane.active {
    display: block;
}

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

.result h2 {
    font-size: 1.5em;
    margin-bottom: 20px;
}

.predicted-digit {
    font-size: 6em;
    font-weight: bold;
    margin: 20px 0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.confidence {
    font-size: 1.2em;
    margin-top: 10px;
}

.probabilities {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
}

.probabilities h3 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.probability-bar {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.probability-label {
    font-weight: 600;
    color: #333;
    width: 30px;
}

.probability-bar-container {
    flex: 1;
    background: #e0e0e0;
    border-radius: 10px;
    height: 25px;
    overflow: hidden;
}

.probability-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
}

.probability-value {
    color: white;
    font-size: 0.8em;
    font-weight: 600;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.probability-value-outside {
    color: #333;
    font-size: 0.85em;
    font-weight: 600;
    min-width: 50px;
    text-align: right;
}

.error {
    background: #ff6b6b;
    color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.hidden {
    display: none !important;
}

.network-section {
    margin-top: 40px;
    padding: 30px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.network-section h2 {
    color: #333;
    text-align: center;
    margin-bottom: 10px;
}

.network-subtitle {
    text-align: center;
    color: #666;
    font-size: 0.9em;
    margin-bottom: 20px;
}

.color-legend {
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.legend-title {
    font-weight: 600;
    color: #333;
    font-size: 0.95em;
}

.gradient-legend {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gradient-bar {
    width: 100%;
    height: 30px;
    border-radius: 15px;
    border: 2px solid #333;
    background: linear-gradient(
        to right,
        #440154 0%,
        #404788 20%,
        #2a788e 40%,
        #22a884 60%,
        #7ad151 80%,
        #fde725 100%
    );
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.gradient-labels {
    display: flex;
    justify-content: space-between;
    padding: 0 5px;
}

.gradient-labels span {
    font-size: 0.85em;
    color: #555;
    font-weight: 500;
}

#networkCanvas {
    overflow-x: auto;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
}

.network-layer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.network-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    min-height: 400px;
    gap: 30px;
    padding: 20px;
}

.layer-label {
    font-weight: 600;
    color: #333;
    font-size: 0.85em;
    margin-bottom: 10px;
    text-align: center;
}

.nodes-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.node-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.node-index {
    font-size: 0.7em;
    color: #666;
    font-family: monospace;
    min-width: 30px;
    text-align: right;
}

.node {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #333;
    transition: all 0.3s ease;
    position: relative;
}

.node:hover::after {
    content: attr(data-activation);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    white-space: nowrap;
    z-index: 10;
}

/* Architecture Page */
.architecture-content {
    display: flex;
    flex-direction: column;
    gap: 40px;
    margin-top: 30px;
}

.architecture-visualizations {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.architecture-visualizations > h2 {
    color: #333;
    font-size: 2em;
    text-align: center;
    margin-bottom: 10px;
}

.architecture-description {
    background: #f8f9fa;
    padding: 30px;
    border-radius: 15px;
}

.architecture-description h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5em;
}

.architecture-description p {
    color: #666;
    margin-bottom: 15px;
    line-height: 1.6;
}

.architecture-description ul {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}

.architecture-description li {
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
    color: #555;
    line-height: 1.6;
}

.architecture-description li:last-child {
    border-bottom: none;
}

.model-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 30px;
}

.stat-item {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: bold;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.architecture-image-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    background: #f8f9fa;
    border-radius: 15px;
}

.architecture-image-container h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3em;
}

.architecture-image {
    width: 100%;
    max-width: 1400px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: white;
    padding: 20px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.architecture-image:hover {
    transform: scale(1.02);
}

/* Make keras plot_model more compact */
.architecture-image-container:last-child .architecture-image {
    max-width: 600px;
    padding: 30px 50px;
}

.image-hint {
    color: #666;
    font-size: 0.9em;
    font-style: italic;
    margin-top: 10px;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.95);
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 95%;
    max-height: 90vh;
    object-fit: contain;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 50px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.modal-close:hover,
.modal-close:focus {
    color: #bbb;
}

footer {
    margin-top: 40px;
    text-align: center;
    color: #666;
    font-size: 0.9em;
}

/* Kernel Visualization Styles */
#kernelsCanvas {
    overflow-x: auto;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
}

.kernels-container {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.kernel-layer-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.kernel-layer-title {
    color: #333;
    font-size: 1.3em;
    text-align: center;
    margin-bottom: 10px;
    font-weight: 600;
}

.kernels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 20px;
    padding: 10px;
}

.kernel-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.kernel-wrapper:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.kernel-label {
    font-size: 0.75em;
    color: #666;
    font-weight: 600;
    text-align: center;
}

.kernel-canvas {
    display: grid;
    gap: 0;
    border-radius: 4px;
    border: 2px solid #333;
    width: fit-content;
    margin: 0 auto;
}

.kernel-cell {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
    position: relative;
}

.kernel-cell:hover {
    transform: scale(1.2);
    z-index: 10;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.kernel-cell:hover::after {
    content: attr(data-value);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75em;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
}

/* Update gradient legend for kernels tab - RdBu colormap */
#kernelsTab .gradient-bar {
    background: linear-gradient(
        to right,
        rgb(5, 48, 97) 0%,
        rgb(33, 102, 172) 25%,
        rgb(103, 169, 207) 40%,
        rgb(247, 247, 247) 50%,
        rgb(253, 219, 199) 60%,
        rgb(244, 165, 130) 75%,
        rgb(103, 0, 31) 100%
    );
}

#kernelsTab .gradient-labels {
    display: flex;
    justify-content: space-between;
}

/* Feature Maps Visualization Styles */
#featuremapsCanvas {
    overflow-x: auto;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
}

.featuremaps-container {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.featuremap-layer-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.featuremap-layer-title {
    color: #333;
    font-size: 1.3em;
    text-align: center;
    margin-bottom: 10px;
    font-weight: 600;
}

.featuremaps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 20px;
    padding: 10px;
}

.featuremap-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.featuremap-wrapper:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.featuremap-label {
    font-size: 0.75em;
    color: #666;
    font-weight: 600;
    text-align: center;
}

.featuremap-canvas {
    display: grid;
    gap: 0;
    border-radius: 4px;
    border: 2px solid #333;
    width: fit-content;
    margin: 0 auto;
}

.featuremap-cell {
    width: 4px;
    height: 4px;
    transition: transform 0.2s ease;
    position: relative;
}

.featuremap-cell:hover {
    transform: scale(1.3);
    z-index: 10;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
}

.featuremap-cell:hover::after {
    content: attr(data-value);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7em;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
}

@media (max-width: 768px) {
    main {
        grid-template-columns: 1fr;
    }

    h1 {
        font-size: 2em;
    }

    .container {
        padding: 20px;
    }

    #canvas {
        width: 100%;
        height: auto;
    }

    .kernels-grid {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    }

    .featuremaps-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    }
}
