body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 5px;
    padding-bottom: 80px;
    /* Match reduced slider height */
    background-color: #f5f5f5;
    box-sizing: border-box;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 15px;
    min-height: calc(100vh - 100px);
    /* 100vh - padding-bottom - margins */
    box-sizing: border-box;
    overflow-x: auto;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 10px;
}

.visualization-container {
    display: grid;
    grid-template-columns: repeat(4, minmax(200px, 1fr));
    gap: clamp(15px, 3vw, 30px);
    margin-top: 10px;
    overflow-x: auto;
}

.matrix-section {
    text-align: center;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.matrix-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
    height: 20px;
    /* Fixed height for alignment */
    text-align: center;
    line-height: 16px;
    padding-top: 17px;
}

.matrix-subtitle {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    height: 40px;
    /* Fixed height for alignment */
    display: flex;
    align-items: center;
    justify-content: center;
}

.matrix-canvas-container {
    height: 200px;
    /* Fixed height for canvas area */
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

canvas {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    max-width: 100%;
    height: auto;
}

.matrix-info {
    margin-top: 15px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 5px;
    font-size: 14px;
    min-height: 80px;
    /* Ensure consistent height */
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
    /* Take remaining space */
}

.controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 15px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-top: 2px solid #007bff;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    height: 80px;
    /* Minimal height for low profile */
    box-sizing: border-box;
}

.slider-container {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: clamp(10px, 2vw, 15px);
    margin: 0;
    max-width: min(800px, 90vw);
    text-align: left;
    width: 100%;
}

.slider-group {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 123, 255, 0.1);
    position: relative;
}

.slider-auto-adjusted {
    animation: sliderHighlight 0.5s ease;
}

@keyframes sliderHighlight {
    0% {
        border-color: rgba(0, 123, 255, 0.1);
    }

    50% {
        border-color: #007bff;
    }

    100% {
        border-color: rgba(0, 123, 255, 0.1);
    }
}

.slider-group h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 15px;
    font-weight: 600;
}

.slider-group label {
    display: block;
    margin-bottom: 4px;
    color: #666;
    font-size: 13px;
}

.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    margin-bottom: 10px;
}

.slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: none;
}

.slider-value {
    font-weight: bold;
    color: #007bff;
    font-size: 16px;
}

button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    margin: 0 10px;
}

button:hover {
    background-color: #0056b3;
}

.flattening-note {
    text-align: center;
    margin: 15px 0 5px 0;
    font-size: 14px;
    color: #666;
    font-style: italic;
}

.u-column-label {
    font-size: 12px;
    font-weight: bold;
    color: #333;
    margin-top: 3px;
    height: 22px;
    line-height: 14px;
    overflow: hidden;
    white-space: nowrap;
    text-align: center;
    padding-top: 2px;
}

.u-column-info {
    font-size: 10px;
    color: #666;
    margin-top: 2px;
    height: 14px;
    line-height: 14px;
}

.equation {
    text-align: center;
    margin: 30px 0 10px;
    font-size: 18px;
    height: 30px;
    font-weight: bold;
    color: #333;
}

.github-link {
    position: fixed;
    bottom: 90px; /* Just above the controls */
    right: 20px; /* GitHub on the rightmost position */
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px; /* Similar height to equation + flattening note */
}

.github-icon {
    width: 28px;
    height: 28px;
    filter: grayscale(1) opacity(0.7);
    transition: filter 0.3s ease;
}

.github-link:hover .github-icon {
    filter: grayscale(0) opacity(1);
}

.website-link {
    position: fixed;
    bottom: 90px; /* Just above the controls */
    right: 78px; /* Website link to the left of GitHub link */
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px; /* Similar height to equation + flattening note */
}

.website-icon {
    width: 28px;
    height: 28px;
    filter: grayscale(1) opacity(0.7);
    transition: filter 0.3s ease;
    border-radius: 50%;
}

.website-link:hover .website-icon {
    filter: grayscale(0) opacity(1);
}

/* Responsive design */
@media (max-width: 1016px) {

    h1,
    .equation,
    .flattening-note {
        margin: 0;
    }


    .visualization-container {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: auto auto;
        gap: 0;
    }

    .matrix-title {
        padding-top: 0;
    }

    .matrix-subtitle {
        margin-bottom: 0;
        height: 30px;
    }

    .matrix-section:first-child {
        grid-column: 2 / 3;
        /* Center the Original Image in top row */
        grid-row: 1;
    }

    .matrix-section:nth-child(2) {
        grid-column: 1 / 2;
        /* U Matrix in bottom left */
        grid-row: 2;
    }

    .matrix-section:nth-child(3) {
        grid-column: 2 / 3;
        /* Σ Matrix in bottom center */
        grid-row: 2;
    }

    .matrix-section:nth-child(4) {
        grid-column: 3 / 4;
        /* V^T Matrix in bottom right */
        grid-row: 2;
    }

    .matrix-canvas-container {
        height: auto;
        min-height: 150px;
    }
}

@media (max-width: 705px) {
    .visualization-container {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(2, auto);
        gap: clamp(10px, 2vw, 20px);
    }

    .matrix-section:first-child {
        grid-column: 1 / 2;
        /* Original Image top left */
        grid-row: 1;
    }

    .matrix-section:nth-child(2) {
        grid-column: 2 / 3;
        /* U Matrix top right */
        grid-row: 1;
    }

    .matrix-section:nth-child(3) {
        grid-column: 1 / 2;
        /* Σ Matrix bottom left */
        grid-row: 2;
    }

    .matrix-section:nth-child(4) {
        grid-column: 2 / 3;
        /* V^T Matrix bottom right */
        grid-row: 2;
    }

    .matrix-canvas-container {
        height: auto;
        min-height: 120px;
    }

    .github-link {
        width: 42px;
        height: 42px;
        right: 15px; /* GitHub on the rightmost position */
    }

    .github-icon {
        width: 24px;
        height: 24px;
    }

    .website-link {
        width: 42px;
        height: 42px;
        right: 63px; /* Website link to the left of GitHub */
    }

    .website-icon {
        width: 24px;
        height: 24px;
    }

    h1 {
        font-size: clamp(18px, 4vw, 24px);
    }
}

@media (max-width: 515px) {
    .container {
        display: flex;
        flex-direction: column;
    }

    h1 {
        order: 0;
        height: 45px;
    }

    .equation {
        order: 1;
        margin: 5px 0 0;
        font-size: 16px;
        height: 25px;
    }

    .flattening-note {
        order: 2;
        font-size: 11px;
    }

    .visualization-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 0;
        order: 3;
    }

    .matrix-section:first-child,
    .matrix-section:nth-child(2),
    .matrix-section:nth-child(3),
    .matrix-section:nth-child(4) {
        grid-column: 1;
        grid-row: auto;
    }

    .matrix-title {
        display: none;
    }

    .matrix-section:first-child .matrix-subtitle::before {
        content: "A:\00a0";
        font-weight: bold;
    }

    .matrix-section:nth-child(2) .matrix-subtitle::before {
        content: "U:\00a0";
        font-weight: bold;
    }

    .matrix-section:nth-child(3) .matrix-subtitle::before {
        content: "Σ:\00a0";
        font-weight: bold;
    }

    .matrix-section:nth-child(4) .matrix-subtitle::before {
        content: "V\1D40:\00a0";
        font-weight: bold;
    }

    .matrix-canvas-container {
        height: auto;
        min-height: 100px;
    }

    .slider-container {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .slider-group {
        padding: 6px 8px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .slider-group label {
        margin-bottom: 0;
        font-size: 12px;
        white-space: nowrap;
    }

    .slider {
        flex: 1;
        margin: 0;
    }

    .slider-value {
        min-width: 20px;
        text-align: center;
        font-size: 12px;
    }

    .controls {
        height: auto;
        min-height: 90px;
        padding: 6px 10px;
    }

    body {
        padding-bottom: 110px;
    }

    .container {
        padding: 8px;
    }

    .links-container {
        display: flex;
        justify-content: center;
        gap: 20px;
        order: 4; /* Position after visualization but before controls */
        margin: 20px 0 0 0;
    }

    .github-link {
        position: static; /* Remove fixed positioning */
        width: 36px;
        height: 36px;
        margin: 0; /* Remove auto margins */
        display: flex; /* Maintain flex properties */
    }

    .github-icon {
        width: 20px;
        height: 20px;
    }

    .website-link {
        position: static; /* Remove fixed positioning */
        width: 36px;
        height: 36px;
        margin: 0; /* Remove auto margins */
        display: flex; /* Maintain flex properties */
    }

    .website-icon {
        width: 20px;
        height: 20px;
    }

    /* RGB mode overrides for mobile */
    .rgb-mode .matrix-section:nth-child(2) .matrix-subtitle::before {
        content: "A_f:\00a0";
        font-weight: bold;
    }

    .rgb-mode .matrix-section:nth-child(3) .matrix-subtitle::before {
        content: "Σ:\00a0";
        font-weight: bold;
    }

    .rgb-mode .matrix-section:nth-child(4) .matrix-subtitle::before {
        content: "I:\00a0";
        font-weight: bold;
    }
}