:root {
  --stone: #DEDAD1;
  --surface: #EDEAE2;
  --ink: #262521;
  --ink-soft: #55524A;
  --pine: #3F5A45;
  --pine-soft: #DCE5DD;
  --ochre: #A9793B;
  --brick: #8B4A42;
  --line: #C9C4B7;
  --radius: 18px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--stone);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button, input, select {
  font-family: inherit;
}

.hidden { display: none !important; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 4px 0;
}

/* ---------- Setup screen ---------- */
#setup {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.setup-inner {
  width: 100%;
  max-width: 420px;
}

.setup-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 2.1rem;
  line-height: 1.1;
  margin: 0 0 28px 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field span {
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.field input, .field select {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--ink);
}

.field input:focus, .field select:focus {
  outline: 2px solid var(--pine);
  outline-offset: 1px;
}

.btn-primary {
  width: 100%;
  background: var(--pine);
  color: var(--surface);
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
}

.btn-primary:active { opacity: 0.85; }

.setup-error {
  color: var(--brick);
  font-size: 0.85rem;
  margin-top: 14px;
}

/* ---------- Main screen ---------- */
#main {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 18px 100px 18px;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 2px 20px 2px;
}

.page-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 2rem;
  margin: 0;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--ink-soft);
}

.offline-banner {
  background: var(--ochre);
  color: var(--surface);
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  text-align: center;
}

.habit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.habit-check {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--pine);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--pine);
  font-size: 1.1rem;
}

.habit-check.done {
  background: var(--pine);
  color: var(--surface);
}

.habit-body {
  flex: 1;
  min-width: 0;
}

.habit-name {
  font-weight: 500;
  font-size: 1.02rem;
  margin: 0 0 2px 0;
  cursor: pointer;
}

.habit-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.habit-streak {
  font-family: var(--font-mono);
  color: var(--ochre);
}

.week-dots {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.week-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
}

.week-dots span.filled {
  background: var(--pine);
}

.week-dots span.today-marker {
  box-shadow: 0 0 0 2px var(--pine-soft);
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}

.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink);
}

.fab {
  position: fixed;
  bottom: 28px;
  right: 50%;
  transform: translateX(280px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--pine);
  color: var(--surface);
  border: none;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(38, 37, 33, 0.25);
}

@media (max-width: 560px) {
  .fab { right: 22px; transform: none; }
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(38, 37, 33, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

@media (min-width: 560px) {
  .modal { align-items: center; justify-content: center; }
}

.modal-card {
  background: var(--stone);
  width: 100%;
  max-width: 460px;
  border-radius: 22px 22px 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
}

@media (min-width: 560px) {
  .modal-card { border-radius: 20px; }
}

.weekdays-picker {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.weekdays-picker button {
  flex: 1;
  padding: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.85rem;
}

.weekdays-picker button.selected {
  background: var(--pine);
  border-color: var(--pine);
  color: var(--surface);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.modal-actions-right {
  display: flex;
  gap: 10px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.95rem;
  padding: 10px 6px;
  cursor: pointer;
}

.btn-text.danger { color: var(--brick); }

#habit-modal .btn-primary,
#settings-modal .btn-primary {
  width: auto;
  padding: 10px 22px;
}
