:root {
  --teal: #0c7c8c;
  --teal-dk: #095c68;
  --sun: #f4a93b;
  --coral: #e8553f;
  --ink: #16323a;
  --bg: #f3f6f7;
  --card: #ffffff;
  --line: #dde6e8;
  --muted: #6c8189;
  --ok: #1e9e6a;
  --shadow: 0 2px 10px rgba(16,50,58,.08);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.screen { min-height: 100dvh; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
#login {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--teal), var(--teal-dk));
  padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 32px 28px;
  width: 100%; max-width: 360px; text-align: center; box-shadow: var(--shadow);
}
.login-card .logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 0; font-size: 1.5rem; }
.login-card .sub { margin: 2px 0 22px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: .72rem; }
.login-card label { display: block; text-align: left; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
#pin {
  width: 100%; font-size: 2rem; text-align: center; letter-spacing: .5em;
  padding: 14px; border: 2px solid var(--line); border-radius: 14px; margin-bottom: 16px;
}
#pin:focus { outline: none; border-color: var(--teal); }
.login-card button {
  width: 100%; padding: 15px; font-size: 1.05rem; font-weight: 700; color: #fff;
  background: var(--coral); border: none; border-radius: 14px; cursor: pointer;
}
.login-card button:active { transform: scale(.98); }
.err { color: var(--coral); font-size: .9rem; margin: 12px 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: var(--teal); color: #fff; padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.topbar .brand { font-weight: 800; font-size: 1.05rem; }
.topbar .week { margin-left: auto; font-size: .8rem; opacity: .9; }
.ghost { background: rgba(255,255,255,.15); color: #fff; border: none; border-radius: 10px; padding: 8px 11px; font-size: 1rem; cursor: pointer; }

/* ---------- Meta ---------- */
.meta { background: var(--card); padding: 14px 16px; border-bottom: 1px solid var(--line); }
.meta label { font-size: .78rem; color: var(--muted); display: block; margin-bottom: 4px; }
#countedBy { width: 100%; padding: 12px; font-size: 1rem; border: 1.5px solid var(--line); border-radius: 12px; }
#countedBy:focus { outline: none; border-color: var(--teal); }
.histlink { display: inline-block; margin-top: 10px; color: var(--teal); text-decoration: none; font-weight: 600; font-size: .88rem; }

/* ---------- Sections ---------- */
main#sections { padding: 8px 12px 120px; }
.section-head { margin: 18px 6px 6px; }
.section-head h2 { margin: 0; font-size: 1.15rem; }
.section-head .blurb { margin: 4px 0 0; font-size: .82rem; color: var(--muted); }
.cat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  margin: 10px 0; overflow: hidden; box-shadow: var(--shadow);
}
.cat > summary {
  list-style: none; cursor: pointer; padding: 13px 16px; font-weight: 700;
  display: flex; align-items: center; gap: 8px; background: #fbfdfd;
}
.cat > summary::-webkit-details-marker { display: none; }
.cat > summary .chev { margin-left: auto; transition: transform .2s; color: var(--muted); }
.cat[open] > summary .chev { transform: rotate(90deg); }
.cat .catnote { padding: 0 16px 8px; font-size: .78rem; color: var(--coral); background: #fbfdfd; }
.cat .count-pill { font-size: .72rem; font-weight: 700; color: var(--teal); background: #e3f1f3; padding: 2px 8px; border-radius: 20px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-top: 1px solid var(--line);
}
.row .name { flex: 1; font-size: .98rem; }
.row.counted .name { font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 0; }
.stepper button {
  width: 40px; height: 40px; font-size: 1.4rem; font-weight: 700; line-height: 1;
  border: 1.5px solid var(--line); background: #fff; cursor: pointer; color: var(--ink);
}
.stepper button:active { background: #eef5f6; }
.stepper .minus { border-radius: 11px 0 0 11px; }
.stepper .plus { border-radius: 0 11px 11px 0; color: var(--teal); }
.stepper input {
  width: 56px; height: 40px; text-align: center; font-size: 1.05rem; font-weight: 700;
  border: 1.5px solid var(--line); border-left: none; border-right: none;
}
.stepper input:focus { outline: none; background: #fffdf5; }

/* ---------- Submit bar ---------- */
.submitbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px; box-shadow: 0 -2px 12px rgba(16,50,58,.06);
}
.progress { font-size: .85rem; color: var(--muted); white-space: nowrap; }
#submitBtn {
  margin-left: auto; padding: 14px 22px; font-size: 1rem; font-weight: 700;
  color: #fff; background: var(--ok); border: none; border-radius: 13px; cursor: pointer;
}
#submitBtn:disabled { background: #b7c6c9; }
#submitBtn:active:not(:disabled) { transform: scale(.98); }

/* ---------- History ---------- */
.modal { position: fixed; inset: 0; background: var(--bg); z-index: 20; }
.histwrap { padding: 14px 16px 40px; }
.hist-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.hist-card h3 { margin: 0 0 4px; font-size: .95rem; }
.hist-card .who { color: var(--muted); font-size: .82rem; }
.hist-card details { margin-top: 8px; }
.hist-card summary { cursor: pointer; color: var(--teal); font-size: .85rem; font-weight: 600; }
.hist-card pre { white-space: pre-wrap; font-size: .8rem; color: var(--ink); margin: 8px 0 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 13px 20px; border-radius: 30px;
  font-weight: 600; font-size: .92rem; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}

/* ---------- Add custom item ---------- */
.add-btn {
  display: block; width: calc(100% - 32px); margin: 8px 16px 12px;
  padding: 11px; border: 1.5px dashed var(--line); background: #fbfdfd;
  color: var(--teal); font-weight: 700; font-size: .9rem; border-radius: 11px; cursor: pointer;
}
.add-btn:active { background: #eef5f6; }
.row.custom .cname {
  flex: 1; min-width: 0; padding: 9px 10px; font-size: .98rem;
  border: 1.5px solid var(--line); border-radius: 9px; background: #fffdf5;
}
.row.custom .cname:focus { outline: none; border-color: var(--teal); }
