/* Language Explorer Styles */

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

html,
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100%;
    width: 100%;
    overflow: hidden;
    /* Prevent scrolling */
    position: fixed;
    /* Lock position on iOS */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    /* Subtle fallback gradient */
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-image 0.6s ease, transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform: translateX(0);
    /* For swipe animations */
}

.language-explorer {
    width: 100%;
    max-width: 31.25rem;
    /* 500px equivalent */
    padding: 2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.content-card {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(0.9375rem);
    border-radius: 1.25rem;
    padding: 3rem 2rem;
    text-align: center;
}

.phrase-text {
    font-size: 3rem;
    color: white;
    font-weight: 300;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.phrase-meaning {
    font-size: 1.2rem;
    color: rgba(255, 255, 255, 0.8);
}

.ui-element {
    position: fixed;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 1.25rem;
    font-size: 0.8rem;
    backdrop-filter: blur(1.25rem) saturate(180%);
    border: 0.03125rem solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.location-bubble {
    top: 1rem;
    left: 1rem;
    text-align: left;
    transition: all 0.3s ease;
    cursor: pointer;
    min-height: 2.75rem;
    /* 44px equivalent */
    min-width: 2.75rem;
    padding: 0.75rem;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.location-bubble:hover {
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transform: translateY(-1px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.location-bubble:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
}

.click-hint {
    position: absolute;
    top: -0.5rem;
    right: -0.5rem;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.location-bubble:hover .click-hint {
    opacity: 1;
}

.location-bubble.expanded {
    padding: 1rem 1.5rem;
    font-size: 0.9rem;
    transform-origin: top left;
    min-width: 17.5rem;
    margin-left: 0.5rem;
}

.progress-indicator {
    top: 1rem;
    right: 1rem;
    text-align: center;
    font-size: 0.75rem;
    opacity: 0.8;
    min-width: 5rem;
}



.photo-credit {
    bottom: 1rem;
    left: 1rem;
    text-align: left;
}



.photo-credit a {
    color: white;
    text-decoration: none;
}

.details {
    margin-top: 0.5rem;
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

.details.show {
    opacity: 1;
    max-height: 12.5rem;
}

.detail-line {
    margin: 0.3rem 0;
    font-size: 0.8rem;
}

.detail-label {
    opacity: 0.7;
    margin-right: 0.5rem;
}

#terminal-dialog {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    border: none;
    background: transparent;
    padding: 0;
    z-index: 3000;
    width: 100%;
    transition: transform 0.3s cubic-bezier(0.1, 0.1, 0.9, 1);
    display: block;
    visibility: visible;
}

#terminal-dialog[aria-hidden="true"] {
    transform: translateX(-50%) translateY(-100%);
    pointer-events: none;
}

#terminal-dialog[aria-hidden="false"] {
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.terminal {
    position: relative;
    top: 0;
    left: 0;
    width: 80vw;
    max-width: 37.5rem;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(1.25rem) saturate(180%);
    border: 0.03125rem solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.1);
    border-radius: 0 0 1.25rem 1.25rem;
    padding: 2rem;
    opacity: 1;
}

.terminal-header {
    color: white;
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.terminal-line {
    margin-bottom: 0.5rem;
    display: flex;
    color: white;
    font-size: 1rem;
    line-height: 1.6;
}

.terminal-prompt {
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    margin-right: 0.5rem;
}

.terminal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 0.125rem solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.75rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.terminal-close:hover,
.terminal-close:focus {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.terminal-close:active {
    transform: scale(0.95);
}

.mobile-instructions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 0.0625rem solid rgba(255, 255, 255, 0.2);
}

.flying-text {
    position: fixed;
    color: white;
    font-weight: 300;
    text-shadow: 0 0 1.25rem rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 2000;
    white-space: nowrap;
}

/* Loading indicator styles */
.loading-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 1rem 2rem;
    border-radius: 0.5rem;
    font-size: 1.1rem;
    z-index: 10000;
    backdrop-filter: blur(0.625rem);
}

.loading-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loading-spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 0.125rem solid #ffffff40;
    border-top: 0.125rem solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Enhanced swipe feedback - responsive movement based on viewport */
.swiping-left {
    transform: translateX(-1.25rem) scale(0.98) !important;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.38, 0.9) !important;
    filter: brightness(0.9) !important;
}

.swiping-right {
    transform: translateX(1.25rem) scale(0.98) !important;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.38, 0.9) !important;
    filter: brightness(0.9) !important;
}

.swiping-up {
    transform: translateY(-1rem) scale(0.98) !important;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.38, 0.9) !important;
    filter: brightness(1.1) !important;
}

.swiping-down {
    transform: translateY(1rem) scale(0.98) !important;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.38, 0.9) !important;
    filter: brightness(0.9) !important;
}

/* Animations */
@keyframes flyThrough {
    0% {
        font-size: 2rem;
        opacity: 0;
    }

    15% {
        opacity: 1;
        font-size: 3rem;
    }

    60% {
        opacity: 1;
        font-size: 6rem;
    }

    85% {
        opacity: 1;
        font-size: 100rem;
    }

    100% {
        font-size: 160rem;
        opacity: 0;
    }
}

@keyframes flyThroughRotate {
    0% {
        font-size: 2rem;
        opacity: 0;
        transform: rotate(0deg);
    }

    15% {
        opacity: 1;
        font-size: 3rem;
        transform: rotate(45deg);
    }

    60% {
        opacity: 1;
        font-size: 6rem;
        transform: rotate(180deg);
    }

    85% {
        opacity: 1;
        font-size: 100rem;
        transform: rotate(540deg);
    }

    100% {
        font-size: 160rem;
        opacity: 0;
        transform: rotate(720deg);
    }
}

@keyframes simpleFlyThrough {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    50% {
        opacity: 1;
        transform: scale(1.2);
    }

    100% {
        opacity: 0;
        transform: scale(2);
    }
}

/* Accessibility Styles */
.skip-link {
    position: absolute;
    top: -2.5rem;
    left: 0.375rem;
    background: #000;
    color: #fff;
    padding: 0.5rem;
    text-decoration: none;
    border-radius: 0.25rem;
    z-index: 10000;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0.375rem;
}

.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 indicators */
.location-bubble:focus,
.terminal-close:focus,
a:focus,
button:focus {
    outline: 0.1875rem solid #4A90E2;
    outline-offset: 0.125rem;
}

/* Touch feedback for all interactive elements */
a:active,
button:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

/* Prevent accidental zoom on inputs */
input,
textarea,
select {
    font-size: 1rem;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ui-element {
        background: rgba(0, 0, 0, 0.95);
        border: 0.125rem solid white;
    }

    .terminal {
        background: rgba(0, 0, 0, 0.95);
        border: 0.125rem solid white;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .flying-text {
        display: none;
    }
}

/* iOS Safari specific fixes and safe area support */
@supports (-webkit-touch-callout: none) {

    html,
    body {
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        /* iOS viewport fix */
        overflow: hidden;
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
    }

    /* Disable iOS bounce scrolling */
    body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: none;
    }
}

/* Safe area support for devices with notches */
:root {
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-right: env(safe-area-inset-right);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
}

/* Adjust UI elements for safe areas */
.location-bubble {
    top: max(1rem, calc(var(--safe-area-inset-top) + 0.5rem));
    left: max(1rem, calc(var(--safe-area-inset-left) + 0.5rem));
}

.photo-credit {
    bottom: max(1rem, calc(var(--safe-area-inset-bottom) + 0.5rem));
    left: max(1rem, calc(var(--safe-area-inset-left) + 0.5rem));
}

#terminal-dialog {
    top: var(--safe-area-inset-top, 0);
}

/* Performance optimizations for low-power devices */
.android .flying-text,
.ios.low-power .flying-text {
    animation-duration: var(--animation-duration, 2s) !important;
}

.android .terminal,
.ios.low-power .terminal {
    backdrop-filter: blur(var(--blur-amount, 1.25rem));
}

.android .ui-element,
.ios.low-power .ui-element {
    backdrop-filter: blur(var(--blur-amount, 1.25rem));
}

/* Reduce motion for accessibility and performance */
@media (prefers-reduced-motion: reduce) {

    .swiping-left,
    .swiping-right,
    .swiping-up,
    .swiping-down {
        transform: none !important;
        filter: none !important;
        transition: none !important;
    }
}

/* Prevent iOS zoom on double tap and control touch behavior */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* Prevents double-tap zoom */
}

/* Specific touch handling for the body */
body {
    touch-action: none;
    /* Disable all default touch behaviors */
}

/* Allow text selection for accessibility */
.terminal-line,
.phrase-meaning,
.photo-credit {
    -webkit-user-select: text;
    user-select: text;
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    .phrase-text {
        font-size: 2.5rem;
        line-height: 1.2;
        margin-bottom: 1rem;
    }

    .phrase-meaning {
        font-size: 1.1rem;
    }

    .ui-element {
        padding: 1rem;
        margin: 0.5rem;
        border-radius: 0.75rem;
        font-size: 0.9rem;
    }

    .location-bubble {
        max-width: calc(100vw - 2rem);
        word-wrap: break-word;
        left: 0.5rem;
    }

    .location-bubble.expanded {
        min-width: calc(100vw - 3rem);
        margin-left: 0;
    }

    .photo-credit {
        left: 0.5rem;
        bottom: 0.5rem;
        max-width: calc(100vw - 2rem);
        word-wrap: break-word;
    }

    .terminal {
        width: 95vw;
        max-height: 85vh;
        padding: 1.5rem;
        margin: 0 auto;
        border-radius: 0 0 1.25rem 1.25rem;
    }

    .terminal-header {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }

    .terminal-line {
        font-size: 0.9rem;
        margin-bottom: 0.75rem;
    }

    /* Optimize flying text for mobile */
    .flying-text {
        max-width: 90vw;
        text-align: center;
        word-wrap: break-word;
    }

    /* Reduce animation complexity on mobile */
    .flying-text {
        animation-duration: 2s !important;
    }

    /* Disable complex animations on older/slower devices */
    @media (max-resolution: 150dpi) {
        .flying-text {
            animation: simpleFlyThrough 1.5s ease-out forwards !important;
        }
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .phrase-text {
        font-size: 2rem;
    }

    .phrase-meaning {
        font-size: 1rem;
    }

    .ui-element {
        padding: 0.75rem;
        font-size: 0.8rem;
    }

    .terminal {
        padding: 1rem;
    }

    .terminal-header {
        font-size: 1.1rem;
    }

    .terminal-line {
        font-size: 0.85rem;
    }
}

/* Landscape orientation optimizations */
@media (orientation: landscape) and (max-height: 500px) {
    .phrase-text {
        font-size: 2rem;
    }

    .ui-element {
        padding: 0.5rem 1rem;
    }

    .terminal {
        height: 90vh;
        padding: 1rem;
    }

    .location-bubble.expanded {
        max-height: 40vh;
        overflow-y: auto;
    }
}