/* Standard Mode Refined (v3) - RESTORED */

/* ========================================
   Root Variables & Premium Tokens
   ======================================== */
:root {
    /* WIDER DRAWER for better legibility on laptops */
    --drawer-width: 600px;
    
    --bottom-bar-height: 90px;
    --top-bar-height: 70px;
    --hero-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ========================================
   Layout Restructuring - GLOBAL RESETS
   ======================================== */

body:not(.focus-mode):not(.video-mode) {
    height: 100vh !important;
    height: 100dvh !important; /* Dynamic viewport - excludes Safari address bar */
    max-height: 100vh !important;
    max-height: 100dvh !important;
    overflow: hidden !important; /* NO SCROLL */
    /* Fix background to viewport to prevent blue gaps */
    background-attachment: fixed !important;
    background-size: cover !important;
    /* Safe areas for notched phones (landscape) */
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

body:not(.focus-mode):not(.video-mode) .container {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    height: 100% !important; /* Fill fixed body */
    padding: 0 !important;
    width: 100% !important;
    overflow: hidden !important; 
    box-sizing: border-box !important;
    position: relative; /* Context for absolute progress if needed */
    max-width: none !important;
}

/* Flashcard Container - The "Hero" Stage */
body:not(.focus-mode):not(.video-mode) .flashcard-container {
    display: flex !important;
    /* FLEX 1: Takes all available space between Top Bar and Bottom Bar */
    flex: 1 !important; 
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
    width: 100% !important;
    padding: 0 !important;
    /* Margins account for Top Bar flow (70px) */
    margin-top: var(--top-bar-height) !important;
    margin-bottom: 0 !important; 
    height: auto !important; /* Let Flex handle height */
    min-height: 0 !important; /* Allow shrinking if needed */
}

/* Flashcard adjustments - Responsive Scale */
body:not(.focus-mode):not(.video-mode) .flashcard {
    /* Responsive height: min 300px, prefer 65% of dynamic viewport, max 900px */
    height: clamp(300px, 65dvh, 900px) !important;
    width: clamp(300px, 90vw, 1000px);
    max-width: 1000px;
    margin: 0 auto !important;
    transition: transform 0.5s var(--hero-ease), box-shadow 0.5s var(--hero-ease);
    position: relative !important;
}

body:not(.focus-mode):not(.video-mode) .card-face {
    height: 100% !important;
    width: 100% !important;
    padding: 30px !important;
    box-sizing: border-box !important;
    background: rgba(255, 255, 255, 0.95);
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    /* FIX: Absolute positioning prevents layout shifts when toggling faces */
    position: absolute !important;
    top: 0;
    left: 0;
}

body:not(.focus-mode):not(.video-mode) .card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    overflow: hidden;
    gap: 20px;
}

/* FIX: Ensure hidden faces stay hidden even with !important overrides */
body:not(.focus-mode):not(.video-mode) .card-face[style*="display: none"] {
    display: none !important;
    border: none !important;
    box-shadow: none !important;
}

/* FIX: Responsive Image Sizing */
body:not(.focus-mode):not(.video-mode) .vocabulary-image {
    width: auto !important;
    height: auto !important;
    max-height: 60% !important; 
    max-width: 100% !important;
    object-fit: contain !important;
    flex-shrink: 1 !important;
}

/* ========================================
   Top Navigation Bar
   ======================================== */
.hero-top-bar {
    position: fixed;
    top: 0;
    top: env(safe-area-inset-top, 0); /* Respect notch on iPhones */
    left: 0;
    width: 100%;
    height: var(--top-bar-height);
    padding: 0 30px;
    padding-left: calc(30px + env(safe-area-inset-left, 0));
    padding-right: calc(30px + env(safe-area-inset-right, 0));
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    pointer-events: none;
    background: transparent;
}

.hero-top-bar > * {
    pointer-events: auto;
}

/* Brand Icon (Left) */
/* HIDDEN: Invisible but keeps layout space for flexbox spacing */
.top-brand {
    visibility: hidden !important;
    font-size: 1.5rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
    cursor: pointer;
    transition: transform 0.3s ease;
}
.top-brand:hover { transform: scale(1.1) rotate(5deg); }


/* Session Stats Pill (Center) */
.session-pill {
    /* FIX: Absolute centering to ignore side element widths */
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 50px;
    padding: 8px 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: white;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.pill-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Right Controls */
.top-controls-right {
    display: flex;
    gap: 15px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease, color 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

/* ========================================
   Search Modal (DEPRECATED - Now using vocab-panel.css)
   Keeping minimal styles for backwards compatibility
   ======================================== */
/* Old modal styles removed - see css/vocab-panel.css */


/* ========================================
   Settings Drawer (Off-Canvas)
   ======================================== */
.settings-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease;
}

.settings-drawer-overlay.active {
    opacity: 1;
    visibility: visible;
}

.settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--drawer-width);
    max-width: 90vw;
    height: 100vh;
    background: #1a1b26;
    z-index: 999;
    transform: translateX(100%);
    transition: transform 0.4s var(--hero-ease);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: -20px 0 50px rgba(0,0,0,0.5);
    overflow-y: auto;
    padding: 40px; /* Increased padding */
    display: flex;
    flex-direction: column;
    color: white;
    scrollbar-width: none;
}
.settings-drawer::-webkit-scrollbar { display: none; }

.settings-drawer.active {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 35px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.drawer-title {
    color: white;
    font-size: 1.8rem; /* Larger */
    font-weight: 700;
}

/* High Contrast inputs */
.settings-drawer select,
.settings-drawer input,
.settings-drawer button {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.settings-drawer option {
    background-color: #1a1b26 !important;
    color: #ffffff !important;
}

.settings-drawer .premium-select {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin-bottom: 10px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

/* Settings drawer toggle alignment - label left, toggle right */
.settings-drawer .settings-section {
    width: 100%;
}

.settings-drawer .settings-section .control-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 15px;
    padding: 8px 0;
}

.settings-drawer .settings-section .control-group > label:first-child {
    flex: 1;
    font-size: 1rem;
}

/* Production controls section */
.settings-drawer .production-controls {
    width: 100%;
}

.settings-drawer .production-controls .control-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 15px;
    padding: 8px 0;
}

.settings-drawer .production-controls .control-group > label:first-child {
    flex: 1;
    font-size: 1rem;
}

.shortcuts-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* ========================================
   Premium Progress Bar (Floating)
   ======================================== */
.premium-progress-wrapper {
    width: 90%;
    max-width: 600px;
    margin: 0 auto 10px auto !important; /* Spacing above bottom bar */
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 90;
    pointer-events: none; /* Let clicks pass through if tight */
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
}

.progress-label {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.progress-percent {
    font-size: 0.9rem;
    color: #fff;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.premium-progress-track {
    width: 100%;
    height: 8px; /* Thicker than before */
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    overflow: hidden;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.premium-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #667eea, #764ba2, #ff758c);
    background-size: 200% 100%;
    border-radius: 10px;
    transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    animation: gradientFlow 3s ease infinite;
    box-shadow: 0 0 10px rgba(118, 75, 162, 0.5);
}

@keyframes gradientFlow {
    0% { background-position: 100% 50%; }
    50% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}

/* ========================================
   Bottom Action Bar (Flex Item)
   ======================================== */
.bottom-action-bar {
    /* Static positioning to participate in Flex Column */
    position: relative !important; 
    bottom: auto !important;
    left: auto !important;
    transform: none !important;
    
    /* Fixed height to reserve space */
    flex: 0 0 90px !important; 
    margin: 0 auto 20px auto !important; /* Bottom padding safe zone */
    
    width: auto;
    max-width: 90%;
    height: 70px;
    background: rgba(20, 20, 25, 0.6);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-radius: 40px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
    z-index: 100;
}

.action-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.3, 1.5, 0.5, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.15);
    color: white;
}

/* Semantic colors for scoring buttons */
.action-btn.btn-known {
    background: rgba(76, 175, 80, 0.25);
    color: #81C784;
}

.action-btn.btn-known:hover {
    background: rgba(76, 175, 80, 0.45);
    color: #A5D6A7;
}

.action-btn.btn-learning {
    background: rgba(255, 167, 38, 0.25);
    color: #FFB74D;
}

.action-btn.btn-learning:hover {
    background: rgba(255, 167, 38, 0.45);
    color: #FFCC80;
}

/* Flag flip button - shows flag emoji */
.action-btn.btn-flag {
    font-size: 1.5rem;
}

/* Order toggle button - similar to language toggle */
.action-btn.btn-order {
    width: auto;
    min-width: 50px;
    padding: 0 12px;
    border-radius: 25px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Video/Revise mode button - accent color */
.action-btn.btn-video {
    background: rgba(168, 85, 247, 0.25);
    color: #C4B5FD;
}

.action-btn.btn-video:hover {
    background: rgba(168, 85, 247, 0.45);
    color: #DDD6FE;
}

/* ========================================
   PROGRESS BAR (Attached to Card) - DISABLED
   ======================================== */
body:not(.focus-mode):not(.video-mode) .progress-container {
   display: none;
}

/* HIDE OLD ELEMENTS */
.shortcuts-info,
.stats-dashboard,
.vocab-sidebar,
.media-status,
.focus-exit-button,
.video-pause-button
{
    display: none !important;
}

/* Mobile Tweaks */
/* Mobile Tweaks - IMMERSIVE MODE */
@media (max-width: 768px) {
    :root {
        --drawer-width: 100%;
        --top-bar-height: 50px; /* Condensed top bar */
    }

    /* Mobile Text Scaling Overrides (Fix Long Kana Clipping) */
    .flashcard[data-text-tier="short"] { --text-size-ja: clamp(2.5rem, 12vw, 4em); }
    .flashcard[data-text-tier="medium"] { --text-size-ja: clamp(1.8rem, 8vw, 3em); }
    .flashcard[data-text-tier="long"] { --text-size-ja: clamp(1.2rem, 6vw, 2.2em); }

    /* Convert Settings Drawer to Full-Screen */
    .settings-drawer {
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        transform: translateY(100%);
        border-radius: 0;
        border-left: none;
        border-top: none;
        padding: 24px;
        padding-top: calc(24px + env(safe-area-inset-top, 0));
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0));
    }

    .settings-drawer.active {
        transform: translateY(0);
    }

    /* No drag handle for full-screen */
    .settings-drawer::after {
        display: none;
    }

    /* Hide top-right buttons when panels are open */
    body.settings-drawer-open .top-controls-right,
    body.vocab-panel-open .top-controls-right {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    /* Hide branding when settings panel is open */
    body.settings-drawer-open .app-branding-topleft {
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    /* Full-width sections */
    .settings-drawer .filter-section,
    .settings-drawer .settings-section,
    .settings-drawer .shortcuts-section {
        width: 100% !important;
    }

    /* Full-width control groups */
    .settings-drawer .control-group {
        width: 100% !important;
    }

    /* Full-width dropdowns */
    .settings-drawer select,
    .settings-drawer .premium-select {
        width: 100% !important;
        font-size: 1rem !important;
        padding: 14px 16px !important;
    }

    /* Stack textbook/lesson dropdowns vertically */
    .settings-drawer .filter-row {
        flex-direction: column !important;
        gap: 12px !important;
    }

    .settings-drawer .filter-group {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* Remove max-width constraint from controls container */
    .settings-drawer .controls {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* IMMERSIVE HERO CARD LAYOUT - Optimized for iPhone 14 Pro Max (430x932) */
    body:not(.focus-mode):not(.video-mode) .flashcard {
        height: calc(100dvh - 140px) !important; /* Full height minus top bar and action bar */
        width: calc(100vw - 12px) !important;
        max-width: none !important;
        margin-top: 0px !important;
    }

    /* Image hero - maximize vertical space */
    body:not(.focus-mode):not(.video-mode) .vocabulary-image {
        max-height: none !important;
        height: 60% !important; /* 60% of card for image */
        min-height: 280px !important;
        width: auto !important;
        max-width: 100% !important;
        margin-bottom: 16px !important; /* Increased spacing */
        object-fit: contain !important;
        flex-shrink: 0 !important;
    }

    /* Card Content - balanced vertical layout */
    body:not(.focus-mode):not(.video-mode) .card-content {
        justify-content: center !important; /* Center vertically - distributes space evenly */
        padding: 45px 20px 20px 20px !important; /* More top padding to clear badges */
        gap: 8px !important;
        align-items: center !important;
        text-align: center !important;
    }

    /* Typography - balanced sizing */
    body:not(.focus-mode):not(.video-mode) .japanese-text {
        /* Let clamp() tier scaling handle font-size */
        margin-bottom: 8px !important;
    }

    body:not(.focus-mode):not(.video-mode) #front-romanization {
        /* Override base position:relative which may cause offset */
        position: static !important;
        /* Don't force display - let JS control visibility */
        font-size: 1.2rem !important;
        opacity: 0.65;
        margin: 0 0 6px 0 !important;
        padding: 6px 16px !important;
    }

    /* Only show romanization when JS hasn't hidden it */
    body:not(.focus-mode):not(.video-mode) #front-romanization:not([style*="display: none"]) {
        display: inline-block !important;
    }

    body:not(.focus-mode):not(.video-mode) .english-text {
        font-size: 1.5rem !important;
        margin-top: 4px !important;
    }

    /* HIDE CLUTTER - but keep card counter */
    .motivation,
    .logo-watermark,
    .session-pill,
    .premium-progress-wrapper,
    .textbook-indicator,
    .textbook-tooltip {
        display: none !important;
    }

    /* Card counter - small and subtle in top-left */
    body:not(.focus-mode):not(.video-mode) .card-number {
        font-size: 0.75rem !important;
        padding: 4px 10px !important;
        opacity: 0.7 !important;
        background: rgba(255,255,255,0.9) !important;
        border-radius: 12px !important;
        top: 12px !important; /* Alignment fix */
        left: 12px !important;
        transition: background 0.3s ease, color 0.3s ease;
    }

    /* Restore Status Colors (Green/Orange) for Mobile */
    body:not(.focus-mode):not(.video-mode) .flashcard.status-known .card-number {
        background: #16a34a !important;
        color: white !important;
        opacity: 1 !important;
        box-shadow: 0 4px 15px rgba(22, 163, 74, 0.4) !important;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    body:not(.focus-mode):not(.video-mode) .flashcard.status-learning .card-number {
        background: #ea580c !important;
        color: white !important;
        opacity: 1 !important;
        box-shadow: 0 4px 15px rgba(234, 88, 12, 0.4) !important;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    /* Minimize POS Badge - top right */
    body:not(.focus-mode):not(.video-mode) .class-badge {
        font-size: 0.7rem;
        padding: 3px 10px;
        opacity: 0.8;
        top: 12px;
        right: 12px;
    }

    /* Hide category badge on mobile - too cluttered */
    body:not(.focus-mode):not(.video-mode) .card-category-badge {
        display: none !important;
    }

    body:not(.focus-mode):not(.video-mode) .flashcard-container {
        padding: 5px 8px !important;
        margin-top: var(--top-bar-height) !important;
    }

    /* Hide focus mode button on mobile - no space for backgrounds */
    .bottom-action-bar .standard-only-btn {
        display: none !important;
    }

    /* IMMERSIVE ACTION BAR */
    .bottom-action-bar {
        position: fixed !important;
        bottom: calc(15px + env(safe-area-inset-bottom, 0)) !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
        
        height: 60px !important;
        width: auto !important;
        min-width: 200px;
        padding: 0 20px !important;
        gap: 20px !important;
        
        background: rgba(20, 20, 25, 0.8) !important;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-radius: 30px !important;
        box-shadow: 0 10px 30px rgba(0,0,0,0.4) !important;
    }

    /* Hide buttons replaced by gestures */
    /* Keep: Lang toggle, Shuffle (🎲), Audio (🎧), Known (✓), Learning (✗) */
    /* Hide: Prev/Next (swipes), Exit, Video mode */
    .bottom-action-bar button[onclick="previousCard()"],
    .bottom-action-bar button[onclick="nextCard()"],
    .bottom-action-bar .exit-mode-btn,
    .bottom-action-bar .btn-video {
        display: none !important;
    }

    /* Show shuffle and audio buttons */
    .bottom-action-bar #shuffleBtn,
    .bottom-action-bar #audioButton {
        display: flex !important;
    }

    .action-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.2rem !important;
        background: transparent !important; /* cleaner look */
    }

    /* Top Bar Minimalist */
    .hero-top-bar {
        padding: 0 15px !important;
        height: 50px !important;
    }

    /* Push search/settings buttons down to align with branding text */
    .top-controls-right {
        margin-top: 8px !important;
    }

    /* Branding - visible but compact */
    .app-branding-topleft {
        left: 12px !important;
        top: 25px !important; /* Vertically centered for 50px header */
        transform: translateY(-50%) !important;
    }

    .app-branding-topleft .branding-title-topleft {
        background: rgba(255, 255, 255, 0.15) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1) !important;
        font-size: 0.8rem !important;
        padding: 6px 12px !important;
        border-radius: 20px !important;
        color: white !important;
        -webkit-text-fill-color: white !important; /* Fix visibility */
        background: none !important; /* Reset gradient */
    }
}

/* Extra small phones (iPhone SE - 375px and below) */
@media (max-width: 375px) {
    body:not(.focus-mode):not(.video-mode) .flashcard {
        height: clamp(400px, 75dvh, 650px) !important;
    }

    body:not(.focus-mode):not(.video-mode) .vocabulary-image {
        height: 50% !important;
    }

    body:not(.focus-mode):not(.video-mode) .japanese-text {
        font-size: 2rem !important;
    }

    .app-branding-topleft .branding-title-topleft {
        font-size: 0.7rem !important;
        padding: 5px 10px !important;
    }
}

/* Prevent horizontal swipe back/forward in browser history on mobile */
body:not(.focus-mode):not(.video-mode) .flashcard-container {
    touch-action: pan-y pinch-zoom;
}

/* Hide textbook indicator on mobile - saves space, prevents image overlap */
@media (max-width: 768px) {
    .textbook-indicator,
    .textbook-tooltip {
        display: none !important;
    }

    /* GESTURE HINTS OVERLAY - Hidden (removed onboarding) */
    .gesture-hints-overlay {
        display: none !important;
    }
}
