/* ===== Responsive Styles - Mobile and Tablet Breakpoints ===== */

/* Mobile auth trigger - hidden by default on desktop */
.mobile-auth-trigger {
    display: none;
}

/* Tablet Logo text */
@media (max-width: 1024px) {
    .logo-text {
        font-size: 24px;
    }
}

/* Mobile Logo text */
@media (max-width: 768px) {
    .logo-text {
        font-size: 22px;
        text-shadow: 1px 1px 0 #f5e6d3, -1px -1px 0 #f5e6d3,
            1px -1px 0 #f5e6d3, -1px 1px 0 #f5e6d3,
            2px 2px 0 rgba(0, 0, 0, 0.15);
    }
}

/* Small mobile Logo text */
@media (max-width: 480px) {
    .logo-text {
        font-size: 20px;
    }
}

/* Mobile sidebar overlay mode */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        box-shadow: 8px 0 0 rgba(92, 64, 51, 0.5);
        transform: translateX(-100%);
        width: 280px;
        transition: transform 0.3s ease;
    }

    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 280px;
    }

    .toggle-sidebar-button {
        z-index: 1001;
    }
}

/* Mobile book cover responsive */
@media (max-width: 768px) {
    .library-book-cover {
        padding: 6px;
    }

    .library-book-cover.size-small img {
        max-width: 60px;
    }

    .library-book-cover.size-medium img {
        max-width: 100px;
    }

    .library-book-cover.size-large img {
        max-width: 150px;
    }
}

/* Mobile: Hide thinking process */
@media (max-width: 768px) {
    .thinking-message {
        display: none !important;
    }

    /* Mobile background — gradient replaces image (image is covered by UI anyway) */
    .page-bg {
        background-image: none;
        background: linear-gradient(180deg, #75CEF3 0%, #C2E8F9 40%, #EEF6FB 100%);
    }

    /* Hide scene characters on mobile */
    .page-scene-characters {
        display: none;
    }

    /* Page overall optimization */
    body {
        font-size: 14px;
    }

    /* Header optimization */
    .header {
        padding: 0.6rem 1rem;
        flex-direction: row;
        justify-content: space-between;
        gap: 0.5rem;
        border-bottom: none;
        box-shadow: none;
        background: transparent;
    }

    .header-left {
        flex: none;
    }

    .header-logo {
        height: 55px;
    }

    /* Mobile: hide header auth, show bottom auth below input */
    .auth-section {
        display: none !important;
    }

    /* Mobile auth trigger (top-right circular button) */
    .mobile-auth-trigger {
        display: flex !important;
        position: fixed;
        top: 1.125rem;
        right: 0.75rem;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        background: var(--parchment, #fff);
        color: var(--brown);
        border: 2px solid var(--brown);
        box-shadow: 2px 2px 0 rgba(92, 64, 51, 0.4);
        font-size: 1.1rem;
        z-index: 1100;
        cursor: pointer;
        padding: 0;
    }

    .mobile-auth-trigger:active {
        transform: translate(2px, 2px);
        box-shadow: none;
    }

    /* Mobile auth panel - fixed popup from top-right trigger */
    .mobile-auth-section {
        display: none;
        position: fixed;
        top: 4.25rem;
        right: 0.75rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.75rem;
        background: #F3F4F6;
        border: 2px solid var(--brown);
        border-radius: 12px;
        box-shadow: 4px 4px 0 rgba(92, 64, 51, 0.4);
        z-index: 1099;
        min-width: 180px;
    }

    .mobile-auth-section.open {
        display: flex !important;
    }

    .mobile-auth-section .language-selector,
    .mobile-auth-section .login-dropdown {
        position: relative;
    }

    /* Inside panel: unify button widths and remove the pixel-art shadow */
    .mobile-auth-section .language-button,
    .mobile-auth-section .login-button {
        width: 100%;
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
        border-width: 1px;
        box-shadow: none;
        justify-content: center;
    }

    .login-button {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .user-info {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    /* SSO options mobile style */
    .sso-option {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
    }

    .sso-icon {
        width: 30px;
        height: 30px;
        font-size: 0.85rem;
        border-width: 2px;
    }

    /* Language options mobile style */
    .language-button {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        border-width: 3px;
        box-shadow: 3px 3px 0 rgba(92, 64, 51, 0.4);
    }

    .language-option {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .language-dropdown {
        border-width: 3px;
        box-shadow: 4px 4px 0 rgba(92, 64, 51, 0.4);
    }

    .dropdown-content {
        border-width: 3px;
        box-shadow: 4px 4px 0 rgba(92, 64, 51, 0.4);
    }

    /* Mobile auth panel dropdown - pop down */
    .mobile-auth-section .language-dropdown,
    .mobile-auth-section .dropdown-content {
        top: 100%;
        bottom: auto;
        margin-top: 0.5rem;
        margin-bottom: 0;
        box-shadow: 4px 4px 0 rgba(92, 64, 51, 0.4);
        right: 0;
        left: auto;
    }

    /* Mobile panel: stack user-info and logout vertically */
    .mobile-auth-section #mobileUserSection {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.4rem;
    }

    /* Mobile panel: render logout inline instead of a popup dropdown */
    .mobile-auth-section #mobileUserDropdown {
        display: block !important;
        position: static;
        background: transparent;
        border: none;
        box-shadow: none;
        margin: 0;
        padding: 0;
        border-radius: 0;
        min-width: 0;
    }

    .user-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
        border-width: 2px;
    }

    /* Chat container optimization */
    .chat-container {
        margin: 0;
        padding-top: 0;
        width: 100%;
        border-radius: 0;
        min-height: 100vh;
        border: none;
        box-shadow: none;
        clip-path: none;
        background: var(--parchment);
    }

    /* Fill portrait screen */
    .main-wrapper {
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin: 0;
        min-height: 100vh;
        background: var(--parchment);
    }

    /* Quick actions optimization */
    .quick-actions {
        padding: 0.75rem 1rem;
    }

    .quick-actions h3 {
        font-size: 0.95rem;
        margin-bottom: 0.5rem;
    }

    .preset-buttons {
        gap: 0.5rem;
        display: flex;
        flex-wrap: wrap;
    }

    .preset-button {
        flex: 0 1 calc(50% - 0.25rem);
        padding: 0.75rem 0.75rem;
        font-size: 0.9rem;
        text-align: center;
        min-width: 0;
        white-space: normal;
        overflow: visible;
        line-height: 1.4;
        min-height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 0;
    }

    /* Messages area optimization */
    .messages {
        padding: 1rem;
        gap: 0.75rem;
        min-height: 300px;
    }

    .message {
        max-width: 95%;
        padding: 0.75rem 1rem;
        border-radius: 0;
        font-size: 0.8rem;
        line-height: 1.5;
    }

    /* Input area optimization */
    .input-area {
        padding: 1rem;
        border-top: 4px solid var(--brown-dark);
        background: linear-gradient(180deg,
                var(--parchment) 0%,
                var(--parchment-dark) 100%);
        position: relative;
        overflow: visible;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* Mobile: Single row — input | mic | send */
    .input-container {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        align-items: center;
    }

    .autocomplete-container {
        flex: 1;
        min-width: 0;
    }

    .input-container > div:nth-child(2) {
        display: flex;
        align-items: center;
        flex-shrink: 0;
    }

    .button-group {
        flex-shrink: 0;
        width: auto;
    }

    .message-input {
        padding: 0.75rem 1rem;
        font-size: 0.8rem;
        border-radius: 0;
        min-height: 45px;
        max-height: 100px;
    }

    .voice-button {
        width: 48px;
        height: 48px;
        flex-shrink: 0;
    }

    /* Mobile: hide duck mascot */
    .input-character {
        display: none !important;
    }

    /* Mobile button group */
    .button-group {
        position: relative;
    }

    .send-button,
    .stop-button {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        border-radius: 14px;
        white-space: nowrap;
    }

    /* Tool call optimization */
    .tool-call {
        padding: 0.5rem;
        margin: 0.5rem 0;
        font-size: 0.7rem;
    }

    .tool-content {
        padding: 0.5rem;
        font-size: 0.7rem;
        line-height: 1.4;
    }

    /* Code block optimization */
    .markdown-content pre {
        font-size: 0.7rem;
        padding: 0.5rem;
        border-radius: 0;
        overflow-x: auto;
        white-space: pre;
    }

    .markdown-content code {
        font-size: 0.75rem;
        padding: 0.2rem 0.3rem;
    }

    /* Ensure touch friendly */
    button,
    .preset-button {
        min-height: 44px;
        touch-action: manipulation;
    }

    /* Prevent zoom */
    input,
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Bottom disclaimer mobile optimization */
    .bottom-disclaimer {
        padding: 0.4rem 0.75rem;
        font-size: 0.55rem;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
}

/* Extra small screen optimization (iPhone SE etc.) */
@media (max-width: 375px) {
    .chat-container {
        margin: 0.5rem auto;
        width: calc(100% - 1rem);
    }

    .header {
        padding: 0.75rem;
    }

    .header h1 {
        font-size: 0.75rem;
    }

    .preset-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .preset-button {
        flex: none;
        width: 100%;
        padding: 0.875rem 0.75rem;
        font-size: 0.9rem;
        white-space: normal;
        line-height: 1.4;
        min-height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 0;
    }

    .button-group {
        flex-direction: row;
        width: auto;
    }

    .send-button,
    .stop-button {
        flex: none;
        width: auto;
    }

    /* Extra small screen bottom disclaimer optimization */
    .bottom-disclaimer {
        padding: 0.3rem 0.5rem;
        font-size: 0.5rem;
    }
}

/* ===== Tour & Welcome Modal Responsive ===== */

/* Tour overlay style */
.tour-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 35, 65, 0.45);
    z-index: 9998;
    display: none;
    animation: fadeIn 0.3s ease-in;
    overflow: hidden;
}

.tour-overlay.active {
    display: block;
}

.tour-spotlight {
    position: fixed;
    border: 3px solid rgba(74, 144, 226, 0.9);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(15, 35, 65, 0.45),
        0 0 0 6px rgba(74, 144, 226, 0.25);
    pointer-events: none;
    z-index: 9999;
    transition: all 0.3s ease;
    animation: spotlightPulse 1.5s infinite;
}

@keyframes spotlightPulse {
    0%,
    100% {
        box-shadow: 0 0 0 9999px rgba(15, 35, 65, 0.45),
            0 0 0 6px rgba(74, 144, 226, 0.25);
    }

    50% {
        box-shadow: 0 0 0 9999px rgba(15, 35, 65, 0.45),
            0 0 0 10px rgba(74, 144, 226, 0.5);
    }
}

.tour-tooltip {
    position: fixed;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(74, 144, 226, 0.25);
    border-radius: 20px;
    padding: 1.5rem;
    max-width: 400px;
    box-shadow: 0 12px 40px rgba(15, 35, 65, 0.18);
    z-index: 10000;
    animation: messageSlideIn 0.3s ease-out;
}

.tour-tooltip-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.tour-tooltip-icon {
    font-size: 2rem;
}

.tour-tooltip-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--brown-dark);
}

.tour-tooltip-content {
    color: #4a5568;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    font-weight: 400;
}

.tour-tooltip-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.tour-progress {
    font-size: 0.75rem;
    color: var(--brown-light);
    font-weight: 500;
}

.tour-buttons {
    display: flex;
    gap: 0.5rem;
}

.tour-button {
    padding: 0.5rem 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s ease;
    border: none;
}

.tour-button-skip {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.tour-button-skip:hover {
    background: #e2e8f0;
}

.tour-button-next {
    background: var(--orange);
    color: white;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.35);
}

.tour-button-next:hover {
    background: var(--orange-dark);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.45);
    transform: translateY(-1px);
}

/* Welcome modal style */
.welcome-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease-in;
    backdrop-filter: blur(4px);
}

.welcome-content {
    background: rgba(255, 255, 255, 0.98);
    border: none;
    border-radius: 24px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 16px 50px rgba(70, 130, 200, 0.25);
    animation: messageSlideIn 0.4s ease-out;
}

.welcome-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.welcome-icon {
    margin-bottom: 1rem;
}

.welcome-icon img {
    width: 160px;
    height: 160px;
    object-fit: contain;
    image-rendering: pixelated;
}

.welcome-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--brown-dark);
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    font-size: 0.8rem;
    color: var(--brown-light);
    font-weight: 600;
}

.welcome-body {
    color: var(--brown-dark);
    line-height: 1.7;
    margin-bottom: 2rem;
    font-weight: 500;
    font-size: 0.85rem;
}

.welcome-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.welcome-feature {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #F8FAFC;
    border: 1.5px solid rgba(74, 144, 226, 0.25);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--brown-dark);
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(74, 144, 226, 0.08);
}

.welcome-feature-icon {
    font-size: 1.5rem;
}

.welcome-buttons {
    display: flex;
    gap: 1rem;
}

.welcome-button {
    flex: 1;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 700;
    transition: all 0.18s ease;
}

.welcome-button-tour {
    background: linear-gradient(180deg, var(--orange-light) 0%, var(--orange) 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(74, 144, 226, 0.35);
}

.welcome-button-tour:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.45);
}

.welcome-button-skip {
    background: transparent;
    color: #64748B;
    border: 1px solid #CBD5E0;
}

.welcome-button-skip:hover {
    background: #F8FAFC;
}

/* Mobile tour optimization */
@media (max-width: 768px) {
    /* Tour tooltip optimization */
    .tour-tooltip {
        max-width: 90%;
        width: calc(100% - 2rem);
        padding: 1rem;
        left: 1rem !important;
        right: 1rem;
    }

    .tour-tooltip-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .tour-tooltip-icon {
        font-size: 1.5rem;
    }

    .tour-tooltip-title {
        font-size: 0.8rem;
    }

    .tour-tooltip-content {
        font-size: 0.75rem;
        margin-bottom: 1rem;
    }

    .tour-tooltip-footer {
        flex-direction: column;
        gap: 0.75rem;
    }

    .tour-buttons {
        width: 100%;
        flex-direction: column;
    }

    .tour-button {
        width: 100%;
        padding: 0.75rem;
    }

    /* Welcome modal optimization */
    .welcome-content {
        padding: 1.5rem;
        max-width: 95%;
        width: 95%;
    }

    .welcome-icon {
        margin-bottom: 0.75rem;
    }

    .welcome-icon img {
        width: 128px;
        height: 128px;
    }

    .welcome-title {
        font-size: 0.9rem;
        line-height: 1.3;
    }

    .welcome-subtitle {
        font-size: 0.75rem;
    }

    .welcome-body {
        font-size: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .welcome-features {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }

    .welcome-feature {
        padding: 0.6rem;
        font-size: 0.7rem;
    }

    .welcome-feature-icon {
        font-size: 1.3rem;
    }

    .welcome-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }

    .welcome-button {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 0.7rem;
    }

    /* Spotlight effect smaller on mobile */
    .tour-spotlight {
        border-width: 4px;
    }

    /* Ensure overlay displays correctly on mobile */
    .tour-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
    }

    /* Mobile sidebar tour step special handling */
    .sidebar.tour-highlight {
        width: 280px !important;
    }
}

/* Extra small screen optimization (iPhone SE etc.) */
@media (max-width: 375px) {
    .tour-tooltip {
        padding: 0.875rem;
    }

    .tour-tooltip-title {
        font-size: 0.95rem;
    }

    .tour-tooltip-content {
        font-size: 0.85rem;
    }

    .welcome-content {
        padding: 1.25rem;
    }

    .welcome-icon img {
        width: 96px;
        height: 96px;
    }

    .welcome-title {
        font-size: 1.15rem;
    }

    .welcome-subtitle {
        font-size: 0.85rem;
    }

    .welcome-body {
        font-size: 0.85rem;
    }

    .welcome-feature {
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    .welcome-button {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* ===== Language Selection Modal ===== */

.language-selection-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    animation: fadeIn 0.3s ease-in;
    backdrop-filter: blur(4px);
}

.language-selection-modal.hidden {
    display: none;
}

.language-selection-content {
    background: rgba(255, 255, 255, 0.98);
    border: none;
    border-radius: 24px;
    padding: 3rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 16px 50px rgba(70, 130, 200, 0.25);
    animation: messageSlideIn 0.4s ease-out;
    text-align: center;
}

.language-selection-header {
    margin-bottom: 2rem;
}

.language-selection-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.language-selection-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--brown-dark);
    margin-bottom: 0.5rem;
}

.language-selection-subtitle {
    font-size: 0.8rem;
    color: var(--brown-light);
    font-weight: 500;
}

.language-options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.language-option-card {
    background: #F8FAFC;
    border: 2px solid #E2E8F0;
    border-radius: 16px;
    padding: 1.5rem 1rem;
    cursor: pointer;
    transition: all 0.18s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    box-shadow: none;
}

.language-option-card:hover {
    background: #F0F7FF;
    border-color: var(--blue);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.2);
}

.language-option-card.selected {
    background: linear-gradient(180deg, var(--orange-light) 0%, var(--orange) 100%);
    border-color: var(--orange);
    color: white;
    transform: none;
    box-shadow: 0 4px 14px rgba(74, 144, 226, 0.35);
}

.language-flag {
    font-size: 2.5rem;
    margin-bottom: 0.25rem;
}

.language-name {
    font-size: 0.9rem;
    font-weight: 700;
}

.language-native-name {
    font-size: 0.75rem;
    opacity: 0.8;
    font-weight: 500;
}

.language-confirm-button {
    width: 100%;
    padding: 1rem 2rem;
    background: linear-gradient(180deg, var(--orange-light) 0%, var(--orange) 100%);
    color: white;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    transition: all 0.18s ease;
    opacity: 0.5;
    pointer-events: none;
    box-shadow: 0 4px 14px rgba(74, 144, 226, 0.35);
}

.language-confirm-button.enabled {
    opacity: 1;
    pointer-events: auto;
}

.language-confirm-button.enabled:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.45);
}

/* Mobile language selection optimization */
@media (max-width: 768px) {
    .language-selection-content {
        padding: 2rem 1.5rem;
        width: 95%;
        max-height: 85vh;
    }

    .language-selection-icon {
        font-size: 3rem;
    }

    .language-selection-title {
        font-size: 1rem;
    }

    .language-selection-subtitle {
        font-size: 0.75rem;
    }

    .language-options-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .language-option-card {
        padding: 1rem 0.75rem;
    }

    .language-flag {
        font-size: 2rem;
    }

    .language-name {
        font-size: 0.8rem;
    }

    .language-native-name {
        font-size: 0.65rem;
    }

    .language-confirm-button {
        padding: 0.875rem 1.5rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 375px) {
    .language-selection-content {
        padding: 1.5rem 1rem;
        max-height: 80vh;
    }

    .language-selection-icon {
        font-size: 2.5rem;
    }

    .language-selection-title {
        font-size: 0.9rem;
    }

    .language-options-grid {
        grid-template-columns: 1fr;
    }
}
