:root {
  --bg: #0e1014;
  --surface: #161a22;
  --surface-2: #1f2530;
  --text: #e6e8ee;
  --muted: #8c93a3;
  --accent: #5cd6a0;
  --accent-2: #2a8f6a;
  --danger: #e26464;
  --border: #252b36;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  padding-bottom: 84px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: #2a3140;
}

button.ghost {
  background: transparent;
}

button.danger {
  background: transparent;
  color: var(--danger);
  border-color: #4a2a2a;
}

input[type="text"],
input[type="password"] {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
}

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

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* Login */
.login-container {
  min-height: 80dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand {
  font-size: 32px;
  margin: 0 0 24px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form label span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.error {
  background: #2a1414;
  border: 1px solid #4a2a2a;
  color: #ffb7b7;
  padding: 10px 12px;
  border-radius: 10px;
}

/* Today */
.today-head,
.range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0 24px;
  gap: 16px;
}

.kicker {
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.human-date {
  font-size: 22px;
  font-weight: 600;
  margin-top: 2px;
}

.score-big {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}

.score-percent {
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.score-frac {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.habit-list {
  display: grid;
  gap: 10px;
}

.habit-row {
  display: grid;
  grid-template-columns: 36px 1fr 28px;
  align-items: center;
  gap: 12px;
  padding: 16px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease, transform 60ms ease;
}

.habit-row:hover {
  background: var(--surface-2);
}

.habit-row:active {
  transform: scale(0.99);
}

.habit-row.is-done {
  background: #133324;
  border-color: #1d4d36;
}

.habit-row .emoji {
  font-size: 22px;
  text-align: center;
}

.habit-row .name {
  font-size: 17px;
}

.habit-row .check {
  font-size: 18px;
  color: var(--accent);
  text-align: center;
  font-weight: 700;
}

.empty {
  color: var(--muted);
}

/* Week */
.week-grid-wrap {
  overflow-x: auto;
}

.week-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.week-grid th,
.week-grid td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.week-grid th.habit-name {
  text-align: left;
  width: 40%;
  min-width: 140px;
  white-space: nowrap;
}

.week-grid th .dow {
  font-size: 11px;
  color: var(--muted);
}

.week-grid th .dom {
  font-size: 16px;
  font-weight: 600;
}

.week-grid th.is-today .dom {
  color: var(--accent);
}

.week-grid td.is-done {
  background: #133324;
  color: var(--accent);
}

.cell-btn {
  width: 100%;
  height: 36px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--accent);
}

.is-done .cell-btn {
  border-style: solid;
  border-color: #1d4d36;
}

.score-row-label {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
}

.score-cell {
  font-weight: 600;
  color: var(--muted);
}

.score-cell.is-today {
  color: var(--accent);
}

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

.dow-head {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.1em;
  padding: 6px 0;
}

.month-cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(92, 214, 160, calc(var(--p, 0) / 100 * 0.55));
  position: relative;
  padding: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.month-cell.is-blank {
  background: transparent;
  border-color: transparent;
}

.month-cell.is-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.month-cell .dom {
  font-size: 12px;
  color: var(--muted);
}

.month-cell .pct {
  font-size: 12px;
  font-weight: 600;
}

.month-nav {
  font-weight: 700;
  padding: 0 8px;
}

/* Habits manage */
.page-head {
  margin-bottom: 16px;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
}

.add-habit {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 8px;
  margin-bottom: 16px;
}

.emoji-input {
  width: 80px;
  text-align: center;
}

.habit-manage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.habit-manage-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: grid;
  gap: 10px;
}

.habit-manage-list li.is-archived {
  opacity: 0.55;
}

.rename-form {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 8px;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 10;
}

.bottom-nav a {
  text-align: center;
  padding: 10px 8px;
  color: var(--muted);
  font-size: 13px;
  border-radius: 10px;
}

.bottom-nav a.is-active {
  color: var(--accent);
  background: rgba(92, 214, 160, 0.08);
}

.nav-logout {
  display: flex;
  align-items: center;
}

.nav-logout button {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 12px;
}

.nav-logout button:hover {
  color: var(--text);
}
