:root {
    --red: #e60023;
    --red-dark: #c40020;
    --ink: #111;
    --ink-2: #444;
    --line: #e5e5e5;
    --bg: #f4f4f4;
    --card: #fff;
    --muted: #888;
    --ok: #1e9a53;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

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

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .9rem; }

/* ---------- Hero ---------- */
.hero {
    background: var(--card);
    padding: 24px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    border-bottom: 1px solid var(--line);
}
.hero-title { display: flex; align-items: center; gap: 16px; }
.hero-number {
    font-size: 4rem;
    font-weight: 900;
    color: var(--red);
    letter-spacing: -.03em;
    line-height: .9;
    font-family: "Impact", "Arial Black", sans-serif;
}
.hero-sub { display: flex; flex-direction: column; }
.hero-label { font-weight: 900; letter-spacing: .1em; font-size: 1.2rem; }
.hero-kicker { color: var(--ink-2); font-size: .75rem; letter-spacing: .15em; }

.user-bar { display: flex; gap: 8px; align-items: center; }
#userSelect {
    font: inherit;
    padding: 8px 12px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 6px;
    min-width: 180px;
}

/* ---------- Buttons ---------- */
.btn {
    font: inherit;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    transition: transform .05s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }

/* ---------- Main layout ---------- */
main {
    max-width: 1080px;
    margin: 24px auto;
    padding: 0 24px 64px;
    display: grid;
    gap: 24px;
}
.card {
    background: var(--card);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.card h2 {
    margin: 0 0 12px;
    font-size: 1.1rem;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.card h3 { margin: 20px 0 8px; font-size: .9rem; letter-spacing: .05em; color: var(--ink-2); }

/* ---------- Today card ---------- */
.today-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.today-daylabel {
    font-size: .75rem;
    letter-spacing: .2em;
    color: var(--muted);
    font-weight: 700;
}
.today-target {
    font-size: 3rem;
    font-weight: 900;
    line-height: 1;
    margin-top: 4px;
}
.today-target span:last-child {
    font-size: 1rem;
    font-weight: 500;
    color: var(--ink-2);
    margin-left: 8px;
    text-transform: uppercase;
    letter-spacing: .1em;
}
.today-sessions {
    font-size: .9rem;
    color: var(--red);
    font-weight: 600;
    margin-top: 6px;
}

/* Ring progress */
.ring { position: relative; width: 120px; height: 120px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 10; }
.ring-fg {
    fill: none;
    stroke: var(--red);
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 326.7;
    stroke-dashoffset: 326.7;
    transition: stroke-dashoffset .4s ease;
}
.ring-fg.done { stroke: var(--ok); }
.ring-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    line-height: 1.1;
}
#ringPct { font-size: 1.4rem; font-weight: 800; }
.ring-sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }

.banner {
    background: #e7f6ec;
    color: var(--ok);
    padding: 10px 14px;
    border-radius: 6px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* ---------- Log form ---------- */
.log-form { display: grid; gap: 14px; margin-top: 8px; }
.log-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.log-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: .8rem;
    color: var(--ink-2);
    letter-spacing: .05em;
    text-transform: uppercase;
    font-weight: 600;
}
.log-form input[type=number],
.log-form input[type=text] {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}
.log-form input:focus { outline: 2px solid var(--red); outline-offset: -1px; }

.diff-buttons { display: flex; gap: 8px; }
.diff {
    font: inherit;
    font-size: 1.4rem;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    cursor: pointer;
    transition: all .15s ease;
}
.diff:hover { border-color: var(--red); }
.diff.active {
    border-color: var(--red);
    background: #fff0f2;
    transform: scale(1.05);
}

.entries ul { list-style: none; padding: 0; margin: 0; }
.entries li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    font-size: .95rem;
}
.entries li:last-child { border-bottom: 0; }
.entry-amount { font-weight: 700; }
.entry-meta { color: var(--muted); font-size: .85rem; }
.entry-del {
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
}
.entry-del:hover { color: var(--red); }

/* ---------- 30-day grid ---------- */
.grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-top: 12px;
}
.grid-cell {
    background: #fafafa;
    border: 2px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: all .15s ease;
    position: relative;
    min-height: 92px;
}
.grid-cell:hover { border-color: var(--ink-2); }
.grid-cell.selected { border-color: var(--red); background: #fff0f2; }
.grid-cell.complete { background: #e7f6ec; border-color: var(--ok); }
.grid-cell.complete.selected { background: #d4f0dd; }
.cell-num {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: .7rem;
    color: var(--muted);
    font-weight: 700;
}
.cell-primary { font-size: 1.4rem; font-weight: 800; margin-top: 4px; }
.cell-unit { font-size: .7rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .05em; }
.cell-progress {
    font-size: .75rem;
    color: var(--red);
    margin-top: 6px;
    font-weight: 600;
}
.grid-cell.complete .cell-progress { color: var(--ok); }
.cell-plank .cell-primary { font-size: 1rem; line-height: 1.2; font-weight: 700; }

/* ---------- Leaderboard ---------- */
.board {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}
.board th, .board td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: .95rem;
}
.board th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--ink-2);
    font-weight: 700;
}
.board tr:first-child td:first-child { color: var(--red); font-weight: 800; }
.board .name-cell { display: flex; align-items: center; gap: 8px; }

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
.modal-inner {
    background: #fff;
    padding: 28px;
    border-radius: 12px;
    max-width: 400px;
    width: calc(100% - 32px);
}
.modal-inner h2 { margin-top: 0; }
.modal-inner form { display: grid; gap: 14px; }
.modal-inner label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; }
.modal-inner input {
    font: inherit;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

/* ---------- Footer ---------- */
.foot {
    text-align: center;
    padding: 24px;
    color: var(--muted);
    font-size: .85rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .hero { padding: 16px; flex-direction: column; align-items: flex-start; }
    .hero-number { font-size: 3rem; }
    main { padding: 0 12px 32px; }
    .card { padding: 16px; }
    .grid { grid-template-columns: repeat(3, 1fr); }
    .log-row { grid-template-columns: 1fr; }
    .today-target { font-size: 2.2rem; }
}
