:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #f0883e;
  --green-0: #161b22;
  --green-1: #0e4429;
  --green-2: #006d32;
  --green-3: #26a641;
  --green-4: #39d353;
  --danger: #f85149;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  position: fixed;   /* lock to the viewport so there's nothing to drag/bounce */
  inset: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; } /* dvh excludes the mobile URL bar */
.center { display: flex; align-items: center; justify-content: center; padding: 24px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.caption { margin: 6px 0 0; line-height: 1.3; }
.error { color: var(--danger); margin: 4px 0 0; font-size: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
}

/* LOGIN */
#login-form { width: 100%; max-width: 340px; text-align: center; }
#login-form .logo { font-size: 48px; }
#login-form h1 { margin: 8px 0 4px; }
#login-form input {
  width: 100%;
  margin: 16px 0 12px;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #1b1000;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}
button.ghost {
  width: auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
}

/* 3-dot menu */
.menu { position: relative; }
.icon-btn {
  width: 38px; height: 38px;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
  border-radius: 10px;
}
.menu-pop {
  position: absolute;
  top: 44px; right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 150px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  z-index: 20;
}
.menu-item {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: none;
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.menu-item:active { background: var(--bg); }

/* APP */
#app {
  max-width: 720px; margin: 0 auto; padding: 9px;
  display: flex; flex-direction: column; gap: 6px;
  height: 100dvh;
  overflow-x: hidden;          /* never scroll sideways (month labels can stick out a hair) */
  overflow-y: auto;            /* fallback: scroll inside the app only if content is taller */
  overscroll-behavior: contain;
}
.topbar { display: flex; align-items: center; justify-content: space-between; padding-top: env(safe-area-inset-top); }
.brand { font-weight: 800; font-size: 18px; }
.logo-sm { font-size: 20px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 7px 5px;
  text-align: center;
}
.stat .num { display: block; font-size: 22px; font-weight: 800; color: var(--accent); }
.stat .num.zero { color: var(--muted); }
.stat .label { font-size: 11px; color: var(--muted); }

.today-head, .grid-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
h2 { margin: 0; font-size: 16px; }
.today-count { color: var(--accent); }

.habits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.habit {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: background .12s, border-color .12s;
}
.habit:active { transform: scale(.99); }
.habit.done { background: rgba(57,211,83,.10); border-color: var(--green-3); }
.habit .check {
  width: 22px; height: 22px; flex: 0 0 22px;
  border: 2px solid var(--border); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: transparent;
}
.habit.done .check { background: var(--green-3); border-color: var(--green-3); color: #04210f; }
.habit .emoji { font-size: 18px; }
.habit .name { font-weight: 600; font-size: 14px; }
.habit.done .name { text-decoration: line-through; opacity: .65; }

/* GRID */
.legend { display: flex; align-items: center; gap: 4px; font-size: 12px; }
.cal {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr); /* minmax(0,..) stops the track expanding to content */
  grid-template-rows: auto auto;
  column-gap: 4px;
  row-gap: 3px;
}
.cal-months {
  grid-column: 2; grid-row: 1;
  display: flex; gap: 3px;
  height: 12px; font-size: 10px; color: var(--muted);
}
.cal-months span {
  flex: 0 0 var(--cell, 13px);
  white-space: nowrap; overflow: visible;
}
.cal-weekdays {
  grid-column: 1; grid-row: 2;
  display: grid; grid-template-rows: repeat(7, var(--cell, 13px)); gap: 3px;
  font-size: 9px; color: var(--muted);
}
.cal-weekdays div { display: flex; align-items: center; }

.grid {
  grid-column: 2; grid-row: 2;
  min-width: 0;        /* don't let the column grow to fit all the dots */
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell, 13px));
  gap: 3px;
  overflow: visible;
}
.cal-months { min-width: 0; }
.cell {
  width: 13px; height: 13px;
  border-radius: 3px;
  background: var(--green-0);
  border: 1px solid rgba(255,255,255,.04);
}
.grid .cell { width: var(--cell, 13px); height: var(--cell, 13px); }
.cell.lvl-0 { background: var(--green-0); }
.cell.lvl-1 { background: var(--green-1); }
.cell.lvl-2 { background: var(--green-2); }
.cell.lvl-3 { background: var(--green-3); }
.cell.lvl-4 { background: var(--green-4); }
.cell.today { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: none; }

/* instant hover tooltip for grid days */
.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,.6);
  max-width: 240px;
}
.tip .tip-date { font-weight: 700; margin-bottom: 2px; }

.motto {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px; padding: 8px 2px 2px;
}
.motto-text { flex: 1; text-align: center; }
.rotate-btn {
  width: auto; background: transparent; border: none; padding: 0;
  cursor: pointer; line-height: 1; flex: 0 0 auto;
  color: var(--muted); display: flex; align-items: center;
}
.rotate-btn svg { display: block; }
.meal-link {
  width: auto; background: transparent; border: none; padding: 0;
  color: var(--text); font-size: 13px; font-weight: 400; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}

/* recipe page (full screen) */
.recipe-page {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  overflow-y: auto;
  padding: 10px 12px env(safe-area-inset-bottom);
}
.recipe-body { max-width: 560px; margin: 0 auto; padding: 10px 2px 24px; }
.recipe-back { margin-bottom: 12px; }
.recipe-body h1 { font-size: 24px; margin: 4px 0; }
.rserves { margin: 0 0 4px; color: var(--accent); font-size: 13px; font-weight: 600; }
.rsec { margin: 20px 0 8px; font-size: 15px; color: var(--accent); }
.rlist, .rsteps { margin: 0; padding-left: 22px; }
.rlist li, .rsteps li { margin: 7px 0; line-height: 1.45; font-size: 15px; }
.rlist { list-style: none; padding-left: 0; }
.rlist li::before { content: "☐ "; color: var(--muted); }
