/**
 * Shared CSS Variables and Base Styles
 * Mobile-first approach with responsive breakpoints
 */

/* ============================================
   FONT FACES
   ============================================ */
@font-face {
    font-family: 'SpongeBoy';
    src: url('../SpongeboyRegular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */
:root {
    /* Colors */
    --color-primary: #ee7413;
    --color-primary-hover: #d96810;
    --color-primary-light: rgba(238, 116, 19, 0.1);
    --color-secondary: #a6d91e;
    --color-secondary-hover: #95c41b;
    --color-text: #333;
    --color-text-light: #666;
    --color-white: #fff;
    --color-error: #dc3545;
    --color-error-bg: rgba(220, 53, 69, 0.1);
    --color-error-dark: #b02a37;
    --color-success: #28a745;
    --color-success-bg: rgba(40, 167, 69, 0.1);
    --color-info: #17a2b8;
    --color-info-bg: rgba(23, 162, 184, 0.1);
    --color-warning: #ffc107;
    --color-warning-bg: rgba(255, 193, 7, 0.15);

    /* Background */
    --bg-gradient: linear-gradient(135deg, #7eefed 0%, #017df0 100%);
    --bg-card: rgba(255, 255, 255, 0.95);
    --bg-card-hover: rgba(255, 255, 255, 1);

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 20px rgba(238, 116, 19, 0.3);

    /* Typography */
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Layout */
    --header-height: 70px;
    --max-content-width: 1400px;
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--color-text);
    background: var(--bg-gradient);
    background-attachment: fixed;
    min-height: 100dvh;
    overflow-x: hidden;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

button {
    font-family: inherit;
    cursor: pointer;
}

select {
    font-family: inherit;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   LAYOUT COMPONENTS
   ============================================ */

/* Flower Background Container */
.flower-background {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
}

/* Header with Home Icon */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: var(--space-md);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-md);
    max-width: var(--max-content-width);
    margin: 0 auto;
}

.header-left {
    display: flex;
    justify-content: flex-start;
}

.header-right {
    display: flex;
    justify-content: flex-end;
}

/* Header Branding (Title + Credits) */
.header-branding {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
    background: rgba(0, 0, 0, 0.15);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(4px);
}

.header-title {
    font-family: 'SpongeBoy', var(--font-family);
    font-size: var(--font-size-xl);
    font-weight: 400;
    color: #ffd700;
    text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.4);
    margin: 0;
    letter-spacing: 0.5px;
}

.header-credits {
    font-size: var(--font-size-sm);
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    transition: color var(--transition-fast);
}

.header-credits:hover {
    color: rgba(255, 255, 255, 0.95);
}

/* Mobile: Smaller title */
@media (max-width: 600px) {
    .header-branding {
        flex-direction: column;
        gap: var(--space-xs);
        align-items: flex-start;
        padding: var(--space-xs) var(--space-sm);
    }

    .header-title {
        font-size: var(--font-size-sm);
    }

    .header-credits {
        font-size: var(--font-size-xs);
    }
}

.home-link {
    display: block;
    width: 50px;
    height: 50px;
    transition: transform var(--transition-fast);
}

.home-link:hover {
    transform: scale(1.1);
}

.home-link img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Main Container */
.main-container {
    min-height: 100dvh;
    padding: var(--space-md);
    padding-top: calc(var(--header-height) + var(--space-md));
    overflow-x: hidden;
}

/* Two Column Layout */
.two-column-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    max-width: var(--max-content-width);
    margin: 0 auto;
    width: 100%;
}

@media (min-width: 900px) {
    .two-column-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
}

/* Left Column (Image Area) */
.image-column {
    display: contents; /* on mobile, dissolve into the flex flow so order works on children */
    gap: var(--space-lg);
    min-width: 0;
    width: 100%;
}

@media (min-width: 900px) {
    .image-column {
        display: flex;
        flex-direction: column;
    }
}

/* Right Column (Controls) */
.controls-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    min-width: 0;
}

/* ============================================
   IMAGE CONTAINER
   ============================================ */
.image-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transition: box-shadow var(--transition-normal);
}

.image-container:hover {
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.image-container img {
    width: 100%;
    max-width: 100%;
    height: 100%;
    object-fit: cover;
    animation: imageLoad var(--transition-slow) ease-out;
}

@keyframes imageLoad {
    from {
        opacity: 0;
        transform: scale(1.02);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.image-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-light);
    font-size: var(--font-size-lg);
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
}

.image-placeholder::after {
    content: '';
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-primary-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: absolute;
}

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

.image-placeholder.error::after {
    display: none;
}

/* ============================================
   CARD COMPONENT
   ============================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

/* ============================================
   STATS BAR
   ============================================ */
.stats-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.stat-item {
    text-align: center;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.stat-item:hover {
    background: rgba(238, 116, 19, 0.05);
}

.stat-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    display: block;
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-primary);
    transition: transform var(--transition-fast);
}

.stat-value.updated {
    animation: statPop 0.3s ease-out;
}

@keyframes statPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Settings Button */
.settings-btn {
    width: 44px;
    height: 44px;
    background: url('../settings-icon.png') center/70% no-repeat;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.settings-btn:hover {
    transform: scale(1.1);
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-base);
    font-weight: 600;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 48px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 50%);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:hover:not(:disabled)::before {
    opacity: 1;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    color: var(--color-white);
    box-shadow: 0 2px 8px rgba(238, 116, 19, 0.3);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(238, 116, 19, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--color-secondary) 0%, var(--color-secondary-hover) 100%);
    color: var(--color-text);
    box-shadow: 0 2px 8px rgba(166, 217, 30, 0.3);
}

.btn-secondary:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(166, 217, 30, 0.4);
}

.btn-outline {
    background: var(--color-white);
    color: var(--color-text);
    border: 2px solid #ddd;
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-primary-light);
}

/* Button with icon */
.btn-icon-left {
    padding-left: var(--space-md);
}

.btn .icon {
    font-size: var(--font-size-lg);
}

/* Button Group */
.button-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

@media (min-width: 500px) {
    .button-group--row {
        flex-direction: row;
    }

    .button-group--row .btn {
        flex: 1;
    }
}

/* ============================================
   FEEDBACK MESSAGE
   ============================================ */
.feedback-message {
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    text-align: center;
    display: none;
    animation: feedbackSlideIn var(--transition-normal) ease-out;
    backdrop-filter: blur(10px);
}

@keyframes feedbackSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback-message.show {
    display: block;
}

.feedback-message.error {
    background: linear-gradient(135deg, rgba(220, 53, 69, 0.15) 0%, rgba(220, 53, 69, 0.08) 100%);
    border: 2px solid var(--color-error);
    color: var(--color-error-dark);
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.2);
}

.feedback-message.success {
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.15) 0%, rgba(40, 167, 69, 0.08) 100%);
    border: 2px solid var(--color-success);
    color: #1e7e34;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.2);
}

.feedback-message.info {
    background: linear-gradient(135deg, rgba(23, 162, 184, 0.15) 0%, rgba(23, 162, 184, 0.08) 100%);
    border: 2px solid var(--color-info);
    color: #117a8b;
    box-shadow: 0 4px 15px rgba(23, 162, 184, 0.2);
}

/* Feedback message content styling */
.feedback-title {
    font-size: var(--font-size-lg);
    font-weight: 700;
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.feedback-episode {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin: var(--space-sm) 0;
    padding: var(--space-sm) var(--space-md);
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-md);
    display: inline-block;
}

.feedback-subtitle {
    font-size: var(--font-size-sm);
    opacity: 0.9;
    margin-top: var(--space-sm);
}

/* ============================================
   SELECT2 OVERRIDES
   ============================================ */
.select2-container {
    width: 100% !important;
}

.select2-container .select2-selection--single {
    height: auto !important;
    min-height: 48px !important;
    padding: var(--space-sm) var(--space-md) !important;
    border: 2px solid #ddd !important;
    border-radius: var(--radius-md) !important;
    background: var(--color-white) !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 1.5 !important;
    padding: var(--space-xs) 0 !important;
    color: var(--color-text) !important;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--color-text-light) !important;
}

.select2-dropdown {
    border: 2px solid #ddd !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-lg) !important;
}

.select2-results__option {
    padding: var(--space-sm) var(--space-md) !important;
}

.select2-results__group {
    padding: var(--space-sm) var(--space-md) !important;
    font-weight: 600 !important;
    background: #f8f9fa !important;
    color: var(--color-text) !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--color-primary) !important;
}

/* Allow JS to control dropdown height dynamically on desktop.
   Use direct child selector to avoid affecting nested optgroup lists. */
.select2-results > .select2-results__options {
    max-height: var(--select2-results-max-height, 200px) !important;
    overflow-y: auto;
}

@media (max-width: 899px) {
    /* Prevent the dropdown from overflowing horizontally.
       With dropdownParent set to .dropdown-container the dropdown is
       already constrained – these rules just add safety. */
    .select2-dropdown {
        max-width: 100% !important;
    }

    /* Force dropdown to always open below on mobile.
       Select2 uses top/bottom inline styles; reset them so it
       always renders below the selection. */
    .select2-dropdown--above {
        top: auto !important;
        bottom: auto !important;
        border-top: 2px solid #ddd !important;
        border-bottom: 2px solid #ddd !important;
        border-radius: var(--radius-md) !important;
        margin-top: -2px;
    }

    .select2-results > .select2-results__options {
        max-height: 45vh !important;
    }
}

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal {
    background: var(--color-white);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
    animation: modalSlideIn var(--transition-normal) ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.modal-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    margin: 0;
}

.modal-close {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    font-size: var(--font-size-2xl);
    color: var(--color-text-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: #f0f0f0;
    color: var(--color-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Form Group */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.form-label {
    font-weight: 600;
    color: var(--color-text);
}

.form-select {
    width: 100%;
    padding: var(--space-md);
    font-size: var(--font-size-base);
    border: 2px solid #ddd;
    border-radius: var(--radius-md);
    background: var(--color-white);
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.form-select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #f5f5f5;
}

.form-hint {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    font-style: italic;
}


/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    top: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 2.7s forwards;
    pointer-events: auto;
    font-weight: 500;
}

.toast.success {
    border-left: 4px solid var(--color-success);
}

.toast.error {
    border-left: 4px solid var(--color-error);
}

.toast.info {
    border-left: 4px solid var(--color-info);
}

.toast-icon {
    font-size: var(--font-size-lg);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* ============================================
   KEYBOARD SHORTCUTS HINT
   ============================================ */
.keyboard-hint {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-md);
    background: var(--bg-card);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    display: none;
    gap: var(--space-md);
    z-index: 50;
}

@media (min-width: 900px) {
    .keyboard-hint {
        display: flex;
    }
}

/* Limit keyboard hint position on wide screens - align with grid */
@media (min-width: 1400px) {
    .keyboard-hint {
        right: calc((100vw - var(--max-content-width)) / 2);
    }
}

.keyboard-hint kbd {
    background: #f0f0f0;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: var(--font-size-xs);
    border: 1px solid #ddd;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ============================================
   SCORE STREAK INDICATOR
   ============================================ */
.streak-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    background: linear-gradient(135deg, var(--color-warning) 0%, #ff9800 100%);
    color: var(--color-text);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 700;
    animation: streakPulse 2s ease-in-out infinite;
}

@keyframes streakPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */
@media (max-width: 899px) {
    :root {
        --header-height: 60px;
    }

    .home-link {
        width: 45px;
        height: 45px;
    }

    .stats-bar {
        gap: var(--space-sm);
    }

    .stat-label {
        font-size: var(--font-size-sm);
    }

    .stat-value {
        font-size: var(--font-size-lg);
    }

    .toast-container {
        width: calc(100% - var(--space-lg) * 2);
    }

    .toast {
        border-radius: var(--radius-md);
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: more) {
    .btn {
        border: 2px solid currentColor;
    }

    .card {
        border: 2px solid var(--color-text);
    }

    .feedback-message {
        border-width: 3px;
    }
}

