:root {
  --paper: #FFF8EC;
  --page: #FFFDF7;
  --line: #D6E4F2;
  --margin: #F4B6B6;
  --ink: #2A2622;
  --ink-soft: #6F6760;
  --ink-faint: #A69E95;
  --accent: #FF4FA3;
  --accent-ink: #fff;
  --card: #FFFFFF;
  --border: #EADFCF;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 18px rgba(60, 40, 20, .08);
  --done: #9C948B;
  --good: #2FA35A;
  --warn: #E3A008;
  --bad: #D9534F;
  --tab-h: 64px;
  --hand: "Patrick Hand", "Comic Sans MS", cursive;
  --ui: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1D1A16;
    --page: #26221D;
    --line: #37404A;
    --margin: #6B3A3A;
    --ink: #F3ECE2;
    --ink-soft: #BDB3A7;
    --ink-faint: #82796F;
    --card: #2B2621;
    --border: #3A332C;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .3);
    --done: #8D857C;
  }
}
:root[data-theme="dark"] {
  --paper: #1D1A16;
  --page: #26221D;
  --line: #37404A;
  --margin: #6B3A3A;
  --ink: #F3ECE2;
  --ink-soft: #BDB3A7;
  --ink-faint: #82796F;
  --card: #2B2621;
  --border: #3A332C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .3);
  --done: #8D857C;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  min-height: 100dvh;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  background: var(--paper);
}
.brand { font-weight: 900; font-size: 20px; letter-spacing: -.3px; }
.brand span { color: var(--accent); }
.me-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--card);
  border-radius: 999px; padding: 4px 12px 4px 4px; font-weight: 800; font-size: 15px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-grid; place-items: center;
  color: #fff; font-weight: 900; font-size: 14px; flex: none;
}

.daynav {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 16px 8px;
}
.day-label {
  border: 0; background: none; font-weight: 800; font-size: 15px; padding: 6px 10px;
  color: var(--ink-soft); min-width: 180px;
}
.day-label.is-today { color: var(--ink); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card);
  font-size: 22px; line-height: 1; display: grid; place-items: center;
}
.icon-btn:disabled { opacity: .35; cursor: default; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* ---------- notebook page ---------- */
.notebook {
  position: relative;
  background:
    linear-gradient(to right, transparent 38px, var(--margin) 38px, var(--margin) 40px, transparent 40px),
    repeating-linear-gradient(to bottom, transparent 0, transparent 43px, var(--line) 43px, var(--line) 44px),
    var(--page);
  background-position: 0 0, 0 58px, 0 0;
  border-radius: 6px 14px 14px 6px;
  box-shadow: var(--shadow);
  padding: 14px 12px 14px 50px;
  min-height: 260px;
}
.nb-title {
  font-family: var(--hand); font-size: 30px; line-height: 44px; margin: 0;
  text-transform: uppercase; letter-spacing: .5px;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.nb-title small { font-size: 20px; text-transform: none; color: var(--ink-soft); letter-spacing: 0; }
.nb-title u { text-decoration-thickness: 2px; text-underline-offset: 4px; }

.items { list-style: none; margin: 0; padding: 0; }
.item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  min-height: 44px;
  font-family: var(--hand); font-size: 23px; line-height: 1.1;
}
.check {
  flex: none; width: 24px; height: 24px; border-radius: 4px;
  border: 2px solid var(--ink); background: transparent; padding: 0;
  display: grid; place-items: center; font-family: var(--hand); font-size: 22px; line-height: 1;
}
.item.done .check { border-color: var(--done); color: var(--ink); }
.item.done .check::after { content: "\2713"; transform: translateY(-1px); }
.item-text {
  flex: 1; min-width: 0; padding: 6px 0; overflow-wrap: anywhere;
  border: 0; background: none; text-align: left; font: inherit;
}
.item.done .item-text {
  color: var(--done);
  text-decoration: line-through; text-decoration-thickness: 2px;
}
.item.carried .item-text::after {
  content: " \21AA"; color: var(--ink-faint); font-size: 18px;
}
.item-stickers { display: flex; align-items: center; flex: none; }
.item-stickers .sticker { margin-left: -8px; filter: drop-shadow(0 1.5px 1.5px rgba(0,0,0,.25)); }
.item-stickers .main-sticker { position: relative; z-index: 2; }
.cheer-mini { position: relative; }
.cheer-mini .by {
  position: absolute; right: -4px; bottom: -4px; z-index: 3;
  width: 16px; height: 16px; border-radius: 50%; font: 900 9px/16px var(--ui);
  text-align: center; color: #fff; border: 1.5px solid var(--page);
}
.sticker-btn { border: 0; background: none; padding: 0; display: flex; }
.slap { animation: slap .45s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes slap {
  0% { transform: scale(2.4) rotate(-40deg); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

.add-row {
  display: flex; align-items: center; gap: 10px; min-height: 44px;
  font-family: var(--hand); font-size: 23px;
}
.add-row .check { border-style: dashed; border-color: var(--ink-faint); }
.add-row input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font-family: var(--hand); font-size: 23px; padding: 6px 0;
}
.add-row input::placeholder { color: var(--ink-faint); }
.edit-input {
  flex: 1; min-width: 0; border: 0; border-bottom: 2px solid var(--accent);
  background: transparent; outline: none; font-family: var(--hand); font-size: 23px; padding: 4px 0;
}
.del-btn {
  flex: none; border: 0; background: var(--bad); color: #fff; border-radius: 8px;
  font: 800 13px var(--ui); padding: 6px 10px;
}

/* ---------- check-in strip ---------- */
.checkin-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 14px; }
.ci {
  border: 1px solid var(--border); background: var(--card); box-shadow: var(--shadow);
  border-radius: 14px; padding: 10px 12px; text-align: left;
  display: flex; flex-direction: column; gap: 2px;
}
.ci b { font-size: 15px; font-weight: 800; }
.ci span { font-size: 13px; color: var(--ink-soft); }
.ci.done { border-color: var(--good); }
.ci.done b::before { content: "\2713  "; color: var(--good); }

.banner {
  display: flex; flex-direction: column; gap: 8px;
  border: 1px dashed var(--ink-faint); border-radius: 14px; padding: 12px; margin-bottom: 14px;
  background: var(--card);
}
.banner p { margin: 0; font-weight: 700; font-size: 15px; }
.banner .row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 0; border-radius: 999px; padding: 9px 16px;
  font-weight: 800; font-size: 15px; background: var(--accent); color: var(--accent-ink);
}
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--ink); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; }

.tally {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--ink-soft); font-weight: 700; font-size: 14px; margin: 12px 0 4px;
}
.empty-hint { font-family: var(--hand); font-size: 20px; color: var(--ink-faint); margin: 4px 0 8px; }
.received { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.note {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 8px 12px;
  font-size: 14px;
}
.note b { font-weight: 800; }
.note .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- crew ---------- */
.crew-card { margin-bottom: 18px; }
.crew-head {
  display: flex; align-items: center; gap: 10px; margin: 0 0 8px;
}
.crew-head h2 { margin: 0; font-size: 18px; font-weight: 900; }
.crew-head .meta { color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.crew-head .spacer { flex: 1; }
.progress {
  height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; margin: 0 0 10px;
}
.progress > i { display: block; height: 100%; border-radius: 99px; transition: width .4s; }
.crew-card .notebook { min-height: 0; padding-top: 6px; background-position: 0 0, 0 7px, 0 0; }
.goal-person .notebook { background-position: 0 0, 0 1px, 0 0; }
.crew-card .item-text { cursor: pointer; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 800;
  background: var(--border); color: var(--ink-soft);
}
.pill.on { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.wrap-note {
  font-family: var(--hand); font-size: 20px; color: var(--ink-soft);
  margin: 6px 0 0; padding-top: 4px;
}

/* ---------- goals ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.week-nav h2 { margin: 0; font-size: 18px; font-weight: 900; text-align: center; }
.week-nav h2 small { display: block; font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.seg { display: flex; background: var(--border); border-radius: 999px; padding: 3px; margin-bottom: 14px; }
.seg button {
  flex: 1; border: 0; background: none; border-radius: 999px; padding: 7px 8px; font-weight: 800; font-size: 14px;
  color: var(--ink-soft);
}
.seg button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.goal-person { margin-bottom: 16px; }
.goal {
  display: flex; align-items: center; gap: 10px; min-height: 44px;
  font-family: var(--hand); font-size: 22px;
}
.goal .item-text { padding: 6px 0; }
.status {
  flex: none; border: 0; border-radius: 999px; padding: 3px 10px; min-width: 76px;
  font: 800 12px var(--ui); text-transform: uppercase; letter-spacing: .3px;
  background: var(--border); color: var(--ink-soft);
}
.status.done { background: var(--good); color: #fff; }
.status.partial { background: var(--warn); color: #fff; }
.status.missed { background: var(--bad); color: #fff; }
.leader { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.leader .chip {
  display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px 4px 4px; font-weight: 800; font-size: 14px;
}
.section-label {
  font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .8px;
  color: var(--ink-faint); margin: 8px 0 8px;
}

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; max-width: 200px; height: var(--tab-h);
  border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-weight: 800; font-size: 12px; color: var(--ink-faint);
}
.tab-ico { font-size: 22px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ---------- bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 640px; margin: 0 auto; max-height: 85dvh; overflow: auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 18px);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet::before {
  content: ""; display: block; width: 40px; height: 5px; border-radius: 9px;
  background: var(--border); margin: 0 auto 10px;
}
.sheet h3 { margin: 4px 0 4px; font-size: 18px; font-weight: 900; }
.sheet p.sub { margin: 0 0 12px; color: var(--ink-soft); font-size: 14px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 8px; }
.sticker-grid button {
  border: 2px solid transparent; background: var(--paper); border-radius: 14px; padding: 6px;
  display: grid; place-items: center; aspect-ratio: 1;
}
.sticker-grid button.sel { border-color: var(--accent); }
.sheet textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--paper);
  padding: 10px 12px; min-height: 70px; resize: vertical; margin: 12px 0; outline: none;
}
.sheet textarea:focus { border-color: var(--accent); }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; }
.people-list { display: flex; flex-direction: column; gap: 8px; }
.people-list button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 1px solid var(--border); background: var(--paper); border-radius: 14px; padding: 10px 12px;
  font-weight: 800; font-size: 17px; text-align: left;
}
.people-list button.sel { border-color: var(--accent); }
.add-person { display: flex; gap: 8px; margin-top: 12px; }
.add-person input {
  flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--paper);
  padding: 10px 12px; outline: none;
}
.summary { display: flex; align-items: center; gap: 10px; font-weight: 800; margin: 6px 0 0; }

/* ---------- toast / celebration ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); z-index: 60;
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper); border-radius: 999px; padding: 10px 18px;
  font-weight: 800; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
  text-align: center;
}
.party {
  position: fixed; inset: 0; z-index: 70; pointer-events: none; overflow: hidden;
}
.party .sticker { position: absolute; top: -60px; animation: fall 1.6s ease-in forwards; }
@keyframes fall {
  to { transform: translateY(115vh) rotate(540deg); }
}

@media (prefers-reduced-motion: reduce) {
  .slap, .party .sticker, .sheet { animation: none; }
}
