:root {
    color-scheme: light;
    --bg: #efeae1;
    --ink: #1b1916;
    --muted: #6e675e;
    --card: #fbf8f3;
    --line: #e2d9cc;
    --green: #0e6b4f;
    --clay: #c24e2a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.45 "Avenir Next", "Segoe UI", sans-serif;
}

.top, main {
    width: min(1040px, calc(100% - 32px));
    margin: 0 auto;
}

.top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 28px 0 8px;
}

.brand {
    color: inherit;
    font-family: Palatino, "Iowan Old Style", Georgia, serif;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.03em;
    text-decoration: none;
}

.top p, .meta, .hint, .empty, .axis {
    color: var(--muted);
}

.top p, .hint, .empty { margin: 0; }

.session {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

.session a,
.session button.text {
    color: var(--ink);
    font-size: 14px;
    text-decoration: none;
}

form.login {
    max-width: 420px;
    margin-top: 16px;
}

.personal { margin-top: 16px; }

.personal a {
    color: var(--ink);
    overflow-wrap: anywhere;
}

.status {
    margin: 16px 0 0;
    padding: 10px 12px;
    background: #e5f3ec;
    color: var(--green);
    border-radius: 10px;
}

.stats, .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.grid > .card:only-child {
    grid-column: 1 / -1;
}

.stats { grid-template-columns: repeat(3, 1fr); }

.stats article, .card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
}

h2 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 650;
}

.figure {
    margin: 0;
    font-family: Palatino, Georgia, serif;
    font-size: 42px;
    letter-spacing: -0.03em;
}

.figure span, .log strong {
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    font-size: 14px;
    font-weight: 600;
}

.meta { margin: 8px 0 0; }

form.card {
    display: grid;
    align-content: start;
    gap: 10px;
}

label {
    display: grid;
    gap: 6px;
    font-size: 14px;
}

input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
    color: var(--ink);
    font: inherit;
}

button {
    width: fit-content;
    justify-self: start;
    border: 0;
    border-radius: 999px;
    padding: 10px 16px;
    background: var(--ink);
    color: white;
    font: inherit;
    cursor: pointer;
}

button.text {
    padding: 0;
    background: transparent;
    color: var(--clay);
}

.error {
    margin: 0;
    color: var(--clay);
    font-size: 14px;
}

svg {
    width: 100%;
    height: auto;
    display: block;
}

.axis { font-size: 12px; }

.log {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
}

.log li {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 12px;
    align-items: center;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

.log .actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
}

.log form.quantity {
    display: flex;
    gap: 6px;
    align-items: center;
}

.log form.quantity input {
    width: 4.5rem;
    padding: 6px 8px;
}

.log form.quantity button { padding: 6px 12px; }

.body-fat-log {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.body-fat-log h3 {
    margin: 0;
    font-size: 15px;
}

.body-fat-log .log li { grid-template-columns: 1fr auto; }

.log small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.lookup {
    position: relative;
    z-index: 4;
}

#barcode-dialog {
    width: min(420px, calc(100% - 32px));
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
    color: var(--ink);
}

#barcode-dialog::backdrop { background: rgba(27, 25, 22, 0.45); }

#barcode-video {
    display: block;
    width: 100%;
    max-height: 55vh;
    border-radius: 12px;
    background: #111;
    object-fit: cover;
}

#barcode-dialog .hint { margin: 10px 0; }

#barcode-dialog label { margin-top: 8px; }

.barcode-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 12px;
}

.lookup:focus-within { z-index: 8; }

.results {
    position: absolute;
    z-index: 5;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    margin: 0;
    padding: 4px;
    list-style: none;
    background: white;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(27, 25, 22, 0.12);
    max-height: 260px;
    overflow: auto;
}

.results button {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    background: transparent;
    color: var(--ink);
    text-align: left;
}

.results button:hover { background: var(--bg); }

.results small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.macro-fields {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

main { padding-bottom: 40px; }

.plan { margin-top: 16px; }

.steps { margin-top: 16px; }

.step-nav {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-top: 8px;
}

.step-nav a {
    color: var(--ink);
    font-size: 14px;
    text-decoration: none;
}

.step-nav .meta { margin: 0; }

.step-month {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    margin-top: 16px;
}

.step-head {
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.step-day {
    display: grid;
    gap: 6px;
    align-content: start;
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.step-day.today { border-color: var(--ink); }

.step-day span {
    color: var(--muted);
    font-size: 13px;
}

.step-day strong { font-variant-numeric: tabular-nums; }

.steps form {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.steps form .step-month { margin-top: 0; }

.step-day input { padding: 6px 8px; }

.facts {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.facts span, .facts p {
    color: var(--muted);
    font-size: 14px;
}

.facts p { margin: 4px 0 0; }

.facts strong {
    display: block;
    margin-top: 4px;
    font-family: Palatino, Georgia, serif;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.plan .hint { margin-top: 16px; }

.reference {
    display: grid;
    grid-template-columns: 1.3fr 0.9fr 1fr;
    gap: 28px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.reference h3 {
    margin: 0 0 8px;
    font-size: 15px;
}

.reference strong {
    display: block;
    font-family: Palatino, Georgia, serif;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.03em;
}

.reference p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.reference table {
    width: 100%;
    margin-top: 12px;
    border-collapse: collapse;
    font-size: 14px;
}

.reference td {
    padding: 7px 0;
    border-top: 1px solid var(--line);
}

.reference td:last-child { text-align: right; }

.reference tr.current td { font-weight: 700; }

.profile {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: start;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.profile > label {
    min-width: 0;
    align-items: start;
}

.profile input:not([type="range"]),
.profile select {
    height: 42px;
    min-width: 0;
    max-width: 100%;
}

.profile button { align-self: end; }

.deficit {
    display: grid;
    grid-column: 1 / -1;
    gap: 8px;
    font-size: 14px;
}

.deficit-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.deficit-heading label { font-size: 14px; }

.deficit-heading strong { font-variant-numeric: tabular-nums; }

.profile input[type="range"] {
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    accent-color: var(--green);
}

.body-fat {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.body-fat h3,
.body-fat .hint,
.body-fat .error { grid-column: 1 / -1; }

.body-fat h3 { margin: 0; }

.body-fat button { align-self: end; }

.profile input:disabled,
.profile select:disabled {
    color: var(--ink);
    background: white;
    opacity: 1;
}

.users-wrap { overflow-x: auto; }

.users {
    width: 100%;
    margin-top: 14px;
    border-collapse: collapse;
    font-size: 14px;
}

.users th,
.users td {
    padding: 8px 16px 8px 0;
    border-top: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

.users th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.users td:last-child,
.users th:last-child { padding-right: 0; }

.users a { color: inherit; }

.users .online { color: var(--green); font-weight: 700; }

select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: white;
    color: var(--ink);
    font: inherit;
}

@media (max-width: 760px) {
    .stats, .grid, .facts, .profile, .macro-fields, .reference, .body-fat, .step-month { grid-template-columns: 1fr; }
    .step-head, .step-pad { display: none; }
    .top { display: block; }
}
