:root {
  --bg: #0f1a17;
  --card: #182622;
  --card-2: #1e2f2a;
  --text: #e8f2ee;
  --muted: #9db8af;
  --accent: #4fd1a5;
  --accent-dim: #2c7a5f;
  --danger: #e07a6a;
  --warn: #e0b76a;
  --radius: 16px;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(84px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.screen { display: flex; flex-direction: column; gap: 14px; }
.screen[hidden] { display: none; }

.hero { text-align: center; padding: 32px 8px 8px; }
.hero-icon { font-size: 56px; margin-bottom: 8px; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); font-size: 15px; margin-top: 6px; line-height: 1.45; }

.top { display: flex; justify-content: space-between; align-items: flex-start; padding: 8px 4px 0; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.muted-card { background: transparent; border: 1px solid var(--card-2); }
.muted-card h2 { font-size: 15px; color: var(--muted); font-weight: 600; }

.card-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.progress-card { gap: 14px; }
.progress-row { display: flex; flex-direction: column; gap: 6px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.progress-head span:last-child { color: var(--text); font-weight: 600; }
.bar { height: 8px; background: var(--card-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width 0.4s ease; }
.bar-fill.pills { background: var(--warn); }
.bar-fill.nicotine { background: var(--danger); }

.nicotine-card { border: 1px solid #3b3028; }
.nicotine-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.nicotine-count { font-size: 20px; font-weight: 700; margin-top: 4px; }
.product-badge {
  background: var(--card-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.nicotine-plan { font-size: 15px; line-height: 1.5; }
.nicotine-log-btn { margin-top: 0; }

.next-pill-card { background: linear-gradient(135deg, var(--card-2), var(--card)); border: 1px solid var(--accent-dim); }
.btn-took { margin-top: 6px; font-size: 17px; padding: 16px 18px; }
.last-taken { text-align: center; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}
.backfill-toggle { align-self: flex-start; padding-left: 0; }
.backfill-row { display: flex; gap: 8px; }
.backfill-row input[type="time"] { flex: 1; }
.btn-small { padding: 10px 18px; font-size: 15px; }
.big-time { font-size: 44px; font-weight: 700; letter-spacing: -0.02em; color: var(--accent); }
.countdown { color: var(--muted); font-size: 15px; }

.pill-times { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.pill-times li {
  background: var(--card-2);
  border-radius: 10px;
  padding: 8px 14px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--muted);
}
.pill-times li.taken { text-decoration: line-through; opacity: 0.45; }
.pill-times li.next { background: var(--accent-dim); color: var(--text); font-weight: 600; }

#day-guidance { line-height: 1.55; font-size: 15px; }

.upcoming-list { list-style: none; display: flex; flex-direction: column; }
.upcoming-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--card-2);
  font-size: 14px;
}
.upcoming-list li:last-child { border-bottom: none; }
.upcoming-list .u-day { font-weight: 600; white-space: nowrap; }
.upcoming-list .u-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.upcoming-list .u-dose { color: var(--muted); text-align: right; }
.upcoming-list li.milestone .u-day { color: var(--warn); }

.banner {
  background: var(--warn);
  color: #1c1608;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}
.banner.success { background: var(--accent); color: #06251b; }

label { font-size: 14px; color: var(--muted); font-weight: 500; }

input[type="datetime-local"], input[type="time"], input[type="number"], select {
  background: var(--card-2);
  border: 1px solid #2a3f38;
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 12px;
  width: 100%;
  color-scheme: dark;
}

.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 18px;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #06251b; }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: var(--card-2); color: var(--text); margin-top: 16px; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.btn-icon {
  background: var(--card);
  border: none;
  border-radius: 10px;
  font-size: 18px;
  padding: 8px 10px;
  cursor: pointer;
}

.hint { font-size: 13px; color: var(--muted); line-height: 1.4; }

.plan-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.plan-table td { padding: 6px 4px; border-bottom: 1px solid var(--card-2); }
.plan-table tr:last-child td { border-bottom: none; }
.plan-table td:last-child { text-align: right; color: var(--muted); }

.disclaimer { font-size: 12px; color: var(--muted); line-height: 1.5; text-align: center; padding: 0 8px; opacity: 0.8; }

.source-link {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  text-decoration: none;
  border-bottom: 1px solid var(--accent-dim);
  align-self: center;
  padding-bottom: 2px;
}
.source-link:hover, .source-link:focus-visible { color: var(--accent); }
.privacy-card { border: 1px solid var(--accent-dim); }
.privacy-card p:not(.card-label) { font-size: 14.5px; line-height: 1.55; }
.github-button {
  display: block;
  background: var(--card-2);
  border: 1px solid #2a3f38;
  border-radius: 10px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 14px;
  text-align: center;
  text-decoration: none;
}
.github-button:active { transform: scale(0.98); }

/* Bottom tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(15, 26, 23, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--card-2);
}
.tabbar[hidden] { display: none; }
.tab {
  flex: 1;
  max-width: 224px;
  background: var(--card);
  border: none;
  border-radius: 12px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
}
.tab.active { background: var(--accent-dim); color: var(--text); }

/* Guide accordions */
details.guide summary {
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
details.guide summary::-webkit-details-marker { display: none; }
details.guide summary::after { content: "＋"; color: var(--muted); font-size: 18px; }
details.guide[open] summary::after { content: "－"; }

.tips { list-style: none; display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.tips li { font-size: 14.5px; line-height: 1.55; padding-left: 14px; border-left: 2px solid var(--accent-dim); }
.tips.timeline li { border-left-color: var(--warn); }
.tips li strong { color: var(--text); }
.tips li em { color: var(--accent); font-style: normal; }

.links-block { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.links-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin-top: 6px;
}
.links { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.links li { font-size: 14px; line-height: 1.5; color: var(--muted); }
.links a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-dim); }
.links a:active { opacity: 0.7; }

dialog {
  border: none;
  border-radius: var(--radius);
  background: transparent;
  padding: 0;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  width: calc(100vw - 32px);
  overflow-y: auto;
  margin: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
dialog .card { background: var(--card); }
dialog h2 { font-size: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head .btn-icon { background: var(--card-2); font-size: 15px; line-height: 1; }
.dialog-actions { display: flex; gap: 10px; margin-top: 8px; }
.dialog-actions .btn-primary { flex: 1; }
.backup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.backup-actions .btn-secondary { margin-top: 0; padding: 12px 10px; font-size: 14px; text-align: center; }
.backup-import-label, .backup-download { display: flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none; }
.cloud-backup {
  margin-top: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-2);
}
.cloud-backup-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.cloud-backup .card-label { margin-bottom: 3px; }
.cloud-status { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.cloud-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.cloud-dot.on { background: #54c28a; box-shadow: 0 0 0 4px rgba(84, 194, 138, 0.12); }
.cloud-dot.busy { background: #e6a94a; box-shadow: 0 0 0 4px rgba(230, 169, 74, 0.12); }
.cloud-dot.error { background: #e86969; box-shadow: 0 0 0 4px rgba(232, 105, 105, 0.12); }
.cloud-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cloud-actions .btn-secondary { margin: 0; padding: 10px 12px; font-size: 13px; }
.btn-link-danger { border: 0; background: transparent; color: var(--danger); padding: 8px; cursor: pointer; }

@media (max-width: 380px) {
  .backup-actions { grid-template-columns: 1fr; }
}

/* Mood picker */
.mood-picker { display: flex; gap: 8px; }
.mood-btn {
  flex: 1;
  background: var(--card-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 0 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.1s ease;
}
.mood-btn:active { transform: scale(0.94); }
.mood-btn .mood-emoji { font-size: 24px; line-height: 1; filter: grayscale(0.5) opacity(0.7); }
.mood-btn .mood-lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.mood-btn.selected { border-color: var(--accent); background: var(--accent-dim); }
.mood-btn.selected .mood-emoji { filter: none; }
.mood-btn.selected .mood-lbl { color: var(--text); }

/* Craving chips */
.btn-craving { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card-2);
  border: 1px solid #2a3f38;
  border-radius: 999px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 14px;
  cursor: pointer;
}
.chip:active { transform: scale(0.96); }
.chip.plain { color: var(--muted); }

.craving-list { list-style: none; display: flex; flex-direction: column; }
.craving-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--card-2);
}
.craving-list li:last-child { border-bottom: none; }
.craving-list .cv-when { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.craving-list .cv-trigger { flex: 1; }
.craving-list .link-btn { margin-left: auto; }

/* Calendar / journey */
.cal-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card-2); border-radius: 12px; padding: 12px 14px; }
.stat .stat-val { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.stat .stat-lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  aspect-ratio: 1;
  background: var(--card-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 3px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.cal-cell .cc-day { font-size: 11px; color: var(--muted); font-weight: 600; }
.cal-cell .cc-mood { font-size: 15px; line-height: 1; }
.cal-cell .cc-dose { font-size: 9.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-cell.full { background: var(--accent-dim); }
.cal-cell.full .cc-dose, .cal-cell.full .cc-day { color: var(--text); }
.cal-cell.partial { border-color: var(--warn); }
.cal-cell.missed { border-color: var(--danger); opacity: 0.9; }
.cal-cell.future { opacity: 0.38; cursor: default; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -1px; }
.cal-cell.quit::before {
  content: "🚭";
  position: absolute;
  bottom: 1px;
  left: 3px;
  font-size: 9px;
}
.cc-craving {
  position: absolute;
  top: 2px;
  right: 3px;
  background: var(--danger);
  color: #2a0f0a;
  font-size: 9px;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.cal-legend span { display: flex; align-items: center; gap: 5px; }
.cal-legend .lg-cv { color: var(--danger); font-weight: 700; }
.lg-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.lg-dot.lg-full { background: var(--accent-dim); }
.lg-dot.lg-partial { border: 1px solid var(--warn); }
.lg-dot.lg-missed { border: 1px solid var(--danger); }

/* Mood chart */
.mood-chart { display: flex; align-items: flex-end; gap: 3px; height: 72px; }
.mood-chart .mc-bar {
  flex: 1;
  min-width: 3px;
  background: var(--accent-dim);
  border-radius: 3px 3px 0 0;
  min-height: 3px;
}
.mood-chart .mc-bar.empty { background: var(--card-2); }

/* Trigger breakdown */
.trigger-breakdown { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.trigger-breakdown li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.trigger-breakdown .tb-label { width: 90px; color: var(--muted); }
.trigger-breakdown .tb-bar { flex: 1; height: 8px; background: var(--card-2); border-radius: 4px; overflow: hidden; }
.trigger-breakdown .tb-fill { height: 100%; background: var(--danger); border-radius: 4px; }
.trigger-breakdown .tb-count { width: 22px; text-align: right; font-variant-numeric: tabular-nums; }

/* Day detail dialog */
#day-dialog-body { display: flex; flex-direction: column; gap: 16px; }
.dd-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.dd-empty { color: var(--muted); font-size: 14px; }
