:root {
    --paper:   #e9edf0;
    --card:    #fbfcfd;
    --ink:     #16212b;
    --muted:   #6b7a85;
    --rule:    #ccd6dc;
    --signal:  #0e5b62;
    --warm:    #9a4b2c;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    padding: 0 0 4rem;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.45;
}

.wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
}

/* masthead */

header.bar {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    border-bottom: 2px solid var(--ink);
    padding-bottom: .5rem;
    margin-bottom: 1rem;
}

header.bar h1 {
    font-family: var(--mono);
    font-size: .95rem;
    font-weight: 600;
    letter-spacing: .16em;
    text-transform: uppercase;
    margin: 0;
}

header.bar nav a {
    font-family: var(--mono);
    font-size: .75rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    text-decoration: none;
    margin-left: .9rem;
}

header.bar nav a:hover,
header.bar nav a:focus-visible { color: var(--signal); }

/* headline calories */

.headline {
    background: var(--card);
    border: 1px solid var(--rule);
    border-left: 3px solid var(--signal);
    padding: .9rem 1rem;
    margin-bottom: 1px;
}

.headline .k {
    display: block;
    font-family: var(--mono);
    font-size: .62rem;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
}

.headline .v {
    font-family: var(--mono);
    font-size: 2.6rem;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.subline {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    border-top: none;
    margin-bottom: 1.25rem;
}

.subline.one   { grid-template-columns: 1fr; }
.subline.three { grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--rule); margin-bottom: .6rem; }

.subline div { background: var(--card); padding: .5rem .6rem; }

.subline .k {
    display: block;
    font-family: var(--mono);
    font-size: .58rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
}

.subline .v {
    font-family: var(--mono);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.subline .v small { font-size: .68rem; color: var(--muted); }

/* readout strip */

.readout {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--rule);
    border: 1px solid var(--rule);
    margin-bottom: 1.25rem;
}

.readout div {
    background: var(--card);
    padding: .7rem .6rem;
}

.readout .k {
    font-family: var(--mono);
    font-size: .62rem;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--muted);
    display: block;
}

.readout .v {
    font-family: var(--mono);
    font-size: 1.35rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.readout .v small {
    font-size: .68rem;
    color: var(--muted);
    letter-spacing: .06em;
}

/* entry box */

form.entry { margin-bottom: 1.5rem; }

form.entry .row { display: flex; gap: .5rem; }

input[type=text], input[type=password], select {
    flex: 1;
    min-width: 0;
    font-family: var(--sans);
    font-size: 1rem;
    padding: .7rem .75rem;
    border: 1px solid var(--rule);
    background: var(--card);
    color: var(--ink);
    border-radius: 0;
}

input:focus-visible, select:focus-visible, button:focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 1px;
}

button {
    font-family: var(--mono);
    font-size: .78rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: .7rem 1rem;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    cursor: pointer;
    border-radius: 0;
}

button:hover { background: var(--signal); border-color: var(--signal); }

.hint {
    font-family: var(--mono);
    font-size: .7rem;
    color: var(--muted);
    margin-top: .45rem;
    letter-spacing: .03em;
}

/* the tape */

.tape { border-top: 1px solid var(--rule); }

.tape .line {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    padding: .55rem 0;
    border-bottom: 1px solid var(--rule);
    font-family: var(--mono);
    font-size: .82rem;
    font-variant-numeric: tabular-nums;
}

.tape .t { color: var(--muted); flex: none; }

.tape .tag {
    flex: none;
    font-size: .62rem;
    letter-spacing: .12em;
    padding: .1rem .35rem;
    border: 1px solid currentColor;
    color: var(--muted);
}

.tape .tag.food     { color: var(--signal); }
.tape .tag.nicotine { color: var(--warm); }
.tape .tag.weight   { color: var(--ink); }
.tape .tag.activity { color: #4a5b8c; }

.tape .proj {
    font-family: var(--mono);
    font-size: .72em;
    color: var(--muted);
    margin-left: .3rem;
}

.srcline {
    font-family: var(--mono);
    font-size: .66rem;
    color: var(--muted);
    letter-spacing: .02em;
    padding: 0 0 .5rem 3.6rem;
    margin-top: -.35rem;
    border-bottom: 1px solid var(--rule);
}

.srcline.low { color: var(--warm); }

.tape .name {
    flex: 1;
    min-width: 0;
    font-family: var(--sans);
    font-size: .9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-bottom: 1px dotted var(--rule);
}

.tape .qty {
    font-family: var(--mono);
    font-size: .78em;
    color: var(--signal);
    margin-right: .15rem;
}

.tape .val { flex: none; }
.tape .val .u { color: var(--muted); font-size: .72rem; }
.tape .low { color: var(--warm); }

/* delete: one button, JS confirms */

.tape .delform { flex: none; display: flex; margin: 0; }

.tape .del {
    background: none;
    border: none;
    color: var(--rule);
    font-size: 1.1rem;
    line-height: 1;
    padding: .2rem .4rem;
    cursor: pointer;
}

.tape .del:hover, .tape .del:focus-visible {
    background: none;
    color: var(--warm);
}

.linky {
    background: none;
    border: none;
    color: var(--signal);
    font-family: var(--mono);
    font-size: .72rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: 0 .2rem;
    cursor: pointer;
}

.linky:hover { background: none; color: var(--warm); }

.notice.undo { border-left-color: var(--signal); }

/* manage cards */

.card {
    background: var(--card);
    border: 1px solid var(--rule);
    padding: .7rem;
    margin-bottom: .6rem;
}

.card.unconfirmed { border-left: 3px solid var(--warm); }

.cardhead { display: flex; gap: .5rem; align-items: center; }

.cardhead input[type=text] { flex: 1; min-width: 0; }

.cardhead .meta {
    font-family: var(--mono);
    font-size: .66rem;
    color: var(--muted);
    letter-spacing: .08em;
    white-space: nowrap;
}

.fields {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    margin-top: .5rem;
}

.fields label {
    font-family: var(--mono);
    font-size: .66rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: .3rem;
}

.fields input[type=text], .fields select {
    flex: none;
    padding: .35rem .4rem;
    font-family: var(--mono);
    font-size: .85rem;
    text-transform: none;
}

.fields .chk { text-transform: none; }
.fields button { padding: .4rem .7rem; font-size: .68rem; }

.empty {
    padding: 1.5rem 0;
    font-family: var(--mono);
    font-size: .8rem;
    color: var(--muted);
}

/* notices */

.notice {
    border-left: 3px solid var(--warm);
    background: var(--card);
    padding: .6rem .75rem;
    margin-bottom: 1rem;
    font-size: .88rem;
}

/* tables */

table { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; }

th, td {
    text-align: right;
    padding: .4rem .3rem;
    border-bottom: 1px solid var(--rule);
    font-family: var(--mono);
    font-size: .8rem;
    font-variant-numeric: tabular-nums;
}

th {
    font-size: .62rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--ink);
}

th:first-child, td:first-child { text-align: left; }

tfoot td { border-bottom: none; border-top: 1px solid var(--ink); font-weight: 600; }

h2 {
    font-family: var(--mono);
    font-size: .7rem;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 1.75rem 0 .6rem;
}

.trace {
    width: 100%;
    height: 90px;
    background: var(--card);
    border: 1px solid var(--rule);
    margin-bottom: 1.5rem;
    display: block;
}

.answer {
    background: var(--card);
    border: 1px solid var(--rule);
    border-left: 3px solid var(--signal);
    padding: .8rem .9rem;
    margin-top: .75rem;
    font-size: .92rem;
    white-space: pre-wrap;
}

@media (prefers-reduced-motion: no-preference) {
    button, a { transition: color .12s ease, background .12s ease; }
}


/* month picker */

.monthgrid {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 1.5rem;
}

.monthcard {
    flex: 1 1 8rem;
    background: var(--card);
    border: 1px solid var(--rule);
    padding: .55rem .6rem;
    text-decoration: none;
    color: var(--ink);
}

.monthcard:hover { border-color: var(--signal); }

.monthcard.on {
    border-left: 3px solid var(--signal);
    background: #fff;
}

.monthcard .mn {
    display: block;
    font-family: var(--mono);
    font-size: .82rem;
    letter-spacing: .06em;
}

.monthcard .md {
    display: block;
    font-family: var(--mono);
    font-size: .62rem;
    color: var(--muted);
    letter-spacing: .06em;
    margin-top: .15rem;
}

/* manage: food blocks */

.foodblock {
    border: 1px solid var(--rule);
    border-left: 3px solid var(--ink);
    padding: .6rem;
    margin-bottom: 1rem;
    background: var(--paper);
}

.foodblock .card { margin-bottom: .4rem; }
.foodblock .card:last-child { margin-bottom: 0; }

.foodname { margin-bottom: .6rem; }
.foodname input[type=text] { font-weight: 600; }

.addrow { border-style: dashed; background: transparent; }


/* day navigation */

.daynav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    font-family: var(--mono);
    font-size: .68rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    margin-bottom: 1rem;
    padding-bottom: .4rem;
    border-bottom: 1px solid var(--rule);
}

.daynav a { color: var(--signal); text-decoration: none; }
.daynav a:hover { color: var(--warm); }
.daynav span { color: var(--muted); }
.daynav .off { visibility: hidden; }


/* live progress */

.progress {
    border: 1px solid var(--rule);
    border-left: 3px solid var(--signal);
    background: var(--card);
    padding: .6rem .7rem;
    margin: -.75rem 0 1.25rem;
    position: relative;
}

.plines {
    max-height: 11rem;
    overflow-y: auto;
    font-family: var(--mono);
    font-size: .7rem;
    line-height: 1.5;
}

.pline {
    padding: .1rem 0;
    border-bottom: 1px dotted var(--rule);
}

.pline:last-child { border-bottom: none; }

.plabel { color: var(--ink); }

.pdetail {
    display: block;
    color: var(--muted);
    padding-left: .8rem;
    word-break: break-word;
}

.pelapsed {
    position: absolute;
    top: .5rem;
    right: .7rem;
    font-family: var(--mono);
    font-size: .68rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

.pline:last-child .plabel { animation: pulse 1.4s ease-in-out infinite; }

.pline.bad .plabel   { color: var(--warm); animation: none; }
.pline.bad .pdetail  { color: var(--warm); }
.pline.muted .plabel { color: var(--muted); }
