:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2421;
  --muted: #6b7773;
  --line: #e1e7e4;
  --green: #2e9e5b;
  --green-bg: #d9f2e3;
  --red: #d64545;
  --red-bg: #fbdada;
  --accent: #1f7a4a;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121715; --card: #1b2220; --text: #e8efec; --muted: #93a09b; --line: #2a3431;
    --green: #3fbf76; --green-bg: #1d4a33; --red: #ef6a6a; --red-bg: #5a2626; --accent: #3fbf76;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #121715; --card: #1b2220; --text: #e8efec; --muted: #93a09b; --line: #2a3431;
  --green: #3fbf76; --green-bg: #1d4a33; --red: #ef6a6a; --red-bg: #5a2626; --accent: #3fbf76;
  --shadow: none;
}
html { scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4; min-height: 100vh; min-height: 100dvh; touch-action: manipulation;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-left, 0px)) 40px max(16px, env(safe-area-inset-right, 0px)); }
h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.3px; }
.sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.banner {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 13px; color: var(--muted); margin-bottom: 14px;
}
.banner.warn { border-color: var(--red); color: var(--text); }
.card {
  background: var(--card); border-radius: 16px; padding: 16px;
  box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 16px;
}
.hero { text-align: center; padding: 22px 16px; }
.hero .big { font-size: 64px; font-weight: 700; color: var(--green); line-height: 1; }
.hero .lbl { font-size: 15px; color: var(--muted); margin-top: 6px; }
.hero .meta { display: flex; justify-content: center; gap: 24px; margin-top: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.hero .meta b { color: var(--text); font-size: 16px; display: block; }
.today-row { display: flex; gap: 10px; margin-top: 16px; }
button {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card);
  color: var(--text); border-radius: 12px; padding: 12px 14px; flex: 1;
}
button:active { transform: scale(.98); }
button, input { min-height: 44px; }
input[type=date] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; flex: 1; min-width: 0;
}
.quit-row { display: flex; gap: 8px; }
.quit-info { font-size: 14px; margin-bottom: 10px; color: var(--muted); }
.quit-info b { color: var(--text); }
@media (max-width: 420px) {
  h1 { font-size: 23px; }
  .hero .big { font-size: 56px; }
  .grid { gap: 4px; }
  .day { font-size: 14px; border-radius: 8px; }
  .today-row { flex-direction: column; }
  .panel .btns button { padding: 12px 6px; }
}
button.g { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
button.r { background: var(--red); color: #fff; border-color: var(--red); font-weight: 600; }
button.ghost { flex: 0 0 auto; padding: 8px 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h2 { margin: 0; font-size: 18px; text-transform: capitalize; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.dow { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 2px; }
.day {
  aspect-ratio: 1 / 1; border-radius: 10px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  padding: 0; background: transparent; flex: initial; min-width: 0;
}
.day.empty { border: none; cursor: default; }
.day.a { background: transparent; border: 1px dashed var(--green); color: var(--green); }
.day.s { background: var(--green-bg); border-color: var(--green); color: var(--green); font-weight: 600; }
.day.d { background: var(--red-bg); border-color: var(--red); color: var(--red); font-weight: 600; }
.day.today { outline: 2px solid var(--text); outline-offset: -2px; }
.day.sel { box-shadow: 0 0 0 2px var(--accent); }
.day.future { opacity: .35; cursor: default; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.panel .t { font-size: 14px; margin-bottom: 10px; }
.panel .btns { display: flex; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat .k { font-size: 12px; color: var(--muted); margin-top: 2px; }
h3 { margin: 0 0 12px; font-size: 16px; }
.ms { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.m { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.m.done { border-color: var(--green); background: var(--green-bg); }
.m .n { font-weight: 600; font-size: 15px; }
.m .p { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 4px; }
.foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 8px; }
[hidden] { display: none !important; }
.login { display: flex; flex-direction: column; gap: 10px; }
.login input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%;
}
a.btn {
  flex: 1; text-align: center; text-decoration: none; color: var(--text);
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 12px 14px; min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.data-btns { display: flex; gap: 8px; }
.dot.dg { background: var(--green); }
.dot.dr { background: var(--red); }
.dot.da { border: 1px dashed var(--green); }
.dot.dn { border: 1px solid var(--line); }
button.auto { flex: 0 0 auto; }
.mt6 { margin-top: 6px; }

.quit-row { flex-wrap: wrap; }
.quit-row input[type=date] { flex: 1 1 100%; width: 100%; }
.quit-row button { flex: 1 1 0; min-width: 0; }
.cheer { border-color: var(--green); }
.cheer.big { background: var(--green-bg); }
.cheer-title { font-size: 18px; font-weight: 700; color: var(--green); margin-bottom: 6px; }
.cheer-text { font-size: 15px; }
.cheer-next { font-size: 13px; color: var(--muted); margin-top: 10px; }
.cheer-next:empty { display: none; }
.confetti { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.note { font-size: 12px; color: var(--muted); }
button.link {
  flex: none; width: 100%; background: none; border: none; color: var(--accent);
  text-decoration: underline; margin-top: 8px; min-height: 40px;
}

button.craving {
  width: 100%; margin-top: 10px; flex: none; background: transparent;
  border: 1px dashed var(--red); color: var(--red);
}
.t2 { font-size: 13px; color: var(--muted); margin: 14px 0 8px; }
.moods { display: flex; gap: 8px; }
.moods button { flex: 1; font-size: 22px; padding: 6px 0; min-width: 0; }
.moods button.on, .tag.on { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
button.tag { flex: none; padding: 6px 12px; border-radius: 20px; min-height: 36px; font-size: 14px; }
textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); width: 100%;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 12px 0 10px; resize: vertical;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type=number] {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg); width: 100%;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.field textarea { margin: 0; }
.yearwrap { overflow-x: auto; padding-bottom: 6px; }
.year { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 11px); grid-auto-columns: 11px; gap: 3px; width: max-content; }
.yc { width: 11px; height: 11px; border-radius: 2px; background: var(--line); }
.yc.s { background: var(--green); }
.yc.a { background: var(--green); opacity: .45; }
.yc.d { background: var(--red); }
.yc.hid { visibility: hidden; }
.warnbox {
  background: var(--red-bg); border: 1px solid var(--red); border-radius: 12px;
  padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}
details.stage { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 0 12px; }
details.stage summary { cursor: pointer; padding: 12px 0; font-weight: 600; font-size: 15px; list-style: none; }
details.stage summary::-webkit-details-marker { display: none; }
details.stage.done summary { color: var(--green); }
details.stage.now { border-color: var(--green); background: var(--green-bg); }
details.stage.now summary { color: var(--green); }
details.stage ul { margin: 0 0 12px; padding-left: 18px; font-size: 14px; }
details.stage li { margin-bottom: 6px; }
.stage .when { font-weight: 400; color: var(--muted); font-size: 13px; }
.ins-row { margin-bottom: 14px; }
.ins-row .h { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.hbar { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.hbar .l { width: 84px; flex: none; }
.hbar .b { flex: 1; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.hbar .b i { display: block; height: 100%; background: var(--red); border-radius: 4px; }
.hbar .c { width: 22px; text-align: right; color: var(--muted); }
.empty-note { font-size: 14px; color: var(--muted); }
.overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--bg); overflow-y: auto;
  padding: env(safe-area-inset-top, 0px) 16px env(safe-area-inset-bottom, 0px);
}
.overlay-in { max-width: 520px; margin: 0 auto; padding: 24px 0 40px; text-align: center; }
.overlay h2 { margin: 0 0 14px; }
.breath-wrap { position: relative; width: 160px; height: 160px; margin: 0 auto 10px; }
.breath {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; border-radius: 50%;
  background: var(--green-bg); border: 2px solid var(--green);
  animation: breathe 8s ease-in-out infinite;
}
.breath-text { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--green); font-weight: 600; }
@keyframes breathe { 0%, 100% { transform: scale(.7); } 50% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .breath { animation: none; } }
.timer { font-size: 44px; font-weight: 700; margin: 8px 0; font-variant-numeric: tabular-nums; }
.crave-sub { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.crave-reason { background: var(--green-bg); border: 1px solid var(--green); border-radius: 14px; padding: 14px; font-size: 17px; margin-bottom: 14px; }
.crave-stat { font-size: 15px; margin-bottom: 14px; }
.crave-tips { text-align: left; font-size: 15px; padding-left: 20px; margin: 0 0 20px; }
.crave-tips li { margin-bottom: 8px; }
.overlay .btns { display: flex; gap: 8px; }

/* ---------- auth ---------- */
body.auth-mode .wrap > h1, body.auth-mode .wrap > .sub, body.auth-mode #banner { display: none !important; }
.auth-box { max-width: 380px; margin: 0 auto; padding: 56px 2px 24px; }
.auth-title { font-size: 22px; font-weight: 650; margin: 0 0 4px; letter-spacing: -.2px; }
.auth-sub { color: var(--muted); font-size: 14px; margin: 0 0 30px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.tabs button {
  flex: 1; background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 12px 0; color: var(--muted); font-size: 15px; margin-bottom: -1px; min-height: 44px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }
.af .row { margin-bottom: 18px; }
.af label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.af input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--card); color: var(--text);
}
.af input:focus { outline: none; border-color: var(--text); }
.pw { position: relative; }
.pw input { padding-right: 90px; }
.pw button.eye {
  position: absolute; right: 4px; top: 4px; bottom: 4px; min-height: 0; flex: none; width: auto;
  border: none; background: none; color: var(--muted); font-size: 13px; padding: 0 12px;
}
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.auth-err { min-height: 20px; font-size: 13px; color: var(--red); margin: 0 0 12px; }
button.primary {
  width: 100%; flex: none; background: var(--text); color: var(--bg); border: none;
  border-radius: 8px; padding: 13px; font-weight: 600; font-size: 15px;
}
button.primary:disabled { opacity: .5; cursor: default; }
.auth-fine { font-size: 12px; color: var(--muted); margin: 18px 0 0; line-height: 1.5; }
.hp { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
button.link.danger { color: var(--red); margin-top: 14px; }
.delbox { margin-top: 10px; }
.delbox input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px; margin: 8px 0 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--card); color: var(--text);
}
.delbox .btns { display: flex; gap: 8px; }
