/* Material Design 3 Color System Properties */
@property --md-sys-color-primary {
    syntax: '<color>';
    inherits: true;
    initial-value: #bb86fc;
}

/* Theme Variables 
 * Defines the color palette and effects for both dark and light themes.
 * Uses rgba for better color blending with transparency.
 */
:root {
    --md-sys-color-background: #0a0a0c;
    --md-sys-color-surface: rgba(28, 27, 31, 0.7);
    --md-sys-color-primary: #c094fc;
    --md-sys-color-secondary: #9573ff;
    --md-sys-color-on-surface: #e6e1e5;
    --md-sys-color-on-surface-variant: #cac4d0;
    --md-sys-color-outline: rgba(147, 143, 153, 0.3);
    
    --surface-shadow: 0 8px 32px rgba(0,0,0,0.24);
    --surface-glow: 0 0 80px rgba(192,148,252,0.03);
    --text-shadow: 0 0 30px rgba(192,148,252,0.3);
    --background-core: rgba(15, 15, 17, 1);
    --background-mid: rgba(13, 13, 15, 1);
    --background-outer: rgba(10, 10, 12, 1);
}

/* Theme Variables for Manual Toggle */
body.light-theme {
    --md-sys-color-background: #f2e8df;           /* Warm beige background */
    --md-sys-color-surface: #fcf6f0;              /* Off-white surface */
    --md-sys-color-on-surface: #4a4440;          /* Dark brown text */
    --md-sys-color-on-surface-variant: #6e6864;   /* Medium brown variant text */
    --md-sys-color-primary: #a38b7a;             /* Muted brown primary color */
    --md-sys-color-secondary: #b39b88;           /* Muted brown secondary color */
    --md-sys-color-outline: rgba(147, 143, 153, 0.15); /* Lighter outline */
    --surface-shadow: 0 4px 16px rgba(0,0,0,0.04); /* Reduced shadow intensity */
    --surface-glow: 0 0 60px rgba(163, 139, 122, 0.06); /* Reduced glow intensity */
    --text-shadow: 0 0 12px rgba(163, 139, 122, 0.15); /* Subtle text shadow */

    background: radial-gradient(
        circle at top center,
        rgba(242, 232, 223, 1) 0%,
        rgba(252, 246, 240, 1) 35%,
        rgba(235, 227, 220, 1) 100%
    ) fixed;
}

body.dark-theme {
    --md-sys-color-background: #0a0a0c;
    --md-sys-color-surface: rgba(28, 27, 31, 0.7);
    --md-sys-color-primary: #c094fc;
    --md-sys-color-secondary: #9573ff;
    --md-sys-color-on-surface: #e6e1e5;
    --md-sys-color-on-surface-variant: #cac4d0;
    --md-sys-color-outline: rgba(147, 143, 153, 0.3);
    --surface-shadow: 0 8px 32px rgba(0,0,0,0.24);
    --surface-glow: 0 0 80px rgba(192,148,252,0.03);
    
    background: radial-gradient(
        circle at top center,
        rgba(15, 15, 17, 1) 0%,
        rgba(13, 13, 15, 1) 35%,
        rgba(10, 10, 12, 1) 100%
    ) fixed;
}

/* Light Theme Overrides - Removed as handled by body class */

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Core Layout Styles 
 * Sets up the base layout with a centered gradient background
 * and proper font rendering
 */
body {
    visibility: hidden;
    font-family: 'Twemoji Country Flags', 'Inter', system-ui, sans-serif;
    background: radial-gradient(
        circle at top center,
        var(--background-core) 0%,
        var(--background-mid) 35%,
        var(--background-outer) 100%
    ) fixed;
    min-height: 100vh;
    color: var(--md-sys-color-on-surface);
    line-height: 1.6;
    padding: 16px;
    -webkit-font-smoothing: antialiased;
    color-scheme: light dark;
    accent-color: var(--md-sys-color-primary);
    letter-spacing: -0.011em;
    /* Add will-change to optimize the gradient rendering */
    will-change: transform;
    transform: translateZ(0);
}

/* Main Container and Surface Components
 * Defines the card-like surfaces with backdrop blur and subtle borders
 */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 8px;  /* Reduce bottom padding of container */
}

.surface {
    background: var(--md-sys-color-surface);
    border-radius: 32px;
    margin-bottom: 16px;  /* Reduced from 24px */
    padding: 32px 32px 24px;  /* Adjust default surface padding */
    box-shadow: 
        var(--surface-shadow),
        inset 0 0 80px rgba(192,148,252,0.03);
    transition: box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
    backdrop-filter: blur(24px);
    border: 1px solid var(--md-sys-color-outline);
    transform: translateZ(0);
    will-change: transform;
}

.surface:hover {
    box-shadow: var(--md-sys-elevation-2);
}

/* Header Component
 * Features a gradient background and special effects for the title area
 */
header.surface {
    background: linear-gradient(
        180deg,
        var(--md-sys-color-surface) 0%,
        rgba(187,134,252,0.05) 100%
    );
    box-shadow: var(--surface-shadow), var(--surface-glow);
    text-align: center;
    padding: 24px 32px 24px;  /* Reduced top padding from 32px to 24px */
    position: relative;
    z-index: 1;
}

header.surface::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        var(--md-sys-color-surface) 0%,
        rgba(187,134,252,0.05) 100%
    );
    border-radius: inherit;
    z-index: -1;
}

.title-container {
    text-align: center;
    margin-bottom: 0;
}

.subtitle {
    font-size: 15px;
    font-weight: 500;
    color: var(--md-sys-color-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 4px;
}

.title {
    font-size: 48px;
    font-weight: 600;
    background: linear-gradient(120deg, var(--md-sys-color-primary), var(--md-sys-color-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin: 0;
}

/* Remove header-divider styles since we removed it */
.header-divider {
    display: none;
}

h1 {
    font-size: 36px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-bottom: 12px;
    letter-spacing: -0.5px;
}

h2 {
    font-size: 16px;
    font-weight: 400;
    color: var(--md-sys-color-on-surface-variant);
}

/* Timer Display Components
 * Contains the main countdown timer and server selection UI
 */
.timer-container {
    padding: 24px 24px 8px; /* Reduced bottom padding to 8px */
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Timer container specific padding */
.timer-container.surface {
    padding: 24px 24px 8px;  /* Reduce bottom padding significantly */
}

/* Server Selection UI
 * Flag-based toggle for switching between US and EU servers
 * Uses emoji flags with smooth transitions and glow effects
 */
.server-toggle {
    padding: 0 0 16px 0;  /* Reduced from 24px */
    margin-bottom: 16px;  /* Reduced from 32px */
    display: flex;
    justify-content: center;
    border-bottom: 1px solid var(--md-sys-color-outline);
}

.toggle-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 16px;
}

.toggle-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.server-switch {
    position: relative;
    cursor: pointer;
    display: block;
}

.server-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.flag-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding: 16px;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 20px;
    box-shadow: var(--surface-shadow);
}

.flag-container:focus-within {
    outline: 2px solid var(--md-sys-color-primary);
    outline-offset: 2px;
}

.flag {
    font-size: 32px;
    line-height: 1;
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
    filter: drop-shadow(0 0 12px rgba(192,148,252,0));
    opacity: 0.5;
    transform: scale(0.85);
    user-select: none; /* Prevent text selection */
    -webkit-user-select: none; /* For Safari */
    -ms-user-select: none; /* For Internet Explorer/Edge */
}

/* Active flag states */
input:not(:checked) ~ .flag-container .flag-left,
input:checked ~ .flag-container .flag-right {
    opacity: 1;
    transform: scale(1.1);
    filter: drop-shadow(0 0 16px rgba(192,148,252,0.3));
}

.server-status {
    font-size: 13px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Countdown Timer Display
 * Large, gradient-colored numbers with dots as separators
 * Includes responsive sizing and smooth animations
 */
.time-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 0 0 8px 0;  /* Reduced from 12px, removed top margin */
}

.time-separator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--md-sys-color-primary);
    opacity: 0.5;
    margin-top: -24px;
}

.time-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.time-value {
    font-size: 72px;
    font-weight: 600;
    background: linear-gradient(120deg, var(--md-sys-color-primary), var(--md-sys-color-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    transform: translateZ(0);
    will-change: transform, opacity;
    font-variant-numeric: tabular-nums;
    letter-spacing: -1px;
    text-shadow: var(--text-shadow);
    transition: transform 0.2s cubic-bezier(0.4,0,0.2,1),
                opacity 0.2s cubic-bezier(0.4,0,0.2,1);
}

.time-unit small {
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 12px;
    opacity: 0.8;
}

/* Remove old toggle styles */
.switch,
.slider,
.handle {
    display: none;
}

/* Current Time */
.current-time { 
    margin-bottom: 0;  /* Remove bottom margin */
}

.current-time h3, .countdown h3 {
    font-size: 16px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-bottom: 8px;
}

.time-text, .reset-text {
    transition: opacity .2s cubic-bezier(0.4,0,0.2,1);
    will-change: opacity;
}

/* Reset Text */
.reset-text {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
    font-weight: 400;
}

/* Footer Component
 * Minimal design with subtle text for server reset times
 */
footer.surface {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 12px 24px;   /* Reduced vertical padding */
    margin-bottom: 8px;   /* Reduced from 16px inherited from .surface */
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

footer.surface:hover {
    opacity: 1;
}

/* Remove duplicate footer p styles and combine into one clear definition */
footer p {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 12px;
    font-weight: 400;
    margin: 4px 0;
    opacity: 0.85;  /* Increased from 0.7 to be more visible */
}

/* Supporting Information Section
 * Contains current time and next reset time
 * Uses subtle typography and borders for hierarchy
 */
.secondary-info {
    margin-top: 24px;
    padding: 16px 0;     /* Added padding top and bottom instead of just padding-top */
    border-top: 1px solid var(--md-sys-color-outline);
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: center;
    margin-bottom: 0;  /* Ensure no bottom margin */
}

.reset-text {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
    font-weight: 400;
}

.current-time {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
    font-weight: 400;
}

.secondary-label {
    color: var(--md-sys-color-outline);
    margin-right: 4px;
}

.time-text {
    transition: opacity .2s cubic-bezier(0.4,0,0.2,1);
    will-change: opacity;
}

/* Theme Toggle Styles */
.theme-toggle {
    position: absolute;
    top: 16px;
    right: 16px;
}

.theme-switch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.theme-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.flag-container.small {
    gap: 4px; /* Further reduced gap between emojis */
    padding: 4px; /* Further reduced padding */
    border-radius: 12px; /* Further reduced border-radius */
    box-shadow: var(--surface-shadow);
}

.flag.small {
    font-size: 16px; /* Further reduced font size of emojis */
}

/* Active flag states for theme toggle */
.theme-switch input:not(:checked) ~ .flag-container .flag-left,
.theme-switch input:checked ~ .flag-container .flag-right {
    opacity: 1;
    transform: scale(1.0); /* Reduced scale on hover */
    filter: drop-shadow(0 0 6px rgba(192,148,252,0.2)); /* Further reduced drop shadow */
}

/* General flag styles (shared with server toggle) */
.flag {
    font-size: 32px;
    line-height: 1;
    transition: all 0.3s cubic-bezier(0.4,0,0.2,1);
    filter: drop-shadow(0 0 12px rgba(192,148,252,0));
    opacity: 0.5;
    transform: scale(0.85);
    user-select: none; /* Prevent text selection */
    -webkit-user-select: none; /* For Safari */
    -ms-user-select: none; /* For Internet Explorer/Edge */
}

/* Responsive Design
 * Adjusts layout and typography for different screen sizes
 * Maintains readability and touch targets on mobile
 */
@media (max-width: 600px) {
    h1 { font-size: 28px; }
    .time-display { gap: 24px; }
    .time-value { font-size: 48px; }
    .time-unit small { font-size: 12px; }
    .surface { border-radius: 24px; padding: 24px; margin-bottom: 16px; }
    .secondary-info { gap: 4px; }
    header.surface { padding: 24px 24px 20px; }
    .container { padding: 16px; }
    .title {
        font-size: 36px;
    }
    
    .time-value {
        font-size: 48px;
    }
    
    .time-separator {
        width: 4px;
        height: 4px;
        margin-top: -16px;
    }
}

/* Large Screen Optimizations
 * Increases spacing and font sizes for better readability
 */
@media (min-width: 1200px) {
    .time-value { font-size: 72px; }
    .time-display { gap: 48px; }
    .time-unit small { font-size: 16px; }
    .container { max-width: 900px; }
}

/* Accessibility
 * Respects user preferences for reduced motion
 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}