:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e4e7ec;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 20px 80px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.header-copy h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.today-line {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.today-line span + span {
  margin-left: 8px;
}

.progress-wrap {
  position: relative;
  width: 84px;
  height: 84px;
  flex: none;
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-track,
.progress-bar {
  fill: none;
  stroke-width: 8;
}

.progress-track {
  stroke: #e5e7eb;
}

.progress-bar {
  stroke: var(--text);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.25s ease;
}

.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  padding-top: 28px;
  font-size: 14px;
  color: var(--text);
}

.progress-label strong {
  font-size: 18px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.summary {
  color: var(--muted);
  font-size: 13px;
}

.habit-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.habit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 0;
  border-bottom: 1px solid #eef0f3;
}

.habit-row:last-child {
  border-bottom: 0;
}

.check-btn {
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 2px solid var(--accent, #9ca3af);
  border-radius: 50%;
  background: #ffffff;
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.check-btn:hover {
  transform: scale(1.06);
}

.check-btn.done {
  background: var(--accent, #9ca3af);
}

.check-btn svg {
  width: 20px;
  height: 20px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.check-btn.done svg {
  opacity: 1;
}

.check-btn svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.habit-name {
  display: block;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.streak-mini {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.delete-btn {
  width: 34px;
  height: 34px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #9ca3af;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.delete-btn:hover {
  background: #fef2f2;
  color: var(--danger);
}

.delete-btn.confirming {
  background: var(--danger);
  color: #ffffff;
}

.delete-btn svg {
  width: 17px;
  height: 17px;
}

.delete-btn svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.add-form {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

#habitInput {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  color: var(--text);
  font: inherit;
}

#habitInput:focus {
  border-color: transparent;
  outline: 2px solid rgba(17, 24, 39, 0.18);
  outline-offset: 1px;
}

#addButton {
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

#addButton:hover {
  background: #374151;
}

#addButton svg {
  width: 20px;
  height: 20px;
}

#addButton svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

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

.cal-weekday {
  padding: 2px 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.cal-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 12px;
  font-weight: 600;
}

.cal-cell .cal-count {
  font-size: 10px;
  font-weight: 700;
}

.cal-cell.level-1 {
  background: #d1fae5;
  color: #065f46;
}

.cal-cell.level-2 {
  background: #6ee7b7;
  color: #064e3b;
}

.cal-cell.level-3 {
  background: #34d399;
  color: #064e3b;
}

.cal-cell.level-4 {
  background: #10b981;
  color: #ffffff;
}

.cal-cell.future {
  opacity: 0.45;
}

.cal-cell.today {
  outline: 2px solid var(--text);
  outline-offset: -2px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0 20px;
}

.stat-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.stat-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.stat-block strong {
  font-size: 22px;
  letter-spacing: 0;
}

.stat-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.subhead {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.streak-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.streak-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.streak-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
}

.streak-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.streak-value {
  margin-left: auto;
  flex: none;
  color: var(--muted);
  font-weight: 600;
}

.empty-state {
  padding: 28px 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: #ffffff;
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .page {
    padding: 24px 16px 72px;
  }

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

@media (max-width: 480px) {
  .app-header {
    align-items: flex-start;
  }

  .header-copy h1 {
    font-size: 24px;
  }

  .progress-wrap {
    width: 72px;
    height: 72px;
  }

  .progress-label {
    padding-top: 22px;
    font-size: 13px;
  }

  .progress-label strong {
    font-size: 16px;
  }

  .panel {
    padding: 18px;
  }
}
