:root {
  --marigold: #f5a623;
  --marigold-dk: #d98613;
  --magenta: #e0407f;
  --purple: #7b5cff;
  --ink: #f4ece6;
  --bg: #140f0e;
  --bg2: #1c1513;
  --card: #241b18;
  --card-hi: #2c211d;
  --line: #3a2c27;
  --muted: #a99388;
  --ok: #3fae6b;
  --low: #ff5b47;
  --shadow: 0 4px 18px rgba(0,0,0,.4);
}
* { 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:
    radial-gradient(120% 90% at 15% 0%, #3a1f2e 0%, transparent 55%),
    radial-gradient(130% 100% at 100% 100%, #2b2410 0%, transparent 55%),
    linear-gradient(160deg, #1c1513, #120d0c);
  padding: 24px;
}
.login-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 34px 28px;
  width: 100%; max-width: 360px; text-align: center; box-shadow: var(--shadow);
}
.login-card .logo { font-size: 52px; filter: drop-shadow(0 2px 6px rgba(245,166,35,.35)); }
.login-card h1 { margin: 10px 0 0; font-size: 1.7rem; font-weight: 800; letter-spacing: .01em; }
.login-card .sub { margin: 4px 0 24px; color: var(--marigold); font-weight: 700; letter-spacing: .22em; 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: 1.5px solid var(--line); border-radius: 14px; margin-bottom: 16px;
  background: #170f0e; color: var(--ink);
}
#pin:focus { outline: none; border-color: var(--marigold); }
.login-card button {
  width: 100%; padding: 15px; font-size: 1.05rem; font-weight: 800; color: #1a1210;
  background: var(--marigold); border: none; border-radius: 14px; cursor: pointer;
}
.login-card button:active { transform: scale(.98); }
.err { color: var(--low); font-size: .9rem; margin: 12px 0 0; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, #241b18, #1c1513);
  color: var(--ink); padding: 14px 16px; border-bottom: 1px solid var(--line);
  padding-top: calc(14px + env(safe-area-inset-top));
}
.topbar .brand { font-weight: 800; font-size: 1.08rem; white-space: nowrap; }
.topbar .ver { font-size: .6rem; font-weight: 800; letter-spacing: .02em; color: #1a1210;
  background: var(--marigold); padding: 2px 6px; border-radius: 6px; vertical-align: middle; white-space: nowrap; }
.topbar .brand .mark { filter: drop-shadow(0 1px 3px rgba(245,166,35,.4)); }
.topbar .week { margin-left: auto; font-size: .78rem; color: var(--marigold); font-weight: 600; }
.ghost { background: rgba(245,166,35,.14); color: var(--marigold); border: none; border-radius: 10px; padding: 8px 11px; font-size: 1rem; cursor: pointer; }

/* ---------- Meta ---------- */
.meta { background: var(--bg2); 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; background: #170f0e; color: var(--ink); }
#countedBy:focus { outline: none; border-color: var(--marigold); }
.metarow { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.histlink { color: var(--marigold); text-decoration: none; font-weight: 700; font-size: .88rem; }
.parswitch { font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 600; }
.parswitch input { width: 16px; height: 16px; accent-color: var(--marigold); }

/* ---------- Sections ---------- */
main#sections { padding: 8px 12px 120px; }
.section-head { margin: 20px 6px 6px; display: flex; align-items: center; gap: 8px; }
.section-head h2 { margin: 0; font-size: 1.2rem; }
.section-head h2::before { content: "✦"; color: var(--magenta); margin-right: 8px; }
.section-head .blurb { margin: 4px 0 0 6px; font-size: .82rem; color: var(--muted); }
.sec-wrap { margin-bottom: 4px; }
.sec-blurb { margin: 2px 6px 8px; font-size: .8rem; 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: var(--card-hi);
}
.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: 8px 16px 4px; font-size: .78rem; color: var(--magenta); background: var(--card-hi); }
.cat .count-pill { font-size: .72rem; font-weight: 800; color: var(--marigold); background: rgba(245,166,35,.14); padding: 2px 9px; border-radius: 20px; }

.row { position: relative; overflow: hidden; border-top: 1px solid var(--line); }
.row-inner { display: flex; align-items: center; gap: 13px; padding: 15px 16px;
  background: var(--card); will-change: transform; }
.swipe-del { position: absolute; top: 0; right: 0; bottom: 0; width: 92px; border: 0;
  background: var(--low); color: #fff; font-weight: 800; font-size: .95rem; cursor: pointer;
  letter-spacing: .01em; }
.row .thumb { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 10px; object-fit: contain;
  background: #170f0e; border: 1px solid var(--line); }
.row .thumb.noimg { display: none; }
.row .name { flex: 1; min-width: 0; font-size: 1.06rem; line-height: 1.2; display: flex; flex-direction: column; gap: 3px; }
.row .name .par { font-size: .78rem; color: var(--muted); font-weight: 600; }
.row .name .meta { font-size: .75rem; color: var(--marigold); opacity: .82; font-weight: 600; }
.row.counted .name { font-weight: 700; }
.row.low .row-inner { background: rgba(255,91,71,.1); }
.row.low .name .par { color: var(--low); }
.row .lowtag { font-size: .58rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  color: #fff; background: var(--low); padding: 2px 6px; border-radius: 6px; }
.par-input { width: 46px; height: 30px; text-align: center; font-size: .85rem; font-weight: 700;
  border: 1.5px solid var(--marigold); border-radius: 8px; background: #170f0e; color: var(--marigold); }

.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: var(--card-hi); cursor: pointer; color: var(--ink);
}
.stepper button:active { background: #34261f; }
.stepper .minus { border-radius: 11px 0 0 11px; }
.stepper .plus { border-radius: 0 11px 11px 0; color: var(--marigold); }
.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;
  background: #170f0e; color: var(--ink);
}
.stepper input:focus { outline: none; background: #23180f; }
.del-item { flex: 0 0 auto; width: 38px; height: 40px; margin-left: 8px; font-size: 1.02rem;
  border: 1.5px solid #5c2323; background: #3a1717; color: #f0a8a8; border-radius: 10px; cursor: pointer; }
.del-item:active { background: #4a1d1d; }

/* ---------- Submit bar ---------- */
.submitbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  background: var(--bg2); 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 -4px 16px rgba(0,0,0,.4);
}
.progress { font-size: .85rem; color: var(--muted); white-space: nowrap; }
#submitBtn {
  margin-left: auto; padding: 14px 22px; font-size: 1rem; font-weight: 800;
  color: #1a1210; background: var(--marigold); border: none; border-radius: 13px; cursor: pointer;
}
#submitBtn:disabled { background: #5a4a3f; color: #a99388; }
#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(--marigold); font-size: .85rem; font-weight: 700; }
.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(--marigold); color: #1a1210; padding: 13px 20px; border-radius: 30px;
  font-weight: 700; 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: var(--card-hi);
  color: var(--marigold); font-weight: 700; font-size: .9rem; border-radius: 11px; cursor: pointer;
}
.add-btn:active { background: #34261f; }
.row.custom .cname {
  flex: 1; min-width: 0; padding: 9px 10px; font-size: .98rem;
  border: 1.5px solid var(--line); border-radius: 9px; background: #23180f; color: var(--ink);
}
.row.custom .cname:focus { outline: none; border-color: var(--marigold); }
