/* Base styles */
:root {
    --color-background: #eaf5ff;
    --background-gradient: linear-gradient(145deg, #f3faff 0%, #d7ecff 48%, #b8d5fa 100%);
    --color-text: #10233f;
    --color-text-secondary: #1c344f;
    --color-text-tertiary: #293d56;
    --color-border: #cccccc;
    --color-error: #d32f2f;
    --color-success: #388e3c;
    --color-warning: #ff9800;
    --color-chart-grid: #496580;
    --color-chart-bar: #275b87;
    --color-chart-outline: #10233f;
    --font-size-base: 16px;
    --font-size-large: 48px;
    --font-size-medium: 24px;
    --font-size-small: 16px;
    --line-height-base: 1.5;
    --spacing-small: 8px;
    --spacing-medium: 16px;
    --spacing-large: 24px;
    --border-radius-small: 4px;
    --border-radius-medium: 8px;
    --box-shadow-small: 0 1px 3px rgba(0, 0, 0, 0.12);
    --box-shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="dark"] {
        --color-background: #0f1923;
        --background-gradient: linear-gradient(145deg, #0a1219 0%, #152230 48%, #1a2d42 100%);
        --color-text: #e8f0f8;
        --color-text-secondary: #c0d0e0;
        --color-text-tertiary: #8aa0b8;
        --color-border: #3a4a5a;
        --color-error: #ef5350;
        --color-success: #66bb6a;
        --color-warning: #ffa726;
        --color-chart-grid: #5a7a9a;
        --color-chart-bar: #3a8abf;
        --color-chart-outline: #e8f0f8;
    }
}

html[data-theme="dark"] {
    --color-background: #0f1923;
    --background-gradient: linear-gradient(145deg, #0a1219 0%, #152230 48%, #1a2d42 100%);
    --color-text: #e8f0f8;
    --color-text-secondary: #c0d0e0;
    --color-text-tertiary: #8aa0b8;
    --color-border: #3a4a5a;
    --color-error: #ef5350;
    --color-success: #66bb6a;
    --color-warning: #ffa726;
    --color-chart-grid: #5a7a9a;
    --color-chart-bar: #3a8abf;
    --color-chart-outline: #e8f0f8;
}

html[data-theme="light"] {
    --color-background: #eaf5ff;
    --background-gradient: linear-gradient(145deg, #f3faff 0%, #d7ecff 48%, #b8d5fa 100%);
    --color-text: #10233f;
    --color-text-secondary: #1c344f;
    --color-text-tertiary: #293d56;
    --color-border: #cccccc;
    --color-error: #d32f2f;
    --color-success: #388e3c;
    --color-warning: #ff9800;
    --color-chart-grid: #496580;
    --color-chart-bar: #275b87;
    --color-chart-outline: #10233f;
}

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

html {
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
}

body {
    background-color: var(--dynamic-bg, var(--color-background));
    background-image: var(--background-gradient);
    color: var(--color-text);
    font-family: "Avenir Next", "Segoe UI Variable", system-ui, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--color-background);
    color: var(--color-text);
    padding: var(--spacing-medium);
    z-index: 100;
}

.skip-link:focus {
    left: 0;
}

/* Theme toggle */
.theme-toggle {
    position: fixed;
    top: var(--spacing-small);
    right: var(--spacing-small);
    z-index: 10;
    background: transparent;
    border: none;
    color: var(--color-text-tertiary);
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.3;
    transition: opacity 0.3s ease;
    padding: 0.25rem;
    line-height: 1;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    opacity: 0.8;
}

.theme-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

main {
    flex: 1;
    padding: var(--spacing-large);
}

footer {
    padding: 0.25rem var(--spacing-small);
    font-size: 0.75rem;
    line-height: 1.25;
    color: var(--color-text-tertiary);
    text-align: center;
}

footer button, .info-dialog button {
    font: inherit;
    color: inherit;
    cursor: pointer;
}

footer button {
    margin-inline-start: 0.4rem;
    padding: 0.25rem 0.35rem;
    border: 0;
    background: transparent;
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.info-dialog {
    width: min(32rem, calc(100% - 2rem));
    max-height: calc(100% - 2rem);
    margin: auto;
    padding: clamp(1rem, 5vw, 2rem);
    border: 1px solid currentColor;
    border-radius: 1rem;
    background: var(--color-background);
    color: var(--color-text);
}

.info-dialog::backdrop {
    background: rgb(16 35 63 / 60%);
}

.info-dialog p, .info-dialog form {
    margin-top: 0.75rem;
}

.info-dialog button {
    padding: 0.4rem 0.8rem;
    border: 1px solid currentColor;
    border-radius: var(--border-radius-small);
    background: transparent;
}

button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Price section */
.price-section {
    margin-bottom: var(--spacing-large);
    text-align: center;
}

.price {
    font-size: var(--font-size-large);
    font-weight: 800;
    color: var(--color-text);
    margin-bottom: var(--spacing-small);
}

.trend-arrow {
    font-size: var(--font-size-medium);
    font-weight: 400;
}

.price-arrow {
    margin-inline-end: 0.35em;
}

.price-message {
    font-size: var(--font-size-small);
    color: var(--color-text-tertiary);
}

.price-message.error {
    color: var(--color-error);
}

.price-message.success {
    color: var(--color-success);
}

.price-message.warning {
    color: var(--color-warning);
}

/* Trend section */
.trend-section {
    margin-bottom: var(--spacing-large);
    text-align: center;
}

.trend {
    font-size: var(--font-size-medium);
    color: var(--color-text-secondary);
}

/* Window section */
.window-section {
    margin-bottom: var(--spacing-large);
    text-align: center;
}

.window {
    font-size: var(--font-size-medium);
    color: var(--color-text-secondary);
}

/* Chart section */
.chart-section {
    max-width: 62rem;
    margin: 0 auto var(--spacing-large);
}

.chart {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
    gap: var(--spacing-medium);
}

.chart-day-label {
    text-align: center;
    font-weight: 700;
}

.price-chart {
    display: block;
    width: 100%;
    height: auto;
}

.price-chart text {
    fill: currentColor;
    font-size: 15px;
}

.chart-grid { stroke: var(--color-chart-grid); }
.chart-zero, .chart-now { stroke: currentColor; stroke-width: 2; }
.chart-marker { pointer-events: none; font-weight: 700; }
.chart-bar { fill: var(--color-chart-bar); cursor: pointer; }
.chart-bar.is-past { fill: none; stroke: var(--color-chart-bar); pointer-events: all; }
.chart-bar.is-current, .chart-bar:focus-visible { stroke: var(--color-chart-outline); stroke-width: 3; }
.chart-bar:focus-visible { outline: 2px solid currentColor; }

.chart-detail:not(:empty) {
    margin-top: var(--spacing-small);
    text-align: center;
}

.chart-status {
    font-size: var(--font-size-small);
    color: var(--color-text-tertiary);
    text-align: center;
}

/* Accessibility */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Responsive */
@media (max-width: 320px) {
    :root {
        --font-size-large: 36px;
        --font-size-medium: 18px;
        --font-size-small: 14px;
    }
}

/* High contrast */
@media (prefers-contrast: more) {
    :root {
        --color-background: #ffffff;
        --background-gradient: none;
        --color-text: #000000;
        --color-text-secondary: #000000;
        --color-text-tertiary: #000000;
        --color-border: #000000;
        --color-error: #000000;
        --color-success: #000000;
        --color-warning: #000000;
        --color-chart-grid: #000000;
        --color-chart-bar: #000000;
        --color-chart-outline: #000000;
    }
}

/* No motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}