:root {
  color-scheme: light;
  --paper: #fff7ec;
  --card: #ffffff;
  --line: #efe3d3;
  --ink: #2b2440;
  --soft: #6a627c;
  --sun: #ffd166;
  --danger: #b3261e;
  --radius: 20px;
  --tabbar: 68px;
  font-family: ui-rounded, "SF Pro Rounded", Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
  /* Keeps a focused card from hiding behind the tab bar. */
  scroll-padding-bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom));
}

/* Each person keeps one color everywhere, on both phones. */
.player-0 { --player: #ff7a66; --player-deep: #b93822; --player-tint: #ffe7e1; }
.player-1 { --player: #2fc4b2; --player-deep: #08695e; --player-tint: #d9f5f0; }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; line-height: 1.35; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 3px solid #6b5bd2; outline-offset: 2px; }

.sprite, .visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.icon {
  width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.icon .solid, #i-flame .solid { fill: currentColor; stroke: none; }
#i-more path { stroke-width: 3.2; }

/* Frame */
.shell {
  max-width: 560px; margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom));
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.brand img { width: 36px; height: 36px; border-radius: 11px; }
.today { color: var(--soft); font-weight: 600; }
.view { display: none; }
.shell[data-view="tasks"] .view-tasks,
.shell[data-view="score"] .view-score,
.shell[data-view="feed"] .view-feed { display: block; }
.view-title { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.tabbar {
  position: fixed; inset: auto 0 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--soft); font-size: 12px; font-weight: 700;
}
.tab[aria-current="page"] { color: var(--ink); }
.tab .icon { width: 44px; height: 28px; padding: 2px 0; border-radius: 14px; }
.tab[aria-current="page"] .icon { background: var(--sun); }

/* Buttons and choices */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 16px; font-weight: 700; text-align: center;
  background: var(--ink); color: #fff; text-decoration: none;
}
.button.quiet { background: #f4ebdf; color: var(--ink); }
.button.danger { background: #fbe9e7; color: var(--danger); }
.button.small { min-height: 44px; padding: 8px 14px; }
.button.small .icon { width: 20px; height: 20px; }
.choices {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px;
  padding: 4px; border-radius: 16px; background: #f4ebdf;
}
.choice { position: relative; display: block; }
.choice input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.choice span, .choices > button {
  display: block; min-height: 44px; padding: 11px 4px; border-radius: 12px;
  color: var(--soft); font-size: 15px; font-weight: 700; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.choice input:checked + span, .choices > button[aria-pressed="true"] {
  background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(43 36 64 / 16%);
}
.choice input:focus-visible + span { outline: 3px solid #6b5bd2; }

/* Score */
.score-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; }
.score-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.score-side:last-child { flex-direction: row-reverse; text-align: right; }
.score-side > div { min-width: 0; }
.avatar {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--player); color: var(--ink); font-size: 18px; font-weight: 800; line-height: 1;
}
.score-name { color: var(--soft); font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-xp { color: var(--player-deep); font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.score-xp small { margin-left: -.15em; font-size: 12px; }
.versus { color: var(--soft); font-size: 13px; font-weight: 700; }
.bar { display: flex; gap: 4px; height: 12px; margin-top: 14px; }
.bar i { flex: var(--share) 1 0; min-width: 12px; border-radius: 6px; background: var(--player); transition: flex-grow .4s ease; }
.leader { margin-top: 12px; text-align: center; font-weight: 700; }
.view-tasks .score { display: block; width: 100%; text-align: left; margin-bottom: 16px; }
.view-score .score { margin-top: 12px; padding: 20px 16px; }
.view-score .score-side { flex-direction: column; text-align: center; }
.view-score .score-side > div { max-width: 100%; }
.view-score .avatar { width: 52px; height: 52px; font-size: 22px; }
.view-score .score-xp { font-size: 32px; }
.week-dates { color: var(--soft); font-weight: 600; }
.heading-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.past { margin-top: 28px; }
.past-list { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.past-week { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.past-week .badge {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 14px;
  background: var(--player-tint, #f4ebdf); color: var(--player-deep, var(--soft));
}
.past-week > div { flex: 1; min-width: 0; }
.past-week strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.past-week small { color: var(--soft); font-size: 14px; }
.past-week output { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 28px; color: var(--soft); }

/* Tasks */
.task-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.task-tools .button { min-height: 52px; }
.group { margin-top: 20px; }
.group h3 { margin-bottom: 8px; color: var(--soft); font-size: 15px; font-weight: 700; }
.cards { display: grid; gap: 10px; }
.card { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 0; overflow: hidden; }
.card-main { display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 14px 0 14px 14px; text-align: left; }
button.card-main:active { background: var(--player-tint); }
button.card-main:focus-visible, .card-more:focus-visible { outline-offset: -3px; border-radius: var(--radius); }
.mark {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border: 2.5px solid var(--player); border-radius: 14px; color: var(--player-deep);
}
.card.done { background: var(--player-tint); border-color: transparent; }
.card.done .mark { background: var(--player); color: var(--ink); }
.card-text { min-width: 0; }
.card-title { display: block; font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 3px; color: var(--soft); font-size: 14px; font-weight: 600; }
.tags > span { display: inline-flex; align-items: center; gap: 4px; }
.tags .icon { width: 17px; height: 17px; }
.tags .xp { color: var(--player-deep); font-weight: 800; }
.tags .flame .icon { color: #e8590c; }
.card-more { display: grid; place-items: center; width: 52px; color: var(--soft); }
.card-done { grid-column: 1 / -1; padding: 0 14px 14px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--player-deep); font-size: 14px; font-weight: 700; }
.card-foot .button { background: rgb(255 255 255 / 75%); color: var(--ink); }
.photo { display: block; width: 100%; border-radius: 14px; overflow: hidden; background: #f4ebdf; }
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-done .photo { height: 160px; margin-bottom: 10px; }
.empty { margin-top: 16px; padding: 28px 20px; text-align: center; }
.empty strong { display: block; font-size: 18px; }
.empty p { margin-top: 4px; color: var(--soft); }

/* Feed */
.feed-list { display: grid; gap: 10px; margin-top: 12px; }
.feed-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.feed-item strong { display: block; overflow-wrap: anywhere; }
.feed-item small { color: var(--soft); font-size: 14px; }
.feed-item .xp { color: var(--player-deep); font-weight: 800; white-space: nowrap; }
.feed-item .photo { grid-column: 1 / -1; height: 260px; margin-top: 10px; }

/* Forms and sheets */
.form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > span, .field > legend { padding: 0; font-weight: 700; }
.field > legend { margin-bottom: 6px; }
.field small { color: var(--soft); font-size: 14px; }
.input {
  width: 100%; min-height: 50px; padding: 12px 14px; border: 1.5px solid #cfc1ae; border-radius: 14px;
  background: var(--card); font-size: 17px;
}
.input::placeholder { color: #7d758c; }
.xp-row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; }
.xp-row .choices { padding: 3px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-weight: 700; cursor: pointer; }
.switch small { display: block; color: var(--soft); font-size: 14px; font-weight: 500; }
.switch input {
  appearance: none; flex: none; position: relative; width: 52px; height: 32px; margin: 0;
  border-radius: 16px; background: #a59bab; cursor: pointer; transition: background .15s;
}
.switch input::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch input:checked { background: #08695e; }
.switch input:checked::after { transform: translateX(20px); }
.error { color: var(--danger); font-weight: 600; }
.error:empty { display: none; }
.actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
[hidden] { display: none !important; }

.welcome { max-width: 440px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom)); }
.welcome header { margin-bottom: 24px; text-align: center; }
.welcome header img { width: 84px; height: 84px; border-radius: 24px; }
.welcome h1 { margin-top: 12px; font-size: 30px; letter-spacing: -.03em; }
.welcome header p { margin-top: 4px; color: var(--soft); }
.welcome header .button { margin-top: 12px; }
.welcome .person { display: grid; gap: 14px; border-color: transparent; background: var(--player-tint); }
.welcome .person h2 { color: var(--player-deep); font-size: 17px; }

dialog { color: inherit; }
dialog::backdrop { background: rgb(43 36 64 / 45%); }
.sheet {
  width: 100%; max-width: 560px; max-height: calc(100dvh - 24px - env(safe-area-inset-top)); margin: auto auto 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain;
  border: 0; border-radius: 28px 28px 0 0; background: var(--paper);
}
.sheet h2 { margin-bottom: 16px; font-size: 22px; letter-spacing: -.02em; }
.sheet > p { margin-bottom: 16px; color: var(--soft); }
.preview { display: block; max-width: 100%; max-height: 50dvh; margin: 0 auto; border-radius: var(--radius); }
.lightbox { max-width: 100vw; max-height: 100dvh; margin: auto; padding: 16px; border: 0; background: none; }
.lightbox button { display: block; border-radius: var(--radius); }
.lightbox img { display: block; max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); border-radius: var(--radius); }

#toast {
  position: fixed; z-index: 10; left: 50%; bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 16px; width: max-content; max-width: calc(100vw - 32px);
  padding: 6px 18px; min-height: 52px; border-radius: 18px; background: var(--ink); color: #fff; font-weight: 700;
  opacity: 0; visibility: hidden; transform: translate(-50%, 12px);
  transition: opacity .2s, transform .2s, visibility .2s;
}
#toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
#toast button { min-height: 44px; color: var(--sun); font-weight: 800; }

@media (min-width: 900px) {
  :root { scroll-padding-bottom: 0; }
  .shell {
    display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-rows: auto auto 1fr;
    gap: 0 32px; max-width: 1080px; padding: 32px;
  }
  .top { grid-column: 1 / -1; margin-bottom: 24px; }
  .shell .view { display: block; }
  .view-tasks { grid-row: 2 / 4; }
  .view-tasks .score { display: none; }
  .view-score { grid-area: 2 / 2; }
  .view-feed { grid-area: 3 / 2; margin-top: 28px; }
  .tabbar { display: none; }
  .sheet { margin: auto; padding: 24px; border-radius: 28px; max-width: 480px; }
  #toast { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
