/* ═══════════════════════════════════════════════
   Ethereal Virtual Companion — Mobile-First UI
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Manrope:wght@200;300;400;500;600;700&display=swap');

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #0d141d;
    --surface: #0d141d;
    --surface-container: #19202a;
    --surface-high: #242a34;
    --surface-highest: #2e353f;
    --on-surface: #dce3f0;
    --on-surface-variant: #bac9cc;
    --primary: #c3f5ff;
    --primary-bright: #00e5ff;
    --primary-dim: #00daf3;
    --primary-container: #004f58;
    --outline: #849396;
    --outline-variant: #3b494c;
    --tertiary: #ffb95a;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --font-headline: 'Space Grotesk', system-ui, sans-serif;
    --font-body: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    background: var(--bg);
    color: var(--on-surface);
}

/* ── View switching ── */

.view {
    display: none;
    height: 100dvh;
    height: 100vh;
    flex-direction: column;
    position: relative;
}
.view.active {
    display: flex;
}

/* ══════════════════════════════════════════════════
   SELECT VIEW — Full-screen Swipeable Discovery
   ══════════════════════════════════════════════════ */

#select-view {
    background: var(--bg);
    overflow: hidden;
    position: relative;
}

/* ── Character Background Stage ── */

.char-stage {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.char-stage-main {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: opacity 0.5s ease;
}

.char-avatar-bg {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 120px;
    filter: brightness(0.85) contrast(1.1);
    mask-image: linear-gradient(to bottom, black 40%, transparent 78%);
    -webkit-mask-image: linear-gradient(to bottom, black 40%, transparent 78%);
}
.char-avatar-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
}

.char-side-preview {
    display: none;
}

/* ── Atmospheric Orbs ── */

.atmos-orb {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(100px);
}
.atmos-orb-1 {
    top: 15%;
    right: 5%;
    width: 300px;
    height: 300px;
    background: rgba(0, 229, 255, 0.06);
}
.atmos-orb-2 {
    bottom: 20%;
    left: 5%;
    width: 250px;
    height: 250px;
    background: rgba(255, 185, 90, 0.04);
}

/* ── Top Header ── */

.select-top-bar {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(12px + var(--safe-top)) 20px 12px;
    background: rgba(13, 20, 29, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.select-brand {
    font-family: var(--font-headline);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 500;
    color: var(--primary);
}

/* ── Pagination Dots ── */

.pagination-dots {
    position: fixed;
    top: calc(72px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.pagination-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(0, 229, 255, 0.2);
    transition: all 0.3s ease;
}
.pagination-dot.active {
    background: var(--primary-bright);
    box-shadow: 0 0 12px var(--primary-bright), 0 0 4px var(--primary-bright);
    width: 20px;
    border-radius: 10px;
}

/* ── Glass Info Overlay ── */

.char-info-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: linear-gradient(180deg, rgba(13, 20, 29, 0) 0%, rgba(13, 20, 29, 0.75) 30%, rgba(13, 20, 29, 0.95) 60%);
    padding: 40px 28px calc(100px + var(--safe-bottom)) 28px;
}

.char-info-label {
    font-size: 10px;
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: 0.3em;
    color: rgba(195, 245, 255, 0.7);
    margin-bottom: 8px;
    font-weight: 700;
}

.char-info-name {
    font-family: var(--font-headline);
    font-size: 42px;
    font-weight: 300;
    color: var(--on-surface);
    letter-spacing: -0.02em;
    margin-bottom: 10px;
    line-height: 1.1;
}

.char-info-bio {
    color: rgba(220, 227, 240, 0.7);
    font-size: 14px;
    font-weight: 300;
    line-height: 1.6;
    max-width: 340px;
    margin-bottom: 14px;
}

.char-info-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.char-info-meta-item {
    font-size: 11px;
    color: rgba(186, 201, 204, 0.7);
    padding: 3px 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
}

.char-info-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.char-info-tag {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(0, 229, 255, 0.1);
    color: var(--primary);
    border: 1px solid rgba(0, 229, 255, 0.15);
}

.char-info-signature {
    margin-top: 10px;
    font-size: 13px;
    font-style: italic;
    color: rgba(255, 185, 90, 0.6);
}

/* ── Start Chat Button ── */

.char-start-btn {
    position: absolute;
    bottom: calc(24px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    padding: 14px 48px;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.2), rgba(0, 79, 88, 0.4));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(0, 229, 255, 0.3);
    border-radius: 28px;
    color: var(--primary);
    font-family: var(--font-headline);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 24px rgba(0, 229, 255, 0.15);
}
.char-start-btn:active {
    transform: translateX(-50%) scale(0.96);
    box-shadow: 0 2px 12px rgba(0, 229, 255, 0.2);
}

/* ══════════════════════════════════════════════════
   CHAT VIEW — Ethereal Conversation
   ══════════════════════════════════════════════════ */

#chat-view {
    background: var(--bg);
    position: relative;
}

/* ── Layer 0: Background ── */

.video-layer {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: var(--bg);
    transition: all var(--transition-smooth);
}
.video-layer video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.55;
}
.video-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(13, 20, 29, 0.3) 0%,
        rgba(13, 20, 29, 0.15) 30%,
        rgba(13, 20, 29, 0.15) 50%,
        rgba(13, 20, 29, 0.5) 80%,
        rgba(13, 20, 29, 0.85) 100%
    );
    pointer-events: none;
}

.video-collapse-btn {
    position: absolute;
    top: calc(12px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.6);
    width: 40px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s;
    z-index: 5;
}
.video-collapse-btn:active { opacity: 0.6; }
.video-collapse-btn svg { width: 16px; height: 16px; }

.video-layer.split-mode {
    bottom: auto;
    height: 45dvh;
    height: 45vh;
    border-radius: 0 0 20px 20px;
    overflow: hidden;
}

/* Animated gradient fallback with character presence */
.video-fallback {
    position: fixed;
    inset: 0;
    z-index: 0;
}
.video-fallback.hidden { display: none; }

.chat-bg-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--surface) 0%, #151c26 40%, var(--surface-highest) 100%);
    opacity: 0.8;
}
.chat-bg-avatar {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 200px;
    opacity: 0.06;
    mix-blend-mode: lighten;
    filter: grayscale(0.5) blur(1px);
    pointer-events: none;
}
.chat-bg-orb-1 {
    position: absolute;
    top: 20%;
    right: 10%;
    width: 500px;
    height: 500px;
    background: rgba(0, 229, 255, 0.04);
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
}
.chat-bg-orb-2 {
    position: absolute;
    bottom: 10%;
    left: 5%;
    width: 400px;
    height: 400px;
    background: rgba(255, 185, 90, 0.03);
    border-radius: 50%;
    filter: blur(100px);
    pointer-events: none;
}

/* ── PiP Thumbnail ── */

.video-pip {
    position: fixed;
    top: calc(64px + var(--safe-top));
    right: 16px;
    width: 100px;
    height: 140px;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 50;
    cursor: pointer;
    transition: all var(--transition-smooth);
    border: 1.5px solid rgba(0, 229, 255, 0.2);
}
.video-pip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.video-pip.hidden { display: none; }
.video-pip:active { transform: scale(0.95); }

/* ── Chat Overlay ── */

.chat-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    pointer-events: none;
}

/* ── Top Bar (glass) ── */

.chat-top-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + var(--safe-top)) 14px 10px;
    background: rgba(13, 20, 29, 0.6);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid rgba(59, 73, 76, 0.1);
    pointer-events: auto;
    flex-shrink: 0;
}

.top-bar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: none;
    border: none;
    color: rgba(220, 227, 240, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}
.top-bar-btn:active { color: var(--primary); }

.top-bar-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--surface-highest);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    border: 1.5px solid rgba(0, 229, 255, 0.2);
}

.top-bar-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.top-bar-name {
    font-family: var(--font-headline);
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.02em;
}
.top-bar-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    color: rgba(186, 201, 204, 0.6);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}
.status-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary-dim);
    animation: pulseSoft 2s infinite ease-in-out;
}

@keyframes pulseSoft {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* ── Messages Area ── */

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px calc(68px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}
.messages::-webkit-scrollbar { width: 2px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 1px; }

.msg-row {
    display: flex;
    flex-direction: column;
    animation: msgSlideIn 0.3s ease;
    max-width: 85%;
}
.msg-row.self {
    align-self: flex-end;
    align-items: flex-end;
}
.msg-row.other {
    align-self: flex-start;
    align-items: flex-start;
}

.msg-label {
    font-size: 10px;
    font-weight: 600;
    color: rgba(195, 245, 255, 0.5);
    margin-bottom: 4px;
    padding-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.msg-bubble {
    padding: 14px 18px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    max-width: 100%;
    font-weight: 300;
}

.msg-row.other .msg-bubble {
    background: linear-gradient(135deg, rgba(46, 53, 63, 0.35) 0%, rgba(21, 28, 38, 0.4) 100%);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    color: var(--on-surface);
    border-radius: 20px 20px 20px 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.msg-row.self .msg-bubble {
    background: linear-gradient(135deg, rgba(0, 104, 117, 0.25) 0%, rgba(0, 79, 88, 0.3) 100%);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    color: var(--on-surface);
    border-radius: 20px 20px 4px 20px;
    border: 1px solid rgba(0, 229, 255, 0.12);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.msg-time {
    font-size: 10px;
    color: rgba(195, 245, 255, 0.3);
    margin-top: 4px;
    padding: 0 4px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.msg-bubble img {
    max-width: 220px;
    max-height: 200px;
    border-radius: 12px;
    display: block;
}
.msg-bubble video {
    max-width: 240px;
    max-height: 180px;
    border-radius: 12px;
    display: block;
}
.msg-bubble audio {
    display: block;
    max-width: 200px;
    margin-top: 4px;
}
.msg-bubble .meta {
    font-size: 11px;
    opacity: 0.5;
    margin-top: 6px;
}

/* ── Generated Media Bubble ── */

.msg-media-bubble {
    padding: 0 !important;
    overflow: hidden;
    background: transparent !important;
    border: none !important;
    margin-top: 6px;
}
.gen-media-img {
    max-width: 260px;
    max-height: 320px;
    border-radius: 16px;
    display: block;
    cursor: pointer;
    transition: transform 0.2s ease;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.gen-media-img:hover {
    transform: scale(1.02);
}
.gen-media-video {
    max-width: 260px;
    max-height: 320px;
    border-radius: 16px;
    display: block;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ── Lightbox ── */

.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.lightbox-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.lightbox-img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}
.lightbox-overlay.active .lightbox-img {
    transform: scale(1);
}

/* ── Clothing Carousel ── */

.carousel-wrap {
    margin-top: 8px;
    overflow: hidden;
    pointer-events: auto;
}
.carousel-track {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 8px;
    scrollbar-width: none;
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-card {
    flex: 0 0 auto;
    width: 80px;
    scroll-snap-align: start;
    cursor: pointer;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(46, 53, 63, 0.6);
    border: 1.5px solid rgba(59, 73, 76, 0.25);
    transition: border-color 0.2s, transform 0.2s;
}
.carousel-card:hover {
    border-color: var(--primary-dim);
    transform: translateY(-2px);
}
.carousel-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(77, 183, 152, 0.3);
}
.carousel-thumb {
    width: 80px;
    height: 96px;
    object-fit: cover;
    display: block;
}
.carousel-name {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    padding: 4px 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Media options (auto-generated multi-choice) ── */

.media-options-wrap {
    margin-top: 10px;
    overflow: hidden;
    pointer-events: auto;
}
.media-options-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    opacity: 0.8;
}
.media-options-track {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 8px;
    scrollbar-width: none;
}
.media-options-track::-webkit-scrollbar { display: none; }
.media-option-card {
    flex: 0 0 auto;
    width: 120px;
    scroll-snap-align: start;
    cursor: pointer;
    border-radius: 12px;
    overflow: hidden;
    background: transparent;
    border: none;
    transition: transform 0.25s, box-shadow 0.25s;
    position: relative;
}
.media-option-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.media-option-card.selected {
    box-shadow: 0 0 0 2px var(--primary);
}
.media-option-img {
    width: 120px;
    height: 150px;
    object-fit: cover;
    display: block;
}
.media-option-num {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    padding: 4px 2px;
    background: transparent;
}

/* ── Shimmer placeholder (media loading) ── */

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.shimmer-placeholder {
    width: 220px;
    height: 280px;
    border-radius: 16px;
    background: linear-gradient(90deg,
        rgba(46, 53, 63, 0.4) 25%,
        rgba(59, 73, 76, 0.3) 50%,
        rgba(46, 53, 63, 0.4) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 12px;
}

.media-gen-label {
    text-align: center;
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 0;
    animation: shimmer 1.5s infinite;
    background: linear-gradient(90deg,
        rgba(186, 201, 204, 0.3) 25%,
        rgba(186, 201, 204, 0.6) 50%,
        rgba(186, 201, 204, 0.3) 75%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Media Loading Card (poster + sparkle overlay) ── */

.media-loading-card {
    flex: 0 0 auto;
    width: 120px;
    height: 150px;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    scroll-snap-align: start;
    border: none;
    background: var(--surface-container);
}

/* Background — blurred when no poster, clear when poster arrives */
.media-loading-card .loading-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}
.media-loading-card .loading-bg img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(12px) brightness(0.5);
    transform: scale(1.15);
    transition: filter 0.5s ease, transform 0.5s ease;
}
.media-loading-card.has-poster .loading-bg img {
    filter: none;
    transform: scale(1);
}

/* Overlay — uses theme surface color for cohesive look */
.media-loading-card .loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: rgba(25, 32, 42, 0.55);
    transition: background 0.5s ease;
}
.media-loading-card.has-poster .loading-overlay {
    background: rgba(25, 32, 42, 0.30);
}

/* Particle container */
.media-loading-card .loading-particles {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
}

/* Individual sparkle dots */
.media-loading-card .loading-particles .particle {
    position: absolute;
    border-radius: 50%;
    animation: particleTwinkle var(--dur, 2s) var(--delay, 0s) infinite ease-in-out;
}
.media-loading-card .loading-particles .particle.dot-sm {
    width: 2px; height: 2px;
    background: rgba(195, 245, 255, 0.5);
}
.media-loading-card .loading-particles .particle.dot-md {
    width: 3px; height: 3px;
    background: rgba(195, 245, 255, 0.7);
}
.media-loading-card .loading-particles .particle.dot-lg {
    width: 4px; height: 4px;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 0 4px rgba(195, 245, 255, 0.6);
}

/* Subtle bottom gradient for generating label */
.media-loading-card .loading-label {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 10px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    padding: 14px 6px 8px;
    background: linear-gradient(to top, rgba(25, 32, 42, 0.65), transparent);
    line-height: 1.4;
    letter-spacing: 0.3px;
}

/* Progress bar inside label area */
.media-loading-card .loading-progress {
    position: absolute;
    bottom: 0; left: 0;
    height: 2px;
    background: rgba(195, 245, 255, 0.6);
    border-radius: 1px;
    width: 0%;
    z-index: 4;
    transition: width 0.8s ease;
}

.media-loading-card.done {
    border: none;
}
.media-loading-card.done .loading-bg,
.media-loading-card.done .loading-overlay,
.media-loading-card.done .loading-particles,
.media-loading-card.done .loading-label,
.media-loading-card.done .loading-progress {
    display: none;
}
.media-loading-card .result-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
    cursor: pointer;
    transition: transform 0.2s ease;
}
.media-loading-card.done .result-img {
    display: block;
}

/* 1x3 grid card — wider horizontal layout */
.media-loading-card.grid-card {
    width: 280px;
    height: 110px;
    border-radius: 10px;
}
.media-loading-card.grid-card.done .result-img {
    object-fit: contain;
    background: var(--surface-container);
}

@keyframes particleTwinkle {
    0%, 100% { opacity: 0; transform: scale(0.5); }
    20% { opacity: 0.6; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.2); }
    60% { opacity: 0.7; transform: scale(1); }
    80% { opacity: 1; transform: scale(1.1); }
}

.media-loading-wrap {
    margin-top: 10px;
    overflow: hidden;
    pointer-events: auto;
    animation: msgSlideIn 0.3s ease;
}
.media-loading-track {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 8px;
    scrollbar-width: none;
}
.media-loading-track::-webkit-scrollbar { display: none; }

.msg-system {
    text-align: center;
    font-size: 11px;
    color: rgba(186, 201, 204, 0.4);
    padding: 6px 16px;
    animation: msgSlideIn 0.2s ease;
    pointer-events: auto;
    font-weight: 500;
    letter-spacing: 0.02em;
}

@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Typing Indicator (ethereal) ── */

.typing-row {
    display: flex;
    align-items: flex-end;
    animation: msgSlideIn 0.25s ease;
    pointer-events: auto;
    align-self: flex-start;
}
.typing-dots {
    padding: 14px 20px;
    background: linear-gradient(135deg, rgba(46, 53, 63, 0.35), rgba(21, 28, 38, 0.4));
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border-radius: 20px 20px 20px 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    gap: 4px;
    align-items: center;
}
.typing-dots span {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-dim);
    animation: dotPulse 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.2; transform: scale(0.85); }
    40% { opacity: 1; transform: scale(1); }
}

/* ── Loading Spinner (for history fetch) ── */

.loading-more {
    text-align: center;
    padding: 12px;
    animation: msgSlideIn 0.2s ease;
}
.loading-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(0, 229, 255, 0.15);
    border-top-color: var(--primary-dim);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════
   Debug Panel
   ══════════════════════════════════════ */

.debug-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: rgba(13, 20, 29, 0.95);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    z-index: 100;
    padding: calc(16px + var(--safe-top)) 16px 16px;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform var(--transition-smooth);
    border-left: 1px solid rgba(59, 73, 76, 0.15);
}
.debug-panel.visible { transform: translateX(0); }
.debug-panel.hidden { transform: translateX(100%); }

.debug-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.debug-panel-header h3 {
    font-family: var(--font-headline);
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.debug-close-btn {
    background: none;
    border: none;
    color: rgba(186, 201, 204, 0.5);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
}

.debug-item {
    margin-bottom: 8px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(59, 73, 76, 0.1);
    border-radius: 10px;
}
.debug-item label {
    display: block;
    font-size: 9px;
    font-weight: 700;
    color: var(--primary-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 3px;
}
.debug-item span {
    font-size: 13px;
    color: rgba(220, 227, 240, 0.8);
    font-weight: 300;
}

/* ══════════════════════════════════════
   Bottom Input Bar (glass)
   ══════════════════════════════════════ */

.input-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: linear-gradient(to top, var(--bg), rgba(13, 20, 29, 0.9) 60%, transparent);
    pointer-events: auto;
}

.input-tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: none;
    border: none;
    color: rgba(186, 201, 204, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s;
}
.input-tool-btn:active { color: var(--primary); }
.input-tool-btn.recording {
    color: #ff4757;
    animation: pulse 1s infinite;
}

.input-field-wrap {
    flex: 1;
    background: rgba(25, 32, 42, 0.7);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    display: flex;
    align-items: flex-end;
    padding: 6px 14px;
    min-width: 0;
}

#msg-input {
    flex: 1;
    background: none;
    border: none;
    font-size: 15px;
    font-weight: 300;
    color: var(--on-surface);
    outline: none;
    min-width: 0;
    padding: 4px 0;
    font-family: var(--font-body);
    resize: none;
    overflow-y: auto;
    line-height: 1.5;
    max-height: 120px;
    height: 24px;
    scrollbar-width: none;
}
#msg-input::-webkit-scrollbar { display: none; }
#msg-input::placeholder {
    color: rgba(186, 201, 204, 0.4);
}

.input-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(186, 201, 204, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}
.input-send-btn:active {
    transform: scale(0.92);
    color: var(--primary);
}

/* ── Voice Recording Bar ── */

.voice-recording-bar {
    position: fixed;
    bottom: calc(58px + var(--safe-bottom));
    left: 16px;
    right: 16px;
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 71, 87, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 71, 87, 0.2);
    border-radius: 28px;
    padding: 12px 18px;
}
.voice-recording-bar.hidden { display: none; }

.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff4757;
    animation: pulse 1s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
#recording-timer {
    font-size: 14px;
    color: var(--on-surface);
    font-variant-numeric: tabular-nums;
    flex: 1;
    font-weight: 400;
}
.voice-cancel-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    padding: 5px 16px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font-body);
}

/* ══════════════════════════════════════
   Bottom Sheet: Attachment Menu
   ══════════════════════════════════════ */

.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity var(--transition-smooth);
}
.sheet-backdrop.visible { opacity: 1; }
.sheet-backdrop.hidden { opacity: 0; pointer-events: none; }

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 35;
    background: var(--surface-container);
    border-radius: 20px 20px 0 0;
    padding: 8px 20px calc(24px + var(--safe-bottom));
    transform: translateY(100%);
    transition: transform var(--transition-smooth);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.bottom-sheet.visible { transform: translateY(0); }
.bottom-sheet.hidden { transform: translateY(100%); }

.sheet-handle {
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin: 4px auto 16px;
}

.sheet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border-radius: 14px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--on-surface);
    font-size: 12px;
    font-family: var(--font-body);
    transition: background 0.15s;
}
.sheet-item:active { background: rgba(255, 255, 255, 0.05); }

.sheet-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sheet-icon-media { background: rgba(66, 133, 244, 0.15); color: #4285f4; }
.sheet-icon-audio { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.sheet-icon-doc   { background: rgba(52, 168, 83, 0.15); color: #34a853; }
.sheet-icon-book  { background: rgba(124, 77, 255, 0.15); color: #7c4dff; }

/* ══════════════════════════════════════
   Content Shelf (Book/Document)
   ══════════════════════════════════════ */

.content-shelf {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 35;
    background: var(--surface-container);
    border-radius: 20px 20px 0 0;
    padding: 0 0 calc(16px + var(--safe-bottom));
    transform: translateY(100%);
    transition: transform var(--transition-smooth);
    max-height: 50dvh;
    max-height: 50vh;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.content-shelf.visible { transform: translateY(0); }
.content-shelf.hidden { transform: translateY(100%); }

.shelf-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--on-surface);
}
.shelf-icon { color: var(--primary-dim); }
.shelf-close-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: rgba(186, 201, 204, 0.5);
    font-size: 20px;
    cursor: pointer;
    padding: 2px 6px;
}

.shelf-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 12px;
    padding: 4px 16px 12px;
    -webkit-overflow-scrolling: touch;
}
.shelf-carousel::-webkit-scrollbar { display: none; }

.book-card {
    scroll-snap-align: start;
    flex-shrink: 0;
    width: 120px;
    cursor: pointer;
    transition: transform 0.15s;
}
.book-card:active { transform: scale(0.96); }

.book-cover {
    width: 120px;
    height: 160px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    margin-bottom: 8px;
    background: var(--surface-highest);
}
.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--on-surface);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.book-author {
    font-size: 11px;
    color: rgba(186, 201, 204, 0.5);
    margin-top: 2px;
}

/* ══════════════════════════════════════
   Reader Panel (split view)
   ══════════════════════════════════════ */

.reader-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    height: 55dvh;
    height: 55vh;
    background: var(--surface-container);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform var(--transition-smooth);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.reader-panel.visible { transform: translateY(0); }
.reader-panel.hidden { transform: translateY(100%); }

.reader-drag-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 4px;
    cursor: grab;
}
.handle-pill {
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.reader-header {
    display: flex;
    align-items: center;
    padding: 4px 16px 12px;
}
.reader-title {
    font-family: var(--font-headline);
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    color: var(--on-surface);
}
.reader-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: rgba(186, 201, 204, 0.5);
    cursor: pointer;
    padding: 4px 8px;
}

.reader-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 16px;
    font-family: "Georgia", "Noto Serif SC", serif;
    font-size: 16px;
    line-height: 1.8;
    color: rgba(220, 227, 240, 0.8);
    -webkit-overflow-scrolling: touch;
}
.reader-content p {
    margin-bottom: 1em;
    text-indent: 2em;
}

.reader-actions {
    padding: 8px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.reader-discuss-btn {
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(0, 229, 255, 0.3);
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.1), rgba(0, 79, 88, 0.2));
    color: var(--primary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s;
    font-family: var(--font-body);
}
.reader-discuss-btn:active { opacity: 0.8; }

/* ══════════════════════════════════════
   Top glow line
   ══════════════════════════════════════ */

.top-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(0, 229, 255, 0.25), transparent);
    z-index: 200;
    pointer-events: none;
}
