/* Your Life in Weeks
   Day and night. Light mode is overcast daylight, dark mode is night.
   Ink is what's lived, pale cells are what's ahead, amber is the week you're in. */

:root {
    color-scheme: light;
    --bg: #EEF0F2;
    --surface: #F8F9FA;
    --ink: #121A24;
    --muted: #5B6673;
    --line: #C9D0D7;
    --cell: #D9DEE3;
    --now: #E6A523;
    --now-soft: rgba(230, 165, 35, 0.4);

    --serif: "Newsreader", Georgia, "Times New Roman", serif;
    --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

    --gap: clamp(1px, 0.35vw, 3px);
    --label-w: clamp(16px, 3.2vw, 30px);
    --measure: 58ch;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0B1017;
        --surface: #131A23;
        --ink: #E7EBEF;
        --muted: #8C98A5;
        --line: #27313C;
        --cell: #1B232D;
        --now: #F3BC42;
        --now-soft: rgba(243, 188, 66, 0.4);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0B1017;
    --surface: #131A23;
    --ink: #E7EBEF;
    --muted: #8C98A5;
    --line: #27313C;
    --cell: #1B232D;
    --now: #F3BC42;
    --now-soft: rgba(243, 188, 66, 0.4);
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 1.0625rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.16em;
}

:focus-visible {
    outline: 2px solid var(--now);
    outline-offset: 2px;
}

.wrap {
    max-width: 920px;
    margin: 0 auto;
    padding-left: 16px;
    padding-right: 16px;
}

/* ---------- header ---------- */

.site-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding-top: 20px;
    padding-bottom: 6px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    display: grid;
    place-items: center;
    padding: 0;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s;
}

.icon-btn:hover { border-color: var(--muted); }
.icon-btn svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle[data-mode="dark"] .icon-sun { display: block; }
.theme-toggle[data-mode="dark"] .icon-moon { display: none; }

/* ---------- hero ---------- */

.hero {
    padding: 36px 0 18px;
    max-width: var(--measure);
}

h1 {
    font-weight: 400;
    font-size: clamp(2.375rem, 6vw, 3.75rem);
    line-height: 1.02;
    letter-spacing: -0.015em;
    margin: 0 0 0.45em;
    font-variation-settings: "opsz" 72;
}

.lede {
    margin: 0;
    color: var(--muted);
    font-size: 1.1875rem;
}

/* ---------- controls ---------- */

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 14px 22px;
    align-items: flex-end;
    padding: 22px 0 6px;
    font-family: var(--sans);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    border: 0;
    padding: 0;
    margin: 0;
    min-width: 0;
}

.field > label,
.field > legend {
    font-size: 0.75rem;
    color: var(--muted);
    padding: 0;
}

input[type="date"] {
    font: inherit;
    font-size: 0.9375rem;
    padding: 8px 12px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
}

.seg-options {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    overflow: hidden;
}

.seg-options label {
    position: relative;
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.9375rem;
    border-left: 1px solid var(--line);
    cursor: pointer;
    white-space: nowrap;
}

.seg-options label:first-child { border-left: 0; }

.seg-options input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.seg-options small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.seg-options label:has(:checked) {
    background: var(--ink);
    color: var(--bg);
}

.seg-options label:has(:focus-visible) {
    outline: 2px solid var(--now);
    outline-offset: -2px;
}

.actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.btn {
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    min-height: 40px;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--bg);
    cursor: pointer;
}

.btn:hover { opacity: 0.88; }

.btn-text {
    font: inherit;
    font-size: 0.9375rem;
    padding: 8px 2px;
    border: 0;
    background: none;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 0.16em;
    cursor: pointer;
}

.btn-text:hover { color: var(--ink); }

.message {
    font-family: var(--sans);
    font-size: 0.9375rem;
    margin: 8px 0 0;
}

.message:empty { display: none; }

/* ---------- result ---------- */

.result { padding: 26px 0 8px; }
.result[hidden] { display: none; }

.stat {
    margin: 0;
    font-weight: 400;
    font-size: clamp(1.625rem, 4.2vw, 2.5rem);
    line-height: 1.15;
    letter-spacing: -0.01em;
    font-variant-numeric: lining-nums tabular-nums;
    font-variation-settings: "opsz" 48;
}

.sub {
    margin: 8px 0 0;
    max-width: var(--measure);
    color: var(--muted);
    font-variant-numeric: lining-nums;
}

.bar {
    height: 6px;
    max-width: 560px;
    margin: 20px 0 8px;
    border-radius: 3px;
    background: var(--cell);
    overflow: hidden;
}

.bar > i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 3px;
    background: var(--ink);
    transition: width 1.1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.bar-label {
    margin: 0;
    font-family: var(--sans);
    font-size: 0.8125rem;
    color: var(--muted);
}

.share {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--sans);
    font-size: 0.875rem;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
}

.btn-ghost:hover { border-color: var(--muted); }
.btn-ghost svg { width: 14px; height: 14px; }

/* ---------- the grid ---------- */

.chart { padding: 28px 0 52px; }

.axis {
    margin: 0 0 12px;
    font-family: var(--sans);
    font-size: 0.8125rem;
    color: var(--muted);
}

.grid {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.row {
    display: grid;
    grid-template-columns: var(--label-w) repeat(52, 1fr);
    gap: var(--gap);
    align-items: center;
}

.row.decade { margin-top: calc(var(--gap) * 3 + 2px); }
.row.hdr { margin-bottom: 2px; }

.lbl,
.wk {
    font-family: var(--sans);
    font-size: 10px;
    line-height: 1;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.lbl { text-align: right; padding-right: 5px; }
.wk { text-align: center; white-space: nowrap; }

.c {
    aspect-ratio: 1;
    border-radius: 1px;
    background: var(--cell);
    transition: background-color 0.35s ease;
}

.c.lived { background: var(--ink); }

.c.now {
    background: var(--now);
    animation: pulse 2.4s ease-in-out infinite;
}

.c.beyond.lived { background: var(--now); opacity: 0.55; }
.c.beyond.now { opacity: 1; }

/* Before the pour-in: lived cells look empty, then transition row by row. */
.grid.pending .c.lived,
.grid.pending .c.now { background: var(--cell); }
.grid.filling .c { transition-delay: calc(var(--r) * 12ms); }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--now-soft); }
    50% { box-shadow: 0 0 0 4px var(--now-soft); }
}

/* ---------- tooltip ---------- */

.tip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
    pointer-events: none;
    font-family: var(--sans);
    font-size: 0.75rem;
    line-height: 1.4;
    padding: 6px 9px;
    border-radius: 4px;
    background: var(--ink);
    color: var(--bg);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.12s;
}

.tip.show { opacity: 1; }
.tip b { font-weight: 600; }

/* ---------- footer ---------- */

.site-footer {
    border-top: 1px solid var(--line);
    padding-top: 22px;
    padding-bottom: 44px;
    font-family: var(--sans);
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--muted);
    text-align: center;
}

.site-footer p {
    margin: 0 0 10px;
}

/* ---------- motion and small screens ---------- */

@media (prefers-reduced-motion: reduce) {
    .c, .bar > i, .tip { transition: none; }
    .grid.filling .c { transition-delay: 0s; }
    .c.now { animation: none; box-shadow: 0 0 0 2px var(--now-soft); }
}

@media (max-width: 480px) {
    .hero { padding-top: 24px; }
    .controls { gap: 12px 16px; }
    .seg-options label { padding: 8px 10px; font-size: 0.875rem; }
    .seg-options small { display: none; }
    .lbl, .wk { font-size: 9px; }
    .chart { padding-bottom: 36px; }
}
