/*
 * Functional/Structural CSS - DO NOT SEND TO AI MODEL
 * These styles ensure core functionality and layout work correctly.
 * The AI model only modifies styles-themeable.css
 */

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

body {
    min-height: 100dvh;
    overflow-x: hidden;
    position: relative;
}

/* Background layer - prevents mobile viewport resize jank */
.bg-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100lvh; /* Large viewport height - stays constant on mobile */
    z-index: -1;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
}

/* Layout structure */
.layout-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.content {
    flex: 0 1 800px;
    max-width: 800px;
    position: relative;
}

.text-container {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 2.5rem;
    border-radius: 2px;
    position: relative;
}

/* Typography structure */
h1 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Modal functionality - CRITICAL */
.modal {
    position: fixed;
    inset: 0;
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-start !important; /* Prevent themes from centering - causes clipping on mobile */
    justify-content: center;
    padding: 1.5rem 1rem;
    z-index: 2000;
    overflow-y: auto;
    min-height: 100dvh;
}

.modal.active {
    display: flex;
}

.modal-content {
    position: relative;
    width: min(520px, 100%);
    margin: 2rem auto;
    max-height: calc(100dvh - 3rem);
    padding: 2rem;
    border-radius: 4px;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 0.8rem;
    right: 0.8rem;
    border-radius: 999px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Links structure */
.links {
    display: flex;
    gap: 1.5rem;
}

/* Ensure links remain visibly underlined across themes */
a,
.bio a,
.interests a,
.theme-line a,
.modal-note a {
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-decoration-skip-ink: auto;
}

.links a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 2px;
    text-decoration: none;
}

/* Theme Picker Container */
.theme-picker-container {
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.6rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(168, 85, 247, 0.4);
    background: white;
    cursor: pointer;
    font: inherit;
    box-shadow:
        0 4px 12px rgba(168, 85, 247, 0.15),
        0 0 0 3px rgba(168, 85, 247, 0.1);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
    box-shadow:
        0 6px 16px rgba(168, 85, 247, 0.25),
        0 0 0 4px rgba(168, 85, 247, 0.15);
}

.theme-toggle .toggle-label {
    font-weight: 600;
}

.theme-toggle i {
    display: inline-flex;
    align-items: center;
}

.theme-toggle .chevron {
    font-size: 0.7rem;
    margin-left: 0.15rem;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.theme-toggle[aria-expanded="true"] .chevron {
    transform: rotate(-180deg);
}

/* Initial state: animated with purple glow, no chevron */
.theme-toggle.theme-toggle-initial {
    animation: buttonBounce 2s ease-in-out infinite;
    border-color: rgba(168, 85, 247, 0.4);
    box-shadow:
        0 4px 12px rgba(168, 85, 247, 0.15),
        0 0 0 3px rgba(168, 85, 247, 0.1);
}

.theme-toggle.theme-toggle-initial .chevron {
    opacity: 0;
    width: 0;
    margin: 0;
    overflow: hidden;
}

.theme-toggle.theme-toggle-initial:hover {
    animation: none;
    transform: scale(1.05);
    box-shadow:
        0 6px 16px rgba(168, 85, 247, 0.25),
        0 0 0 4px rgba(168, 85, 247, 0.15);
}

/* Theme Popover */
.theme-popover {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 280px;
    max-height: 320px;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.theme-popover.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.theme-popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 0.8rem;
    color: #666;
}

.theme-popover-header span {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.theme-info-link {
    color: #666;
    text-decoration: underline;
    font-size: 0.75rem;
}

.theme-info-link:hover {
    color: #333;
}

.theme-popover-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.theme-popover-list button {
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-size: 0.9rem;
    color: #333;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-popover-list button:hover {
    background: rgba(0, 0, 0, 0.05);
}

.theme-popover-list button.active {
    background: rgba(168, 85, 247, 0.1);
    color: #7c3aed;
}

.theme-popover-list button.active::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #a855f7;
    flex-shrink: 0;
}

.theme-popover-list button:not(.active)::before {
    content: "";
    width: 6px;
    height: 6px;
    flex-shrink: 0;
}

.theme-popover-list .theme-item-title {
    font-weight: 500;
}

.theme-popover-list .theme-item-meta {
    font-size: 0.75rem;
    color: #888;
    margin-left: auto;
}

.theme-popover-footer {
    padding: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.theme-off-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.05);
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    color: #666;
    transition: background 0.15s ease, color 0.15s ease;
}

.theme-off-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #333;
}

.theme-off-btn.active {
    background: rgba(168, 85, 247, 0.1);
    color: #7c3aed;
}

.theme-off-btn i {
    font-size: 0.8rem;
}


/* Responsive layout - CRITICAL */
@media (max-width: 1200px) {
    .content {
        max-width: 90%;
        flex: none;
    }
}

@media (max-width: 768px) {
    .layout-container {
        padding: 1.5rem 1rem;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
    }

    .content {
        max-width: 100%;
        flex: none;
    }

    .theme-picker-container {
        position: fixed;
        right: 1rem;
        bottom: 1.5rem;
        top: auto;
        z-index: 100;
    }

    .theme-popover {
        top: auto;
        bottom: calc(100% + 0.5rem);
        transform: translateY(8px);
    }

    .theme-popover.active {
        transform: translateY(0);
    }

    .text-container {
        padding: 1.5rem;
    }

    .content::after {
        content: '';
        display: block;
        height: 50rem;
    }

    body.theme-off .content::after {
        display: none;
    }

    .links {
        gap: 1.2rem;
    }

    .links a {
        width: 40px;
        height: 40px;
    }

    .modal {
        padding-top: 3rem;
    }

    .modal-content {
        margin-top: 0;
    }
}

/* ============================================
   Button Bounce Animation (used by theme toggle initial state)
   ============================================ */

@keyframes buttonBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-3px);
    }
}

/* ============================================
   Loading Screen
   ============================================ */

.theme-loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.theme-loading.active {
    opacity: 1;
    pointer-events: auto;
}

.loading-content {
    text-align: center;
}

.loading-text {
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.15em;
    margin-bottom: 1rem;
    color: #666;
    text-transform: uppercase;
}

.loading-bar-container {
    width: 160px;
    height: 4px;
    background: #e5e5e5;
    border-radius: 2px;
    overflow: hidden;
}

.loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #a855f7, #6366f1);
    border-radius: 2px;
    transition: width 0.05s linear;
}
