:root {
    /* Modern Dark Theme Palette */
    --bg-body: #050505; /* Deepest Black/Gray */
    --bg-panel: rgba(15, 23, 42, 0.65); /* Slate 900 with transparency */
    --border-panel: rgba(56, 189, 248, 0.2); /* Subtle Blue border */
    
    --text-primary: #f1f5f9; /* Slate 100 */
    --text-secondary: #94a3b8; /* Slate 400 */
    --text-muted: #64748b; /* Slate 500 */

    /* Accents */
    --accent-primary: #38bdf8; /* Sky 400 */
    --accent-primary-dim: rgba(56, 189, 248, 0.1);
    --accent-secondary: #818cf8; /* Indigo 400 */
    
    --input-bg: rgba(2, 6, 23, 0.6); /* Very dark input background */
    
    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

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

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    padding: 20px;
    line-height: 1.5;
    position: relative; /* For absolute positioning of starfield */
}

/* Canvas Background */
#starfield {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1; /* Behind everything */
    background: radial-gradient(circle at center, #0f172a 0%, #000000 100%); /* Deep space gradient */
}

/* --- Main UI Container --- */
.container {
    width: 100%;
    max-width: 1000px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px); /* Glass effect */
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-panel);
    border-radius: 24px;
    padding: 48px;
    box-shadow: 
        0 20px 50px -12px rgba(0, 0, 0, 0.8),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    position: relative;
    z-index: 1;
}

/* Header */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-panel);
    padding-bottom: 24px;
}

.title-block {
    flex: 1;
    margin-right: 40px;
}

h1 {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 2rem;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #fff, #38bdf8);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 12px;
}

.subtitle {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-secondary);
    max-width: 650px;
}

/* Lang Switch - Global positioning for large screens, then override for small */
.lang-switch {
    position: absolute;
    top: 48px; /* Aligned with container's top padding */
    right: calc((100vw - min(1000px, 100vw - 40px)) / 2 + 48px); /* Aligned with container's right edge + padding */
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.4);
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-panel);
    z-index: 10;
}

@media (max-width: 1350px) {
    .lang-switch {
        position: static; /* Remove absolute positioning */
        order: -2; /* Place it above presets-sidebar (-1) */
        margin-bottom: 24px; /* Space below it */
        align-self: flex-start; /* Align to start in flex column */
        /* Max width to match container, centered */
        width: 100%;
        max-width: 1000px;
        display: flex;
        justify-content: center; /* Center buttons horizontally */
        margin-left: auto;
        margin-right: auto;
    }
}

.lang-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 6px;
}

.lang-btn:hover {
    color: var(--text-primary);
}

.lang-btn--active {
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent-primary);
    font-weight: 600;
}

.lang-separator { display: none; }

/* Adjust header-row as lang-switch is moved out */
.header-row {
    display: flex;
    justify-content: flex-start; /* No need to justify-content: space-between */
    align-items: flex-start;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-panel);
    padding-bottom: 24px;
}

/* Layout Grid */
.layout {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: 48px;
}

/* Chart */
.chart-section {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-panel);
    border-radius: 16px;
    padding: 24px;
}

.chart-title {
    font-family: var(--font-sans);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

canvas#timeChart {
    width: 100%;
    height: auto;
    border-radius: 8px;
}

.chart-description {
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Controls */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

.inputs-row {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.input-group {
    position: relative;
}

label {
    display: block;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--accent-primary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="number"] {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-panel);
    color: var(--text-primary);
    padding: 14px 16px;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    border-radius: 12px;
    transition: all 0.2s ease;
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-dim);
    background: rgba(2, 6, 23, 0.8);
}

.input-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.4;
}

/* Note Box */
.note {
    font-size: 0.85rem;
    background: rgba(56, 189, 248, 0.05);
    border-left: 3px solid var(--accent-primary);
    border-radius: 4px;
    padding: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Results */
.result {
    margin-top: 40px;
    background: linear-gradient(to right, rgba(56, 189, 248, 0.05), transparent);
    border: 1px solid var(--border-panel);
    padding: 32px;
    border-radius: 16px;
}

.result-line {
    font-family: var(--font-sans);
    margin-bottom: 12px;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.result-line:last-child {
    margin-bottom: 0;
}

.highlight {
    color: var(--accent-primary);
    font-weight: 600;
    text-shadow: 0 0 15px rgba(56, 189, 248, 0.3); /* Gentle glow */
}

/* Presets Sidebar */
.presets-sidebar {
    position: fixed;
    /* Dynamically position relative to the main content container's right edge */
    /* (100vw - container_max_width)/2 - (sidebar_width + desired_gap) */
    /* min(1000px, 100vw - 40px) accounts for body padding. */
    right: calc((100vw - min(1000px, 100vw - 40px)) / 2 - (260px + 30px));
    top: 50%;
    transform: translateY(-50%);
    width: 260px;
    background: rgba(15, 23, 42, 0.8); /* Darker opacity */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-panel);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    z-index: 50;
}

.presets-sidebar .presets-title {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-panel);
    padding-bottom: 12px;
}

.presets-sidebar .presets-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.preset-btn {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    border-radius: 8px;
}

.preset-btn:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: var(--accent-primary-dim);
    color: var(--text-primary);
    transform: translateX(4px);
}

/* SEO Text */
.seo-text {
    margin-top: 60px;
    border-top: 1px solid var(--border-panel);
    padding-top: 32px;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.7;
}

.seo-text h2 {
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 16px;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 1350px) {
    body {
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 40px;
        padding-bottom: 40px;
        height: auto;
    }

    .presets-sidebar {
        display: block;
        position: static;
        transform: none;
        width: 100%;
        max-width: 1000px;
        margin-top: 0;
        margin-bottom: 24px;
        order: -1;
        background: rgba(15, 23, 42, 0.6);
        right: auto;
        top: auto;
        border: 1px solid var(--border-panel);
    }

    .presets-sidebar .presets-title {
        border-bottom: none;
        margin-bottom: 16px;
    }

    .presets-sidebar .presets-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 12px;
    }

    .preset-btn {
        height: 100%;
        display: flex;
        align-items: center;
        background: rgba(255, 255, 255, 0.03);
    }

    .preset-btn:hover {
        transform: translateY(-2px);
    }
}

@media (max-width: 850px) {
    .layout { grid-template-columns: 1fr; }
    .chart-section { order: -1; }
    .container { padding: 32px 24px; }
    .result { scroll-margin-top: 20px; }
}

@media (max-width: 480px) {
    h1 { font-size: 1.5rem; }
    .header-row { flex-direction: column; gap: 20px; }
    .lang-switch { align-self: flex-start; }
}