* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2196F3;
  --primary-dark: #1976D2;
  --primary-light: #BBDEFB;
  --success: #4CAF50;
  --error: #F44336;
  --warning: #FFC107;
  --background: #F5F5F5;
  --surface: #FFFFFF;
  --text-primary: #212121;
  --text-secondary: #757575;
  --divider: #E0E0E0;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--background);
}

.header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 {
  font-size: 18px;
  font-weight: 500;
}

.icon-btn {
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.1);
}

.main-content {
  padding: 16px;
  padding-bottom: 80px;
}

.section {
  animation: fadeIn 0.3s ease;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  margin-top: 40px;
}

.auth-card h2 {
  text-align: center;
  margin-bottom: 24px;
  color: var(--primary);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 14px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-danger {
  width: 100%;
  padding: 12px;
  background: var(--error);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
}

.auth-switch {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
}

.greeting {
  margin-bottom: 20px;
}

.greeting h2 {
  font-size: 24px;
  margin-bottom: 4px;
}

.greeting p {
  color: var(--text-secondary);
  font-size: 14px;
}

.today-progress {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  padding: 20px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.progress-ring {
  position: relative;
  width: 80px;
  height: 80px;
}

.progress-ring svg {
  transform: rotate(-90deg);
}

.progress-bg {
  fill: none;
  stroke: var(--divider);
  stroke-width: 8;
}

.progress-value {
  fill: none;
  stroke: var(--primary);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 0.5s ease;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.progress-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.habits-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habit-item {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}

.habit-color {
  width: 8px;
  height: 40px;
  border-radius: 4px;
}

.habit-info {
  flex: 1;
}

.habit-title {
  font-size: 16px;
  font-weight: 500;
}

.habit-streak {
  font-size: 12px;
  color: var(--text-secondary);
}

.habit-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--divider);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.habit-btn.completed {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.habit-btn:active {
  transform: scale(0.95);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  margin-bottom: 16px;
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.calendar-header h2 {
  font-size: 18px;
}

.nav-btn {
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--primary);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--surface);
  padding: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.calendar-weekday {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 0;
}

.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s;
}

.calendar-day:hover {
  background: var(--primary-light);
}

.calendar-day.today {
  border: 2px solid var(--primary);
}

.calendar-day.selected {
  background: var(--primary);
  color: white;
}

.calendar-day.has-record {
  background: var(--success);
  color: white;
}

.calendar-day.empty {
  color: var(--divider);
  cursor: default;
}

.day-records {
  margin-top: 16px;
}

.day-records h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.record-item {
  background: var(--surface);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.stats-card.main-stat {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.stat-icon {
  font-size: 48px;
}

.stat-info .stat-value {
  font-size: 36px;
  font-weight: 600;
}

.stat-info .stat-label {
  font-size: 14px;
  opacity: 0.9;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 500;
}

.user-info h2 {
  font-size: 20px;
}

.user-info p {
  color: var(--text-secondary);
  font-size: 14px;
}

.profile-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: none;
  border-radius: 12px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  width: 100%;
  text-align: left;
}

.menu-item svg {
  color: var(--primary);
}

.menu-item.danger {
  color: var(--error);
}

.menu-item.danger svg {
  color: var(--error);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item span {
  font-size: 11px;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 18px;
}

.close-btn {
  background: transparent;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text-secondary);
}

.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-option {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
}

.color-option.selected {
  border-color: var(--text-primary);
}

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 300;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--error);
}

.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
  }
}