:root {
    --bg: #f3f7fb;
    --fg: #0f1b2a;
    --muted: #5b6b7d;
    --card: #ffffff;
    --border: #d5dfea;
    --deep: #0d47a1;   /* empty part of the circle */
    --water: #1976d2;  /* filled part */
    --water-top: #64b5f6;
    --accent: #1565c0;
    --error: #c62828;
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1420;
        --fg: #e6eef7;
        --muted: #93a4b8;
        --card: #142233;
        --border: #24384f;
        --deep: #0a2f66;
        --water: #1e74d0;
        --water-top: #5aa9f0;
        --accent: #64b5f6;
        --error: #ef9a9a;
    }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: grid;
    grid-template-rows: auto 1fr auto;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    -webkit-tap-highlight-color: transparent;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 0;
}
h1 { font-size: 1.1rem; font-weight: 600; margin: 0; }

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
}

.circle {
    position: relative;
    width: min(72vw, 52vh, 340px);
    aspect-ratio: 1;
    border-radius: 50%;
    border: 0;
    padding: 0;
    overflow: hidden;
    background: var(--deep);
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    box-shadow: 0 12px 32px rgb(13 71 161 / 0.28);
    transition: transform 120ms ease;
}
.circle:active { transform: scale(0.97); }
.circle:focus-visible { outline: 4px solid var(--water-top); outline-offset: 6px; }
.circle:disabled { cursor: progress; }

.water {
    position: absolute;
    inset: auto 0 0 0;
    height: 0%;
    background: var(--water);
    border-top: 3px solid var(--water-top);
    transition: height 600ms cubic-bezier(.2,.8,.2,1);
}
.circle.goal-reached .water { border-top-color: transparent; }

.label {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
}
.count { font-size: clamp(3rem, 16vw, 5.5rem); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.unit { font-size: 1.15rem; margin-top: 4px; }
.hint { font-size: 0.85rem; opacity: 0.8; margin-top: 10px; }

.circle.bump { animation: bump 380ms ease; }
@keyframes bump {
    0% { transform: scale(1); }
    35% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.summary { font-size: 1.25rem; margin: 20px 0 0; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }

footer { display: flex; justify-content: center; gap: 8px; padding: 0 16px 24px; }

.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.chip {
    padding: 12px 4px; border-radius: 10px; cursor: pointer;
    border: 1px solid var(--border); background: var(--bg); color: var(--fg);
    font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--accent); }
.chip:active { background: var(--border); }

button { font: inherit; }
.icon-button {
    background: none; border: 0; color: var(--muted);
    width: 44px; height: 44px; border-radius: 50%;
    display: grid; place-items: center; cursor: pointer;
}
.icon-button:hover { background: var(--border); }
.text-button {
    background: none; border: 0; color: var(--accent);
    padding: 10px 16px; border-radius: 8px; cursor: pointer;
}
.text-button:disabled { color: var(--muted); opacity: 0.5; cursor: default; }
.text-button:not(:disabled):hover { background: var(--border); }
.primary {
    background: var(--accent); color: #fff; border: 0;
    padding: 10px 20px; border-radius: 8px; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .primary { color: #0b1420; } }

dialog {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    color: var(--fg);
    width: min(92vw, 360px);
    padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { margin: 0 0 16px; font-size: 1.15rem; }
dialog label { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
input[type=number] {
    width: 96px; padding: 8px 10px; font: inherit; text-align: right;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--fg);
}
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.error { color: var(--error); min-height: 1.2em; margin: 4px 0 0; font-size: 0.9rem; }

.toast {
    position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(20px);
    background: var(--fg); color: var(--bg);
    padding: 10px 16px; border-radius: 8px;
    opacity: 0; pointer-events: none;
    transition: opacity 200ms, transform 200ms;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Login page */
.login { display: grid; place-items: center; }
.login form {
    background: var(--card); border: 1px solid var(--border); border-radius: 14px;
    padding: 24px; width: min(92vw, 340px); display: grid; gap: 12px;
}
.login h1 { font-size: 1.3rem; display: flex; align-items: center; gap: 10px; }
.login input[type=password] {
    padding: 10px 12px; font: inherit;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--fg);
}

@media (prefers-reduced-motion: reduce) {
    .water, .circle, .toast { transition: none; }
    .circle.bump { animation: none; }
}
