/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --text-color: #333;
    --nav-bg: rgba(255, 255, 255, 0.1);
    --nav-border: rgba(255, 255, 255, 0.2);
    --nav-text: rgba(255, 255, 255, 0.9);
    --tile-shadow: rgba(0, 0, 0, 0.1);
    --tile-shadow-hover: rgba(0, 0, 0, 0.15);
    --page-bg: white;
    --page-text: #333;
    --link-color: #667eea;
    --link-hover: #764ba2;
    --input-bg: #f5f5f5;
    --input-bg-hover: #eeeeee;
    --input-text: #333;
    --input-text-white: #777777;
    --input-text-cyan: #00AAAA;
    --input-text-magenta: #AA00AA;
    --input-text-yellow: #AAAA00;
    --input-text-green: #00FF00;
}

[data-theme="dark"] {
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #16213e;
    --text-color: #e0e0e0;
    --nav-bg: rgba(0, 0, 0, 0.3);
    --nav-border: rgba(255, 255, 255, 0.1);
    --nav-text: #e0e0e0;
    --tile-shadow: rgba(0, 0, 0, 0.4);
    --tile-shadow-hover: rgba(0, 0, 0, 0.6);
    --page-bg: #2a2a2a;
    --page-text: #e0e0e0;
    --link-color: #8892b0;
    --link-hover: #a8b2d1;
    --input-bg: #1a1a1a;
    --input-bg-hover: #2a2a2a;
    --input-text: #e0e0e0;
    --input-text-white: #ffffff;
    --input-text-cyan: #00ffff;
    --input-text-magenta: #ff00ff;
    --input-text-yellow: #ffff00;
    --input-text-green: #00ff00;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    color: var(--text-color);
    line-height: 1.6;
    transition: all 0.3s ease;
}

/* Top Navigation Bar */
.top-nav {
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--nav-border);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* Language Selector Styles */
.language-selector-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.language-selector {
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    padding-right: 2.5rem;
    color: #333;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.language-selector:hover {
    background: rgba(0, 0, 0, 0.15);
    border-color: rgba(0, 0, 0, 0.3);
}

.language-selector:focus {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(102, 126, 234, 0.5);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
}

/* Dark theme select option styling */
[data-theme="dark"] .language-selector option {
    background: #16213e;
    color: #e0e0e0;
}

[data-theme="dark"] .language-selector {
    background: rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
}

/* Calculator Select Styles */
.calc-select {
    background: var(--page-bg);
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    padding-right: 2.5rem;
    color: var(--page-text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    min-width: 200px;
}

.calc-select:hover {
    border-color: var(--link-color);
}

.calc-select:focus {
    border-color: var(--link-color);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
}

.calc-select option {
    background: var(--page-bg);
    color: var(--page-text);
    padding: 0.5rem;
}

[data-theme="dark"] .calc-select option {
    background: #2a2a2a;
    color: #e0e0e0;
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-left {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.nav-right {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.back-button {
    background: transparent;
    border: none;
    color: var(--nav-text);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.back-button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.home-link {
    color: var(--nav-text);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.home-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

.theme-switcher {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem;
    border-radius: 20px;
}

.theme-button {
    background: transparent;
    border: none;
    color: var(--nav-text);
    padding: 0.5rem 1rem;
    border-radius: 16px;
    cursor: pointer;
    transition: background 0.3s ease;
    font-size: 0.9rem;
}

.theme-button.active {
    background: rgba(255, 255, 255, 0.2);
}

.profile-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: var(--nav-text);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.profile-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 4rem;
    color: white;
}

header h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

header .subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Tile Container */
.tiles-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin: 0 auto;
}

/* Tile Styles */
.tile {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.tile:hover {
    transform: translateY(-5px);
}

.tile:active {
    transform: translateY(-2px) scale(0.98);
}

.tile-content {
    background: var(--page-bg);
    border-radius: 20px;
    padding: 2.5rem 2rem;
    text-align: center;
    box-shadow: 0 4px 6px var(--tile-shadow);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.tile:hover .tile-content {
    box-shadow: 0 8px 12px var(--tile-shadow-hover);
}

/* Tile Icons */
.tile-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: inline-block;
}

/* Individual Tile Colors */
.youtube-tile .tile-content {
    background: #ff6b6b;
    color: white;
}

.email-tile .tile-content {
    background: #667eea;
    color: white;
}

.articles-tile .tile-content {
    background: #11998e;
    color: white;
}

.l2ench-tile .tile-content {
    background: #fa709a;
    color: white;
}

/* Tile Text */
.tile-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    z-index: 2;
    position: relative;
}

.tile-content p {
    font-size: 1rem;
    opacity: 0.9;
    z-index: 2;
    position: relative;
    font-weight: 300;
}

/* Ripple Effect */
.tile::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
    z-index: 1;
}

.tile:active::before {
    width: 300px;
    height: 300px;
}

/* Mobile Navigation Menu */
.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--nav-text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background 0.3s ease;
}

.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    header .subtitle {
        font-size: 1.1rem;
    }

    .tiles-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .tile-content {
        padding: 2rem 1.5rem;
        border-radius: 16px;
    }

    .tile-icon {
        font-size: 2.5rem;
        margin-bottom: 0.75rem;
    }

    .tile-content h2 {
        font-size: 1.3rem;
        margin-bottom: 0.4rem;
    }

    .tile-content p {
        font-size: 0.95rem;
    }

    .nav-content {
        padding: 0 1rem;
        position: relative;
    }

    .nav-menu {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
        flex-direction: column;
        padding: 1.5rem;
        gap: 1.25rem;
        transform: translateX(-100%);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 999;
        overflow-y: auto;
        isolation: isolate;
        border: none;
        /* Auto-size to content, max 2/3 of viewport height */
        height: auto;
        max-height: 66.67vh;
        min-height: min-content;
    }

    .nav-menu.active {
        transform: translateX(0);
        opacity: 1;
        visibility: visible;
        backdrop-filter: blur(10px);
    }

    .nav-menu.active .nav-right {
        /* Center the content vertically if there's extra space */
        justify-content: center;
    }

    .nav-right {
        flex-direction: column;
        width: 100%;
        gap: 1.5rem;
        align-items: stretch;
        /* Allow nav-right to grow and fill available space */
        flex: 1;
        display: flex;
    }

    .mobile-menu-toggle {
        display: block;
    }

    .theme-switcher {
        justify-content: center;
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }

    .language-selector-wrapper {
        width: 100%;
        justify-content: center;
    }

    .language-selector {
        width: 100%;
        max-width: 300px;
    }

    .profile-button {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }

    /* Ensure proper spacing and display for menu items */
    .nav-menu.active .nav-right>* {
        flex-shrink: 0;
    }

    .nav-menu.active .theme-switcher,
    .nav-menu.active .language-selector-wrapper,
    .nav-menu.active .profile-button {
        margin-bottom: 0.5rem;
    }

    .calc-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .calc-row label {
        min-width: auto;
        font-size: 14px;
    }

    .calc-row input[type="range"] {
        width: 100%;
    }

    .calc-row .calc-value {
        text-align: center;
        font-size: 14px;
        font-weight: 600;
    }

    .calc-results {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .calc-metric {
        padding: 0.75rem;
    }

    .calc-metric .metric-value {
        font-size: 18px;
    }

    .page-content {
        padding: 2rem 1.5rem;
        margin-top: 1.5rem;
        border-radius: 16px;
    }

    .back-link {
        margin-top: 1.5rem;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }

    header {
        margin-bottom: 2.5rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    header .subtitle {
        font-size: 1rem;
    }

    .container {
        padding: 0.75rem;
    }

    .tile-content {
        padding: 1.75rem 1.25rem;
    }

    .tile-content h2 {
        font-size: 1.25rem;
    }

    .tile-icon {
        font-size: 2.25rem;
    }

    .top-nav {
        padding: 0.75rem;
    }

    .nav-left {
        gap: 0.5rem;
    }

    .back-button {
        font-size: 1.1rem;
        padding: 0.4rem;
    }

    .home-link {
        padding: 0.4rem;
        font-size: 0.9rem;
    }

    .theme-button {
        padding: 0.4rem 0.7rem;
        font-size: 0.85rem;
    }

    .theme-switcher {
        gap: 0.25rem;
        padding: 0.2rem;
    }

    .calc-card {
        padding: 1rem;
        margin-bottom: 10px;
        border-radius: 12px;
    }

    .calc-results {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .calc-section-title {
        font-size: 13px;
        margin-bottom: 10px;
    }

    .calc-row input[type="range"] {
        height: 8px;
    }

    .calc-row input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    .calc-row input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }
}

/* Touch Device Optimization */
@media (hover: none) {
    .tile:hover {
        transform: none;
    }

    .tile-content {
        -webkit-tap-highlight-color: transparent;
    }

    .tile:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}

/* Landscape Mode Adjustments */
@media (max-height: 600px) and (orientation: landscape) {
    header {
        margin-bottom: 2rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .tile-icon {
        font-size: 2rem;
    }

    .page-content {
        padding: 1.5rem;
    }
}


/* Page Content Styles (for subpages) */
.page-content {
    background: var(--page-bg);
    color: var(--page-text);
    border-radius: 20px;
    padding: 3rem;
    margin-top: 2rem;
    box-shadow: 0 4px 6px var(--tile-shadow);
    text-align: center;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.coming-soon {
    font-size: 1.5rem;
    color: var(--page-text);
    font-weight: 300;
}

.back-link {
    display: inline-block;
    margin-top: 2rem;
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
}

.back-link:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* Calculator Styles */
.scroll-calculator {
    width: 100%;
}

.calc-card {
    background: var(--page-bg);
    border: 0.5px solid var(--nav-border);
    border-radius: var(--border-radius-lg, 16px);
    padding: 1.25rem;
    margin-bottom: 12px;
    box-shadow: 0 4px 6px var(--tile-shadow);
}

.calc-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1rem;
}

.calc-row:last-child {
    margin-bottom: 0;
}

.calc-row label {
    font-size: 13px;
    color: var(--page-text);
    opacity: 0.8;
    min-width: 220px;
    font-weight: 500;
}

.calc-row input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--nav-bg);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.calc-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--link-color);
    border-radius: 50%;
    cursor: pointer;
}

.calc-row input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--link-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.calc-row .calc-value {
    font-size: 13px;
    font-weight: 500;
    min-width: 40px;
    text-align: right;
    color: var(--page-text);
}

/* Number input styles with themed backgrounds and dynamic text colors */
.calc-row input {
    background: var(--input-bg);
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    color: var(--input-text);
    font-size: 0.9rem;
    transition: all 0.3s ease;
    outline: none;
    min-width: 150px;
    font-weight: 600;
}

.calc-row input:hover {
    background: var(--input-bg-hover);
    border-color: var(--link-color);
}

.calc-row input:focus {
    border-color: var(--link-color);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
}

/* Dark theme specific adjustments for better contrast */
[data-theme="dark"] .calc-row input {
    background: var(--input-bg);
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .calc-row input:hover {
    background: var(--input-bg-hover);
    border-color: var(--link-color);
}

.calc-results {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 1rem;
}

.calc-metric {
    background: var(--nav-bg);
    border-radius: var(--border-radius-md, 12px);
    padding: 0.85rem 1rem;
    transition: transform 0.2s ease;
}

.calc-metric:hover {
    transform: translateY(-2px);
}

.calc-metric .metric-label {
    font-size: 12px;
    color: var(--page-text);
    opacity: 0.7;
    margin-bottom: 4px;
    font-weight: 500;
}

.calc-metric .metric-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--page-text);
    line-height: 1.2;
}

.calc-metric .metric-sub {
    font-size: 11px;
    color: var(--page-text);
    opacity: 0.6;
    margin-top: 2px;
}

/* Cost display styles - Full width with enhanced colors */
.calc-cost {
    grid-column: 1 / -1;
    /* Span full width */
    text-align: center;
    padding: 1rem 2rem;
    margin: 0.5rem 0;
}

.calc-cost .metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--page-text);
    line-height: 1.3;
}

.calc-cost .metric-label {
    font-size: 14px;
    color: var(--page-text);
    opacity: 0.8;
    margin-bottom: 8px;
}

.calc-cost.cost-white .metric-value {
    color: var(--input-text-white);
}

.calc-cost.cost-cyan .metric-value {
    color: var(--input-text-cyan);
    text-shadow: 0 0 8px rgba(0, 170, 170, 0.3);
}

.calc-cost.cost-magenta .metric-value {
    color: var(--input-text-magenta);
    text-shadow: 0 0 8px rgba(170, 0, 170, 0.3);
}

.calc-cost.cost-yellow .metric-value {
    color: var(--input-text-yellow);
    text-shadow: 0 0 8px rgba(170, 170, 0, 0.3);
}

.calc-cost.cost-green .metric-value {
    color: var(--input-text-green);
    text-shadow: 0 0 8px rgba(0, 255, 0, 0.3);
}

.calc-warning {
    font-size: 12px;
    color: var(--color-text-warning, #ff6b6b);
    margin-top: 8px;
    font-weight: 500;
}

.calc-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--page-text);
    opacity: 0.8;
    margin: 0 0 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Popup Styles */
.metric-popup {
    position: absolute;
    background: var(--page-bg);
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 8px 24px var(--tile-shadow-hover);
    width: auto;
    min-width: 200px;
    max-width: 280px;
    z-index: 2000;
    transition: opacity 0.2s ease;
    display: none;
}

.metric-popup.show {
    display: block;
}

.popup-content {
    display: flex;
    flex-direction: column;
}

.popup-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--nav-border);
    background: var(--nav-bg);
}

.popup-header h3 {
    margin: 0;
    font-size: 0.875rem;
    color: var(--page-text);
    font-weight: 600;
    text-align: center;
}

.close-button {
    display: none;
}

.popup-body {
    padding: 0.75rem 1rem;
}

.popup-metric-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--link-color);
    margin-bottom: 0.25rem;
    text-align: center;
}

.popup-metric-sub {
    font-size: 0.75rem;
    color: var(--page-text);
    opacity: 0.8;
    text-align: center;
    margin-bottom: 0.5rem;
}

.popup-metric-description {
    font-size: 0.875rem;
    color: var(--page-text);
    opacity: 0.9;
    line-height: 1.5;
    text-align: left;
    padding: 0.5rem 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.click-outside-detector {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1999;
    background: transparent;
    display: none;
}

.click-outside-detector.show {
    display: block;
}

/* Ensure popup can expand for long descriptions */
.metric-popup {
    max-width: 320px;
    width: 90vw;
}

@media (max-width: 480px) {
    .metric-popup {
        max-width: 85vw;
    }

    .popup-metric-description {
        font-size: 0.8125rem;
        line-height: 1.4;
    }
}