:root {
  --bg: #fff7f2;
  --surface: #ffffff;
  --surface-2: #fdeee8;
  --text: #3b2a2f;
  --muted: #8a7277;
  --accent: #e86a8a;
  --accent-ink: #ffffff;
  --accent-soft: #fbd9e1;
  --gold: #f2b544;
  --ok: #4caf7d;
  --line: #f1dcd5;
  --shadow: 0 6px 20px rgba(150, 70, 90, 0.12);
  --radius: 20px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1719;
    --surface: #2b2023;
    --surface-2: #35282c;
    --text: #f7e9ec;
    --muted: #b99aa1;
    --accent: #f07c99;
    --accent-ink: #2a1418;
    --accent-soft: #4a2a33;
    --line: #3f2f34;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 16px;
  min-height: 100dvh;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand { font-weight: 900; font-size: 20px; letter-spacing: -0.3px; }
.icon-btn { border: 0; background: var(--surface); border-radius: 999px; width: 40px; height: 40px; font-size: 18px; box-shadow: var(--shadow); }

main {
  max-width: 520px; margin: 0 auto;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px);
}
.loading, .empty { text-align: center; color: var(--muted); padding: 48px 12px; }

h2 { font-size: 18px; font-weight: 800; margin: 28px 0 12px; }
.muted { color: var(--muted); }

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #f39a7c 100%);
  color: #fff; border-radius: 26px; padding: 20px; box-shadow: var(--shadow);
}
.hello { margin: 0 0 14px; font-size: 20px; font-weight: 800; }
.stats { display: flex; gap: 10px; }
.stat {
  flex: 1; background: rgba(255, 255, 255, 0.2); border-radius: 16px; padding: 10px 12px;
  display: flex; flex-direction: column; font-size: 13px; font-weight: 600;
}
.stat .big { font-size: 24px; font-weight: 900; line-height: 1.2; }
.progress { height: 10px; background: rgba(255, 255, 255, 0.3); border-radius: 99px; margin-top: 16px; overflow: hidden; }
.progress > div { height: 100%; background: #fff; border-radius: 99px; transition: width 0.6s cubic-bezier(.2,.9,.3,1.2); }
.hint { margin: 8px 0 0; font-size: 14px; font-weight: 600; opacity: 0.95; }

.banner {
  display: flex; align-items: center; gap: 12px;
  margin-top: 14px; padding: 12px 14px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
}
.banner p { margin: 0; flex: 1; }

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.card {
  position: relative; overflow: hidden;
  min-height: 150px; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 14px; text-align: left;
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  transition: transform 0.15s ease;
}
.card:active { transform: scale(0.97); }
.card .emoji { font-size: 34px; line-height: 1; }
.card .label { font-weight: 800; font-size: 16px; line-height: 1.2; }
.card .pts { font-size: 13px; color: var(--muted); font-weight: 700; }
.card .cta {
  align-self: flex-start; background: var(--accent-soft); color: var(--text);
  border-radius: 99px; padding: 5px 10px; font-size: 13px; font-weight: 800;
}
.card.done { border: 0; box-shadow: var(--shadow); background: var(--surface-2); }
.card.done.has-photo {
  color: #fff;
  background: linear-gradient(to top, rgba(40, 15, 22, 0.85), rgba(40, 15, 22, 0.05) 70%), var(--photo) center / cover;
}
.card.done .comment { font-size: 12.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card.weekly { grid-column: 1 / -1; min-height: 120px; border-color: var(--gold); }
.card.weekly.done { border: 0; }
.card .week { display: block; margin-top: 4px; font-size: 13px; font-weight: 800; color: var(--gold); }
.card.has-photo .week { color: #ffe08a; }
.card .week.reached { color: var(--ok); }
.card .check {
  position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ok); color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 15px;
}

.btn {
  border: 0; border-radius: 99px; padding: 12px 20px; font-weight: 800;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
}
.btn:disabled { opacity: 0.45; box-shadow: none; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; border: 1.5px solid var(--line); }
.btn.block { width: 100%; }

.balance-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); box-shadow: var(--shadow); border-radius: 99px;
  padding: 8px 14px; font-weight: 900; font-size: 18px;
}

.list { display: flex; flex-direction: column; gap: 10px; }
.reward, .order, .row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow);
}
.r-emoji { font-size: 30px; width: 40px; text-align: center; flex-shrink: 0; }
.r-body { flex: 1; min-width: 0; }
.r-title { margin: 0; font-weight: 700; line-height: 1.25; }
.r-cost { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-weight: 700; }
.mini-progress { height: 6px; background: var(--surface-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.mini-progress > div { height: 100%; background: var(--gold); border-radius: 99px; }
.chip { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); white-space: nowrap; }
.chip.pending { background: #fff1cc; color: #7a5a00; }
.chip.delivered { background: #d8f3e4; color: #1f6b43; }
@media (prefers-color-scheme: dark) {
  .chip.pending { background: #4a3d16; color: #ffe08a; }
  .chip.delivered { background: #1d3d2c; color: #9be3bb; }
}
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 700; text-decoration: underline; padding: 4px; }
.remove-btn { border: 0; background: var(--surface-2); border-radius: 50%; width: 32px; height: 32px; color: var(--muted); font-weight: 900; flex-shrink: 0; }

details.add { margin-top: 12px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); }
details.add summary { padding: 14px; font-weight: 800; list-style: none; cursor: pointer; }
details.add summary::-webkit-details-marker { display: none; }
.form { display: grid; gap: 10px; padding: 0 14px 14px; }
.form .pair { display: grid; grid-template-columns: 72px 1fr; gap: 10px; }
.field {
  width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 14px;
  padding: 11px 12px; font-size: 16px;
}
.field:focus { outline: 2px solid var(--accent); border-color: transparent; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick button { border: 1.5px solid var(--line); background: var(--bg); border-radius: 99px; padding: 8px 14px; font-weight: 800; }
.quick button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.day { background: var(--surface); border-radius: 20px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.day header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.day h3 { margin: 0; font-size: 16px; font-weight: 800; text-transform: capitalize; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.thumb {
  flex-shrink: 0; width: 76px; height: 76px; border-radius: 14px; border: 0;
  background: var(--surface-2) center / cover; position: relative; font-size: 26px;
  display: grid; place-items: center;
}
.thumb.has-photo span { position: absolute; bottom: 4px; right: 4px; font-size: 16px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.gift { margin: 10px 0 0; font-size: 14px; font-weight: 700; }

.mini-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mini-cards .thumb { width: 100%; height: auto; aspect-ratio: 1; }
.mini-cards .thumb.todo { opacity: 0.4; filter: grayscale(1); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting p { margin: 0; font-weight: 700; }
.setting small { display: block; color: var(--muted); font-weight: 600; }
.switch { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: 0.2s; }
.switch span::after { content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: 0.2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); box-shadow: 0 -4px 20px rgba(150, 70, 90, 0.1);
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
  border-radius: 22px 22px 0 0;
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 800; padding: 4px 0; border-radius: 14px;
}
.tabs a b { font-weight: 800; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs a span { font-size: 22px; transition: transform 0.2s; }
.tabs a.active { color: var(--accent); background: var(--accent-soft); }
.tabs a.active span { transform: translateY(-2px) scale(1.1); }

.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(30, 12, 18, 0.6);
  display: grid; place-items: center; padding: 20px; animation: fade 0.2s ease;
}
.sheet {
  width: 100%; max-width: 420px; background: var(--surface); border-radius: 26px; padding: 22px;
  box-shadow: var(--shadow); animation: pop 0.35s cubic-bezier(.2,.9,.3,1.3);
}
.sheet h2 { margin-top: 0; }
.celebrate { text-align: center; }
.celebrate .burst { font-size: 64px; animation: wiggle 0.8s ease; }
.celebrate .plus { font-size: 44px; font-weight: 900; color: var(--accent); margin: 4px 0; }
.celebrate .bonus { margin: 4px 0; font-weight: 800; color: var(--gold); }
.celebrate .comment { font-size: 17px; font-weight: 700; margin: 14px 0 20px; line-height: 1.4; }
.viewer img { width: 100%; max-height: 62dvh; object-fit: contain; border-radius: 18px; background: #000; }
.viewer p { font-weight: 700; margin: 12px 0; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.spinner { text-align: center; font-weight: 800; font-size: 18px; color: #fff; }
.spinner div { font-size: 48px; animation: bob 1s ease-in-out infinite; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); z-index: 30;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 16px;
  font-weight: 700; font-size: 14px; box-shadow: var(--shadow); animation: pop 0.25s ease;
}

.sparkle { position: fixed; z-index: 25; pointer-events: none; font-size: 22px; animation: float 1.6s ease-out forwards; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg) scale(1.15); } 60% { transform: rotate(10deg); } }
@keyframes bob { 50% { transform: translateY(-10px); } }
@keyframes float { to { transform: translateY(-60vh) rotate(40deg); opacity: 0; } }
