:root {
  --bg: #fafaf7;
  --fg: #1a1a1a;
  --muted: #888;
  --line: #e4e4e0;
  --green: #86efac;
  --green-dark: #16a34a;
  --red: #fca5a5;
  --accent: #2563eb;
  --danger: #b91c1c;
  --cell-off: #ececea;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

a { color: var(--accent); }
h1 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: white;
}
.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--fg);
  font-size: 1.15rem;
}
nav { display: flex; gap: 1rem; align-items: center; }
nav a { text-decoration: none; }
nav a:hover { text-decoration: underline; }

.inline { display: inline; }
.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

.flash {
  list-style: none;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
  background: #fff3cd;
  border: 1px solid #f0d27a;
  border-radius: 6px;
}
.flash li { padding: 0; }

.grid-header { flex-wrap: wrap; gap: 0.5rem 1rem; }
.grid-header .epigraph {
  margin: 0;
  padding: 0;
  font-style: italic;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
  text-align: right;
}
.epigraph .quote-text { white-space: nowrap; }
.epigraph cite {
  display: block;
  margin-top: 0.2rem;
  font-style: normal;
  font-size: 0.75rem;
}
@media (max-width: 720px) {
  .grid-header .epigraph { text-align: left; }
  .epigraph .quote-text { white-space: normal; }
}

/* User list (explore) */
.user-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.user-list li { margin-bottom: 0.5rem; }
.user-card {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg);
}
.user-card:hover { border-color: var(--accent); }
.user-name { font-weight: 600; }
.user-meta { font-size: 0.85rem; color: var(--muted); margin-top: 0.15rem; }

/* Auth forms */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 320px;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
  color: var(--muted);
}
.auth-form input {
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  margin-top: 0.25rem;
}
.auth-form small { color: var(--muted); margin-top: 0.25rem; }
.auth-form button {
  align-self: flex-start;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

/* Grid header */
.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.grid-header h1 { margin: 0; }

.profile-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1rem;
}
.profile-meta strong { color: var(--fg); }
.profile-meta .dot { color: var(--line); }
.btn-follow {
  margin-left: 0.5rem;
  padding: 0.3rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 500;
}
.btn-follow:hover { opacity: 0.9; }
.btn-follow.active {
  background: white;
  color: var(--accent);
}
.btn-follow.active:hover {
  background: #fee2e2;
  border-color: var(--danger);
  color: var(--danger);
}

.row-actions {
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
  margin-left: auto;
  align-items: center;
}
.move-btn {
  font-size: 1rem;
  padding: 0 0.25rem;
  line-height: 1;
}
.vis-toggle {
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  white-space: nowrap;
  flex-shrink: 0;
}
.vis-toggle.vis-private   { color: var(--muted); }
.vis-toggle.vis-followers { color: #b45309; border-color: #fde68a; background: #fffbeb; }
.vis-toggle.vis-public    { color: #166534; border-color: #bbf7d0; background: #f0fdf4; }
.vis-toggle:hover { border-color: var(--accent); }

/* Add habit */
.add-habit { margin-top: 1.5rem; }

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.presets > form { display: contents; }
.chip {
  background: white;
  color: var(--fg);
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
}
.chip:hover { background: #f0f0ed; border-color: var(--accent); }

.custom-add summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.25rem 0;
  list-style: none;
}
.custom-add summary:hover { color: var(--accent); }
.custom-add[open] summary { margin-bottom: 0.5rem; }
.add-form {
  display: flex;
  gap: 0.5rem;
}
.add-form input {
  font-size: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}
.emoji-input { width: 3rem; text-align: center; }
.add-form input[name="name"] { flex: 1; min-width: 0; }
.add-form button {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

/* Grid strips */
.strip {
  margin: 0.75rem 0;
  padding: 0.75rem;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.strip-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.strip-label .emoji { font-size: 1.2rem; flex-shrink: 0; }
.strip-label .name { font-weight: 500; white-space: nowrap; flex-shrink: 0; }
.strip-label .reorder {
  display: flex;
  gap: 0.15rem;
  margin-left: 0.25rem;
}

.day-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 4px;
}
.day-labels span { user-select: none; }

.cells {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cell {
  height: 28px;
  background: var(--cell-off);
  border-radius: 4px;
  border: none;
  padding: 0;
  position: relative;
  font-size: 0.75rem;
  color: var(--muted);
}
button.cell { cursor: pointer; }
button.cell:hover { outline: 2px solid var(--accent); outline-offset: 1px; }
button.cell:disabled { opacity: 0.5; cursor: wait; }
.cell.state-done { background: var(--green); color: #14532d; }
.cell.future { opacity: 0.45; }
.cell.empty { background: transparent; }

.cell .num {
  position: absolute;
  top: 2px;
  left: 4px;
  font-weight: 500;
}

/* Month nav */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.75rem 0;
}
.month-nav a {
  text-decoration: none;
  font-size: 1.2rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  color: var(--fg);
}
.month-nav a:hover { background: white; border: 1px solid var(--line); padding: calc(0.25rem - 1px) calc(0.6rem - 1px); }
.month-title { font-weight: 600; min-width: 9rem; text-align: center; }

@media (max-width: 600px) {
  .topbar { padding: 0.5rem 0.75rem; }
  nav { gap: 0.6rem; font-size: 0.9rem; }
  .strip.view-week .cells { gap: 4px; }
}
