:root {
  --bg: #f4f5f0;
  --card: #ffffff;
  --ink: #1b2422;
  --muted: #66716d;
  --line: #e2e5de;
  --teal: #0e7c86;
  --teal-2: #33c3d0;
  --teal-soft: #dff4f5;
  --amber: #f2b31b;
  --amber-soft: #fff4cf;
  --green: #23905a;
  --green-soft: #dcf2e4;
  --red: #c0412d;
  --red-soft: #fbe3de;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 4px 16px rgba(20, 30, 28, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615; --card: #1a2120; --ink: #e8eeec; --muted: #94a19c; --line: #2a3432;
    --teal: #3cc2cd; --teal-2: #3cc2cd; --teal-soft: #15393c; --amber: #f2b31b; --amber-soft: #3a3014;
    --green: #4cc584; --green-soft: #173726; --red: #f07a63; --red-soft: #3e1f1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--teal); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
img { max-width: 100%; }

/* ---- shell ---- */
.topbar { background: var(--teal); color: #fff; position: sticky; top: 0; z-index: 10; }
@media (prefers-color-scheme: dark) { .topbar { background: #0b4e54; } }
.topbar-in { max-width: 920px; margin: 0 auto; padding: .6rem 16px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .01em; }
.nav { display: flex; align-items: center; gap: 1rem; font-size: .95rem; }
.nav a, .nav .linkbtn { color: #fff; text-decoration: none; opacity: .92; }
.nav a:hover, .nav .linkbtn:hover { opacity: 1; text-decoration: underline; }
.wrap { max-width: 920px; margin: 0 auto; padding: 16px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 16px 2.5rem; }
.inline { display: inline; margin: 0; }

/* ---- building blocks ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 700; color: var(--muted); margin: 0 0 .25rem; }
.pagetitle { margin: .25rem 0 1rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.wrapgap { margin-bottom: .5rem; }
.stack { display: grid; gap: .85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--teal); }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06292c; } }
.btn-go { background: var(--green); border-color: var(--green); color: #fff; }
.btn-ghost { background: transparent; }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding: .7rem 1.4rem; width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--teal); cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--red); }

label { display: grid; gap: .3rem; font-weight: 600; font-size: .92rem; }
input, select, textarea {
  width: 100%; font: inherit; font-weight: 400; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .65rem .75rem; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-2); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.check input { width: auto; min-height: 0; }
.err { color: var(--red); font-weight: 500; font-size: .85rem; }
.hint { color: var(--muted); font-weight: 400; font-size: .82rem; min-height: 1em; }
.hint.bad { color: var(--red); }

.flash { border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .95rem; }
.flash-ok { background: var(--green-soft); }
.flash-warn { background: var(--amber-soft); }
.banner { background: var(--teal-soft); border-radius: 10px; padding: .7rem .9rem; margin-bottom: 1rem; }
.banner-win { background: var(--amber-soft); font-weight: 600; }

.pill { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.pill-today { background: var(--amber-soft); color: #7a5600; }
.pill-done { background: var(--green-soft); color: var(--green); }
.pill-muted { background: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) { .pill-today { color: var(--amber); } }
.tag { display: inline-block; background: var(--teal-soft); color: var(--teal); border-radius: 6px; padding: .05rem .45rem; font-size: .78rem; font-weight: 600; }

/* ---- auth / hero ---- */
.auth { max-width: 420px; margin: 2rem auto; }
.hero { max-width: 620px; margin: 1.5rem auto; }
.hero h1 { font-size: 1.9rem; }
.rules { padding-left: 1.2rem; color: var(--muted); margin: 1rem 0 1.25rem; }
.rules li { margin: .25rem 0; }

/* ---- day strip ---- */
.strip {
  display: flex; gap: 6px; overflow-x: auto; padding: 3px 3px 10px; margin-bottom: .5rem;
  scroll-snap-type: x proximity; scrollbar-width: none;
  /* phones: swipe, with a soft fade hinting there's more to the right */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
}
.strip::-webkit-scrollbar { display: none; }
/* wider screens: show all 30 days, wrapped — no scrolling at all */
@media (min-width: 760px) {
  .strip { flex-wrap: wrap; overflow: visible; -webkit-mask-image: none; mask-image: none; }
}
.chip {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 700; font-size: .9rem; text-decoration: none; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  scroll-snap-align: center;
}
.chip-done { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip-open { background: var(--amber-soft); color: #7a5600; border-color: var(--amber); }
@media (prefers-color-scheme: dark) { .chip-open { color: var(--amber); } }
.chip-locked { opacity: .55; }
.chip-sel { outline: 2px solid var(--teal); outline-offset: 1px; }

/* ---- day card ---- */
.daycard { border-top: 4px solid var(--amber); }
.daycard.state-ok { border-top-color: var(--green); }
.daycard.state-over { border-top-color: var(--teal); }
.dayhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.budget { font-size: 2.2rem; font-variant-numeric: tabular-nums; margin: 0; letter-spacing: -.01em; }
.bar { position: relative; height: 12px; background: var(--line); border-radius: 99px; margin: 1rem 0 .75rem; overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--amber); border-radius: 99px; transition: width .4s ease; max-width: 100%; }
.state-ok .bar .fill { background: var(--green); }
.state-over .bar .fill { background: var(--teal-2); }
.bar .mark { position: absolute; top: 0; bottom: 0; left: 90%; width: 2px; background: var(--muted); opacity: .6; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 0 0 .75rem; }
.stats dt { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.stats dd { margin: 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats dd.neg { color: var(--teal); }
.closeform { margin-top: .5rem; text-align: center; }
.closeform p { margin: .4rem 0 0; }
.next { margin: .5rem 0 0; padding: .6rem .8rem; background: var(--teal-soft); border-radius: 10px; }

/* ---- items ---- */
.items { display: grid; gap: .75rem; margin-bottom: 1rem; }
.empty { text-align: center; padding: 1rem; }
.item { display: grid; grid-template-columns: 84px 1fr; gap: .85rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; box-shadow: var(--shadow); }
.thumb { width: 84px; height: 84px; border-radius: 10px; overflow: hidden; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; }
.thumb a { display: block; width: 100%; height: 100%; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb-ph { font-size: 1.6rem; font-weight: 800; color: var(--teal); background: var(--teal-soft); width: 100%; height: 100%; display: grid; place-items: center; }
.img-broken { visibility: hidden; }
.item-body { min-width: 0; }
.item-top { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.item-top h3 { font-size: 1rem; margin: 0; overflow-wrap: anywhere; }
.cost { white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-meta { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .3rem; }
.item-meta a { overflow-wrap: anywhere; }
.notes { margin: .4rem 0 0; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.item-actions { display: flex; gap: 1rem; margin-top: .5rem; font-size: .88rem; }
@media (min-width: 640px) {
  .item { grid-template-columns: 120px 1fr; }
  .thumb { width: 120px; height: 120px; }
}

/* ---- item form ---- */
.itemform { grid-template-columns: 1fr; }
.preview { display: flex; gap: .6rem; align-items: center; margin-top: .3rem; }
.preview img { width: 72px; height: 72px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
@media (min-width: 640px) {
  .itemform { grid-template-columns: 1fr 1fr; }
  .itemform .span2 { grid-column: span 2; }
  .btn-lg { width: auto; }
}

/* ---- history / overview ---- */
.games { display: grid; gap: .75rem; }
.gamecard { display: block; text-decoration: none; color: inherit; margin: 0; }
.gamecard:hover { border-color: var(--teal); }
.gamecard p { margin: .3rem 0 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; box-shadow: var(--shadow); min-width: 0; }
.tile span { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.tile strong { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; margin-top: .2rem; }
.tile em { display: block; font-style: normal; color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catbars { list-style: none; padding: 0; margin: 0; display: grid; gap: .55rem; }
.catbars li { display: grid; grid-template-columns: 6.5rem 1fr auto; gap: .6rem; align-items: center; font-size: .92rem; }
.catbar { position: relative; height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.catbar .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--teal-2); border-radius: 99px; transition: width .4s ease; }
.catval { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; min-width: 9.5rem; text-align: right; }
@media (max-width: 420px) { .catbars li { grid-template-columns: 5.2rem 1fr; } .catval { grid-column: 2; min-width: 0; text-align: left; } }
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
.board a { aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #fff; border: 1px solid var(--line); display: block; }
.board img { width: 100%; height: 100%; object-fit: contain; display: block; }
.daytable { width: 100%; border-collapse: collapse; font-size: .92rem; }
.daytable th, .daytable td { padding: .45rem .3rem; border-bottom: 1px solid var(--line); text-align: left; }
.daytable th { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.danger-zone summary { cursor: pointer; font-weight: 600; }
.danger-zone form { margin-top: .75rem; }

@media print {
  .topbar, .nav, .strip, #add, .item-actions, .closeform, .foot, .danger-zone { display: none !important; }
  body { background: #fff; }
  .card, .item, .tile { box-shadow: none; break-inside: avoid; }
}

/* ---- admin ---- */
.userlist { list-style: none; padding: 0; margin: 0 0 .75rem; }
.userlist li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.userlist p { margin: .25rem 0 0; }
.actions { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: .4rem; font-size: .92rem; }
@media (max-width: 480px) {
  .brand span { display: none; }
  .nav { gap: .9rem; font-size: .92rem; }
}
.reveal code { font-size: 1.1rem; font-weight: 700; padding: .1rem .4rem; background: var(--card); border-radius: 6px; user-select: all; }
.reveal .small { display: block; margin-top: .3rem; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.checks li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem .6rem; border-radius: 8px; background: var(--green-soft); }
.checks li.bad { background: var(--amber-soft); }
