/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Brand palette */
    --brand-start: #667eea;
    --brand-end: #764ba2;
    --accent-gold: #fbbf24;
    --text-primary: #1a202c;
    --text-secondary: #64748b;
    --bg-gradient-start: #f8fafc;
    --bg-gradient-end: #e2e8f0;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-border: rgba(203, 213, 225, 0.8);
    --box-bg-start: #ffffff;
    --box-bg-end: #f8f9fa;
    --box-border: rgba(203, 213, 225, 0.6);
    --section-title-color: #1e293b;
    --overscroll-bg: #f8f9fa;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.15);
    --shadow-brand: 0 4px 12px rgba(102, 126, 234, 0.4);
    
    /* Brand gradients */
    --gradient-brand: linear-gradient(135deg, var(--brand-start) 0%, var(--brand-end) 100%);
    --gradient-brand-subtle: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    --gradient-brand-bg: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);

    /* Radii */
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 22px;

    /* Timeline tile unified color (no price color-coding) */
    --timeline-box-bg: #eef2ff;
    --timeline-box-border: rgba(102, 126, 234, 0.25);
    
    /* Current price box glow colors */
    --glow-color-light: rgba(0, 0, 0, 0.4);
    --glow-color-medium: rgba(0, 0, 0, 0.3);
    --glow-color-strong: rgba(0, 0, 0, 0.2);
    --glow-color-light-hover: rgba(0, 0, 0, 0.6);
    --glow-color-medium-hover: rgba(0, 0, 0, 0.5);
    --glow-color-strong-hover: rgba(0, 0, 0, 0.4);
}

/* Dark Mode Variables */
body[data-theme="dark"] {
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #16213e;
    --card-bg: rgba(30, 30, 46, 0.95);
    --card-border: rgba(255, 255, 255, 0.1);
    --box-bg-start: #2a2a3e;
    --box-bg-end: #1f1f2e;
    --box-border: rgba(255, 255, 255, 0.2);
    --section-title-color: #e8eaed;
    --timeline-box-bg: #252538;
    --timeline-box-border: rgba(102, 126, 234, 0.3);
    
    /* Current price box glow colors for dark mode */
    --glow-color-light: rgba(255, 255, 255, 0.4);
    --glow-color-medium: rgba(255, 255, 255, 0.3);
    --glow-color-strong: rgba(255, 255, 255, 0.2);
    --glow-color-light-hover: rgba(255, 255, 255, 0.6);
    --glow-color-medium-hover: rgba(255, 255, 255, 0.5);
    --glow-color-strong-hover: rgba(255, 255, 255, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    background-color: var(--overscroll-bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    width: 100%;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    gap: 16px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--card-border);
    border-top: 4px solid var(--brand-start);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    font-size: 16px;
    color: var(--brand-start);
    font-weight: 500;
}

/* Error Message */
.error-message {
    display: none;
    background: #e74c3c;
    color: white;
    padding: 16px;
    text-align: center;
    font-weight: 500;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Header */
.header {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 20px 0;
    box-shadow: var(--shadow-lg);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 100;
    padding-top: max(20px, env(safe-area-inset-top));
    transition: background 0.3s ease, border 0.3s ease;
}

.header .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.emoji {
    font-size: 28px;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: center;
}

.api-notice {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
    font-style: italic;
    opacity: 0.8;
}

.refresh-btn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: #10b981;
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.refresh-btn:active {
    transform: translateY(-50%) scale(0.92);
    box-shadow: 0 1px 4px rgba(16, 185, 129, 0.4);
}

.refresh-btn svg {
    animation: fadeIn 0.3s ease;
}

.refresh-btn.refreshing {
    animation: refreshPulse 0.6s ease-out;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

.refresh-btn.refreshing svg {
    animation: refreshIconSpin 0.75s ease-out;
    transform-origin: center;
}

.refresh-btn.refreshing::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 2px solid rgba(16, 185, 129, 0.35);
    opacity: 0;
    animation: refreshRipple 0.75s ease-out;
    pointer-events: none;
}

@keyframes refreshPulse {
    0% {
        transform: translateY(-50%) scale(1);
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    }
    45% {
        transform: translateY(-50%) scale(1.08);
        box-shadow: 0 8px 24px rgba(16, 185, 129, 0.45);
    }
    100% {
        transform: translateY(-50%) scale(1);
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
    }
}

@keyframes refreshIconSpin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

@keyframes refreshRipple {
    0% {
        opacity: 0.75;
        transform: scale(0.85);
    }
    100% {
        opacity: 0;
        transform: scale(1.4);
    }
}

body.page-refreshing::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 20% 20%, rgba(102, 126, 234, 0.5), transparent 55%),
        radial-gradient(circle at 80% 30%, rgba(118, 75, 162, 0.48), transparent 60%),
        linear-gradient(135deg, rgba(15, 118, 110, 0.25), rgba(45, 55, 72, 0.25));
    opacity: 0;
    pointer-events: none;
    z-index: 950;
    animation: refreshBackdropPulse 1s ease-in-out infinite;
    animation-fill-mode: both;
}

body.page-refreshing .header,
body.page-refreshing .main-content,
body.page-refreshing .footer {
    animation: refreshContentPulse 1s ease-in-out infinite;
}

@keyframes refreshBackdropPulse {
    0%, 100% {
        opacity: 0;
    }
    45% {
        opacity: 0.65;
    }
    70% {
        opacity: 0.2;
    }
}

@keyframes refreshContentPulse {
    0%, 100% {
        transform: translateY(0);
        box-shadow: none;
    }
    45% {
        transform: translateY(-4px);
        box-shadow: 0 12px 35px rgba(15, 118, 110, 0.18);
    }
}

/* Theme Toggle Button */
.theme-toggle {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--card-bg);
    color: var(--text-primary);
    border: 2px solid var(--card-border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.theme-toggle:hover {
    transform: translateY(-50%) scale(1.05);
    border-color: var(--brand-start);
}

.theme-toggle:active {
    transform: translateY(-50%) scale(0.95);
}

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

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

body[data-theme="light"] .theme-toggle .moon-icon {
    opacity: 0;
    transform: rotate(180deg);
}

body[data-theme="dark"] .theme-toggle .sun-icon {
    opacity: 0;
    transform: rotate(-180deg);
}

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

/* Main Content */
.main-content {
    padding: 24px 0 20px;
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--section-title-color);
    margin-bottom: 16px;
    text-align: center;
}

/* Price Timeline */
.price-timeline {
    margin-bottom: 12px;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--card-border);
    transition: background 0.3s ease, border 0.3s ease;
    overflow: visible;
    position: relative;
}

.price-timeline .section-title {
    color: var(--section-title-color);
    font-size: 20px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.current-datetime {
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-top: 0;
    margin-bottom: 16px;
    padding: 4px 12px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--card-border);
    position: relative;
    z-index: 1;
    transition: background 0.3s ease, border 0.3s ease;
}

.price-grid {
    display: grid;
    gap: 12px;
    margin: 0 auto;
    max-width: 100%;
    place-items: center;
    align-items: stretch;
    position: relative;
    z-index: 10;
    isolation: isolate;
    overflow: visible;
}

/* Dynamic grid columns based on visible boxes */
.price-grid[data-count="5"] {
    grid-template-columns: repeat(5, 1fr);
    --box-scale: 1;
}

.price-grid[data-count="7"] {
    grid-template-columns: repeat(7, 1fr);
    --box-scale: 0.95;
}

.price-grid[data-count="9"] {
    grid-template-columns: repeat(9, 1fr);
    --box-scale: 0.85;
}

.price-grid[data-count="11"] {
    grid-template-columns: repeat(11, 1fr);
    --box-scale: 0.75;
}

/* Apply scaling to boxes based on count */
.price-grid[data-count="7"] .price-box,
.price-grid[data-count="9"] .price-box,
.price-grid[data-count="11"] .price-box {
    font-size: calc(1em * var(--box-scale, 1));
}

.price-grid[data-count="7"] .price-box {
    min-height: clamp(95px, 16vw, 165px);
    padding: clamp(4px, 0.8vw, 8px) clamp(3px, 0.6vw, 6px);
}

.price-grid[data-count="9"] .price-box {
    min-height: clamp(90px, 14vw, 120px);
    padding: clamp(3px, 0.6vw, 6px) clamp(2px, 0.4vw, 4px);
}

.price-grid[data-count="11"] .price-box {
    min-height: clamp(85px, 13vw, 110px);
    padding: clamp(2px, 0.4vw, 5px) clamp(2px, 0.3vw, 3px);
}

.price-grid[data-count="7"] .price-box.current {
    min-height: clamp(105px, 17vw, 165px);
    padding: clamp(4px, 0.8vw, 8px) clamp(3px, 0.6vw, 6px);
}

.price-grid[data-count="9"] .price-box.current {
    min-height: clamp(100px, 16vw, 155px);
    padding: clamp(3px, 0.6vw, 6px) clamp(2px, 0.4vw, 4px);
}

.price-grid[data-count="11"] .price-box.current {
    min-height: clamp(110px, 18vw, 155px);
    padding: clamp(2px, 0.4vw, 5px) clamp(2px, 0.3vw, 3px);
}

.price-box {
    background: linear-gradient(135deg, var(--box-bg-start) 0%, var(--box-bg-end) 100%);
    border-radius: var(--radius-lg);
    padding: clamp(4px, 0.8vw, 8px) clamp(3px, 0.6vw, 6px);
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    align-self: stretch;
    justify-self: stretch;
    min-height: clamp(100px, 15vw, 140px);
    border: 2px solid var(--box-border);
    position: relative;
    z-index: 20;
    overflow: visible;
    backdrop-filter: blur(10px);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.price-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at top right, rgba(102, 126, 234, 0.1), transparent 70%);
    opacity: 0;
    border-radius: inherit;
}

.price-box::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.4) 0%, rgba(118, 75, 162, 0.4) 50%, rgba(102, 126, 234, 0.4) 100%);
    border-radius: inherit;
    opacity: 0;
    z-index: -1;
    filter: blur(10px);
}

.price-box.refresh-blink {
    animation: priceRefreshPulse 0.85s ease-in-out 0s 2;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.price-box.refresh-blink::before {
    opacity: 1;
    animation: priceRefreshGlow 0.85s ease-in-out 0s 2;
}

.price-box.refresh-blink::after {
    opacity: 0.55;
    animation: priceRefreshHalo 0.85s ease-in-out 0s 2;
}

.price-box.current {
    background: var(--timeline-box-bg);
    color: var(--text-primary);
    border: 1px solid var(--timeline-box-border);
    animation: borderGlow 2s ease-in-out infinite;
    min-height: clamp(110px, 18vw, 180px);
    padding: clamp(4px, 0.8vw, 8px) clamp(3px, 0.6vw, 6px);
    z-index: 30;
}

.price-box.current.refresh-blink {
    animation: borderGlow 2s ease-in-out infinite, priceRefreshPulse 0.85s ease-in-out 0s 2;
}

.price-box.current .price-label {
    font-size: clamp(8px, 1.4vw, 11px);
    margin-bottom: clamp(2px, 0.4vw, 4px);
}

.price-box.current .price-value {
    font-size: clamp(18px, 4vw, 32px);
    line-height: 1.1;
}

.price-box.current .price-unit {
    font-size: clamp(7px, 1.2vw, 10px);
    margin-top: clamp(1px, 0.2vw, 2px);
}

.price-box.current::before {
    opacity: 0;
}

.price-box.current::after {
    opacity: 0;
}

@media (hover: hover) and (pointer: fine) {
    .price-box.current:hover {
        box-shadow: 0 0 25px var(--glow-color-light-hover), 0 0 35px var(--glow-color-medium-hover), 0 0 45px var(--glow-color-strong-hover), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    }
}

@keyframes borderGlow {
    0%, 100% {
        box-shadow: 0 0 10px var(--glow-color-light), 0 0 20px var(--glow-color-medium), 0 0 30px var(--glow-color-strong), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    }
    50% {
        box-shadow: 0 0 20px var(--glow-color-light-hover), 0 0 30px var(--glow-color-medium-hover), 0 0 40px var(--glow-color-strong-hover), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    }
}

@keyframes priceRefreshPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.028);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes priceRefreshGlow {
    0% {
        opacity: 0;
    }
    45% {
        opacity: 0.75;
    }
    100% {
        opacity: 0;
    }
}

@keyframes priceRefreshHalo {
    0% {
        opacity: 0.55;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(1.3);
    }
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .price-box,
    .price-box.current {
        animation: none !important;
        transition: none !important;
    }

    .refresh-btn.refreshing,
    .refresh-btn.refreshing svg,
    .refresh-btn.refreshing::after {
        animation: none !important;
    }

    .price-box.refresh-blink,
    .price-box.refresh-blink::before,
    .price-box.refresh-blink::after {
        animation: none !important;
    }

    body.page-refreshing {
        animation: none !important;
        filter: none !important;
    }

    body.page-refreshing::before {
        animation: none !important;
        opacity: 0 !important;
    }

    body.page-refreshing .header,
    body.page-refreshing .main-content,
    body.page-refreshing .footer {
        animation: none !important;
    }
}

.price-label {
    font-size: clamp(7px, 1.2vw, 10px);
    font-weight: 800;
    text-transform: uppercase;
    opacity: 0.85;
    margin-bottom: clamp(2px, 0.4vw, 4px);
    letter-spacing: 1.2px;
    position: relative;
    z-index: 1;
    text-align: center;
    display: inline-block;
    padding: clamp(2px, 0.3vw, 3px) clamp(4px, 0.7vw, 6px);
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.price-box.current .price-label {
    opacity: 0.85;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.price-value {
    font-size: clamp(20px, 5vw, 38px);
    font-weight: 900;
    letter-spacing: -1px;
    position: relative;
    z-index: 1;
    text-align: center;
    width: 100%;
    line-height: 1.05;
    font-variant-numeric: tabular-nums lining-nums;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin-bottom: clamp(1px, 0.2vw, 2px);
    white-space: nowrap;
    overflow: hidden;
}

.price-box.current .price-value {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.price-unit {
    font-size: clamp(6px, 1vw, 9px);
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    z-index: 1;
    text-align: center;
    width: 100%;
    font-variant-caps: all-small-caps;
    margin-top: clamp(1px, 0.2vw, 2px);
}

.price-box.current .price-unit {
    opacity: 0.85;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Statistics */
/* Chart Section */
.chart-section,
.tomorrow-section {
    margin-bottom: 12px;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--card-border);
    transition: background 0.3s ease, border 0.3s ease;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    background: var(--card-bg);
    padding: 12px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--card-border);
    transition: background 0.3s ease, border 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.stat-item {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-low {
    color: #2ecc71 !important;
}

.stat-high {
    color: #e74c3c !important;
}

.chart-section .section-title,
.tomorrow-section .section-title {
    color: var(--section-title-color);
    font-size: 20px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.chart-section .section-title::before {
    content: "📊";
    font-size: 24px;
}

.tomorrow-section .section-title::before {
    content: "🌅";
    font-size: 24px;
}

#today-chart-stats,
#tomorrow-stats {
    margin-bottom: 12px;
}

.chart-container {
    background: transparent;
    padding: 20px;
    border-radius: 12px;
    box-shadow: none;
    border: none;
    transition: background 0.3s ease;
    height: 320px;
    position: relative;
}

.tomorrow-info {
    text-align: center;
    padding: 20px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.tomorrow-info .info-text {
    color: var(--text-secondary);
    font-size: 14px;
    font-style: italic;
}

/* Last Updated */
.last-updated {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    display: block;
    width: fit-content;
    margin: 16px auto 0;
    padding: 6px 14px;
    border-radius: 9999px;
    background: rgba(102, 126, 234, 0.08);
    transition: background-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}

.last-updated.flash {
    background: var(--gradient-brand);
    color: #ffffff;
    box-shadow: var(--shadow-brand);
}

body[data-theme="dark"] .last-updated {
    background: rgba(102, 126, 234, 0.16);
    color: var(--text-secondary);
}

body[data-theme="dark"] .last-updated.flash {
    color: #f8fafc;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.45);
}

/* Focus styles for keyboard users */
.refresh-btn:focus-visible,
.price-box:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.6), 0 0 0 6px rgba(102, 126, 234, 0.6);
    border-color: rgba(102, 126, 234, 0.6);
}

/* Datetime chip embellishment */
.current-datetime::before {
    content: "🕐";
    margin-right: 10px;
    font-size: 16px;
}

/* Calculator Section */
.calculator-section {
    margin-bottom: 12px;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--card-border);
    transition: background 0.3s ease, border 0.3s ease;
}

.calculator-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.calculator-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 6px;
    align-items: end;
}

.label-with-hints {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 8px;
    min-height: 36px;
}

.form-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.label-main {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.label-sub {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.form-input,
.form-select {
    width: 100%;
    height: 50px;
    padding: 0 14px;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 10px;
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.form-input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
    padding-right: 40px;
}

/* Hide default spinners completely for custom implementation */
.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Custom number input spinner buttons */
.number-input-wrapper {
    position: relative;
    width: 100%;
}

.number-input-controls {
    position: absolute;
    right: 2px;
    top: 2px;
    bottom: 2px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 32px;
}

.number-input-controls button {
    flex: 1;
    border: none;
    background: var(--card-bg);
    border-left: 1px solid var(--card-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 600;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.number-input-controls button:first-child {
    border-radius: 0 8px 0 0;
}

.number-input-controls button:last-child {
    border-radius: 0 0 8px 0;
}

.number-input-controls button:hover {
    background: var(--gradient-brand-subtle);
    color: var(--brand-start);
    border-left-color: var(--brand-start);
}

.number-input-controls button:active {
    background: var(--gradient-brand-bg);
    transform: scale(0.95);
}

.number-input-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.number-input-controls button svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

/* Mobile optimizations */
@media (max-width: 767px) {
    .number-input-controls {
        width: 36px;
    }
    
    .number-input-controls button {
        font-size: 18px;
    }
    
    .number-input-controls button svg {
        width: 16px;
        height: 16px;
    }
}

.form-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a202c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

body[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e8eaed' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--brand-start);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-input.error {
    border-color: #e74c3c;
}

.usage-hints-row {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
    align-items: flex-end;
    max-width: 65%;
    justify-content: flex-end;
}

.hint-btn {
    padding: 3px 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 20px;
    white-space: nowrap;
    flex-shrink: 0;
}

.hint-btn:hover {
    background: var(--card-border);
    color: var(--text-primary);
}

.form-actions {
    display: flex;
    gap: 12px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 0 24px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 50px;
}

.btn-primary {
    background: var(--gradient-brand);
    color: white;
    box-shadow: var(--shadow-brand);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--card-border);
}

.btn-secondary:hover {
    background: var(--card-border);
}

.calculator-results {
    padding: 20px;
    background: var(--gradient-brand-subtle);
    border-radius: 12px;
    border: 1px solid var(--card-border);
}

.results-header {
    text-align: center;
    margin-bottom: 16px;
}

.results-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.results-amount {
    font-size: 36px;
    font-weight: 700;
    color: var(--brand-start);
}

.results-breakdown {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--card-border);
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.breakdown-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.breakdown-value {
    color: var(--text-primary);
    font-weight: 600;
}

.results-disclaimer {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
}

/* Price Count Toggle Buttons */
.price-count-toggle {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding: 8px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--card-border);
    transition: background 0.3s ease, border 0.3s ease;
}

.toggle-btn {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 48px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.toggle-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    border-color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.toggle-btn.active {
    background: var(--card-bg);
    border-color: var(--text-primary);
    color: var(--text-primary);
    box-shadow: 0 0 8px var(--text-primary), 0 0 16px var(--text-primary);
}

.toggle-btn:active {
    transform: translateY(0);
}

.toggle-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

/* Footer */
.footer {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 24px 0;
    text-align: center;
    color: var(--text-primary);
    margin-top: 40px;
    border-top: 1px solid var(--card-border);
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.footer p {
    margin: 4px 0;
    font-size: 14px;
}

.footer .small {
    font-size: 12px;
    opacity: 0.8;
}

/* Mobile Optimizations */
@media (max-width: 767px) {
    body {
        background: linear-gradient(180deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    }

    .container {
        padding: 0 12px;
    }

    .header {
        padding: 16px 0;
    }

    .title {
        font-size: 19px;
        line-height: 1.3;
    }

    .emoji {
        font-size: 22px;
    }

    .subtitle {
        font-size: 11px;
        line-height: 1.4;
        opacity: 0.9;
    }

    .main-content {
        padding: 16px 0 32px;
    }

    .price-timeline {
        padding: 12px;
        margin-bottom: 12px;
    }

    .section-title,
    .price-timeline .section-title,
    .chart-section .section-title,
    .tomorrow-section .section-title {
        font-size: 16px;
        margin-bottom: 12px;
    }

    .calculator-section {
        padding: 12px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .label-with-hints {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .label-main {
        white-space: normal;
    }

    .label-sub {
        white-space: normal;
    }

    .usage-hints-row {
        width: 100%;
        max-width: 100%;
        gap: 5px;
        justify-content: flex-start;
    }

    .hint-btn {
        font-size: 10px;
        padding: 3px 6px;
        min-height: 22px;
    }

    .form-actions {
        flex-direction: column;
    }

    .results-amount {
        font-size: 28px;
    }

    .price-timeline .section-title::before {
        font-size: 18px;
    }

    .current-datetime {
        font-size: 10px;
        padding: clamp(5px, 1.6vw, 8px) clamp(10px, 3.2vw, 16px);
        margin-top: 0;
        margin-bottom: clamp(12px, 3.8vw, 20px);
    }

    .price-grid {
        --timeline-mobile-gap: clamp(8px, 2.6vw, 14px);
        --timeline-mobile-padding-top: clamp(10px, 3.2vw, 18px);
        --timeline-mobile-padding-bottom: clamp(20px, 6vw, 30px);
        display: grid;
        gap: var(--timeline-mobile-gap);
        margin-top: 0;
        padding: var(--timeline-mobile-padding-top) 0 var(--timeline-mobile-padding-bottom);
    }

    /* On mobile with default 5 boxes: simple 5-column horizontal scroll */
    .price-grid[data-count="5"] {
        grid-template-columns: repeat(5, minmax(75px, 1fr));
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding-bottom: var(--timeline-mobile-padding-bottom);
    }

    .price-grid[data-count="5"] .price-box {
        scroll-snap-align: center;
    }

    /* For 7, 9, 11 on mobile: use horizontal scroll */
    .price-grid[data-count="7"],
    .price-grid[data-count="9"],
    .price-grid[data-count="11"] {
        grid-template-columns: repeat(var(--count), minmax(75px, 1fr));
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        padding-bottom: var(--timeline-mobile-padding-bottom);
    }

    .price-grid[data-count="7"] { --count: 7; }
    .price-grid[data-count="9"] { --count: 9; }
    .price-grid[data-count="11"] { --count: 11; }

    .price-grid[data-count="7"] .price-box,
    .price-grid[data-count="9"] .price-box,
    .price-grid[data-count="11"] .price-box {
        scroll-snap-align: center;
    }

    /* Mobile: Use base clamp() styles with border radius override */
    .price-box {
        border-radius: 14px;
    }

    .chart-section {
        padding: 12px;
        margin-bottom: 12px;
    }

    .chart-container {
        padding: 12px 8px;
        height: 260px;
    }

    .refresh-btn {
        width: 42px;
        height: 42px;
        right: 12px;
    }

    .refresh-btn svg {
        width: 19px;
        height: 19px;
    }

    .last-updated {
        font-size: 10px;
        padding: 0 12px;
    }

    .footer {
        padding: 20px 0;
        margin-top: 24px;
    }

    .footer p {
        font-size: 12px;
        line-height: 1.5;
        padding: 0 12px;
    }

    .footer .small {
        font-size: 10px;
    }

    .price-count-toggle {
        gap: clamp(6px, 2vw, 12px);
        padding: clamp(6px, 2vw, 10px);
        margin-top: clamp(8px, 2.3vw, 12px);
    }

    .toggle-btn {
        padding: 6px 12px;
        font-size: 12px;
        min-width: 40px;
    }
}

/* Extra Small Screens */
@media (max-width: 374px) {
    .title {
        font-size: 17px;
    }

    .subtitle {
        font-size: 10px;
    }

    .price-timeline {
        padding: 12px;
    }

    .price-grid {
        gap: 6px;
    }

    /* Use base clamp() styles with border radius override */
    .price-box {
        border-radius: 12px;
    }


    .current-datetime {
        font-size: 9px;
        padding: 5px 8px;
    }

    .stats-grid {
        padding: 12px;
        gap: 10px;
    }

    .stat-label {
        font-size: 9px;
    }

    .stat-value {
        font-size: 13px;
    }

    .chart-section {
        padding: 12px;
    }

    .chart-container {
        padding: 10px 6px;
        height: 220px;
    }

    .refresh-btn {
        width: 38px;
        height: 38px;
        right: 10px;
    }

    .refresh-btn svg {
        width: 17px;
        height: 17px;
    }

    .hint-btn {
        font-size: 9px;
        padding: 3px 5px;
        min-height: 20px;
    }
}

/* Medium Mobile (375px - 480px) */
@media (min-width: 375px) and (max-width: 480px) {
    .price-grid {
        gap: 7px;
    }

    /* Reduce padding for tighter fit */
    .price-box {
        padding: clamp(6px, 1.2vw, 8px) clamp(5px, 1vw, 6px);
        min-height: 105px;
    }
}

/* Large Mobile (481px - 767px) */
@media (min-width: 481px) and (max-width: 767px) {
    .container {
        padding: 0 20px;
    }

    .title {
        font-size: 22px;
    }

    .emoji {
        font-size: 24px;
    }

    .subtitle {
        font-size: 12px;
    }

    .price-timeline {
        padding: 12px;
    }

    .section-title,
    .price-timeline .section-title,
    .chart-section .section-title,
    .tomorrow-section .section-title {
        font-size: 18px;
        margin-bottom: 12px;
    }

    .current-datetime {
        font-size: 11px;
        padding: 7px 12px;
        margin-bottom: 14px;
    }

    .price-grid {
        display: grid;
        gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: auto auto;
        grid-template-areas:
            "prev2 current next2"
            "prev1 current next1";
    }

    /* Use base clamp() styles with border radius override */
    .price-box {
        border-radius: 16px;
    }


    .stats-grid {
        padding: 12px;
        gap: 14px;
    }

    .stat-label {
        font-size: 11px;
    }

    .stat-value {
        font-size: 17px;
    }

    .chart-section {
        padding: 12px;
    }

    .chart-container {
        padding: 14px 12px;
        height: 300px;
    }

    .hint-btn {
        font-size: 10px;
        padding: 3px 7px;
    }
}

/* Tablet Optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        padding: 0 24px;
    }

    .price-grid {
        gap: 12px;
    }

    /* Use base clamp() styles */

    .chart-container {
        height: 350px;
    }

    .usage-hints-row {
        gap: 3px;
        max-width: 60%;
    }

    .hint-btn {
        font-size: 9px;
        padding: 3px 5px;
        min-height: 20px;
    }
}

/* Tablet and Desktop */
@media (min-width: 768px) {
    .main-content {
        padding: 20px 0;
    }

    .price-timeline {
        padding: 12px;
    }

    .section-title,
    .price-timeline .section-title,
    .chart-section .section-title,
    .tomorrow-section .section-title {
        font-size: 24px;
        margin-bottom: 12px;
    }

    .calculator-section {
        padding: 20px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .usage-hints-row {
        gap: 4px;
        max-width: 65%;
    }

    .hint-btn {
        font-size: 10px;
        padding: 3px 7px;
        min-height: 22px;
    }

    .hint-btn:active {
        transform: scale(0.95);
    }

    .form-actions {
        flex-direction: row;
        max-width: 400px;
    }

    .results-amount {
        font-size: 42px;
    }

    .price-timeline .section-title::before {
        font-size: 28px;
    }

    .current-datetime {
        font-size: 14px;
        padding: 8px 16px;
        margin-bottom: 20px;
    }

    .price-grid {
        display: grid;
        max-width: 900px;
        gap: 14px;
        overflow: visible;
    }

    .price-grid[data-count="5"] {
        grid-template-columns: repeat(5, 1fr);
        max-width: 900px;
    }

    .price-grid[data-count="7"] {
        grid-template-columns: repeat(7, 1fr);
        max-width: 100%;
    }

    .price-grid[data-count="9"] {
        grid-template-columns: repeat(9, 1fr);
        max-width: 100%;
        gap: 10px;
    }

    .price-grid[data-count="11"] {
        grid-template-columns: repeat(11, 1fr);
        max-width: 100%;
        gap: 8px;
    }

    /* Desktop: Use base clamp() styles with border radius override */
    .price-box {
        border-radius: 18px;
    }

    .stats-grid {
        padding: 12px;
        gap: 24px;
    }

    .stat-label {
        font-size: 14px;
    }

    .stat-value {
        font-size: 20px;
    }

    .chart-section {
        padding: 12px;
    }

    .chart-section .section-title::before {
        font-size: 28px;
    }

    .chart-container {
        padding: 28px;
        height: 420px;
    }
}

/* Landscape Mode on Mobile */
@media (max-width: 767px) and (orientation: landscape) {
    .header {
        padding: 16px 0;
    }

    .title {
        font-size: 18px;
    }

    .subtitle {
        font-size: 11px;
    }

    .main-content {
        padding: 20px 0;
    }

    .price-timeline {
        padding: 12px;
        margin-bottom: 12px;
    }

    .section-title,
    .price-timeline .section-title,
    .chart-section .section-title,
    .tomorrow-section .section-title {
        font-size: 16px;
        margin-bottom: 12px;
    }

    .current-datetime {
        font-size: 10px;
        padding: 6px 10px;
        margin-top: 0;
        margin-bottom: 10px;
    }

    .price-box {
        min-height: 90px;
    }

    .chart-section {
        padding: 12px;
        margin-bottom: 12px;
    }

    .chart-container {
        height: 220px;
        padding: 12px;
    }

    .stats-grid {
        padding: 12px;
    }

    .footer {
        padding: 16px 0;
        margin-top: 24px;
    }
}

/* Print Styles */
@media print {
    .refresh-btn,
    .loading-overlay {
        display: none !important;
    }

    body {
        background: white;
    }
}

/* Container Queries for Responsive Typography */
@supports (font-size: 1cqw) {
    .price-box { 
        container-type: inline-size;
        container-name: pricebox;
    }

    .price-value {
        font-size: clamp(18px, 18cqw, 42px);
        line-height: 1.05;
    }

    .price-box.current .price-value {
        font-size: clamp(18px, 18cqw, 42px);
        line-height: 1.05;
    }

    .price-label {
        font-size: clamp(7px, 6cqw, 11px);
        margin-bottom: clamp(1px, 0.5cqw, 3px);
        padding: clamp(2px, 0.5cqw, 3px) clamp(4px, 1cqw, 6px);
    }

    .price-box.current .price-label {
        font-size: clamp(8px, 7cqw, 12px);
        margin-bottom: clamp(1px, 0.5cqw, 3px);
    }

    .price-unit {
        font-size: clamp(6px, 5cqw, 10px);
        margin-top: clamp(1px, 0.3cqw, 2px);
    }

    .price-box.current .price-unit {
        font-size: clamp(7px, 5.5cqw, 11px);
        margin-top: clamp(1px, 0.3cqw, 2px);
    }

    .price-grid[data-count="11"] .price-box.current .price-value {
        font-size: clamp(18px, 18cqw, 42px);
        line-height: 1.05;
        margin-bottom: clamp(1px, 0.3cqw, 2px);
    }

    .price-grid[data-count="11"] .price-box.current .price-label {
        font-size: clamp(8px, 6.5cqw, 11px);
        margin-bottom: clamp(1px, 0.3cqw, 2px);
    }

    .price-grid[data-count="11"] .price-box.current .price-unit {
        font-size: clamp(7px, 5cqw, 10px);
        margin-top: clamp(1px, 0.2cqw, 2px);
    }
}

/* Large Desktop Screens */
@media (min-width: 1025px) {
    .usage-hints-row {
        gap: 4px;
        max-width: 65%;
    }

    .hint-btn {
        font-size: 10px;
        padding: 3px 8px;
        min-height: 22px;
    }

    .hint-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
}