/* Pierside 75: Coastal Dawn palette (matches piersidesaints.org) */
:root, [data-theme='light'] {
  --bg: #f4efe5;
  --surface: #fbf8f2;
  --surface-2: #ffffff;
  --surface-offset: #ece5d6;
  --divider: #ddd3bf;
  --border: #cfc4ae;
  --text: #1e2a30;
  --muted: #5c6669;
  --faint: #8a9193;
  --inverse: #fbf8f2;
  --primary: #1c5563;
  --primary-hover: #143f49;
  --primary-soft: #d9e5e3;
  --gold: #b9772a;
  --gold-soft: #f1e2cc;
  --danger: #a13a2c;
  --shadow-sm: 0 1px 2px rgba(40, 32, 18, 0.07);
  --shadow-md: 0 6px 18px rgba(20, 50, 58, 0.10);
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1.125rem;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Satoshi', 'Inter', system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --tabbar-h: 68px;
}
[data-theme='dark'] {
  --bg: #111a1e;
  --surface: #182329;
  --surface-2: #1e2a31;
  --surface-offset: #151f26;
  --divider: #2a373e;
  --border: #34434b;
  --text: #dde3e5;
  --muted: #90a0a4;
  --faint: #6c7a7e;
  --inverse: #111a1e;
  --primary: #5fa9b7;
  --primary-hover: #7ab9c5;
  --primary-soft: #1e3740;
  --gold: #d49a4e;
  --gold-soft: #3a2e1e;
  --danger: #e07a6a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.25);
  --shadow-md: 0 6px 18px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; line-height: 1.15; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.boot { flex: 1; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--divider); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--primary); text-decoration: none; min-width: 0; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand-name { font-family: var(--font-display); font-size: 19px; font-weight: 600; color: var(--text); white-space: nowrap; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; color: var(--text); padding: 0;
}
.icon-btn svg { width: 18px; height: 18px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--primary); color: var(--inverse);
  font-weight: 700; font-size: 14px; display: grid; place-items: center; letter-spacing: .02em;
}

main.view { flex: 1; padding: 8px 20px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--divider);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar-inner { max-width: 560px; margin: 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; height: var(--tabbar-h); }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--faint); font-size: 12px; font-weight: 500; position: relative;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current='page'] { color: var(--primary); }
.tab[aria-current='page']::before {
  content: ''; position: absolute; top: 0; left: 30%; right: 30%; height: 2px; background: var(--primary); border-radius: 0 0 2px 2px;
}

/* Common */
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 14px; }
.xs { font-size: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-lg);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.stack > * + * { margin-top: 14px; }
.stack-lg > * + * { margin-top: 22px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.section-title { font-size: 20px; margin-bottom: 10px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 20px; }
.link-btn { background: none; border: none; color: var(--primary); font-weight: 700; padding: 6px 0; font-size: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 700; font-size: 16px; text-decoration: none; transition: background .18s var(--ease), transform .12s var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: var(--inverse); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* Forms */
.field { display: block; }
.field > span { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface-2); font-size: 16px;
}
.textarea { min-height: 76px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.pin { letter-spacing: .5em; font-variant-numeric: tabular-nums; text-align: center; font-size: 22px; }
.form-error { color: var(--danger); font-size: 14px; font-weight: 500; min-height: 1.4em; }
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-offset);
  border-radius: 999px; padding: 4px; gap: 4px;
}
.segmented button {
  border: none; background: transparent; border-radius: 999px; min-height: 40px; font-weight: 700; font-size: 14px; color: var(--muted);
}
.segmented button[aria-pressed='true'] { background: var(--surface-2); color: var(--text); box-shadow: var(--shadow-sm); }

/* Auth */
.auth { flex: 1; display: flex; flex-direction: column; }
.auth-hero {
  position: relative; padding: calc(env(safe-area-inset-top) + 36px) 24px 32px; color: #fbf8f2;
  background:
    radial-gradient(120% 80% at 50% 110%, rgba(185,119,42,.55) 0%, rgba(185,119,42,0) 55%),
    linear-gradient(180deg, #0e2e35 0%, #1c5563 70%, #2d6a74 100%);
  overflow: hidden;
}
.auth-hero .mark { width: 54px; height: 54px; color: #fbf8f2; margin-bottom: 18px; }
.auth-hero h1 { font-size: 40px; color: #fbf8f2; }
.auth-hero p { color: rgba(251,248,242,.82); margin-top: 8px; max-width: 34ch; }
.auth-hero .eyebrow { color: #e9b977; }
.waves { position: absolute; left: 0; right: 0; bottom: -1px; width: 100%; height: 26px; color: var(--bg); display: block; }
.auth-body { padding: 24px 20px 40px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0 0 20px; }
.fact { background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-md); padding: 12px; text-align: center; }
.fact b { display: block; font-family: var(--font-display); font-size: 24px; color: var(--primary); line-height: 1.1; }
.fact span { font-size: 12px; color: var(--muted); }
.team-pick { display: grid; gap: 8px; }
.team-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); text-align: left; width: 100%;
}
.team-opt[aria-pressed='true'] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.team-opt[disabled] { opacity: .5; }
.spots { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* Today hero */
.day-hero { padding: 6px 0 4px; }
.day-hero h1 { font-size: 34px; }
.day-hero .sub { color: var(--muted); margin-top: 4px; }
.block-track { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 14px; }
.block-seg { height: 6px; border-radius: 3px; background: var(--surface-offset); overflow: hidden; }
.block-seg i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
.block-labels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; font-size: 12px; color: var(--faint); }
.block-labels .on { color: var(--primary); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-md); padding: 14px 12px; }
.stat b { display: block; font-family: var(--font-display); font-size: 28px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat.accent { background: var(--primary); border-color: var(--primary); color: var(--inverse); }
.stat.accent span { color: color-mix(in srgb, var(--inverse) 78%, transparent); }

.day-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.day-chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 7px 13px; font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.chip[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); margin-left: 6px; vertical-align: middle; }

.habits { display: grid; gap: 10px; }
.habit {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-lg);
  padding: 14px 16px; min-height: 68px; transition: background .2s var(--ease), border-color .2s var(--ease);
}
.habit .check {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border);
  display: grid; place-items: center; transition: all .2s var(--ease); color: transparent;
}
.habit .check svg { width: 16px; height: 16px; }
.habit .h-label { font-weight: 700; display: block; }
.habit .h-detail { font-size: 13px; color: var(--muted); }
.habit .h-pts { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--faint); white-space: nowrap; }
.habit[aria-pressed='true'] { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.habit[aria-pressed='true'] .check { background: var(--primary); border-color: var(--primary); color: var(--inverse); }
.habit[aria-pressed='true'] .h-pts { color: var(--primary); }
.habit[disabled] { opacity: .6; cursor: default; }
.perfect {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--gold-soft); color: var(--text); font-weight: 500; font-size: 14px;
}
.perfect svg { color: var(--gold); width: 20px; height: 20px; flex: none; }

.notice { padding: 14px 16px; border-radius: var(--radius-md); background: var(--surface-offset); font-size: 14px; color: var(--muted); }

/* Goals */
.goals { display: grid; gap: 10px; }
.goal {
  background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-lg); padding: 14px 16px;
}
.goal-top { display: flex; align-items: center; gap: 14px; width: 100%; background: none; border: none; padding: 0; text-align: left; }
.goal .check { flex: none; width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--border); display: grid; place-items: center; color: transparent; }
.goal .check svg { width: 16px; height: 16px; }
.goal.done { border-color: color-mix(in srgb, var(--gold) 45%, transparent); background: var(--gold-soft); }
.goal.done .check { background: var(--gold); border-color: var(--gold); color: #fff; }
.goal .g-label { font-weight: 700; display: block; }
.goal .g-detail { font-size: 13px; color: var(--muted); }
.goal .g-pts { margin-left: auto; font-size: 13px; font-weight: 700; color: var(--gold); white-space: nowrap; }
.goal-note { margin-top: 12px; }
.goal-note .note-text { font-size: 14px; color: var(--muted); font-style: normal; margin-top: 10px; }
.goal[data-locked='true'] .goal-top { cursor: default; }

/* 75 grid */
.block-card h3 { font-size: 18px; }
.grid75 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 12px; }
.cell {
  aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--divider); background: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0;
  font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; position: relative;
}
.cell small { font-size: 10px; font-weight: 500; opacity: .8; }
.cell.l1 { background: color-mix(in srgb, var(--primary) 14%, var(--surface-2)); }
.cell.l2 { background: color-mix(in srgb, var(--primary) 30%, var(--surface-2)); }
.cell.l3 { background: color-mix(in srgb, var(--primary) 48%, var(--surface-2)); color: var(--text); }
.cell.l4 { background: color-mix(in srgb, var(--primary) 68%, var(--surface-2)); color: var(--inverse); }
.cell.l5 { background: var(--primary); color: var(--inverse); border-color: var(--primary); }
.cell.future { background: transparent; border-style: dashed; color: var(--faint); }
.cell.today { box-shadow: 0 0 0 2px var(--gold); }
.cell.editable { cursor: pointer; }
.cell.locked { cursor: default; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid var(--divider); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-offset); color: var(--muted); }
.pill.live { background: var(--primary-soft); color: var(--primary); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

/* Leaderboard */
.board { display: grid; gap: 8px; }
.brow {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-md); padding: 12px 14px;
}
.brow.me { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.rank {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: var(--surface-offset); color: var(--muted); font-variant-numeric: tabular-nums; font-size: 15px;
}
.rank.r1 { background: var(--gold); color: #fff; }
.rank.r2 { background: #8e9a9d; color: #fff; }
.rank.r3 { background: #9a6a45; color: #fff; }
.bname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bmeta { font-size: 13px; color: var(--muted); }
.bpts { text-align: right; }
.bpts b { display: block; font-family: var(--font-display); font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.bpts span { font-size: 11px; color: var(--muted); }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 8px; align-items: end; margin-bottom: 14px; }
.pod { background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-lg); padding: 14px 8px; text-align: center; min-width: 0; }
.pod.first { background: var(--primary); border-color: var(--primary); color: var(--inverse); padding-top: 20px; padding-bottom: 20px; }
.pod .rank { margin: 0 auto 8px; }
.pod .bname { font-size: 14px; }
.pod b { font-family: var(--font-display); font-size: 24px; display: block; line-height: 1.1; }
.pod .bmeta { font-size: 12px; }
.pod.first .bmeta { color: color-mix(in srgb, var(--inverse) 78%, transparent); }

/* Team */
.team-hero { background: var(--primary); color: var(--inverse); border-radius: var(--radius-lg); padding: 20px; position: relative; overflow: hidden; }
.team-hero h1 { font-size: 30px; color: var(--inverse); }
.team-hero .eyebrow { color: #e9b977; }
.team-hero .row { margin-top: 14px; gap: 24px; }
.team-hero .kpi b { font-family: var(--font-display); font-size: 28px; display: block; line-height: 1; }
.team-hero .kpi span { font-size: 12px; opacity: .8; }
.dots { display: inline-flex; gap: 3px; vertical-align: middle; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--surface-offset); border: 1px solid var(--border); }
.dots i.on { background: var(--primary); border-color: var(--primary); }

/* Sheet / dialog */
.scrim { position: fixed; inset: 0; background: rgba(14, 26, 30, .45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s var(--ease); }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 24px); max-height: 92dvh; overflow-y: auto;
  animation: up .28s var(--ease);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; }
.sheet h2 { font-size: 24px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 640px) { .scrim { align-items: center; } .sheet { border-radius: 22px; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  z-index: 60; box-shadow: var(--shadow-md); max-width: calc(100% - 40px); text-align: center;
}

/* Admin */
.admin-list { display: grid; gap: 8px; }
.admin-item { background: var(--surface); border: 1px solid var(--divider); border-radius: var(--radius-md); padding: 12px 14px; }
.admin-item .row { flex-wrap: wrap; }
.admin-item .select { min-height: 40px; padding: 6px 10px; font-size: 14px; width: auto; flex: 1; min-width: 130px; }
.inline-form { display: flex; gap: 8px; }
.inline-form .input { min-height: 44px; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--surface-offset); border-radius: var(--radius-md); padding: 8px 8px 8px 14px; font-size: 14px; word-break: break-all; }
.copybox span { flex: 1; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 20px; margin-bottom: 6px; }

.foot-note { text-align: center; font-size: 12px; color: var(--faint); margin-top: 28px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- v2: reading, journal, captains ---------- */
.reading-card { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; border-left: 4px solid var(--gold); }
.reading-card:hover { border-color: var(--gold); }
.reading-card .r-ref { font-family: var(--font-display, 'Fraunces', serif); font-size: 26px; font-weight: 600; color: var(--primary); line-height: 1.15; }
.reading-card .r-key { font-size: 14px; color: var(--muted); }
.reading-card .r-cta { font-size: 13px; font-weight: 700; color: var(--gold); margin-top: 4px; }
.reading-card[aria-pressed='true'] .r-cta::before { content: '\2713  '; }
.habit.opens .h-pts::after { content: ' \203A'; }
.journal-text { min-height: 42vh; font-size: 16px; line-height: 1.55; }
.title-input { font: inherit; font-family: var(--font-display, 'Fraunces', serif); font-size: 30px; font-weight: 600; color: inherit; background: transparent; border: 0; border-bottom: 1.5px dashed color-mix(in srgb, currentColor 40%, transparent); padding: 2px 0; width: 100%; margin: 4px 0 14px; border-radius: 0; }
.title-input:focus { outline: none; border-bottom-style: solid; border-bottom-color: currentColor; }
.cap-tools { display: flex; gap: 14px; margin-top: 6px; flex-wrap: wrap; }
.linkbtn { background: none; border: 0; padding: 4px 0; font: inherit; font-size: 13px; font-weight: 700; color: var(--primary); cursor: pointer; }
.linkbtn.danger { color: #a3402c; }
[data-theme='dark'] .linkbtn.danger { color: #e08a74; }

/* ---------- v3: invites, reminders ---------- */
.invite-card { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border-radius: var(--radius-lg); background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent); }
.invite-card b { font-family: var(--font-display); font-size: 26px; font-weight: 600; color: var(--primary); line-height: 1.15; }
.push-card { border-left: 4px solid var(--primary); display: flex; flex-direction: column; gap: 8px; }
#teamLink { word-break: break-all; }
