/* ==========================================
   CSS Reset & Base Styles with Modern Features
   ========================================== */

/* Modern CSS Reset with improved defaults */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Smooth scrolling and text rendering */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Base font size for rem units */
:root {
    font-size: 16px;
    
    /* Fluid typography */
    @media (min-width: 320px) {
        font-size: calc(16px + (20 - 16) * ((100vw - 320px) / (1920 - 320)));
    }
    
    @media (min-width: 1920px) {
        font-size: 20px;
    }
    /* Light Mode Colors */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --accent-primary: #09253F; /* Updated light mode accent */
    --accent-hover: #0a2e4f;
    --border-color: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.1);
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    
    /* Strength Meter Colors */
    --strength-very-weak: #ff3b30;    /* Red */
    --strength-weak: #ff9500;        /* Orange */
    --strength-medium: #ffcc00;      /* Yellow */
    --strength-strong: #34c759;      /* Green */
    --strength-very-strong: #30b0c7; /* Blue */
    
    /* Transitions */
    --transition-speed: 0.3s;
    
    /* Responsive Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --accent-primary: #00B8D9; /* Updated dark mode accent */
    --accent-hover: #00c9f0;
    --border-color: #333;
    --shadow: rgba(0, 0, 0, 0.3);
    --card-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    
    --strength-very-weak: #ff453a;   /* Brighter red for dark theme */
    --strength-weak: #ff9f0a;        /* Brighter orange */
    --strength-medium: #ffd60a;      /* Brighter yellow */
    --strength-strong: #30d158;      /* Brighter green */
    --strength-very-strong: #64d2ff; /* Brighter blue */
}

/* ==========================================
   Base Styles with Enhanced Typography
   ========================================== */

body {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    transition: background var(--transition-speed), color var(--transition-speed);
    position: relative;
    line-height: 1.6;
    text-rendering: optimizeLegibility;
    
    /* Better text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    
    /* Prevent layout shifts */
    overflow-x: hidden;
    overflow-y: auto;
    
    /* iOS momentum scrolling */
    -webkit-overflow-scrolling: touch;
    
    /* Hide scrollbar for cleaner look */
    scrollbar-width: thin;
    scrollbar-color: var(--accent-primary) transparent;
    
    &::-webkit-scrollbar {
        width: 8px;
    }
    
    &::-webkit-scrollbar-track {
        background: transparent;
    }
    
    &::-webkit-scrollbar-thumb {
        background-color: var(--accent-primary);
        border-radius: 4px;
    }
    
    /* Hide focus outline if not using keyboard */
    &:not(:focus-visible) {
        outline: none;
    }
}

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

/* ==========================================
   Theme Toggle Button
   ========================================== */

.theme-toggle {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    z-index: 1000;
    box-shadow: var(--card-shadow);
}

.theme-toggle:hover {
    transform: rotate(180deg) scale(1.1);
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.theme-toggle:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.theme-toggle .sun-icon,
.theme-toggle .moon-icon {
    position: absolute;
    transition: opacity 0.3s, transform 0.3s;
}

[data-theme="light"] .moon-icon,
[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(90deg);
}

[data-theme="light"] .sun-icon,
[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0deg);
}

/* ==========================================
   Main Container
   ========================================== */

.container {
    width: 100%;
    max-width: 500px;
    animation: fadeInUp 0.6s ease-out;
}

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

/* ==========================================
   Header Section
   ========================================== */

.header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background-color: var(--bg-secondary);
    margin-right: 16px;
    color: var(--accent-primary);
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--shadow);
    transition: all var(--transition-speed) ease;
    overflow: hidden;
    border: 2px solid var(--accent-primary);
}

.logo .logo-svg {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.logo-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ==========================================
   Card Component with Modern Effects
   ========================================== */
.card {
    --card-padding: var(--spacing-md);
    --card-radius: var(--radius-lg);
    
    background: var(--bg-secondary);
    border-radius: var(--card-radius);
    padding: var(--spacing-lg);
    box-shadow: var(--card-shadow);
    margin: var(--spacing-md) auto;
    max-width: 480px;
    width: calc(100% - 2rem);
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    transition: all var(--transition-speed) ease;
    position: relative;
    overflow: hidden;
}

/* Subtle gradient overlay */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent-primary);
    opacity: 0.8;
}

/* Mobile styles */
@media (max-width: 480px) {
    .card {
        --card-padding: var(--spacing-md);
        padding: var(--spacing-md);
        width: calc(100% - var(--spacing-md) * 2);
        margin: var(--spacing-sm) auto;
    }

    /* Form controls */
    .form-group {
        margin-bottom: 1rem;
    }

    /* Buttons */
    .btn {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    /* Password display */
    .password-display {
        padding: 0.75rem 1rem;
        font-size: 1.1rem;
    }
}

@media (min-width: 481px) {
    .container {
        padding: 2rem;
    }
    
    .card {
        padding: 2rem;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: no-preference) {
    .card {
        transition: transform 0.2s ease, box-shadow 0.3s ease;
    }
}

/* Reduced motion */
@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;
    }
    
    .card {
        transition: none;
    }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
    .card {
        background: var(--bg-secondary);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }
}

/* Hover/focus effects for card */
.card:hover,
.card:focus-within {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.15);
}

/* ==========================================
   Password Display
   ========================================== */

.password-display {
    position: relative;
    margin-bottom: 1.5rem;
    min-height: 4.5rem; /* Ensure minimum height for empty state */
}

.password-output {
    width: 100%;
    padding: 0.75rem 3.5rem 0.75rem 1rem;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-primary);
    transition: all var(--transition-speed);
    letter-spacing: 0.5px;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    min-height: 3.5rem;
    line-height: 1.4;
    font-size: 1rem; /* Base size */
    overflow-y: auto;
    max-height: 8rem; /* Limit height and add scroll if needed */
    text-align: left;
}

/* Adjust font size based on password length */
.password-output[data-length='16'] { font-size: 1rem; }
.password-output[data-length='24'] { font-size: 0.9rem; }
.password-output[data-length='32'] { font-size: 0.8rem; }
.password-output[data-length='48'] { font-size: 0.7rem; }
.password-output[data-length='64'] { font-size: 0.6rem; }

.password-output:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 191, 166, 0.1);
}

.password-output::placeholder {
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-weight: 400;
}

.copy-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5rem;
    height: 2.5rem;
    min-height: 2.5rem; /* Ensure minimum size for touch targets */
    border: none;
    background: var(--accent-primary);
    color: white;
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    z-index: 2; /* Ensure button stays above the text */
}

/* Adjust copy button for wrapped text */
@media (max-width: 480px) {
    .password-output {
        padding-right: 3.5rem; /* Ensure space for the copy button */
    }
    
    .copy-btn {
        top: auto;
        bottom: 0.5rem;
        right: 0.5rem;
        transform: none;
    }
}

.copy-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-50%) scale(1.05);
}

.copy-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.copy-btn:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ==========================================
   Strength Meter
   ==========================================/* ==========================================
   Strength Meter
   ========================================== */
.strength-indicator {
    margin: 1.5rem 0;
}

.strength-meter {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    height: 6px;
}

.strength-meter-segment {
    flex: 1;
    height: 100%;
    border-radius: 3px;
    background-color: var(--border-color);
    transition: all 0.3s ease;
}

/* Base colors for each strength level */
.strength-meter-segment.very-weak {
    background-color: var(--strength-very-weak);
}

.strength-meter-segment.weak {
    background-color: var(--strength-weak);
}

.strength-meter-segment.medium {
    background-color: var(--strength-medium);
}

.strength-meter-segment.strong {
    background-color: var(--strength-strong);
}

.strength-meter-segment.very-strong {
    background-color: var(--strength-very-strong);
}

/* Inactive state */
.strength-meter-segment:not(.active) {
    opacity: 0.3;
}

/* Active state */
.strength-meter-segment.active {
    opacity: 1;
    transform: scaleY(1.2);
}

/* Text styling */
.strength-text {
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0 0 0.25rem 0;
    transition: color 0.3s ease;
    display: flex;
    align-items: center;
}

/* Text colors for each strength level */
.strength-text.very-weak {
    color: var(--strength-very-weak);
}

.strength-text.weak {
    color: var(--strength-weak);
}

.strength-text.medium {
    color: var(--strength-medium);
}

.strength-text.strong {
    color: var(--strength-strong);
}

.strength-text.very-strong {
    color: var(--strength-very-strong);
}

/* Add a dot before the strength text */
.strength-text::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
    background-color: currentColor;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .strength-text {
        font-size: 0.8125rem;
    }
    
    .strength-meter {
        height: 5px;
        gap: 0.375rem;
    }
}

.strength-meter-segment.active.weak {
    background: var(--strength-weak);
    box-shadow: 0 0 5px 0 var(--strength-weak);
}

.strength-meter-segment.active.medium {
    background: var(--strength-medium);
    box-shadow: 0 0 5px 0 var(--strength-medium);
}

.strength-meter-segment.active.strong {
    background: var(--strength-strong);
    box-shadow: 0 0 5px 0 var(--strength-strong);
}

.strength-meter-segment.active.very-strong {
    background: var(--strength-very-strong);
    box-shadow: 0 0 5px 0 var(--strength-very-strong);
}

.strength-text {
margin: 0.5rem 0;
font-size: 0.9rem;
font-weight: 500;
text-align: right;
transition: all 0.3s ease;
display: flex;
justify-content: space-between;
align-items: center;
}

.strength-text::before {
content: '';
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 8px;
background: currentColor;
}

.strength-text.very-weak {
color: var(--strength-very-weak);
}

.strength-text.weak {
color: var(--strength-weak);
}

.strength-text.medium {
color: var(--strength-medium);
}

.strength-text.strong {
color: var(--strength-strong);
}

.strength-text.very-strong {
color: var(--strength-very-strong);
}

.strength-bar.medium {
width: 66.66%;
background: var(--strength-medium);
}

.strength-bar.strong {
    width: 100%;
    background: var(--strength-strong);
}

.strength-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: center;
}

.strength-text #strengthValue {
    font-weight: 600;
    color: var(--text-primary);
}

/* ==========================================
   Control Group (Slider)
   ========================================== */

.control-group {
    margin-bottom: 1.5rem;
}

.control-label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.control-label #lengthValue {
    color: var(--accent-primary);
    font-weight: 700;
}

/* Custom Slider Styles */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-primary);
    outline: none;
    transition: all var(--transition-speed);
}

.slider:hover {
    background: var(--border-color);
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: 0 2px 8px rgba(0, 191, 166, 0.3);
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(0, 191, 166, 0.5);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: none;
    transition: all var(--transition-speed);
    box-shadow: 0 2px 8px rgba(0, 191, 166, 0.3);
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 4px 12px rgba(0, 191, 166, 0.5);
}

/* ==========================================
   Options Group (Checkboxes)
   ========================================== */

.options-group {
    margin-bottom: 1.5rem;
}

.options-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.option-item {
    margin-bottom: 0.75rem;
}

.checkbox {
    display: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    font-size: 0.9375rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    transition: color var(--transition-speed);
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all var(--transition-speed);
}

.checkbox-label:hover {
    background: var(--bg-primary);
}

.checkbox-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    margin-right: 0.75rem;
    position: relative;
    transition: all var(--transition-speed);
    flex-shrink: 0;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: var(--spacing-md);
    position: relative;
    
    @media (min-width: 480px) {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
    }
}

.checkbox:checked + .checkbox-label .checkbox-custom {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.checkbox:checked + .checkbox-label .checkbox-custom::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 4px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox:focus + .checkbox-label .checkbox-custom {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ==========================================
   Generate Button
   ========================================== */

.generate-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1.0625rem;
    font-weight: 600;
    color: white;
    background: var(--accent-primary);
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all var(--transition-speed);
    box-shadow: 0 4px 12px rgba(0, 191, 166, 0.3);
}

.generate-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 191, 166, 0.4);
}

.generate-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 191, 166, 0.3);
}

.generate-btn:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.generate-btn svg {
    animation: rotate 0s linear;
}

.generate-btn.generating svg {
    animation: rotate 0.6s linear;
}

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

/* ==========================================
   Toast Notification
   ========================================== */

.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(150px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9375rem;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast svg {
    color: var(--accent-primary);
    flex-shrink: 0;
}

/* ==========================================
   Footer
   ========================================== */

.footer {
    text-align: center;
    margin-top: 2rem;
    padding: 1rem;
    color: var(--text-secondary);
}

.footer p {
    font-size: 0.9375rem;
    margin: 0.25rem 0;
}

.footer strong {
    color: var(--accent-primary);
    font-weight: 600;
}

.footer-small {
    font-size: 0.8125rem;
    opacity: 0.8;
}

/* ==========================================
   Responsive Design
   ========================================== */

/* Mobile Devices (≤480px) */
@media (max-width: 480px) {
    .header h1 {
        font-size: 2rem;
    }
    
    .card {
        padding: 1.5rem;
        border-radius: 1.25rem;
    }
    
    .password-output {
        font-size: 0.9375rem;
        padding: 1rem 3rem 1rem 1rem;
    }
    
    .theme-toggle {
        top: 1rem;
        right: 1rem;
        width: 2.5rem;
        height: 2.5rem;
    }
    
    .logo {
        width: 3.5rem;
        height: 3.5rem;
    }
    
    .logo svg {
        width: 28px;
        height: 28px;
    }
}

/* Tablet Devices (481px–1024px) */
@media (min-width: 481px) and (max-width: 1024px) {
    .container {
        max-width: 600px;
    }
    
    .card {
        padding: 2.5rem;
    }
}

/* Desktop (≥1025px) */
@media (min-width: 1025px) {
    .container {
        max-width: 500px;
    }
    
    .card:hover {
        transform: translateY(-4px);
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    }
}

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

/* Print Styles */
@media print {
    .theme-toggle,
    .generate-btn,
    .copy-btn {
        display: none;
    }
}
