:root {
  --bg: #0b0f14; --card: #141b23; --line: #233040; --fg: #e8eef5; --dim: #8597a8; --accent: #4fd1c5; --warn: #f6ad55;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
body { min-height: 100dvh; }
#app { max-width: 520px; margin: 0 auto; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 96px); }
button { font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-height: 48px; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.4; }
button.primary { background: var(--accent); border-color: var(--accent); color: #062420; font-weight: 700; }
button.subtle { background: transparent; color: var(--dim); }
button.link { background: none; border: 0; color: var(--accent); padding: 6px 0; min-height: 0; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
button.wide { width: 100%; margin-top: 12px; }
button.big { font-size: 1.1rem; }
input, select { font: inherit; color: var(--fg); background: #0f151c; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 46px; min-width: 0; }
input[type="time"] { min-width: 0; }
h1, h2, h3 { margin: 0.2em 0 0.4em; }
h2 { font-size: 1.25rem; }
h3 { color: var(--dim); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 24px; }
.small { font-size: 0.85rem; color: var(--dim); }
.hint { margin-top: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; margin-top: 12px; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row > * { flex: 1; }
.col { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chips button { flex: 1 0 auto; min-width: 64px; }
.dot, i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; flex: none; }
.seg { display: inline-flex; background: #0f151c; border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { min-height: 36px; padding: 6px 12px; border: 0; background: transparent; color: var(--dim); border-radius: 9px; font-size: 0.9rem; }
.seg button.on { background: var(--card); color: var(--fg); }

/* top bar */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.date { font-weight: 700; font-size: 1.15rem; }
.kl { color: var(--dim); font-variant-numeric: tabular-nums; }
.kl span { font-size: 0.7rem; letter-spacing: 0.08em; opacity: 0.7; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 600; background: rgba(79, 209, 197, 0.12); color: var(--accent); white-space: nowrap; }
.pill.behind { background: rgba(246, 173, 85, 0.12); color: var(--warn); }

/* the ring */
.ring-wrap { position: relative; width: min(300px, 80vw); aspect-ratio: 1; margin: 10px auto 0; }
.ring { width: 100%; height: 100%; }
.ring .track { fill: none; stroke: #18222d; stroke-width: 14; }
.ring .arc { fill: none; stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset 0.9s linear; }
.ring-in { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 40px; }
.bucket { font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 700; }
.name { font-size: 1.1rem; font-weight: 600; margin-top: 2px; }
.left { font-size: clamp(2.6rem, 13vw, 3.6rem); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.1; margin-top: 4px; }
.until { color: var(--dim); font-size: 0.9rem; }
.note { text-align: center; color: var(--dim); margin: 6px 12px 0; font-size: 0.92rem; }
.controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.controls button { padding: 10px 4px; font-size: 0.92rem; }
.quota .controls { grid-template-columns: repeat(3, 1fr); }
.next { display: flex; align-items: center; gap: 4px; }
.next > div:nth-child(2) { flex: 1; }
.lbl { font-size: 0.75rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.when { text-align: right; font-weight: 600; }
.when small { display: block; font-weight: 400; color: var(--dim); }

/* quota */
.quota { border-color: rgba(79, 209, 197, 0.35); }
.quota.paid { border-color: rgba(139, 147, 255, 0.35); }
.q-head { display: flex; justify-content: space-between; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.q-left { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.q-sub { color: var(--dim); font-size: 0.88rem; }

/* banners */
#banners { position: sticky; top: calc(var(--safe-t) + 6px); z-index: 20; }
#banners.floating { position: fixed; left: 12px; right: 12px; top: calc(var(--safe-t) + 8px); max-width: 500px; margin: 0 auto; }
.banner { position: relative; background: #1b2834; border: 1px solid var(--accent); border-radius: 16px; padding: 12px 44px 12px 14px; margin-bottom: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); animation: drop 0.25s ease-out; }
.banner.checkin { border-color: var(--warn); }
.banner.msg { border-color: var(--line); }
.b-t { font-weight: 700; }
.b-b { color: #c3d0dc; font-size: 0.92rem; margin-top: 2px; }
.b-x { position: absolute; top: 6px; right: 6px; min-height: 0; padding: 6px 10px; background: none; border: 0; color: var(--dim); }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: rgba(11, 15, 20, 0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding: 6px 8px calc(var(--safe-b) + 6px); z-index: 10; }
.tabs button { background: none; border: 0; color: var(--dim); display: flex; flex-direction: column; align-items: center; gap: 0; font-size: 0.72rem; min-height: 52px; padding: 4px; }
.tabs button span { font-size: 1.3rem; line-height: 1.2; }
.tabs button.on { color: var(--fg); }
body.offline .tabs { border-top-color: rgba(246, 173, 85, 0.5); }

/* sheets */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 30; display: flex; align-items: flex-end; opacity: 0; transition: opacity 0.2s; }
.sheet-bg.open { opacity: 1; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow-y: auto; background: #111820; border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0; padding: 8px 18px calc(var(--safe-b) + 18px); transform: translateY(30px); transition: transform 0.2s; }
.sheet-bg.open .sheet { transform: none; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: #2c3a48; margin: 4px auto 10px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: center; margin: 6px 0; }
.stepper button { width: 64px; height: 64px; font-size: 1.6rem; border-radius: 50%; }
.stepper .big { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.notes { margin: 12px 0 6px; padding-left: 18px; color: #c3d0dc; font-size: 0.92rem; }
.diff { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-top: 6px; }
.diff td { padding: 6px 4px; border-bottom: 1px solid #1c2631; white-space: nowrap; }
.diff td:first-child { white-space: normal; }
.diff tr:not(.moved) { color: var(--dim); }
.diff tr.moved td:nth-child(2) { color: var(--accent); }
.diff tr.gone { color: var(--warn); }
.diff s, .totals-mini s, .tot s { color: var(--dim); font-size: 0.8em; }
.totals-mini { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.85rem; margin-top: 12px; color: #c3d0dc; }

/* day */
.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { display: grid; grid-template-columns: 74px 5px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid #18222d; cursor: pointer; }
.timeline li.past { opacity: 0.6; }
.timeline li.cur { opacity: 1; background: linear-gradient(90deg, rgba(79, 209, 197, 0.08), transparent); border-radius: 12px; }
.timeline .t { font-variant-numeric: tabular-nums; font-size: 0.9rem; text-align: right; }
.timeline .t small { display: block; color: var(--dim); }
.timeline .bar { border-radius: 3px; }
.timeline .nm { font-weight: 600; }
.timeline .meta { font-size: 0.85rem; color: var(--dim); }
.timeline .meta b { color: var(--fg); font-weight: 600; }

/* totals */
.bk { margin: 10px 0; }
.bk-h { display: flex; justify-content: space-between; font-size: 0.95rem; }
.bk-h small, .tot small { color: var(--dim); }
.bk-bar { position: relative; height: 10px; border-radius: 5px; background: #0f151c; margin-top: 6px; overflow: hidden; }
.bk-bar .plan { position: absolute; inset: 0 auto 0 0; background: #223042; border-radius: 5px; }
.bk-bar .act { position: absolute; inset: 0 auto 0 0; border-radius: 5px; opacity: 0.9; }
.hist { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.hist th { font-weight: 500; color: var(--dim); text-align: right; padding: 4px 2px; }
.hist th i { margin-right: 3px; width: 7px; height: 7px; }
.hist td { text-align: right; padding: 6px 2px; border-bottom: 1px solid #18222d; }
.hist td:first-child, .hist th:first-child { text-align: left; }
.hist td small { color: var(--dim); }
.hist td.low { color: var(--warn); }

/* edit */
.edit { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.eb { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 14px; padding: 10px; }
.e-name { width: 100%; font-weight: 600; background: transparent; border-color: transparent; padding: 4px 6px; min-height: 36px; }
.e-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; margin-top: 6px; }
.e-row select { grid-column: 1 / 3; }
.e-row .e-del { min-height: 44px; padding: 8px; color: var(--dim); }
.e-meta { font-size: 0.8rem; color: var(--dim); margin: 6px 4px 0; }
.tot { display: flex; justify-content: space-between; padding: 4px 0; }
.problems { color: var(--warn); font-size: 0.9rem; padding-left: 18px; }
.sticky { position: sticky; bottom: calc(var(--safe-b) + 78px); background: var(--bg); padding: 8px 0; }
details summary { cursor: pointer; font-weight: 600; }
details label { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0; font-size: 0.92rem; }
details label input { width: 120px; }
details label.check { justify-content: flex-start; }
details label.check input { width: auto; min-height: 0; }

/* login */
.login { text-align: center; padding-top: 18vh; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.login .err { color: var(--warn); }
.logo-ring { width: 84px; height: 84px; margin: 0 auto 12px; border-radius: 50%; border: 10px solid #18222d; border-top-color: var(--accent); border-right-color: var(--accent); transform: rotate(20deg); }
