:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --ink: #1d2433;
  --muted: #5d6677;
  --line: #e6dfd3;
  --navy: #1f3a5f;
  --gold: #f4b740;
  --gold-soft: #fdf0d2;
  --green: #2f8f5b;
  --green-soft: #dff2e6;
  --red: #c2413b;
  --radius: 14px;
  --tap: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabs-h: calc(64px + var(--safe-bottom));
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--navy); color: #fff;
}
.brand { font-size: 18px; letter-spacing: .02em; }
.brand b { color: var(--gold); }
.year-progress { font-size: 13px; opacity: .85; }

main {
  max-width: 560px; margin: 0 auto;
  padding: 16px 14px calc(var(--tabs-h) + 24px);
}
body.no-tabs main { padding-bottom: 32px; }

h1 { font-size: 24px; margin: 4px 0 4px; line-height: 1.2; }
h2 { font-size: 18px; margin: 24px 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.center { text-align: center; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: var(--tabs-h); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabs a span { font-size: 22px; line-height: 1; }
.tabs a.active { color: var(--navy); }
.tabs a.active span { transform: scale(1.1); }

/* Forms & buttons */
.card-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px;
}
label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px;
  font-size: 16px; /* prevents iOS zoom */
  border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
}
textarea { resize: none; min-height: 84px; }
input:focus, textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31,58,95,.15); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap); padding: 12px 18px; margin-top: 16px;
  border: 0; border-radius: 12px; cursor: pointer;
  font-weight: 700; font-size: 16px; text-decoration: none;
  background: var(--navy); color: #fff;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; }
.btn.secondary { background: #eef1f6; color: var(--navy); }
.btn.gold { background: var(--gold); color: #3a2a00; }
.btn.green { background: var(--green); color: #fff; }
.btn.danger { background: transparent; color: var(--red); border: 1.5px solid #f0c9c6; }
.btn.small { width: auto; min-height: 40px; padding: 8px 14px; margin: 0; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.linkrow { text-align: center; margin-top: 18px; }
.linkrow a { color: var(--navy); font-weight: 600; }
.error { color: var(--red); font-size: 14px; margin-top: 10px; min-height: 1em; }

/* Bingo grid */
.card-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-bottom: 12px; }
.card-head .stats { text-align: right; font-size: 14px; color: var(--muted); white-space: nowrap; }
.card-head .stats b { color: var(--ink); font-size: 20px; }
.bingo-letters, .grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px;
}
.bingo-letters { margin-bottom: 5px; }
.bingo-letters span {
  text-align: center; font-weight: 900; font-size: 20px; color: var(--navy);
}
.cell {
  position: relative; aspect-ratio: 1; overflow: hidden;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 4px; border-radius: 10px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--line);
  font-size: clamp(9.5px, 2.7vw, 13px); line-height: 1.15; font-weight: 600;
  word-break: break-word; hyphens: auto;
}
.cell .txt {
  position: relative; z-index: 1;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.cell .fill {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--gold-soft);
}
.cell .count {
  position: absolute; z-index: 1; bottom: 3px; right: 5px; font-size: 9px; color: var(--muted); font-weight: 700;
}
.cell.empty { color: #a5a9b3; border-style: dashed; font-weight: 500; }
.cell.done { background: var(--green-soft); border-color: #9fd2b3; color: #1a5236; }
.cell.done::after {
  content: "✓"; position: absolute; top: 2px; right: 5px; font-size: 12px; color: var(--green); font-weight: 900;
}
.cell.inline { border-color: var(--gold); border-width: 2.5px; background: #fff6dc; }
.cell.inline.done { background: #fdeebf; color: #5a4200; }
.cell.free { background: var(--navy); color: #fff; border-color: var(--navy); font-size: clamp(10px, 3vw, 14px); }
.cell:active { transform: scale(.96); }
.cell:focus-visible { outline: 3px solid var(--navy); outline-offset: 1px; }
.readonly .cell { cursor: pointer; }

.banner {
  background: var(--gold-soft); border: 1px solid #f2dca5; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px; font-size: 15px;
}
.legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }

/* Progress bars */
.bar { height: 8px; background: #eee6d8; border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }
.bar.big { height: 12px; }

/* Group list & member cards */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; min-height: 64px; color: inherit; text-decoration: none;
}
.item:active { background: #f6f2ea; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 14px; margin: 2px 0 8px; }
.item .chev { color: #b9bcc4; font-size: 22px; }
.rank { width: 32px; text-align: center; font-size: 24px; font-weight: 800; color: var(--muted); flex: none; }
.rank.num { font-size: 17px; }
.mini { display: grid; grid-template-columns: repeat(5, 9px); gap: 2px; flex: none; }
.mini i { width: 9px; height: 9px; border-radius: 2px; background: #ece5d8; }
.mini i.on { background: var(--green); }
.mini i.free { background: var(--navy); }
.mini i.line { background: var(--gold); }
.me-tag { font-size: 11px; background: #eef1f6; color: var(--navy); padding: 2px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; }

.invite {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--navy); color: #fff; border-radius: var(--radius); padding: 14px 16px; margin: 14px 0 18px;
}
.invite .code { font-family: ui-monospace, Menlo, monospace; font-size: 22px; letter-spacing: .15em; color: var(--gold); font-weight: 800; }
.invite small { display: block; opacity: .8; font-size: 12px; }

.back { display: inline-flex; align-items: center; min-height: 40px; color: var(--navy); font-weight: 600; text-decoration: none; margin: -6px 0 4px; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(15,20,30,.45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(22px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-top {
  position: sticky; top: -10px; z-index: 2;
  display: flex; justify-content: flex-end;
  height: 0; margin: -10px -18px 0; padding: 0 8px;
  pointer-events: none; /* only the button itself takes taps */
}
.sheet-close {
  pointer-events: auto; margin-top: 8px;
  box-shadow: 0 0 0 4px var(--surface);
  width: 44px; height: 44px; border: 0; border-radius: 50%; cursor: pointer;
  background: #eef1f6; color: var(--navy);
  font-size: 28px; line-height: 1; font-weight: 400;
  display: flex; align-items: center; justify-content: center;
}
.sheet-close:active { transform: scale(.94); background: #e2e7ef; }
.sheet h3 { margin: 0 0 4px; font-size: 19px; }
/* Leave room on the right of the title for the close button. */
.sheet h3, .sheet .goal-text { padding-right: 52px; min-height: 44px; display: flex; align-items: center; }
.sheet { padding-top: 10px; }
.sheet .goal-text { font-size: 20px; font-weight: 700; margin: 6px 0 14px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 0 8px; }
.stepper button {
  width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 32px; font-weight: 700; background: #eef1f6; color: var(--navy);
}
.stepper button.plus { background: var(--green); color: #fff; }
.stepper button:active { transform: scale(.94); }
.stepper .val { font-size: 34px; font-weight: 800; text-align: center; }
.stepper .val small { display: block; font-size: 14px; font-weight: 600; color: var(--muted); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; min-height: var(--tap); }
.toggle-row input[type=checkbox] { width: 26px; height: 26px; min-height: 0; accent-color: var(--navy); }
.target-row { display: flex; align-items: center; gap: 10px; }
.target-row input { width: 110px; flex: none; text-align: center; }
.divider { height: 1px; background: var(--line); margin: 20px 0 6px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + 14px); z-index: 30;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 99px;
  font-weight: 600; font-size: 15px; max-width: 90vw; text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.party { background: var(--gold); color: #3a2a00; }

.welcome { text-align: center; padding: 18px 0 6px; }
.welcome .logo { width: 72px; height: 72px; }
.welcome h1 { font-size: 28px; }

@media (min-width: 600px) {
  main { padding-top: 24px; }
  .cell { font-size: 13px; padding: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Private goals */
.cell .lock { position: absolute; z-index: 1; bottom: 3px; left: 5px; font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cell.private:not(.done) { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(31,58,95,.04) 6px 12px); }
