:root {
    --bg: #f5f1e8;
    --surface: #fffdf8;
    --ink: #1f2a24;
    --muted: #6b726c;
    --line: #e2dccd;
    --accent: #2f5d50;
    --accent-ink: #fff;
    --weekend: #efe9dc;
    --out: #b3b0a6;
    --danger: #b3261e;
    --radius: 10px;
    --bar: 1.35rem;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161a17;
        --surface: #1e2420;
        --ink: #e8e6df;
        --muted: #9aa19b;
        --line: #2e3530;
        --accent: #7fb8a4;
        --accent-ink: #10201a;
        --weekend: #1a201c;
        --out: #59605a;
        --danger: #f2827a;
    }
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.4; }
h1, h2, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.logo { width: 2.4rem; height: auto; color: var(--accent); flex: none; }

/* ---- Buttons ---- */
.btn {
    border: 1px solid transparent; border-radius: 999px;
    padding: 0.5rem 1rem; min-height: 2.5rem; font-weight: 600; background: none;
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { border-color: var(--line); color: var(--muted); }
.btn--danger { color: var(--danger); border-color: currentColor; margin-right: auto; }
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible, .seg:focus-visible, .day__num:focus-visible, .trip:focus-visible, .month__nav:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---- Top bar ---- */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    max-width: 60rem; margin: 0 auto; padding: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.25rem; color: inherit; text-decoration: none; }
.topbar__actions { display: flex; gap: 0.5rem; }
.topbar__actions form { margin: 0; }

.page { max-width: 60rem; margin: 0 auto; padding: 0 1rem 3rem; display: flex; flex-direction: column; gap: 1.5rem; }

/* ---- Month ---- */
.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.month__head { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem; }
.month__head h1 { font-size: 1.3rem; }
.month__nav {
    display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: 999px;
    color: var(--ink); text-decoration: none; font-size: 1.6rem; line-height: 1;
}
.month__nav:hover { background: var(--weekend); }

.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.dow {
    padding: 0.35rem 0.5rem; font-size: 0.75rem; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.05em; border-top: 1px solid var(--line);
}
.day {
    position: relative; min-height: 4.75rem; padding: 0.3rem 0 0.4rem;
    border-top: 1px solid var(--line); border-left: 1px solid var(--line);
}
.day:nth-child(7n + 1) { border-left: none; }
.day--we, .dow--we { background: var(--weekend); }
.day--out { color: var(--out); }

.day__num {
    border: none; background: none; padding: 0 0.45rem; font-size: 0.85rem; font-weight: 600;
    color: inherit; text-align: left; display: block; min-height: 1.5rem;
}
/* Stretch the tap target over the whole cell. The track comes later in the
   DOM, so its bars sit above it without a z-index; a z-index on .track would
   make each day a stacking context and cut off names that run on. */
.day__num::after { content: ""; position: absolute; inset: 0; }
.day__num:hover::after { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.day--today .day__num { color: var(--accent); }
.day--today .day__num::before {
    content: ""; position: absolute; top: 0.25rem; left: 0.2rem; width: 1.6rem; height: 1.6rem;
    border-radius: 999px; border: 2px solid var(--accent); pointer-events: none;
}

.track { position: relative; display: flex; gap: 2px; margin-top: 0.35rem; pointer-events: none; }
.gap { flex: 1; }
.seg {
    flex: 1; min-width: 0; height: var(--bar); padding: 0; border: none; border-radius: 0;
    background: var(--c); pointer-events: auto; text-align: left; position: relative;
}
.seg--start { border-top-left-radius: 999px; border-bottom-left-radius: 999px; margin-left: 2px; }
.seg--end { border-top-right-radius: 999px; border-bottom-right-radius: 999px; margin-right: 2px; }
.day--out .seg { opacity: 0.55; }
/* The name may run on over the following days of the same week. */
.seg__label {
    position: absolute; left: 0.45rem; top: 50%; transform: translateY(-50%); z-index: 2;
    white-space: nowrap; font-size: 0.75rem; font-weight: 700; color: #fff;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.55), 0 1px 1px rgba(0, 0, 0, 0.35); pointer-events: none;
}

/* ---- Legend ---- */
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; color: var(--muted); font-size: 0.9rem; }
.legend li { display: flex; align-items: center; gap: 0.4rem; }
.legend li::before { content: ""; width: 0.8rem; height: 0.8rem; border-radius: 999px; background: var(--c); }

/* ---- Upcoming ---- */
.upcoming h2 { font-size: 1.05rem; margin-bottom: 0.6rem; }
.trips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.trip {
    width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 0.25rem 1rem;
    text-align: left; padding: 0.7rem 0.9rem; background: var(--surface);
    border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: var(--radius);
}
.trip:hover { border-color: var(--c); }
.trip__who { font-weight: 700; }
.trip__when { font-variant-numeric: tabular-nums; }
.trip__len { color: var(--muted); font-size: 0.9rem; }
.trip__len strong { color: var(--accent); }
.empty { color: var(--muted); }

/* ---- Dialog + form ---- */
dialog {
    width: min(28rem, calc(100vw - 2rem)); padding: 0; border: none; border-radius: 14px;
    background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(20, 26, 22, 0.45); }
.form { display: flex; flex-direction: column; gap: 1rem; padding: 1.25rem; }
.form h2 { font-size: 1.2rem; }
.who { border: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.who legend { padding: 0; margin-bottom: 0.5rem; font-weight: 600; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick span {
    display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.4rem 0.8rem;
    border: 2px solid var(--line); border-radius: 999px; cursor: pointer;
}
.pick span::before { content: ""; width: 0.75rem; height: 0.75rem; border-radius: 999px; background: var(--c); }
.pick input:checked + span { border-color: var(--c); background: color-mix(in srgb, var(--c) 15%, transparent); font-weight: 600; }
.pick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.dates label, .login__form label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
input[type="date"], .login__form input {
    width: 100%; min-width: 0; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 8px;
    background: var(--bg); font-size: 1rem; font-weight: 400;
}
.hint { color: var(--muted); font-size: 0.85rem; }
.form__actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }
.alert {
    padding: 0.6rem 0.8rem; border-radius: 8px; color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

/* ---- Login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login__card {
    width: min(22rem, 100%); padding: 2rem 1.5rem; background: var(--surface);
    border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; gap: 0.75rem;
}
.login__card .logo { width: 4rem; }
.login__sub { color: var(--muted); margin-bottom: 0.5rem; }
.login__form { display: flex; flex-direction: column; gap: 0.9rem; }
.login__form .btn { margin-top: 0.4rem; }

/* ---- Small screens ---- */
@media (max-width: 40rem) {
    :root { --bar: 1.05rem; }
    .topbar { padding: 0.75rem 1rem; }
    .brand span { display: none; }
    .day { min-height: 3.6rem; }
    .day__num { font-size: 0.8rem; padding: 0 0.3rem; }
    .seg__label { font-size: 0.65rem; left: 0.3rem; }
    .trip { grid-template-columns: 1fr auto; }
    .trip__when { grid-column: 1 / -1; grid-row: 2; }
}
