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

:root {
  --app-max-width: 900px;
}

html, body {
  margin: 0;
  height: 100%;
  background: #0f1115;
  color: #f1f1f4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

#app {
  max-width: var(--app-max-width);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

.topbar {
  padding: calc(16px + env(safe-area-inset-top)) 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 700;
}

.today {
  color: #9a9aa5;
  font-size: 14px;
  text-transform: capitalize;
}

main {
  flex: 1;
  padding: 10px 16px 100px;
  position: relative;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  position: relative;
}

.date-nav-btn {
  background: #1a1c23;
  border: 1px solid #262833;
  color: #f1f1f4;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  flex-shrink: 0;
}

.date-nav-btn:disabled {
  opacity: 0.3;
}

.date-nav-label {
  flex: 1;
  background: #1a1c23;
  border: 1px solid #262833;
  color: #f1f1f4;
  border-radius: 10px;
  padding: 9px 0;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-transform: capitalize;
}

.habit-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  align-items: start;
}

.empty-state {
  text-align: center;
  color: #777885;
  margin-top: 60px;
  font-size: 15px;
  line-height: 1.5;
}

.habit-card {
  background: #1a1c23;
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid #262833;
}

.habit-check {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--accent, #4f46e5);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: transparent;
  transition: background .15s, transform .1s;
}

.habit-check.done {
  background: var(--accent, #4f46e5);
}

.habit-check:active {
  transform: scale(0.9);
}

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

.habit-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.habit-icon {
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.habit-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-meta {
  font-size: 13px;
  color: #9a9aa5;
  display: flex;
  gap: 10px;
  align-items: center;
}

.streak-flame {
  color: #f59e0b;
}

.habit-edit {
  background: none;
  border: none;
  color: #777885;
  font-size: 18px;
  padding: 6px;
}

.fab {
  position: fixed;
  bottom: calc(86px + env(safe-area-inset-bottom));
  right: max(20px, calc(50% - (var(--app-max-width) / 2) + 20px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #4f46e5;
  color: white;
  font-size: 28px;
  border: none;
  box-shadow: 0 6px 16px rgba(79,70,229,0.4);
  z-index: 10;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  background: #15171d;
  border-top: 1px solid #262833;
  padding-bottom: env(safe-area-inset-bottom);
  width: 100%;
  max-width: var(--app-max-width);
  margin: 0 auto;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: #777885;
  padding: 14px 0;
  font-size: 14px;
  font-weight: 600;
}

.tab.active {
  color: #4f46e5;
}

.hidden { display: none !important; }

.stats-view {
  padding: 10px 16px 100px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-mode-tabs {
  display: flex;
  background: #1a1c23;
  border: 1px solid #262833;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.stats-mode-tab {
  flex: 1;
  background: none;
  border: none;
  color: #9a9aa5;
  padding: 9px 0;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
}

.stats-mode-tab.active {
  background: #4f46e5;
  color: white;
}

.stats-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stats-nav-btn {
  background: #1a1c23;
  border: 1px solid #262833;
  color: #f1f1f4;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  flex-shrink: 0;
}

.stats-nav-btn:disabled {
  opacity: 0.3;
}

.stats-nav-label {
  font-weight: 600;
  font-size: 15px;
  text-transform: capitalize;
  text-align: center;
  flex: 1;
}

.habit-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.habit-filter-chip {
  background: #1a1c23;
  border: 1px solid #262833;
  color: #9a9aa5;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.habit-filter-chip.active {
  background: var(--accent, #4f46e5);
  border-color: transparent;
  color: white;
}

.general-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.general-cell {
  min-height: 54px;
  border-radius: 8px;
  background: #262833;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.general-cell.empty {
  background: transparent;
}

.general-cell.future {
  opacity: 0.4;
}

.general-cell-daynum {
  font-size: 10px;
  color: #9a9aa5;
}

.general-cell-icons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  font-size: 12px;
  line-height: 1.1;
}

.general-cell-icons span {
  text-align: center;
}

.stats-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  align-items: start;
}

.stat-card {
  background: #1a1c23;
  border-radius: 16px;
  padding: 16px;
  border: 1px solid #262833;
}

.stat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.stat-card-title {
  font-weight: 600;
  font-size: 15px;
}

.stat-card-pct {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent, #4f46e5);
}

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

.week-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.week-day-label {
  font-size: 10px;
  color: #777885;
}

.week-day-dot {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #262833;
}

.week-day-dot.filled {
  background: var(--accent, #4f46e5);
}

.week-day-dot.future {
  opacity: 0.4;
}

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

.month-head-label {
  font-size: 10px;
  color: #777885;
  text-align: center;
  padding-bottom: 4px;
}

.month-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #9a9aa5;
  background: #262833;
}

.month-cell.empty {
  background: transparent;
}

.month-cell.filled {
  background: var(--accent, #4f46e5);
  color: white;
  font-weight: 700;
}

.month-cell.future {
  opacity: 0.4;
}

.month-bar-wrap {
  margin-top: 10px;
}

.month-bar-track {
  height: 8px;
  border-radius: 4px;
  background: #262833;
  overflow: hidden;
}

.month-bar-fill {
  height: 100%;
  background: var(--accent, #4f46e5);
}

.month-bar-label {
  font-size: 12px;
  color: #9a9aa5;
  margin-top: 6px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  background: #1a1c23;
  border-radius: 18px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  border: 1px solid #262833;
}

.modal-card h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

#habitNameInput {
  width: 100%;
  background: #0f1115;
  border: 1px solid #333543;
  color: #f1f1f4;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  margin-bottom: 16px;
}

.icon-picker-row {
  margin-bottom: 16px;
}

.date-select-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.date-select {
  flex: 1;
  min-width: 0;
  background: #0f1115;
  border: 1px solid #333543;
  color: #f1f1f4;
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 14px;
  text-align: center;
}

.icon-input {
  width: 64px;
  text-align: center;
  background: #0f1115;
  border: 1px solid #333543;
  color: #f1f1f4;
  border-radius: 10px;
  padding: 10px;
  font-size: 18px;
  margin-bottom: 10px;
}

.icon-suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-suggestion-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #0f1115;
  border: 1px solid #333543;
  font-size: 16px;
}

.color-picker {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
}

.color-dot.selected {
  border-color: white;
}

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

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

.btn-primary, .btn-ghost, .btn-danger {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary {
  background: #4f46e5;
  color: white;
}

.btn-ghost {
  background: #262833;
  color: #f1f1f4;
}

.btn-danger {
  background: #3a1620;
  color: #f87171;
}
