/* ScribbleTools Main Stylesheet - Optimized for Production */

/* === CSS Variables for Consistent Theming === */
:root {
    --primary-gradient: linear-gradient(135deg, #f0f9ff 0%, #fef3f2 25%, #f7fee7 50%, #fdf4ff 75%, #f0f9ff 100%);
    --text-primary: #4A4A4A;
    --text-secondary: #6B7280;
    --bg-white: #ffffff;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Reduced Motion Support - Respects User Preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Base Styles */
body, html {
    overflow-x: hidden;
    width: 100%;
    margin: 0;
    min-width: 100%;
}

body { 
    font-family: 'Poppins', sans-serif; 
    background: var(--primary-gradient);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    color: var(--text-primary);
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    padding: clamp(0.125rem, 2vw, 1rem);
    line-height: 1.4;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
}

h1, h2, h3 {
    font-size: clamp(1.25rem, 4vw, 2rem);
    line-height: 1.2;
    margin: 0.5rem 0;
}

.handwritten {
    font-family: 'Caveat', cursive;
    cursor: pointer;
}

#app-container, .container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: clamp(0.25rem, 3vw, 1.5rem);
    margin: 0 auto;
    overflow-x: hidden;
    will-change: scroll-position;
    contain: layout style paint;
}

/* Smooth Scrolling */
* {
    scroll-behavior: smooth;
    box-sizing: border-box;
}

/* Touch Targets */
button, a, input, select, textarea {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Custom Scrollbar */
body::-webkit-scrollbar, #app-container::-webkit-scrollbar, .container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

body::-webkit-scrollbar-track, #app-container::-webkit-scrollbar-track, .container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

body::-webkit-scrollbar-thumb, #app-container::-webkit-scrollbar-thumb, .container::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    transition: background 0.3s ease;
}

body::-webkit-scrollbar-thumb:hover, #app-container::-webkit-scrollbar-thumb:hover, .container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* Firefox Scrollbar */
body, #app-container, .container {
    scrollbar-width: thin;
    scrollbar-color: #667eea rgba(0, 0, 0, 0.05);
}

#app-container > * {
    max-width: 100%;
    overflow-x: auto;
    animation: fadeIn 0.5s ease-in-out;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

@keyframes shimmer {
    0% { background-position: -468px 0; }
    100% { background-position: 468px 0; }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 20px rgba(217, 83, 79, 0.3); }
    50% { box-shadow: 0 0 40px rgba(217, 83, 79, 0.6); }
}

@keyframes marquee {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Navigation Styles */
.nav-category summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: 700;
    color: #333;
    padding: clamp(0.4rem, 2vw, 0.75rem);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    list-style: none;
    min-height: 44px;
    box-sizing: border-box;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.nav-category summary::-webkit-details-marker { display: none; }

.nav-category summary:hover { 
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-color: #D9534F;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(217, 83, 79, 0.1);
}

.nav-category summary .arrow { 
    margin-left: auto; 
    transition: transform 0.2s ease;
    color: #D9534F;
    font-weight: bold;
}

.nav-category[open] > summary .arrow { transform: rotate(90deg); }

.nav-category[open] > summary { 
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    border-color: #D9534F;
    color: #D9534F;
}

.nav-links {
    padding-left: clamp(0.25rem, 2vw, 1rem);
    border-left: none;
    margin-left: clamp(0.25rem, 2vw, 0.75rem);
    margin-top: 0.5rem;
    background: linear-gradient(135deg, #fafbfc 0%, #f8fafc 100%);
    border-radius: 0.5rem;
    padding: 0.5rem;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

.nav-link {
    display: block;
    padding: clamp(0.3rem, 1.5vw, 0.5rem) clamp(0.4rem, 2vw, 1rem);
    border-radius: 0.375rem;
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    color: #6C6C6C;
    transition: all 0.2s ease;
    font-weight: 500;
    min-height: 40px;
    display: flex;
    align-items: center;
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
    background: white;
    border: 1px solid transparent;
    margin-bottom: 0.125rem;
}

.nav-link:hover { 
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    color: #333; 
    border-color: #D9534F;
    transform: translateX(4px);
    box-shadow: 0 2px 4px rgba(217, 83, 79, 0.1);
}

.nav-link.active { 
    background: linear-gradient(135deg, #D9534F 0%, #c44347 100%);
    color: white; 
    border-color: #D9534F;
    box-shadow: 0 2px 8px rgba(217, 83, 79, 0.3);
}

/* External Link Styling */
.external-link {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%) !important;
    border-color: #22c55e !important;
    color: #15803d !important;
    font-weight: 500 !important;
}

.external-link:hover {
    background: linear-gradient(135deg, #bbf7d0 0%, #86efac 100%) !important;
    border-color: #16a34a !important;
    color: #14532d !important;
    transform: translateX(4px) !important;
}

/* Spinner */
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid #D9534F;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

/* Marquee */
.marquee-content {
    display: inline-block;
    animation: marquee 20s linear infinite;
    animation-delay: 0.5s;
    font-size: 14px;
    font-weight: 500;
    will-change: transform;
    backface-visibility: hidden;
}

#mobile-marquee {
    contain: layout style paint;
}

/* Mobile Navigation */
#mobile-nav-toggle, #mobile-header-toggle {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-width: 44px;
    min-height: 44px;
    font-size: clamp(0.8rem, 2.5vw, 1.3rem);
    padding: clamp(0.5rem, 2vw, 0.6rem);
    border-radius: 0.5rem;
    touch-action: manipulation;
}

/* Hamburger Menu */
#hamburger-menu {
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    will-change: transform, opacity;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.2), 0 15px 35px rgba(147, 51, 234, 0.15);
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Responsive Design - Mobile First */
@media (max-width: 768px) {
    #app-container { width: 100%; margin: 0; padding: 0.5rem; }
    #hamburger-menu { max-width: 16rem; max-height: 70vh; }
    #tool-content {
        padding: 1rem;
        margin: 0.5rem 0;
        width: 100%;
        max-width: 100%;
        border-radius: 12px;
        background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        border: 1px solid #e2e8f0;
    }
}

@media (max-width: 480px) {
    body { padding: 0.25rem; font-size: clamp(0.813rem, 2vw, 0.875rem); }
    .container, #app-container { padding: 0.5rem; }
    button, a.nav-link, input, select { min-height: 48px; font-size: 16px; padding: 0.75rem; }
}

@media (max-width: 360px) {
    body { padding: 0.0313rem; font-size: 0.8rem; }
    .container, #app-container { padding: 0.0625rem; }
}

@media (min-width: 769px) {
    #hamburger-menu { max-width: 20rem; max-height: 70vh; }
}

@media (min-width: 1024px) {
    #hamburger-menu { max-width: 22rem; max-height: 65vh; }
}
