/* General Styles */
@font-face {
    font-family: 'Digital-7';
    src: url('../assets/digital_7.ttf') format('truetype');
    font-display: swap;
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    max-width: 100%;
    /* Prevent iOS/Safari horizontal rubber-band from wide descendants */
    -webkit-text-size-adjust: 100%;
    /* Set by logic.js to match #fixed-header height (no extra gap below bar) */
    --fixed-header-clearance: 200px;
    /* Page background themes (Settings → Background) */
    --page-background: #1a2d4a;
    --page-text: #e8eef4;
    --page-text-muted: #a8b8cc;
}

html[data-theme="light"] {
    --page-background: #f5f5f5;
    --page-text: #333333;
    --page-text-muted: #666666;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--page-background);
    color: var(--page-text);
    overflow-x: hidden;
    max-width: 100%;
    position: relative;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* Main app wrapper: contain any child that would extend past viewport */
#main-app {
    overflow-x: hidden;
    max-width: 100%;
    position: relative;
}

/* Prevent oversized images from causing horizontal scroll; keep dial needles as styled */
img:not(.dial-needle):not(.dial-needle-small) {
    max-width: 100%;
    height: auto;
}

/* Splash Screen */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.splash-screen img {
    max-width: 70%;
    max-height: 70%;
    object-fit: contain;
}

/* Fixed Header */
#fixed-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    background-color: #ffffff;
    z-index: 1000;
    padding: 8px 0 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border-bottom: 2px solid #e0e0e0;
}

/* Top results bar only — scales for laptop/desktop readability (QML-style row) */
#fixed-header .header-row {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: nowrap;
    padding: 0 clamp(8px, 2vw, 16px);
    gap: clamp(14px, 2.8vw, 36px);
    max-width: 100%;
    box-sizing: border-box;
}

#fixed-header .header-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    min-width: 0;
}

#fixed-header .header-col:last-child {
    align-items: flex-start;
}

#fixed-header .header-label {
    font-weight: bold;
    font-size: clamp(12px, 0.95vw + 9px, 16px);
    text-align: center;
    margin-bottom: 6px;
    color: #333;
}

#fixed-header .header-label-small {
    font-weight: bold;
    font-size: clamp(11px, 0.8vw + 8px, 14px);
    text-align: left;
    line-height: 1.2;
    color: #333;
}

#fixed-header .counter-dial-small {
    position: relative;
    width: clamp(168px, 28vw, 250px);
    height: auto;
    aspect-ratio: 3279 / 1396;
    margin: 6px 0;
}

#fixed-header .dial-bg-small {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

#fixed-header .dial-needle-small {
    position: absolute;
    width: auto;
    height: 75%;
    max-width: 42%;
    left: 50%;
    bottom: 4.5%;
    transform-origin: 50% 90%;
    transform: translate(-50%, 0) rotate(-90deg);
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    object-fit: contain;
}

#fixed-header .digital-cost-display-small {
    /* QML DigitalCostDisplay: dark bezel behind red/green digits */
    background-color: #000;
    color: #ff0000;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: clamp(14px, 1.05vw + 11px, 22px);
    /* Snug left/right; JS may tighten further to match white-box variant */
    padding: clamp(6px, 1vw, 10px) clamp(4px, 0.7vw, 8px);
    /* line-height: 1.15; */
    border: 2px solid #666;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 4px 0;
    box-shadow: inset 0 0 10px rgba(255, 0, 0, 0.3);
    width: fit-content;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    /* Do not let flex/grid shrink the panel to invisibility on narrow layouts */
    flex-shrink: 0;
}

#fixed-header .unit-text {
    font-size: 0.78em;
    margin-left: 3px;
    color: inherit;
}

#fixed-header .header-sub-row {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1.2vw, 12px);
    margin: 5px 0;
}

/* Label above the digital readout (QML: digits sit in a dark panel; label stays outside it) */
#fixed-header .header-cost-label-row {
    width: 100%;
    margin: 2px 0 4px;
}

#fixed-header .header-cost-label {
    color: #000;
    font-weight: bold;
}

#fixed-header .status-light {
    width: clamp(18px, 1.6vw + 12px, 28px);
    height: clamp(18px, 1.6vw + 12px, 28px);
    border-radius: 50%;
    background-color: #4eff00;
    border: 2px solid #555;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s ease;
    flex-shrink: 0;
}

#fixed-header .shortfall-text-top {
    text-align: center;
    color: #ff0000;
    font-size: clamp(11px, 0.7vw + 9px, 15px);
    font-weight: bold;
    margin: 8px 10px 6px;
    min-height: 1.2em;
    line-height: 1.3;
    padding: 0 6px;
}

/* Legacy class hooks (only used in #fixed-header in this app) */
.header-row {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 10px;
    gap: 30px;
    flex-wrap: wrap;
}

.header-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
}

.header-label {
    font-weight: bold;
    font-size: 11px;
    text-align: center;
    margin-bottom: 5px;
    color: #333;
}

.header-label-small {
    font-weight: bold;
    font-size: 10px;
    text-align: center;
    line-height: 1.2;
    color: #333;
}

.counter-dial-small {
    position: relative;
}

.dial-bg-small {
    width: 100%;
    height: auto;
    display: block;
}

.dial-needle-small {
    position: absolute;
    width: auto;
    height: 75%;
    left: 50%;
    bottom: 4.5%;
    transform-origin: 50% 90%;
    transform: translate(-50%, 0) rotate(-90deg);
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.digital-cost-display-small {
    background-color: #000;
    color: #ff0000;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 13px;
    padding: 4px 8px;
    border: 2px solid #666;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 2px 0;
    box-shadow: inset 0 0 10px rgba(255, 0, 0, 0.3);
    min-width: 90px;
}

.unit-text {
    font-size: 0.75em;
    margin-left: 5px;
    color: inherit;
}

.header-sub-row {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 2px 0;
}

.status-light {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: #4eff00;
    border: 2px solid #555;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transition: background-color 0.3s ease;
}

.shortfall-text-top {
    text-align: center;
    color: #ff0000;
    font-size: 10px;
    font-weight: bold;
    margin: 3px 0;
    min-height: 12px;
}

.gap-line {
    height: 5px;
    width: 100%;
    position: relative;
    margin-top: 3px;
}

.separated-line {
    height: 2px;
    width: 100%;
    background-color: #000;
    position: absolute;
    bottom: 0;
}

/* Top padding follows measured #fixed-header height via --fixed-header-clearance */
.container {
    padding: 20px;
    padding-top: var(--fixed-header-clearance);
    max-width: min(650px, 100%);
    margin: 0 auto;
    width: 100%;
}

/* When "Show results at top" is off: fixed header hidden — drop reserved top space */
#main-app.hide-top-results .container {
    padding-top: 20px;
}

@media (max-width: 768px) {
    #main-app.hide-top-results .container {
        padding-top: 15px;
    }
}

/* Row Styles */
.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header-row-main {
    align-items: flex-start;
    gap: 16px;
}

.header-row-main .row-left {
    flex: 1 1 auto;
    min-width: 0;
}

.header-row-main .icons-row {
    flex: 0 0 auto;
}

.row-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.row-left h2 {
    margin: 0;
    font-size: 1.3em;
    color: var(--page-text);
    font-weight: bold;
}

.icons-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    width: 35px;
    height: 35px;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s, filter 0.25s ease;
}

.icon-btn:hover {
    transform: scale(1.1);
    opacity: 0.8;
}

.icon-small {
    width: 24px;
    height: 24px;
}

/*
 * Default (dark blue) theme: black monochrome icons on the page background are
 * hard to see. Treat the image as a mask: force to black, then invert to white.
 */
html:not([data-theme="light"]) .icons-row .icon-btn[src*="questionMark"],
html:not([data-theme="light"]) .icons-row .icon-btn[src*="Setting"],
html:not([data-theme="light"]) .icons-row .icon-btn[src*="tutorial_Icon"],
html:not([data-theme="light"]) .icons-row .icon-btn[src*="Sponsor"],
html:not([data-theme="light"]) .header-row-main .tooltip-container .icon-small,
html:not([data-theme="light"]) .header-row-section .tooltip-container .icon-small,
html:not([data-theme="light"]) .result-row .tooltip-container .icon-small,
html:not([data-theme="light"]) .scroll-indicator img {
    filter: brightness(0) invert(1);
}

.icon-large {
    width: 40px;
    height: 40px;
}

/* Control Rows */
.control-row {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    background-color: #ffffff;
    padding: 12px 15px;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.2s;
}

.control-row:hover {
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.icon-col {
    width: 50px;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.label-col {
    width: 80px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.label-title {
    font-weight: bold;
    font-size: 14px;
    color: #333;
}

.label-unit {
    color: #777;
    font-size: 12px;
}

.input-col {
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

/* Sliders */
.slider {
    flex-grow: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right,
            var(--selected-color) 0%,
            var(--selected-color) var(--slider-percent, 0%),
            #d3d3d3 var(--slider-percent, 0%),
            #d3d3d3 100%);
    outline: none;
    transition: opacity 0.2s;
    cursor: pointer;
}

.slider:hover {
    opacity: 0.9;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--selected-color);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border: 3px solid #fff;
    transition: transform 0.1s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--selected-color);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border: 3px solid #fff;
    transition: transform 0.1s;
}

.slider::-moz-range-thumb:hover {
    transform: scale(1.1);
}

.slider-value {
    width: 50px;
    text-align: right;
    font-weight: bold;
    font-size: 15px;
    color: #333;
    flex-shrink: 0;
}

/* QML HorizontalTumbler — discrete chips + « » scroll hints; range input stays in DOM for logic only */
.control-row .input-col {
    position: relative;
}

.control-row .input-col>input.slider[type="range"] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.control-row .input-col>.slider-value {
    display: none;
}

.horizontal-tumbler {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: 42px;
    box-sizing: border-box;
}

.horizontal-tumbler-scroll {
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-behavior: smooth;
    overscroll-behavior-x: contain;
}

.horizontal-tumbler-scroll::-webkit-scrollbar {
    display: none;
}

/* Mouse / trackpad: thin horizontal scrollbar so desktop users can drag-scroll */
@media (pointer: fine) {
    .horizontal-tumbler-scroll {
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.35) transparent;
    }

    .horizontal-tumbler-scroll::-webkit-scrollbar {
        display: block;
        height: 6px;
    }

    .horizontal-tumbler-scroll::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.28);
        border-radius: 4px;
    }

    .horizontal-tumbler-scroll::-webkit-scrollbar-track {
        background: transparent;
    }
}

.horizontal-tumbler-chip {
    flex: 0 0 auto;
    min-width: clamp(50px, 8vw, 74px);
    padding: 6px 11px;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-family: inherit;
    font-weight: bold;
    font-size: clamp(17px, 2.8vw, 22px);
    line-height: 1.15;
    color: #333;
    opacity: 0.5;
    cursor: pointer;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

.horizontal-tumbler-chip.is-selected {
    opacity: 1;
    color: #111;
    background: rgba(128, 128, 128, 0.12);
    background: color-mix(in srgb, var(--tumbler-color) 22%, transparent);
}

.horizontal-tumbler-arrow {
    flex: 0 0 auto;
    align-self: center;
    font-size: clamp(14px, 3.2vw, 18px);
    font-weight: bold;
    color: #555;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    user-select: none;
}

.horizontal-tumbler-arrow.is-visible {
    opacity: 0.85;
}

/* Larger tumbler digits on phones (QML uses ~80% of row height) */
@media (max-width: 768px) {
    .horizontal-tumbler {
        height: 46px;
    }

    .horizontal-tumbler-chip {
        font-size: clamp(19px, 5.8vw, 26px);
        min-width: clamp(54px, 16vw, 88px);
        padding: 8px 12px;
        border-radius: 9px;
    }

    .horizontal-tumbler-arrow {
        font-size: clamp(18px, 5vw, 24px);
    }
}

/* Section Headers */
.header-row-section {
    margin-top: 30px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-row-section h2 {
    font-size: 1.3em;
    margin: 0;
    color: var(--page-text);
    font-weight: bold;
}

/* Tooltips */
.tooltip-container {
    position: relative;
    display: inline-block;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tooltip-icon {
    cursor: pointer;
    vertical-align: middle;
}

.tooltip-text {
    visibility: hidden;
    width: min(250px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 8px;
    /* position + placement set by JS (viewport-safe); fallback for no-JS */
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 6000;
    margin-left: 0;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
    font-size: 12px;
    line-height: 1.4;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

/* Arrow points down (tooltip above trigger) */
.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: var(--tooltip-arrow-left, 50%);
    transform: translateX(-50%);
    margin-left: 0;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

/* Arrow points up (tooltip below trigger) */
.tooltip-text.tooltip-below::after {
    top: auto;
    bottom: 100%;
    border-color: transparent transparent #333 transparent;
}

/* Desktop hover + tap-to-pin open state (mobile / touch) */
.tooltip-container:hover .tooltip-text,
.tooltip-container.tooltip-open .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Results Rectangle */
.results-rectangle {
    background-color: #a9a9a9;
    padding: 15px;
    /* Avoid negative horizontal margins — they extend past the container and cause
       horizontal scroll + white gap on narrow viewports (mobile browsers). */
    margin: 30px 0;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.results-rectangle h3 {
    margin: 0 0 5px 0;
    font-size: 1.4em;
    color: #000;
}

.results-rectangle p {
    font-size: 13px;
    margin: 5px 0 0 0;
    font-weight: bold;
    color: #222;
}

/* Result Rows */
.result-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.result-label {
    font-weight: bold;
    font-size: 15px;
    color: var(--page-text);
}

/* Counter Dial Large */
.counter-dial-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.counter-dial-large {
    position: relative;
    width: 250px;
    height: 106.5px;
}

.counter-dial-large .dial-bg {
    width: 100%;
    height: auto;
    display: block;
}

.counter-dial-large .dial-needle {
    position: absolute;
    width: auto;
    height: 75%;
    left: 50%;
    bottom: 4.5%;
    transform-origin: 50% 90%;
    transform: translate(-50%, 0) rotate(-90deg);
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

/* Shortfall Text */
.shortfall-text {
    text-align: center;
    color: #ff0000;
    font-weight: bold;
    font-size: 14px;
    margin: 10px 0;
    min-height: 20px;
}

/* Result Indicator Row */
.result-indicator-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.status-text {
    font-weight: bold;
    font-size: 16px;
    color: #ff0000;
    transition: color 0.3s ease;
}

.red-green-light {
    width: 180px;
    height: 60px;
    background-color: #000;
    border-radius: 15px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.light {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid #666;
    transition: background-color 0.3s ease;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.light.red {
    background-color: #8b0000;
}

.light.green {
    background-color: #006400;
}

/* Digital Cost Display Large */
.digital-cost-display-large {
    background-color: #000;
    color: #ff0000;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    padding: 15px 25px;
    border: 3px solid #666;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    width: fit-content;
    margin: 20px auto;
    box-shadow: inset 0 0 15px rgba(255, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.3);
}

/* Annual Cost Display */
.annual-cost-display {
    background-color: #000;
    color: #00ff00;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    padding: 10px 15px;
    border: 2px solid #666;
    border-radius: 5px;
    font-size: 18px;
    box-shadow: inset 0 0 10px rgba(0, 255, 0, 0.2);
}

/* Chart Container */
.chart-container {
    width: 100%;
    max-width: 350px;
    height: 350px;
    margin: 20px auto;
}

/* Pressure Dial (CO2) */
.pressure-dial-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.pressure-dial {
    position: relative;
    width: 250px;
    height: 110.5px;
}

.pressure-dial .dial-bg {
    width: 100%;
    height: auto;
    display: block;
}

.pressure-dial .dial-needle {
    position: absolute;
    width: auto;
    height: 75%;
    left: 50%;
    bottom: 4.9%;
    transform-origin: 50% 90%;
    transform: translate(-50%, 0) rotate(-90deg);
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

/* CO2 Slider Container */
.co2-slider-container {
    width: 200px;
    margin: 20px auto;
}

.range-labels,
.range-labels-bottom {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--page-text-muted);
    font-weight: bold;
}

.co2-bar-bg {
    height: 20px;
    background-color: #bdbebf;
    border-radius: 3px;
    position: relative;
    margin: 8px 0;
    overflow: hidden;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}

.co2-bar-fill {
    height: 100%;
    background-color: #21be2b;
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease;
}

/* Bill Input Container */
.bill-input-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.bill-input-container label {
    font-weight: bold;
    color: #333;
}

.bill-input-container input {
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    width: 100%;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 5000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    /* Vertical scroll only — avoid horizontal bar + white gap on narrow phones */
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background-color: rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 0;
    border: 1px solid #888;
    width: min(90%, calc(100vw - 24px));
    max-width: 500px;
    box-sizing: border-box;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content-large {
    max-width: min(800px, calc(100vw - 24px));
    width: min(90%, calc(100vw - 24px));
    height: 80vh;
    margin: 5% auto;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-width: 0;
}

.modal-header {
    padding: 15px 20px;
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    border-radius: 12px 12px 0 0;
    min-width: 0;
}

.modal-scroll-content {
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.modal-scroll-content img {
    max-width: 100%;
    height: auto;
}

.modal-scroll-content h1 {
    color: #333;
    font-size: 1.8em;
    margin-top: 0;
}

.modal-scroll-content h2 {
    color: #444;
    font-size: 1.4em;
    margin-top: 20px;
}

.modal-scroll-content p {
    line-height: 1.6;
    color: #555;
    margin: 10px 0;
}

.modal-scroll-content a {
    color: #0066cc;
    text-decoration: none;
    word-break: break-word;
}

.modal-scroll-content a:hover {
    text-decoration: underline;
}

.tutorial-image {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 20px auto;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.close-btn,
.font-btn {
    background-color: transparent;
    color: #666;
    border: none;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0 10px;
}

.close-btn:hover,
.close-btn:focus,
.font-btn:hover,
.font-btn:focus {
    color: #000;
}

.font-btn {
    font-size: 24px;
}

/* Settings modal: padded body + table alignment for labels vs controls */
.modal-content-settings {
    position: relative;
    padding: 0;
}

.modal-content-settings .close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    z-index: 2;
}

.settings-modal-body {
    padding: 20px 24px 24px;
    padding-top: 48px;
}

.settings-modal-body h2 {
    margin: 0 0 16px 0;
    font-size: 1.35em;
    color: #333;
}

.settings-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.settings-table-label {
    vertical-align: top;
    text-align: left;
    padding: 10px 16px 10px 0;
    width: 48%;
    font-weight: 600;
    color: #333;
}

.settings-table-label label {
    display: inline-block;
    line-height: 1.4;
}

.settings-table-value {
    vertical-align: top;
    padding: 6px 0 10px 0;
}

.settings-table-checkbox {
    padding: 10px 0 4px 0;
    vertical-align: top;
}

.settings-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.4;
    cursor: pointer;
    font-weight: normal;
    color: #333;
}

.settings-checkbox-label input {
    margin-top: 3px;
    flex-shrink: 0;
}

/* Price field: number box + unit label on one row, visibly attached */
.settings-price-input {
    display: flex;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    border: 2px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
    box-sizing: border-box;
}

/* Do not let flex shrink the field to 0 — long unit text used to steal all width on phones */
.settings-price-input input {
    flex: 0 0 auto;
    width: 6.5rem;
    min-width: 6.5rem;
    padding: 8px 10px;
    border: none;
    border-radius: 0;
    font-size: 16px;
    /* avoids iOS zoom-on-focus; still readable */
    color: #333;
    background: #fff;
    box-sizing: border-box;
}

.settings-price-input input:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px #0066cc;
}

.settings-price-input .settings-unit {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 10px;
    background: #f0f0f0;
    font-size: 12px;
    color: #333;
    border-left: 1px solid #ddd;
    white-space: normal;
    line-height: 1.3;
    hyphens: auto;
}

.settings-select {
    width: 100%;
    max-width: 100%;
    padding: 8px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    color: #333;
    background: #fff;
    box-sizing: border-box;
    cursor: pointer;
}

.settings-select:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
}

@media (max-width: 480px) {
    .settings-modal-body {
        padding: 18px 16px 20px;
        padding-top: 44px;
    }

    .settings-table tbody tr:first-child {
        display: flex;
        flex-direction: column;
    }

    .settings-table tbody tr:first-child .settings-table-label,
    .settings-table tbody tr:first-child .settings-table-value {
        display: block;
        width: 100%;
        padding-left: 0;
        padding-right: 0;
    }

    .settings-table tbody tr:first-child .settings-table-value {
        padding-top: 4px;
        padding-bottom: 8px;
    }

    /* Stack price field on very narrow screens so the number box stays full width and visible */
    .settings-price-input {
        flex-direction: column;
        align-items: stretch;
    }

    .settings-price-input input {
        width: 100%;
        min-width: 0;
        flex: 0 0 auto;
    }

    .settings-price-input .settings-unit {
        border-left: none;
        border-top: 1px solid #ddd;
        justify-content: center;
        text-align: center;
        padding: 8px 10px;
    }
}

/* Responsive Design */
@media (max-width: 768px) {

    /* QML mobile: top results = horizontal row, scaled dial (Main.qml CounterDial) */
    #fixed-header {
        padding: 6px 0 4px;
    }

    /* flex-end: dial baseline and bottom of right stack (Carbon emissions) share one line on narrow screens */
    #fixed-header .header-row {
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: center;
        align-items: flex-end;
        gap: 10px;
        padding: 0 6px;
        max-width: 100%;
        box-sizing: border-box;
    }

    #fixed-header .header-col {
        min-width: 0;
    }

    #fixed-header .header-col:first-child {
        flex: 1 1 auto;
        max-width: min(250px, calc(100vw * 0.6));
    }

    #fixed-header .header-col:last-child {
        flex: 0 1 auto;
        min-width: 0;
    }

    /* QML: width min(250, fixedHeader.width*1.2/2) when half-width ≤ 250 */
    #fixed-header .counter-dial-small {
        width: 100%;
        max-width: min(250px, calc(100vw * 0.6));
        height: auto;
        margin: 4px auto;
        aspect-ratio: 3279 / 1396;
    }

    #fixed-header .dial-bg-small {
        width: 100%;
        height: auto;
        object-fit: contain;
        display: block;
    }

    #fixed-header .dial-needle-small {
        height: 75%;
        width: auto;
        max-width: 45%;
        object-fit: contain;
    }

    #fixed-header .header-label {
        font-size: clamp(10px, 2.9vw, 12px);
        margin-bottom: 4px;
    }

    #fixed-header .header-label-small {
        font-size: clamp(9px, 2.6vw, 11px);
        text-align: left;
        line-height: 1.15;
    }

    #fixed-header .header-sub-row {
        gap: 8px;
        margin: 3px 0;
        align-items: center;
    }

    #fixed-header .header-cost-label-row {
        margin: 1px 0 2px;
    }

    #fixed-header .status-light {
        width: clamp(14px, 4.5vw, 22px);
        height: clamp(14px, 4.5vw, 22px);
        flex-shrink: 0;
        border-width: 2px;
    }

    /* QML DigitalCostDisplay height ~50 on mobile */
    #fixed-header .digital-cost-display-small {
        width: fit-content;
        max-width: 100%;
        font-size: clamp(12px, 3.8vw, 17px);
        padding: 6px 4px;
        margin: 5px 0;
        box-sizing: border-box;
    }

    #fixed-header .unit-text {
        font-size: 0.72em;
    }

    #fixed-header .shortfall-text-top {
        font-size: clamp(9px, 2.7vw, 11px);
        margin: 6px 8px 4px;
        line-height: 1.25;
        padding: 0 4px;
    }

    #fixed-header .gap-line {
        margin-top: 2px;
    }

    .container {
        padding: 15px;
        padding-top: var(--fixed-header-clearance);
    }

    /*
     * Power Generation row (mobile): toolbar on top; title + section help (?) below.
     */
    .header-row-main {
        flex-wrap: wrap;
        row-gap: 12px;
    }

    .header-row-main .icons-row {
        order: -1;
        flex: 1 1 100%;
        width: 100%;
        justify-content: flex-end;
        gap: 12px;
        padding-bottom: 10px;
    }

    .header-row-main .row-left {
        order: 0;
        flex: 1 1 100%;
        width: 100%;
        max-width: 100%;
    }

    html:not([data-theme="light"]) .header-row-main .icons-row {
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }

    html[data-theme="light"] .header-row-main .icons-row {
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    }

    .control-row {
        padding: 10px;
    }

    .label-col {
        width: 70px;
    }

    .icon-col {
        width: 45px;
    }

    .icon-large {
        width: 35px;
        height: 35px;
    }

    .counter-dial-large {
        width: 200px;
        height: 85.2px;
    }

    .pressure-dial {
        width: 200px;
        height: 88.4px;
    }

    .chart-container {
        max-width: 280px;
        height: 280px;
    }

    .modal-content-large {
        width: min(95%, calc(100vw - 16px));
        max-width: min(800px, calc(100vw - 16px));
        height: 90vh;
    }

    .tooltip-text {
        width: min(200px, calc(100vw - 24px));
    }
}

@media (max-width: 480px) {

    /* Top header: keep QML-style horizontal row (only .header-row is in #fixed-header) */
    #fixed-header .header-row {
        gap: 8px;
        padding: 0 4px;
    }

    #fixed-header .counter-dial-small {
        max-width: min(250px, calc(100vw * 0.58));
    }

    .result-indicator-row {
        flex-direction: column;
        gap: 15px;
    }
}

/* Scroll Indicator */
.scroll-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    display: none;
    animation: bounce 2s infinite;
}

.scroll-indicator img {
    width: 35px;
    height: auto;
    opacity: 0.7;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateX(-50%) translateY(0);
    }

    40% {
        transform: translateX(-50%) translateY(-10px);
    }

    60% {
        transform: translateX(-50%) translateY(-5px);
    }
}