@font-face { font-family: 'JetBrains Mono'; font-weight: 400; font-display: swap; src: url("../fonts/jetbrains-mono-400-zjT1pI9.woff2") format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-weight: 500; font-display: swap; src: url("../fonts/jetbrains-mono-500-l4pIovd.woff2") format('woff2'); }
@font-face { font-family: 'Orbitron'; font-weight: 500; font-display: swap; src: url("../fonts/orbitron-500-HkxIlJU.woff2") format('woff2'); }

:root {
    --bg: #04070a;
    --panel: #050a0e;
    --page: var(--panel);
    --frame: #2a6577;
    --frame-dim: #12313b;
    --grid: #0d222a;
    --ice: #6fe3ff;
    --ice-soft: #9fdcec;
    --text: #e6fbff;
    --muted: #5fa9bd;
    --sun: #ff9a3c;
    --sun-soft: #ffb877;
    --ok: #7dffb0;
    --warn: #ffd166;
    --alert: #ff6b6b;
    --glow-ice: 0 0 8px rgba(111, 227, 255, 0.45);
    --glow-sun: 0 0 8px rgba(255, 154, 60, 0.5);
    --font: 'JetBrains Mono', ui-monospace, monospace;
    --font-display: 'Orbitron', var(--font);
    --tabbar-h: 64px;
    --radius-button: 3px;
    --radius-panel: 5px;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--page); }

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--page);
    color: var(--text);
    font: 400 14px/1.5 var(--font);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--ice); }

.app {
    max-width: 480px;
    margin: 0 auto;
    padding: 12px 12px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 4px 2px;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.topbar__brand { font-family: var(--font-display); color: var(--ice); text-shadow: var(--glow-ice); letter-spacing: 0.18em; }
.topbar__brand small { color: var(--muted); font-family: var(--font); text-shadow: none; letter-spacing: 0.1em; }

.topbar__right { display: inline-flex; align-items: center; gap: 12px; }
.topbar__alert { color: var(--warn); text-decoration: none; text-shadow: 0 0 6px rgba(255, 209, 102, 0.5); }
.backup-ok { color: var(--ok); }
.backup-warn { color: var(--warn); text-transform: none; letter-spacing: 0.02em; }

.status { display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.status.is-stale { color: var(--warn); }
.status.is-stale::before { background: var(--warn); box-shadow: 0 0 6px var(--warn); }

.panel {
    position: relative;
    margin: 16px 4px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--frame);
    border-radius: var(--radius-panel);
    outline: 1px solid var(--frame-dim);
    outline-offset: 3px;
    box-shadow: inset 0 0 24px rgba(111, 227, 255, 0.04);
}

button { border-radius: var(--radius-button); }

.panel__head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 4px; }
.tiles .panel { margin: 4px 0; }

.value { font-family: var(--font-display); font-size: 22px; color: var(--text); text-shadow: var(--glow-ice); line-height: 1.2; }
.value small { font-family: var(--font); font-size: 11px; color: var(--muted); text-shadow: none; margin-left: 2px; }
.value--sun { color: var(--sun-soft); text-shadow: var(--glow-sun); }
.sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.flow { display: block; width: 100%; height: auto; overflow: visible; }
.flow text { font-family: var(--font); font-size: 11px; }
.flow__node { fill: none; stroke-width: 1.2; }
.flow__line { fill: none; stroke-width: 1.4; stroke-dasharray: 4 7; animation: flow var(--speed, 1.5s) linear infinite; }
.flow__line.is-idle { opacity: 0.15; animation: none; }
@keyframes flow { to { stroke-dashoffset: -22; } }

.sun { color: var(--sun); stroke: var(--sun); }
.ice { color: var(--ice); stroke: var(--ice); }

.phases { display: grid; grid-template-columns: 28px 1fr 72px; gap: 8px; align-items: center; font-size: 12px; }
.bar { position: relative; height: 6px; border: 1px solid var(--frame); }
.bar > span { position: absolute; inset: 0 auto 0 0; background: var(--ice); box-shadow: var(--glow-ice); transition: width 0.6s ease; }
.bar--sun { border-color: rgba(255, 154, 60, 0.6); }
.bar--sun > span { background: var(--sun); box-shadow: var(--glow-sun); }
.num { text-align: right; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }

.empty { color: var(--muted); font-size: 12px; }

.seg { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.seg button {
    flex: 1;
    padding: 6px 4px;
    font: 400 11px var(--font);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    background: transparent;
    border: 1px solid var(--frame);
    cursor: pointer;
}
.seg button[aria-selected='true'] { color: var(--bg); background: var(--ice); border-color: var(--ice); box-shadow: var(--glow-ice); }
.seg button:focus-visible { outline: 1px solid var(--ice); outline-offset: 2px; }

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.totals .value { font-size: 18px; }
.note { margin: 10px 0 0; font-size: 11px; color: var(--warn); }
.compare { margin: 10px 0 0; font-size: 11px; color: var(--ice-soft); }
.chart { width: 100%; height: 220px; margin-top: 8px; }
.chart--tall { height: min(60vh, 460px); }
.window { margin: 6px 0 0; font-size: 12px; color: var(--ice-soft); text-align: center; }
.seg button[aria-pressed='true'] { color: var(--bg); background: var(--ice); border-color: var(--ice); box-shadow: var(--glow-ice); }
.period-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 6px; }
.period-nav__label { color: var(--ice); font-size: 13px; letter-spacing: 0.04em; text-align: center; }
.hint { margin: 8px 0 0; text-align: center; }
.chart--calendar { height: 790px; }
.seg--wrap { flex-wrap: wrap; }
.seg--grid { display: grid; grid-template-columns: 1fr 1fr; }
.compare-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.compare-table th, .compare-table td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--frame-dim); font-weight: 400; }
.compare-table thead th { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.compare-table tbody th { text-align: left; color: var(--muted); }
.compare-table td.up { color: var(--sun-soft); }
.compare-table td.down { color: var(--ice); }
.year-nav { display: inline-flex; align-items: center; gap: 8px; color: var(--ice); }
.year-nav .ghost { padding: 2px 8px; }
.ghost:disabled { opacity: 0.3; cursor: default; }
.day { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--frame-dim); }
.day__link { display: inline-block; margin-top: 10px; text-decoration: none; }
.ghost {
    padding: 6px 10px;
    font: 400 11px var(--font);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ice);
    background: transparent;
    border: 1px solid var(--frame);
    cursor: pointer;
}
.legend { display: flex; gap: 16px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 2px; background: var(--ice); box-shadow: var(--glow-ice); }
.swatch--sun { background: var(--sun); box-shadow: var(--glow-sun); }

.tabbar {
    position: fixed;
    inset: auto 0 0 0;
    display: flex;
    justify-content: space-around;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 8px 0 env(safe-area-inset-bottom);
    background: rgba(5, 10, 14, 0.94);
    border-top: 1px solid var(--frame-dim);
    backdrop-filter: blur(6px);
}

.tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 64px;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--muted);
}

.tabbar a[aria-current='page'] { color: var(--ice); text-shadow: var(--glow-ice); }
.tabbar svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.tabbar a[aria-current='page'] svg { filter: drop-shadow(0 0 4px rgba(111, 227, 255, 0.6)); }

@media (min-width: 900px) {
    .app { max-width: 1040px; display: grid; grid-template-columns: 1fr 1fr; column-gap: 16px; align-content: start; }
    .app > .topbar, .app > .span-2 { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
    .flow__line { animation: none; }
}

.money-table td small { display: block; font-size: 10px; color: var(--muted); }
.money-table__total th, .money-table__total td { color: var(--ice); border-bottom: 0; }
.money-diff { margin: 8px 0 0; font-size: 12px; text-align: right; color: var(--ice); }
.money-diff.is-worse { color: var(--sun-soft); }
.money-fixed { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--frame-dim); }

:root { --gas: #c3a6ff; --glow-gas: 0 0 8px rgba(195, 166, 255, 0.45); }
.value--gas { color: var(--gas); text-shadow: var(--glow-gas); }
.swatch--gas { background: var(--gas); box-shadow: var(--glow-gas); }
.gas-now { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.gas-now .value { font-size: 20px; }
.heating-result { margin: 8px 0 0; font-size: 12px; color: var(--ice-soft); text-align: center; }
.gas-now .is-on { color: var(--gas); }
.seg--grid button:last-child:nth-child(odd) { grid-column: span 2; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.fields span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.fields input {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    font: 400 14px var(--font);
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--frame);
    border-radius: var(--radius-button);
}
.fields input:focus-visible { outline: 1px solid var(--ice); outline-offset: 1px; }
.fields input:invalid { border-color: var(--warn); }
.swatch--muted { background: var(--muted); box-shadow: none; }

/* Login, authenticator and account pages */
.auth { max-width: 420px; width: 100%; justify-self: center; margin-top: 8vh; }
.auth__notice { margin: 0 0 10px; font-size: 12px; color: var(--ok); }
.fields--stack { grid-template-columns: 1fr; margin-top: 8px; }
.fields--stack label { font-size: 12px; }
/* Empty required fields are not an error until the user has typed something. */
.fields--stack input:invalid { border-color: var(--frame); }
.fields--stack input:user-invalid { border-color: var(--warn); }
.btn {
    margin-top: 4px;
    padding: 9px 12px;
    font: 500 12px var(--font);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--bg);
    background: var(--ice);
    border: 1px solid var(--ice);
    border-radius: var(--radius-button);
    box-shadow: var(--glow-ice);
    cursor: pointer;
}
.btn:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; }
.qr { display: flex; justify-content: center; margin: 14px 0 4px; }
.qr a { display: block; padding: 8px; background: #fff; border-radius: var(--radius-button); line-height: 0; }
.qr svg { width: 200px; height: 200px; }
.qr__secret { color: var(--ice); letter-spacing: 0.08em; word-break: break-all; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.account-actions .ghost { text-decoration: none; }
.ghost--warn { color: var(--warn); border-color: var(--warn); }
