/* ============================================
   SAHIRA — Overlays & Panels
   Character Creation, Settings, Save/Load, Log
   ============================================ */

/* ── Overlay Backdrop ── */
.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 50;
    animation: fadeIn 0.3s var(--ease-out);
}

.overlay-panel {
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    padding: var(--space-2xl);
    background: var(--bg-surface);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-elevated);
    overflow-y: auto;
    animation: scaleIn 0.4s var(--ease-out);
}

.overlay-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--space-xl);
    background: var(--gradient-aurora);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 5s ease infinite;
}

/* ══════════════════════════════════════════
   Character Creation
   ══════════════════════════════════════════ */

#screen-creation {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(-45deg, #0a0a1a, #1a0a2e, #0e1a25, #1a0a1a);
    background-size: 400% 400%;
    animation: gradientShift 18s ease infinite;
}

.creation-panel {
    width: 90%;
    max-width: 560px;
    padding: var(--space-2xl) var(--space-xl);
    background: var(--bg-surface);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-elevated);
    animation: scaleIn 0.6s var(--ease-out);
    position: relative;
    overflow: hidden;
}

/* Decorative gradient border on top */
.creation-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-rainbow);
    background-size: 200% 100%;
    animation: shimmer 4s linear infinite;
}

.creation-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: var(--space-xl);
    background: var(--gradient-sunset);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 4s ease infinite;
}

.creation-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.form-group label {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.form-group input[type="text"] {
    padding: var(--space-md);
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-glass);
    border: 2px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
    outline: none;
    transition: all var(--transition-fast);
}

.form-group input[type="text"]:focus {
    border-color: var(--pink);
    box-shadow: var(--shadow-glow-pink);
    background: rgba(253, 121, 168, 0.04);
}

.form-group input[type="text"]::placeholder {
    color: var(--text-muted);
}

/* ── Avatar & Outfit Grid ── */
.avatar-grid, .outfit-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
}

.avatar-option, .outfit-option {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    background: var(--bg-glass);
    border: 2px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    gap: 2px;
}

.avatar-option .option-label,
.outfit-option .option-label {
    font-family: var(--font-body);
    font-size: 0.6rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

.avatar-option:hover, .outfit-option:hover {
    background: var(--bg-glass-hover);
    border-color: rgba(255, 255, 255, 0.12);
    transform: scale(1.06);
}

.avatar-option.selected {
    border-color: var(--coral);
    box-shadow: var(--shadow-glow-coral);
    background: rgba(255, 107, 107, 0.08);
}

.outfit-option.selected {
    border-color: var(--teal);
    box-shadow: var(--shadow-glow-teal);
    background: rgba(0, 206, 201, 0.08);
}

/* ══════════════════════════════════════════
   Settings Panel
   ══════════════════════════════════════════ */

.settings-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.settings-group {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) 0;
}

.settings-group label {
    flex: 0 0 130px;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.settings-group input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
    outline: none;
}

.settings-group input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: var(--radius-full);
}

.settings-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gradient-aurora);
    cursor: pointer;
    box-shadow: 0 0 12px rgba(85, 239, 196, 0.4);
    margin-top: -7px;
    transition: transform var(--transition-fast);
}

.settings-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.25);
}

.settings-group span {
    flex: 0 0 55px;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text-muted);
    text-align: right;
}

.btn-toggle {
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-glass);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-glass-hover);
}

.btn-toggle.active {
    color: var(--mint);
    border-color: var(--mint);
    box-shadow: var(--shadow-glow-teal);
    background: rgba(85, 239, 196, 0.06);
}

/* ══════════════════════════════════════════
   Save/Load Panel
   ══════════════════════════════════════════ */

.saveload-panel {
    max-width: 600px;
}

.saveload-tabs {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.tab-btn {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab-btn:hover {
    color: var(--text-secondary);
    background: var(--bg-glass);
}

.tab-btn.active {
    color: var(--text-primary);
    background: var(--bg-glass);
    border-color: var(--purple);
    box-shadow: var(--shadow-glow-purple);
}

.save-slots {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.save-slot {
    padding: var(--space-md);
    background: var(--bg-glass);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.save-slot::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--gradient-ocean);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.save-slot:hover {
    background: var(--bg-glass-hover);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.save-slot:hover::before {
    opacity: 1;
}

.save-slot .slot-label {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--purple);
    margin-bottom: var(--space-xs);
}

.save-slot .slot-info {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.save-slot .slot-time {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--text-muted);
}

.save-slot.empty {
    opacity: 0.45;
}

.save-slot.empty .slot-info {
    color: var(--text-muted);
    font-style: italic;
}

/* ══════════════════════════════════════════
   Dialogue Log
   ══════════════════════════════════════════ */

.log-panel {
    max-width: 600px;
}

.log-entries {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.log-entry {
    padding: var(--space-sm) var(--space-md);
    border-left: 3px solid var(--purple);
    background: var(--bg-glass);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.log-entry .log-speaker {
    font-family: var(--font-heading);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--teal);
    margin-bottom: 2px;
}

.log-entry .log-text {
    font-family: var(--font-body);
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.log-entry.narration {
    border-left-color: var(--gold);
    font-style: italic;
}

/* ══════════════════════════════════════════
   Orientation Lock (Force Landscape on Mobile)
   ══════════════════════════════════════════ */
.orientation-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    background: #0a0a1a;
    background: radial-gradient(circle at center, #1a0a2e 0%, #0a0a1a 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: var(--space-xl);
    text-align: center;
}

/* Show overlay automatically whenever device orientation is portrait on mobile/tablet screens */
@media screen and (orientation: portrait) and (max-width: 1024px) {
    .orientation-overlay {
        display: flex !important;
    }
}

.orientation-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    max-width: 380px;
    animation: scaleIn 0.5s var(--ease-out);
}

.phone-icon-wrapper {
    position: relative;
    font-size: 4rem;
    margin-bottom: var(--space-md);
    animation: float 4s ease-in-out infinite;
}

.phone-icon {
    display: inline-block;
    animation: rotatePhone 2.5s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}

.rotate-arrow {
    position: absolute;
    top: -10px;
    right: -15px;
    font-size: 2rem;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes rotatePhone {
    0%, 20% { transform: rotate(0deg); }
    50%, 70% { transform: rotate(-90deg); }
    90%, 100% { transform: rotate(0deg); }
}

.orientation-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    background: var(--gradient-sunset);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 4s ease infinite;
}

.orientation-subtitle {
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.orientation-subtitle strong {
    color: var(--gold);
}

/* ── Overlays Mobile Landscape (Heights <= 550px) ── */
@media screen and (max-height: 550px) {
    .overlay-panel, .creation-panel {
        max-height: 94vh;
        max-height: 94dvh;
        padding: var(--space-md);
        border-radius: var(--radius-lg);
    }
    .overlay-title, .creation-title {
        font-size: 1.2rem;
        margin-bottom: var(--space-md);
    }
    .creation-form {
        gap: var(--space-sm);
    }
    .avatar-grid, .outfit-grid {
        grid-template-columns: repeat(8, 1fr);
    }
    .save-slots {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-xs);
    }
    .save-slot {
        padding: var(--space-sm);
    }
}

/* ══════════════════════════════════════════
   Gallery Overlay & Lightbox
   ══════════════════════════════════════════ */

.gallery-panel {
    max-width: 720px;
    width: 90%;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    max-height: 400px;
    overflow-y: auto;
    padding-right: 6px;
}

@media screen and (max-height: 550px) {
    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        max-height: 220px;
    }
}

.gallery-card {
    position: relative;
    aspect-ratio: 16/9;
    background: #090915;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-fast) var(--ease-out);
}

.gallery-card:not(.locked):hover {
    transform: translateY(-4px);
    border-color: var(--coral);
    box-shadow: 0 8px 24px rgba(255, 107, 107, 0.2);
}

.gallery-thumb {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: transform var(--transition-normal) var(--ease-out);
}

.gallery-card:not(.locked):hover .gallery-thumb {
    transform: scale(1.06);
}

.gallery-card.locked {
    cursor: not-allowed;
}

.gallery-card.locked .gallery-thumb {
    filter: grayscale(100%) brightness(0.4) blur(1px);
    opacity: 0.6;
}

.gallery-lock {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    z-index: 2;
    pointer-events: none;
}

.gallery-lock-icon {
    font-size: 1.8rem;
    color: rgba(255, 255, 255, 0.45);
    transition: transform var(--transition-fast) var(--ease-out);
}

.gallery-card.locked:hover .gallery-lock-icon {
    transform: scale(1.12);
    color: var(--coral);
}

.gallery-card-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(10, 10, 26, 0.95) 0%, rgba(10, 10, 26, 0.6) 80%, transparent 100%);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--text-primary);
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 3;
}

/* Lightbox Modal */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000000;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: fadeIn 0.3s ease-out;
}

.lightbox-overlay img {
    max-width: 90%;
    max-height: 82%;
    border-radius: var(--radius-md);
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: max(30px, env(safe-area-inset-right));
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.7);
    transition: color var(--transition-fast);
}

.lightbox-close:hover {
    color: var(--coral);
}

#lightbox-caption {
    margin-top: var(--space-md);
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-style: italic;
    color: var(--text-primary);
    text-align: center;
    max-width: 80%;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}
