:root[data-theme="dark"] {
  --bg: #14171a;
  --bg-elevated: #1b1e22;
  --bg-card: #1a1d21;
  --bg-input: #22262b;
  --text: #ece9e4;
  --text-muted: #9a9ea6;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #e8a33d;
  --accent-contrast: #14171a;
  --danger: #d9736c;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f6f4ef;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0eee8;
  --text: #201d18;
  --text-muted: #6b6660;
  --border: rgba(32, 29, 24, 0.1);
  --border-strong: rgba(32, 29, 24, 0.18);
  --accent: #c9791e;
  --accent-contrast: #ffffff;
  --danger: #b23b3b;
  --shadow: 0 10px 30px rgba(32, 29, 24, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: var(--accent);
}

h1,
h2 {
  font-family: "Manrope", system-ui, sans-serif;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--text);
  letter-spacing: -0.01em;
}

.brand-mark {
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-user {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Buttons ---------- */

.btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: var(--accent-contrast);
}

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-block {
  width: 100%;
}

.inline-form {
  display: inline;
}

/* ---------- Flash messages ---------- */

.flash-stack {
  max-width: 960px;
  margin: 16px auto 0;
  padding: 0 24px;
  display: grid;
  gap: 8px;
}

.flash {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
}

/* ---------- Layout ---------- */

.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 36px 24px 80px;
}

.dash-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
}

.dash-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}

/* ---------- Habit grid & cards ---------- */

.habit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.habit-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  overflow: hidden;
}

.habit-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--habit-color, var(--accent));
}

.habit-card.is-finished {
  opacity: 0.65;
}

.habit-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.habit-emoji {
  font-size: 1.8rem;
  line-height: 1;
}

.habit-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 16px;
  letter-spacing: -0.01em;
}

.odometer {
  display: flex;
  gap: 3px;
  margin-bottom: 6px;
}

.odometer-digit {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
  font-size: 1.9rem;
  font-variant-numeric: tabular-nums;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-bottom: 2px solid var(--habit-color, var(--accent));
  border-radius: 6px;
  min-width: 28px;
  text-align: center;
  padding: 4px 0;
}

.odometer-label {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.habit-meta {
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.habit-saved {
  margin: 0 0 4px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--habit-color, var(--accent));
}

.habit-since {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.habit-card-add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  color: var(--text-muted);
  font-family: inherit;
  font-weight: 600;
  min-height: 180px;
  cursor: pointer;
}

.habit-card-add:hover {
  color: var(--text);
  border-color: var(--accent);
}

.add-icon {
  font-size: 1.6rem;
  line-height: 1;
}

/* ---------- Habit edit panel (inline) ---------- */

.habit-edit {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 12px;
}

.habit-edit[hidden] {
  display: none;
}

.habit-edit-actions {
  display: flex;
  gap: 8px;
}

.habit-edit-actions .btn {
  flex: 1;
}

/* ---------- Forms ---------- */

.stack-form {
  display: grid;
  gap: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"] {
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
}

input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.input-emoji {
  width: 100%;
  text-align: center;
  font-size: 1.2rem;
}

.input-color {
  padding: 3px;
  height: 42px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
}

.emoji-field {
  position: relative;
}

.emoji-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  max-width: 220px;
}

.emoji-preset {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  padding: 4px 6px;
  cursor: pointer;
}

.emoji-preset:hover {
  border-color: var(--accent);
}

/* ---------- Auth pages ---------- */

.auth-wrap {
  display: flex;
  justify-content: center;
  padding-top: 40px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
}

.auth-card h1 {
  margin-bottom: 20px;
  font-size: 1.4rem;
}

.auth-switch {
  margin: 18px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Modal ---------- */

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.55);
}

.modal-panel {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-head h2 {
  font-size: 1.2rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 520px) {
  .topbar {
    padding: 14px 16px;
  }

  .main {
    padding: 24px 16px 64px;
  }

  .habit-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
