/* =============================================
   PANEL.CSS - Shared Core Styles
   =============================================
   This file contains the foundational styles shared across
   all panel components including:
   - Font face declarations
   - Global reset and base styles
   - CSS custom properties
   - Universal selectors
   - Core panel layout & structure
   - Debug & development styles
   ============================================= */

/* =============================================
   FONT FACE DECLARATIONS
   ============================================= */
/* DigitalStripBB font family - Regular, Italic, Bold Italic */
@font-face {
    font-family: 'DigitalStripBB';
    src: url('/static/fonts/DigitalStripBB_Reg.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'DigitalStripBB';
    src: url('/static/fonts/DigitalStripBB_Ital.otf') format('opentype');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'DigitalStripBB';
    src: url('/static/fonts/DigitalStripBB_BoldItal.otf') format('opentype');
    font-weight: bold;
    font-style: italic;
    font-display: swap;
}

/* Outset (Outfit) font family - Regular and Bold */
@font-face {
    font-family: 'Outset';
    src: url('/static/fonts/Outfit/static/Outfit-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Outset';
    src: url('/static/fonts/Outfit/static/Outfit-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

/* Shantell Sans - self-hosted to match mobile exactly (no synthesis) */
@font-face {
    font-family: 'ShantellSans-Regular';
    src: url('/static/fonts/ShantellSans-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'ShantellSans-SemiBold';
    src: url('/static/fonts/ShantellSans-SemiBold.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'ShantellSans-Italic';
    src: url('/static/fonts/ShantellSans-Italic.ttf') format('truetype');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}

@font-face {
    font-family: 'ShantellSans-SemiBoldItalic';
    src: url('/static/fonts/ShantellSans-SemiBoldItalic.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* =============================================
   GLOBAL STYLES & RESET
   ============================================= */

/* CSS Custom Properties (CSS Variables) */
:root {
    /* CSS custom properties for viewport height */
    --vh: 1vh;
    --dvh: 1dvh;
    
    /* Initial default for narration background color */
    --narration-bg-color: rgba(15, 15, 25, 1);
    
    /* Dynamic container background color for gradients */
    --container-bg-color: rgba(0, 0, 0, 1);
}

/* Top safe-area black bar (camera/notch) — parity with native iOS/Android */
.safe-area-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top, 0px);
    background: #000;
    z-index: 9999;
    pointer-events: none;
}

/* Push panel page content below the safe-area bar */
body.panel-page {
    padding-top: env(safe-area-inset-top, 0px);
}

/* Panel logo sits below safe area (matches native) */
.panel-page .panel-logo {
    top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
}
.panel-page[data-hide-video-ui="true"] .panel-logo {
    top: calc(env(safe-area-inset-top, 0px) + 100px) !important;
}

/* HTML Element - Base layout */
html {
    scroll-behavior: smooth;
    /* Ensure no overflow on mobile */
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height */
    overflow: hidden;
}

/* Body Element - Global page styles */
body {
    margin: 0;
    padding: 0;
    background-color: #000;
    color: #fff;
    font-family: 'NewSpirit-Medium', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    width: 100%;
    /* Use dynamic viewport height for mobile compatibility */
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height - adjusts for mobile UI */
    overflow: hidden; /* Prevent scrollbars on any axis */
    box-sizing: border-box;
    
    /* Disable text selection and touch callouts for better mobile UX */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Universal Box Sizing Reset */
*, *:before, *:after {
    box-sizing: inherit;
}

/* =============================================
   UTILITY CLASSES
   ============================================= */

/* Transparent tap highlight for better touch UX */
.container, .tap-zone, .panel-content, .panel-v2-main {
  -webkit-tap-highlight-color: transparent;
}

/* =============================================
   CORE PANEL LAYOUT & STRUCTURE
   ============================================= */

/* Panel Container */
.container {
    width: 100%;
    /* Use dynamic viewport height for mobile compatibility */
    min-height: 100vh; /* Fallback for older browsers */
    min-height: 100dvh; /* Dynamic viewport height - adjusts for mobile UI */
    max-height: 100vh; /* Fallback for older browsers */
    max-height: 100dvh; /* Prevent overflow on mobile */
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    overflow: hidden; /* Prevent any scrollbars */
    outline: none; /* Remove focus outline */
    isolation: isolate; /* Create a new stacking context to contain z-index */
}

/* Container background - zoomed, blurred copy of panel image (desktop only) */
.container::before {
    content: '';
    position: absolute;
    top: -10%;
    left: -10%;
    right: -10%;
    bottom: -10%;
    background-image: var(--panel-bg-image, none);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(40px) brightness(0.4);
    transform: scale(1.2);
    z-index: 1; /* Blurred background layer */
}

/* Disable blurred background on mobile - not needed and causes performance issues */
@media (max-width: 768px) {
    .container::before {
        display: none;
    }
}

/* Panel Image - within container for tap navigation */
.panel-image {
    width: auto;
    max-width: 100vw;
    /* Fill height unless width would exceed viewport, then scale down */
    height: 100vh; /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height - adjusts for mobile UI */
    display: block;
    position: relative;
    z-index: 10; /* Ensure it stays above the blurred background */
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    object-fit: contain; /* Ensure image fits within bounds */
}

.panel-image.navigation-disabled {
    cursor: default;
}

.container.navigation-disabled {
    pointer-events: none;
}

.container.navigation-disabled .choice-option,
.container.navigation-disabled .custom-choice-container,
.container.navigation-disabled button,
.container.navigation-disabled input {
    pointer-events: auto;
}

/* =============================================
   DEBUG & DEVELOPMENT STYLES
   ============================================= */

/* Status indicators for connection states */
.status {
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    font-weight: bold;
}

.status.connected {
    background-color: #223322;
    color: #b6fcb6;
    border: 1px solid #3e6c3e;
}

.status.disconnected {
    background-color: #331a1a;
    color: #ffb6b6;
    border: 1px solid #6c3e3e;
}

.status.connecting {
    background-color: #33321a;
    color: #ffeaa7;
    border: 1px solid #ffeaa7;
}

/* Form elements for debug/development */
.form-group {
    margin: 15px 0;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="text"] {
    width: 100%;
    box-sizing: border-box;
}

input[type="text"][readonly] {
    background-color: #f8f9fa;
    color: #6c757d;
    cursor: not-allowed;
}

button {
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* button:hover {
    background-color: rgba(255, 255, 255, 0.0);
} */

button:disabled {
    background-color: #ffffff1f;
    cursor: not-allowed;
}

/* Log display styles */
.log {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 10px;
    height: 300px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
    margin-top: 20px;
}

.log-entry {
    margin: 2px 0;
    padding: 2px 0;
}

.log-entry.info {
    color: #0066cc;
}

.log-entry.success {
    color: #28a745;
}

.log-entry.error {
    color: #dc3545;
}

.log-entry.warning {
    color: #ffc107;
}

.panel-status-list {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 10px;
    min-height: 60px;
    font-family: monospace;
    font-size: 14px;
}

.panel-status-item {
    margin: 5px 0;
    padding: 2px 0;
}

.panel-status-item.loading {
    color: #856404;
}

.panel-status-item.completed {
    color: #155724;
}

.panel-status-item.error {
    color: #721c24;
}

/* Image container for panel images */
.image-container {
    position: relative;
    display: inline-block;
    width: fit-content;
    height: fit-content;
    z-index: 16; /* Above tap-zones (z-index: 15) so speech bubble interactions work */
    isolation: isolate; /* Helps with backdrop-filter in children */
}

/* Ensure image container can contain absolutely positioned choice overlay */
.image-container.has-choice-overlay {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
}

/* =============================================
   CHAPTER NOTIFICATION STYLES
   ============================================= */
.chapter-notification {
    position: fixed;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.95) 0%, rgba(91, 33, 182, 0.95) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(139, 92, 246, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    z-index: 10000;
    transition: top 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    overflow: hidden;
}

.chapter-notification.show {
    top: 20px;
}

.chapter-notification-content {
    padding: 20px 24px;
    color: #FFFFFF;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.chapter-notification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    cursor: pointer;
}

.chapter-notification-title {
    font-size: 18px;
    font-weight: 600;
    color: #FFFFFF;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    margin-bottom: 4px;
}

.chapter-notification-subtitle {
    font-size: 14px;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
}

.chapter-notification-close {
    font-size: 24px;
    color: #FFFFFF;
    opacity: 0.8;
    cursor: pointer;
    transition: opacity 0.2s;
    padding: 0 8px;
    margin-right: -8px;
}

.chapter-notification-close:hover {
    opacity: 1;
}

.chapter-notification-body {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 8px;
}

.chapter-notification-summary {
    font-size: 16px;
    line-height: 1.4;
    color: #E0E0E0;
    margin: 0;
}

.chapter-notification-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #B0B0B0;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #FFFFFF;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 10px;
}

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

.chapter-notification.expanded {
    box-shadow: 0 12px 40px rgba(139, 92, 246, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.chapter-notification.summary-loaded {
    animation: pulse-glow 0.5s ease-out;
}

@keyframes pulse-glow {
    0% { box-shadow: 0 8px 32px rgba(139, 92, 246, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
    50% { box-shadow: 0 12px 48px rgba(139, 92, 246, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
    100% { box-shadow: 0 8px 32px rgba(139, 92, 246, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2); }
}

/* Custom scrollbar for chapter summary */
.chapter-notification-body::-webkit-scrollbar {
    width: 6px;
}

.chapter-notification-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.chapter-notification-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.chapter-notification-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Chapter Start Header Styles */
.chapter-start-header {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.chapter-start-header.show {
    opacity: 1;
}

.chapter-start-header.fade-out {
    opacity: 0;
    transition: opacity 1s ease-out;
}

.chapter-start-content {
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 12px 24px;
    backdrop-filter: blur(10px);
}

.chapter-start-title {
    color: white;
    font-size: 20px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

/* =============================================
   CHAPTER HEADER OVERLAY STYLES
   ============================================= */
.chapter-header-overlay {
    position: absolute;
    top: calc(10% + 50px);
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 0 20px;
    pointer-events: none;
    animation: chapter-fade-in 1s ease-out;
}

.chapter-header-text {
    color: #FFFFFF;
    font-size: 24px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 
        2px 2px 4px rgba(0, 0, 0, 0.8),
        -1px -1px 2px rgba(0, 0, 0, 0.5);
    padding: 0 30px;
    white-space: nowrap;
    font-family: 'Georgia', 'Times New Roman', serif;
}

.chapter-header-line {
    height: 2px;
    flex: 1;
    position: relative;
    min-width: 50px;
}

.chapter-header-line.left {
    background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.8));
    margin-right: 20px;
}

.chapter-header-line.right {
    background: linear-gradient(to left, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.8));
    margin-left: 20px;
}


/* Add subtle animation */
@keyframes chapter-fade-in {
    from {
        opacity: 0;
        transform: translateX(-50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) scale(1);
    }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .chapter-header-text {
        font-size: 20px;
        padding: 0 20px;
        letter-spacing: 2px;
    }
    
    .chapter-header-overlay {
        top: calc(15% + 50px);
    }
}

/* =============================================
   IMAGE CHOICE (dual-gen picker)
   ============================================= */

/* Block forward navigation and hide action bar while image choice picker is active */
body.image-choice-active .tap-zone.right,
body.image-choice-active .halo.right {
    pointer-events: none !important;
    opacity: 0 !important;
}

body.image-choice-active .custom-action-bar,
body.image-choice-active #bottomOverlay,
body.image-choice-active .action-bar-container {
    display: none !important;
}

.image-choice-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100dvh;
    padding: 24px 16px;
    box-sizing: border-box;
    position: relative;
    z-index: 20;
    overflow: hidden;
}

.image-choice-container::before {
    content: '';
    position: absolute;
    top: -10%;
    left: -10%;
    right: -10%;
    bottom: -10%;
    background-image: var(--choice-bg-image, none);
    background-size: cover;
    background-position: center;
    filter: blur(40px) brightness(0.35);
    transform: scale(1.2);
    z-index: -1;
}

.image-choice-header {
    color: rgba(255, 255, 255, 0.7);
    font-family: 'ShantellSans-Regular', 'Shantell Sans', sans-serif;
    font-size: 15px;
    font-weight: 400;
    font-style: italic;
    text-align: center;
    margin-bottom: 20px;
    letter-spacing: 0.3px;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.image-choice-row {
    display: flex;
    gap: 14px;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    max-width: 480px;
}

/* --- Dialogue area below images --- */

.image-choice-dialogue {
    margin-top: 20px;
    max-width: 420px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.image-choice-speech {
    background: rgba(255, 255, 255, 0.92);
    border-radius: 14px;
    padding: 10px 14px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    line-height: 1.45;
}

.image-choice-speaker {
    display: block;
    font-family: 'ShantellSans-Regular', 'Shantell Sans', sans-serif;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.45);
    margin-bottom: 3px;
    letter-spacing: 0.5px;
}

.image-choice-speech-text {
    font-family: 'ShantellSans-Regular', 'Shantell Sans', sans-serif;
    font-size: 15px;
    color: #1a1a1a;
    line-height: 1.5;
}

.image-choice-narration {
    background: rgba(255, 251, 234, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 0;
    padding: 10px 14px;
    font-family: 'ShantellSans-Regular', 'Shantell Sans', sans-serif;
    font-size: 15px;
    font-style: italic;
    color: #1c1507;
    line-height: 1.55;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

/* --- Image option card --- */

.image-option {
    flex: 1;
    max-width: 210px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.image-option-img-wrap {
    position: relative;
    width: 100%;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.image-option:active .image-option-img-wrap {
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.4),
        0 0 0 2px rgba(139, 92, 246, 0.3);
}

.image-option-img {
    display: block;
    width: 100%;
    aspect-ratio: 9 / 16;
    object-fit: cover;
}

/* Expand button — glass pill */
.image-option-expand {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    z-index: 2;
}

.image-option-expand:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.55);
}

/* --- Expanded state --- */

.image-option.expanded {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    z-index: 100;
    margin: 0;
    cursor: default;
    justify-content: center;
    background: rgba(0, 0, 0, 0.94);
    border-radius: 0;
}

.image-option.expanded .image-option-img-wrap {
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-option.expanded .image-option-img {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: contain;
    cursor: pointer;
}

.image-option.expanded .image-option-expand {
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    font-size: 18px;
    opacity: 1;
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.25);
}

/* --- Selection animation --- */

.image-option-chosen {
    opacity: 1;
}

.image-option-chosen .image-option-img-wrap {
    border-color: rgba(139, 92, 246, 0.7);
    box-shadow:
        0 0 0 2px rgba(139, 92, 246, 0.4),
        0 4px 24px rgba(139, 92, 246, 0.3);
}

.image-option-dismissed {
    opacity: 0.1;
    transform: scale(0.95);
    pointer-events: none;
}


