*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* --- Base Styles --- */
body {
    font-family: 'Inter', sans-serif;
    background-color: #212121;
    color: #e0e0e0;
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Layout --- */
.main-container {
    display: flex !important; 
    flex-direction: row;
    height: 100vh !important;
    width: 100vw !important;
    padding: 12px;
    gap: 24px;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    .main-container {
        flex-direction: row;
        padding: 16 px 24px;
        gap: 20px;
        min-height: 100vh;
        height: auto;
    }
}

.app-wrapper {
    display: flex;
    flex-direction: column; /* Stack sidebar on top of content for mobile */
    flex: 1;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    gap: 16px;
}

@media (min-width: 768px) {
    .app-wrapper {
        flex-direction: row; /* Sidebar to the left on desktop */
        height: auto;
        min-height: 100%;
    }
}

.sidebar {
    background: #2c2c2c;
    border-radius: 8px;
    padding: 4px 12px; 
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    overflow: hidden;
    gap: 4px;
    width: 100%;
    height: auto;
    flex-shrink: 0;
    box-sizing: border-box;
}

.sidebar > * {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    box-sizing: border-box;
}

.sidebar img, 
.sidebar svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

@media (min-width: 768px) {
    .sidebar {
        flex-direction: column;
        width: 80px;
        height: auto;
        min-height: 100%;
        justify-content: space-evenly;
        flex-wrap: nowrap;
        overflow: hidden;
    }
}


.content-area {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    height: 100%;
}

.display-wrapper {
    display: flex;
    flex-direction: row; /* Puts Figure and Options side-by-side */
    align-items: stretch;
    width: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
    gap: 8px;
}

@media (min-width: 768px) {
    .display-wrapper {
        flex-direction: row; /* Switch to side-by-side for tablets/desktops */
    }
}

#enlarge-hint {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-family: Inter, sans-serif;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 25;
}

#enlarge-hint.is-visible {
    opacity: 1;
}

/* --- Figure Display --- */
#figure-display {
    flex: 3;
    flex-shrink: 0;
    width: 100%;
    height: 100%;
    min-height: 200px;
    min-width: 0;
    background: #000;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    overflow: auto;
    overflow-y: auto;
}

#figure-display > img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* --- Welcome Container --- */

#welcome-message {
    width: 100%;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: center;
    justify-content: flex-start;
    padding: 8px;
    text-align: center;
    color: #e0e0e0;
    box-sizing: border-box;
    overflow: visible;
}

.welcome-message .main-logo, 
#main-logo {
    max-width: 100%;
    max-height: 14vh;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    margin: 0 auto 12px auto;
    box-sizing: border-box;
}

#welcome-message p {
    font-size: clamp(0.7rem, 1.5vw + 0.3rem, 1rem);
    line-height: 1.35;
    margin-bottom: 8px;
}

@media (max-width: 480px) {
    #welcome-message p {
        font-size: 0.875rem;
    }
}

#main-logo {
    display: block;
    max-width: 100%;
    max-height: 30vh;
    width: auto;      
    height: auto;        
    margin: 0 auto; 
    object-fit: contain; 
    box-sizing: border-box;
}

@media (min-width: 768px) {
    #main-logo {
        max-width: 300px; /* Use a fixed max size for desktop to keep it professional */
        max-height: none;
    }
}

/* --- Options Container --- */
#options-container {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    grid-template-columns: 1fr;
    gap: 12px;
    align-content: start;
    justify-content: center;
}

@media (min-width: 768px) {
    #options-container {
        grid-template-columns: 1fr 1fr;
    }
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 6px;
    overflow-y: auto;
    flex: 1;
}

@media (min-width: 768px) {
    .options-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- Components --- */
.md-card {
    position: relative;
    appearance: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.3s;
    padding: 0;
    text-align: left;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease-in-out;
    overflow: hidden;
    height: auto;
    width: 100%;
    max-width: 200px;
    margin: 0 auto;
}

.md-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transform: scale(1.05);
}

.md-card.is-selected {
    border-color: #ffc107;
}
.md-card img {
    display: block;
    width: 100%;
    height: 120px;
    flex-grow: 1;
    height: auto;
    object-fit: cover;
    border-top-left-radius: 8px; 
    border-top-right-radius: 8px;
    margin: 0;
}

/* The label text */
.md-card p {
    text-align: center;
    font-size: 0.875rem; 
    padding: 8px; 
    font-weight: 500; 
    margin: 0; 
    border-bottom-left-radius: 8px; 
    border-bottom-right-radius: 8px;
    background: #2c2c2c;
    color: #e0e0e0;
}

/* LOCK BUTTON */
.lock-action-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    transition: background 0.2s, transform 0.2s;
}

.lock-action-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

.lock-action-btn svg {
    width: 18px;
    height: 18px;
    fill: #9ca3af;
    transition: fill 0.2s;
}

.lock-action-btn.is-locked svg {
    fill: #ffc107;
}

/* ICON BUTTONS */

.icon-btn {
    width: 100%; 
    height: 46px;
    min-width: 0;
    min-height: 46px;
    background: rgba(255, 255, 255, 0.03); /* Subtle background so they feel like buttons */
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    color: #9ca3af;
    transition: transform 0.2s ease, color 0.2s ease, background 0.2s ease;
    padding: 3px;           /* Gives the SVG room to breathe inside a 46px box */
    border-radius: 12px;     /* Modern rounded square style works great on mobile */
    flex-shrink: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.icon-btn:hover {
    transform: translateY(-2px); 
    background: rgba(255, 255, 255, 0.08);
}

.icon-btn svg {
    width: 100%;
    height: 100%;
    fill: #9ca3af;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.icon-btn.is-active svg {
    fill: #ffc107 !important;
    filter: drop-shadow(0 0 8px rgba(255, 193, 7, 0.6));
    transition: filter 0.3s ease;
    animation: pulse 2s infinite ease-in-out;
}

/* Larger desktop override using your clamp preference */
@media (min-width: 768px) {
    .icon-btn {
        width: clamp(32px, 7vw, 56px);
        height: clamp(32px, 7vw, 56px);
        min-width: 32px;
        min-height: 32px;
        background: none;
        border: none;
        padding: 6px;
        border-radius: 50%;
    }
}

/* ---- HELP PANE ---- */
#help-pane {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

#help-pane .md-card {
    width: 100%;
    max-width: 80vw;
    max-height: 90vh;
    padding: 24px;
    position: relative;
    text-align: left;
    cursor: default;
    overflow-y: auto;
    border-radius: 8px;
}

#help-pane .md-card h2 {
    font-size: clamp(1.5rem, 5vw + 1rem, 2.5rem);
    margin-top: 0;
}

#help-pane .md-card div, 
#help-pane .md-card p, 
#help-pane .md-card li {
    font-size: clamp(0.875rem, 2vw + 0.5rem, 1rem);
    line-height: 1.6;
    text-align: left;
}

#help-pane a.externallink {
    color: #c107ff; /* Purple complement to yellow */
    text-decoration: underline;
    font-weight: bold;
}

#help-pane a.externallink:hover {
    color: #e0a3ff; /* Lighter shade on hover */
}

@media (max-width: 480px) {
    #help-pane .md-card {
        padding: 16px; 
    }
}

#close-help-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    color: #e0e0e0;
}

#close-help-btn svg {
    width: 24px;
    height: 24px;
}

#fullscreen-pane {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px; /* Provides a safe buffer from the edges */
    margin: 0;
}

#fullscreen-content {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 90vw; /* Keeps it within screen width */
    max-height: 90vh; /* Keeps it within screen height */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Prevents overflow */
}

/* Ensure images inside the fullscreen content don't exceed the container */
#fullscreen-content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.fullscreen-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.close-fullscreen-btn {
    position: absolute;
    top: 16px;       
    right: 16px;     
    padding: 8px;    
    color: #9ca3af;  
background: rgba(0, 0, 0, 0.5); /* Add a background to see the hit-box */
    border: 1px solid white;
    cursor: pointer;
    z-index: 999 !important;
    transition: color 0.2s ease;
}

.close-fullscreen-btn svg {
    display: block;
    width: 32px; /* Force specific width */
    height: 32px; /* Force specific height */
    fill: currentColor; /* Inherits the color from the button */
    pointer-events: none; /* Ensures clicking the SVG registers as clicking the button */
}

.close-fullscreen-btn:hover {
    color: #e5e7eb;  
}

/* --- Utility --- */
.is-hidden {
    display: none !important;
}

.is-visible {
    opacity: 1 !important;
}

.highlight {
    color: #ffc107; 
}

/* Download Button */
.download-action-btn {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #8f6f18;
    color: #111;
    border: none;
    padding: 0.5rem 1rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 100;
}

.download-action-btn:hover {
    background: #e0b034;
}

/* Screen Reader */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus for better usability */
button:focus-visible, 
.md-card:focus-visible {
    outline: 3px solid #ffc107;
    outline-offset: 2px;
}