:root {
  --bg-1: #ffd9a0;
  --bg-2: #ff9a6c;
  --bg-3: #ff6b8b;
  --ink: #3a2b3a;
  --ink-soft: #8a7585;
  --card: rgba(255, 255, 255, 0.82);
  --card-solid: #ffffff;
  --line: rgba(58, 43, 58, 0.08);
  --shadow: 0 10px 30px rgba(120, 60, 60, 0.18);
  --radius: 26px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* The hidden attribute must always win over display rules below
   (.picker/.app/.sheet set display, which would otherwise override it). */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Fredoka", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 48%, var(--bg-3) 100%);
  min-height: 100dvh;
  overflow: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* Decorative sky */
.sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.sun {
  position: absolute; top: -90px; right: -60px;
  width: 280px; height: 280px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.95), rgba(255,236,170,0.65) 55%, rgba(255,236,170,0) 72%);
}
.glow {
  position: absolute; bottom: -140px; left: -80px;
  width: 360px; height: 360px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,107,139,0.4), rgba(255,107,139,0) 70%);
}

/* Layout shell */
.app {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  gap: 12px;
  max-width: 460px; margin: 0 auto;
  height: 100dvh;
  padding: calc(14px + var(--safe-top)) 16px calc(10px + var(--safe-bottom));
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: 18px; font-size: 30px;
  background: var(--card-solid); box-shadow: var(--shadow);
}
.brand-mark.small { width: 40px; height: 40px; border-radius: 13px; font-size: 22px; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.05; color: #fff; text-shadow: 0 1px 8px rgba(150,60,60,0.25); }
.brand-sub { font-size: 13px; font-weight: 500; color: rgba(255,255,255,0.92); }
.daypill {
  flex: none; text-align: center;
  background: var(--card-solid); border-radius: 16px;
  padding: 7px 13px; box-shadow: var(--shadow); line-height: 1.1;
}
.daypill .d-num { font-size: 16px; font-weight: 700; }
.daypill .d-lbl { display: block; font-size: 10px; font-weight: 500; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

/* Cards */
.card {
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Report card */
.report { padding: 16px 18px; }
.report-greet { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.report-greet .ava { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; flex: none; box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.report-greet .greet-text h2 { font-size: 18px; font-weight: 600; line-height: 1.1; }
.report-greet .greet-text .date { font-size: 13px; color: var(--ink-soft); font-weight: 500; }

/* Input mode */
.input-row { display: flex; align-items: stretch; gap: 10px; }
.step-field {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--card-solid); border: 2px solid var(--line);
  border-radius: 18px; padding: 4px 14px; transition: border-color 0.15s;
}
.step-field:focus-within { border-color: var(--bg-2); }
.step-field .sf-ico { font-size: 22px; }
.step-field input {
  flex: 1; min-width: 0; border: none; outline: none; background: none;
  font-family: inherit; font-size: 30px; font-weight: 700; color: var(--ink);
  padding: 10px 0; -moz-appearance: textfield;
}
.step-field input::-webkit-outer-spin-button,
.step-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step-field input::placeholder { color: #d7c4cf; }

.btn {
  border: none; cursor: pointer; font-family: inherit; font-weight: 600;
  border-radius: 18px; transition: transform 0.08s ease, box-shadow 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  padding: 0 20px; font-size: 16px; color: #fff;
  background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
  box-shadow: 0 8px 18px rgba(255,107,139,0.4);
}
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-block { width: 100%; padding: 14px; font-size: 16px; }

/* Logged (done) mode */
.logged { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logged .big {
  font-size: 38px; font-weight: 700; line-height: 1; letter-spacing: -0.02em;
}
.logged .big small { font-size: 15px; font-weight: 500; color: var(--ink-soft); margin-left: 4px; }
.logged .tick { font-size: 13px; font-weight: 500; color: #1aa86b; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.btn-edit {
  padding: 11px 20px; font-size: 15px; color: var(--ink);
  background: var(--card-solid); box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  border: 1px solid var(--line);
}

.hint { margin-top: 9px; font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }

/* Standings */
.standings { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 16px 6px; }
.standings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.standings-head h2 { font-size: 16px; font-weight: 600; }
.toggle { display: flex; background: rgba(58,43,58,0.06); border-radius: 12px; padding: 3px; }
.toggle-btn {
  border: none; background: none; cursor: pointer; font-family: inherit;
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  padding: 6px 12px; border-radius: 9px; transition: all 0.15s;
}
.toggle-btn.is-active { background: var(--card-solid); color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,0.08); }

.board { list-style: none; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-bottom: 6px; }
.board::-webkit-scrollbar { width: 0; }
.row {
  display: grid; grid-template-columns: 22px 40px 1fr auto 10px; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 16px; background: rgba(255,255,255,0.5);
  transition: background 0.15s, transform 0.08s; cursor: pointer;
}
.row:active { transform: scale(0.985); }
.row .chev { font-size: 18px; color: var(--ink-soft); opacity: 0.5; text-align: center; }
.row.me { background: #fff; box-shadow: 0 4px 14px rgba(0,0,0,0.08); outline: 2px solid rgba(255,154,108,0.55); }
.row .rank { font-size: 15px; font-weight: 700; text-align: center; color: var(--ink-soft); }
.row .ava { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; }
.row .who { min-width: 0; }
.row .who .nm { font-size: 15px; font-weight: 600; line-height: 1.1; display: flex; align-items: center; gap: 5px; }
.row .who .tag { font-size: 10px; font-weight: 700; color: #fff; background: var(--bg-2); padding: 1px 6px; border-radius: 8px; }
.bar-wrap { height: 6px; border-radius: 4px; background: rgba(58,43,58,0.08); margin-top: 5px; overflow: hidden; }
.bar { height: 100%; border-radius: 4px; transition: width 0.5s cubic-bezier(.22,1,.36,1); }
.row .val { font-size: 17px; font-weight: 700; text-align: right; letter-spacing: -0.01em; }
.row .val small { display: block; font-size: 10.5px; font-weight: 500; color: var(--ink-soft); letter-spacing: 0; }

/* Footer */
.footer { text-align: center; flex: none; }
.footer { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.link { background: none; border: none; cursor: pointer; font-family: inherit; font-size: 13px; color: rgba(255,255,255,0.95); font-weight: 500; padding: 5px 6px; }
.link strong { font-weight: 700; }
.link-sub { font-size: 12px; color: rgba(255,255,255,0.78); }

/* Picker */
.picker {
  position: fixed; inset: 0; z-index: 5;
  display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--bg-1), var(--bg-3));
}
.picker-card {
  width: 100%; max-width: 380px;
  background: var(--card); backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 30px; padding: 28px 22px; box-shadow: var(--shadow);
  text-align: center;
}
.picker-head .brand-mark { margin: 0 auto 14px; width: 64px; height: 64px; border-radius: 20px; font-size: 36px; }
.picker-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.picker-sub { color: var(--ink-soft); font-weight: 500; margin-top: 4px; margin-bottom: 20px; }
.picker-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  border: none; cursor: pointer; font-family: inherit;
  background: var(--card-solid); border-radius: 20px; padding: 18px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08); transition: transform 0.08s, box-shadow 0.15s;
  border: 2px solid transparent;
}
.tile:active { transform: scale(0.96); }
.tile .ava { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-size: 30px; }
.tile .nm { font-size: 16px; font-weight: 600; }

/* Confetti */
.confetti { position: fixed; inset: 0; z-index: 20; pointer-events: none; overflow: hidden; }
.confetti span {
  position: absolute; top: -20px; font-size: 18px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 30; background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 14px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25); max-width: 88vw; text-align: center;
}
.toast.err { background: #c0334d; }

/* Skeleton while loading */
.loading { opacity: 0.6; }

/* ---- Logo ---- */
.emblem { display: block; flex: none; }
.emblem-sm { width: 46px; height: 46px; border-radius: 14px; filter: drop-shadow(0 6px 14px rgba(120,60,60,0.22)); }
.emblem-lg { width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 22px; filter: drop-shadow(0 10px 22px rgba(120,60,60,0.25)); }

.wordmark { display: flex; flex-direction: column; line-height: 1; min-width: 0; }
.wm-line1 { font-weight: 600; text-transform: uppercase; }
.wm-summer { font-weight: 700; letter-spacing: 0.005em; }

.wordmark-lg { align-items: center; gap: 3px; }
.wordmark-lg .wm-line1 { font-size: 14px; letter-spacing: 0.22em; color: var(--ink-soft); padding-left: 0.22em; }
.wordmark-lg .wm-summer {
  font-size: 36px;
  background: linear-gradient(95deg, #ff8a4c, #ff5d8f 55%, #c44bd8);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

.wordmark-sm .wm-line1 { font-size: 10px; letter-spacing: 0.16em; color: rgba(255,255,255,0.9); padding-left: 0.16em; }
.wordmark-sm .wm-summer { font-size: 20px; color: #fff; text-shadow: 0 1px 8px rgba(150,60,60,0.3); }

/* ---- Health sync chip + cheer ---- */
.health-chip {
  margin-left: auto; flex: none; border: none; cursor: pointer; font-family: inherit;
  font-weight: 600; font-size: 12.5px; color: var(--ink);
  background: rgba(58,43,58,0.06); padding: 8px 12px; border-radius: 13px; white-space: nowrap;
  transition: transform 0.08s, background 0.15s;
}
.health-chip:active { transform: scale(0.95); }
.logged .cheer { font-size: 13px; font-weight: 600; color: #c43f6b; margin-top: 5px; line-height: 1.25; max-width: 22ch; }

/* ---- Bottom sheet (Apple Health) ---- */
.sheet {
  position: fixed; inset: 0; z-index: 25;
  display: grid; place-items: end center;
  background: rgba(58,43,58,0.45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.sheet-card {
  width: 100%; max-width: 460px; position: relative;
  background: #fff; border-radius: 28px 28px 0 0;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  box-shadow: 0 -12px 44px rgba(0,0,0,0.28);
  max-height: 90dvh; overflow-y: auto;
  animation: sheetUp 0.3s cubic-bezier(.22,1,.36,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 50%;
  border: none; cursor: pointer; background: rgba(58,43,58,0.06); color: var(--ink-soft); font-size: 13px;
}
.sheet-head { text-align: center; margin-bottom: 4px; }
.sheet-ico { font-size: 42px; }
.sheet-head h2 { font-size: 21px; font-weight: 700; margin-top: 6px; }
.sheet-head p { font-size: 13.5px; color: var(--ink-soft); margin-top: 4px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.sheet .btn-block { margin-top: 14px; }
.setup { margin-top: 16px; background: rgba(255,154,108,0.08); border: 1px solid rgba(255,154,108,0.18); border-radius: 18px; padding: 14px 16px; }
.setup-title { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--bg-2); margin-bottom: 10px; }
.steps-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; line-height: 1.45; color: var(--ink); }
.steps-list em { font-style: normal; font-weight: 600; }
.steps-list code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.kv { display: flex; gap: 8px; align-items: baseline; margin-top: 6px; }
.kv span { flex: none; width: 84px; font-size: 11.5px; color: var(--ink-soft); font-weight: 600; }
.kv code { word-break: break-all; }
.sheet-note { font-size: 12.5px; color: var(--ink-soft); margin-top: 12px; line-height: 1.45; }

/* ---- Daily history sheet ---- */
.hist-head { display: flex; align-items: center; gap: 12px; padding-right: 32px; }
.hist-head .ava { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 27px; flex: none; }
.hist-head h2 { font-size: 19px; font-weight: 700; line-height: 1.1; }
.hist-head p { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.hist-caption { display: flex; align-items: baseline; justify-content: space-between; margin-top: 16px; padding: 0 2px; }
.cap-date { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.cap-val { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.cap-val small { font-size: 12px; color: var(--ink-soft); font-weight: 500; }
.hist-chart {
  display: flex; align-items: flex-end; gap: 4px; height: 124px; margin-top: 8px;
  padding: 8px 2px 0; overflow-x: auto; justify-content: safe center;
}
.hist-chart::-webkit-scrollbar { height: 0; }
.bar-col { flex: 0 0 auto; width: 15px; height: 100%; display: flex; align-items: flex-end; justify-content: center; border: none; background: none; padding: 0; cursor: pointer; }
.bar-fill { width: 100%; min-height: 3px; border-radius: 6px 6px 3px 3px; background: color-mix(in srgb, var(--c) 42%, #fff); transition: height 0.4s cubic-bezier(.22,1,.36,1); }
.bar-col.today .bar-fill { background: var(--c); }
.bar-col.empty .bar-fill { background: rgba(58,43,58,0.1); }
.bar-col.sel .bar-fill { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); }
.hist-axis { text-align: center; font-size: 11.5px; color: var(--ink-soft); margin-top: 8px; }
.hist-entries { margin-top: 12px; display: flex; flex-direction: column; max-height: 34vh; overflow-y: auto; }
.hist-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.hist-row:last-child { border-bottom: none; }
.hist-row strong { font-weight: 700; font-size: 15px; }

@media (max-height: 640px) {
  .emblem-sm { width: 42px; height: 42px; }
  .report { padding: 13px 16px; }
  .logged .big { font-size: 32px; }
  .row { padding: 7px 10px; }
}
