:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0b1020);
  --surface: var(--tg-theme-secondary-bg-color, #141b2f);
  --surface-2: #1b2440;
  --text: var(--tg-theme-text-color, #f5f7ff);
  --muted: var(--tg-theme-hint-color, #8c96b3);
  --accent: var(--tg-theme-button-color, #7c5cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --green: #32d583;
  --orange: #fdb022;
  --red: #f97066;
  --line: rgba(255, 255, 255, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -10%, rgba(124, 92, 255, 0.24), transparent 38%),
    radial-gradient(circle at -10% 32%, rgba(45, 212, 191, 0.09), transparent 30%),
    var(--bg);
}

button { font: inherit; }

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px calc(36px + env(safe-area-inset-bottom));
}

.topbar, .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar { margin-bottom: 24px; }
.topbar h1 { margin: 2px 0 0; font-size: 27px; letter-spacing: -0.8px; }
.eyebrow { margin: 0; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 1.7px; }

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 15px;
  color: white;
  background: linear-gradient(145deg, #9b8afb, #6045db);
  box-shadow: 0 9px 24px rgba(81, 57, 190, .35);
  font-weight: 800;
}

.hero-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 174px;
  padding: 24px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(124,92,255,.96), rgba(70,50,171,.92));
  box-shadow: 0 22px 55px rgba(22, 16, 64, .42);
}

.hero-card::after {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  right: -70px;
  top: -80px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
}

.hero-copy { max-width: 61%; z-index: 1; }
.hero-date { margin: 0 0 10px; color: rgba(255,255,255,.72); font-size: 12px; font-weight: 700; }
.hero-copy h2 { margin: 0 0 8px; font-size: 24px; line-height: 1.08; letter-spacing: -.6px; }
.hero-copy > p:last-child { margin: 0; color: rgba(255,255,255,.74); font-size: 12px; line-height: 1.5; }

.progress-ring {
  --progress: 0deg;
  display: grid;
  width: 94px;
  height: 94px;
  flex: 0 0 94px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(#fff var(--progress), rgba(255,255,255,.18) 0);
  z-index: 1;
}

.progress-ring::before {
  content: "";
  grid-area: 1 / 1;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #674bd8;
}

.progress-ring div { grid-area: 1 / 1; z-index: 1; text-align: center; }
.progress-ring strong { display: block; font-size: 21px; }
.progress-ring span { color: rgba(255,255,255,.68); font-size: 10px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 14px 11px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(20,27,47,.78);
  backdrop-filter: blur(14px);
}

.stat-icon { display: grid; width: 28px; height: 28px; flex: 0 0 28px; place-items: center; border-radius: 9px; font-weight: 900; }
.stat-done .stat-icon { color: var(--green); background: rgba(50,213,131,.12); }
.stat-pending .stat-icon { color: var(--orange); background: rgba(253,176,34,.12); }
.stat-missed .stat-icon { color: var(--red); background: rgba(249,112,102,.12); }
.stat-card strong { display: block; font-size: 18px; line-height: 1; }
.stat-card div span { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; }

.discipline-card,
.chart-card {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(22, 30, 52, .96), rgba(15, 21, 39, .92));
  box-shadow: 0 16px 38px rgba(0, 0, 0, .18);
}

.discipline-card {
  position: relative;
  margin-bottom: 14px;
  padding: 20px;
  overflow: hidden;
}

.discipline-card::after {
  content: "";
  position: absolute;
  width: 130px;
  height: 130px;
  right: -50px;
  top: -60px;
  border-radius: 50%;
  background: rgba(124, 92, 255, .12);
  pointer-events: none;
}

.discipline-card[data-tone="success"] { border-color: rgba(50, 213, 131, .24); }
.discipline-card[data-tone="warning"] { border-color: rgba(253, 176, 34, .26); }
.discipline-card[data-tone="danger"] { border-color: rgba(249, 112, 102, .28); }

.discipline-head,
.chart-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.discipline-head h2,
.chart-heading h2 { margin: 5px 0 0; font-size: 18px; letter-spacing: -.3px; }

.score-badge {
  display: flex;
  min-width: 74px;
  height: 58px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(124, 92, 255, .28);
  border-radius: 17px;
  color: #c7bdff;
  background: rgba(124, 92, 255, .13);
}
.score-badge strong { font-size: 22px; line-height: 1; }
.score-badge span { margin-top: 4px; color: var(--muted); font-size: 9px; }

.insight-text {
  max-width: 92%;
  margin: 13px 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.discipline-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.discipline-metrics > div {
  min-width: 0;
  padding: 11px 9px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .035);
}
.discipline-metrics span { display: block; margin-bottom: 7px; font-size: 15px; }
.discipline-metrics strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.discipline-metrics small { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }

.chart-card { margin-bottom: 30px; padding: 20px 16px 16px; }
.chart-legend { display: flex; gap: 12px; padding-top: 3px; color: var(--muted); font-size: 8px; }
.chart-legend span::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 2px; }
.legend-done::before { background: var(--green); }
.legend-missed::before { background: var(--red); }

.weekly-chart {
  display: grid;
  height: 166px;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.chart-column {
  display: grid;
  min-width: 0;
  grid-template-rows: 15px 1fr 16px;
  gap: 5px;
  color: var(--muted);
  text-align: center;
}
.chart-value { overflow: hidden; font-size: 8px; font-weight: 800; text-overflow: ellipsis; }
.chart-track {
  display: flex;
  min-height: 0;
  align-items: flex-end;
  justify-content: center;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.chart-stack {
  display: flex;
  width: min(22px, 72%);
  min-height: 4px;
  flex-direction: column;
  overflow: hidden;
  border-radius: 7px 7px 4px 4px;
  background: rgba(255, 255, 255, .04);
  transition: height .35s ease;
}
.chart-stack i { display: block; min-height: 0; }
.bar-pending { background: rgba(140, 150, 179, .22); }
.bar-missed { background: linear-gradient(#ff8d85, var(--red)); }
.bar-done { background: linear-gradient(#5be8a3, var(--green)); }
.chart-column > span { font-size: 9px; font-weight: 700; }
.chart-column.today > span { color: #b9acff; }
.chart-column.today .chart-stack { box-shadow: 0 0 0 2px rgba(124, 92, 255, .28); }

.section-heading h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.35px; }
.day-progress { padding: 7px 11px; border-radius: 11px; color: #b9acff; background: rgba(124,92,255,.13); font-size: 12px; font-weight: 800; }

.date-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(42px, 1fr));
  gap: 5px;
  margin: 17px -3px 20px;
}

.date-chip {
  display: flex;
  min-width: 0;
  padding: 9px 2px 7px;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  border-radius: 15px;
  color: var(--muted);
  background: transparent;
}

.date-chip span { font-size: 9px; font-weight: 700; }
.date-chip strong { color: var(--text); font-size: 15px; }
.date-chip i { width: 4px; height: 4px; border-radius: 50%; background: transparent; }
.date-chip i.complete { background: var(--green); }
.date-chip i.missed { background: var(--red); }
.date-chip.active { color: white; background: var(--accent); box-shadow: 0 8px 18px rgba(82,60,190,.28); }
.date-chip.active strong { color: white; }

.task-list { display: grid; gap: 10px; }
.task-card {
  display: grid;
  grid-template-columns: 45px 42px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  padding: 13px 12px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: rgba(20,27,47,.78);
  transition: opacity .2s ease, transform .2s ease;
}

.task-time strong, .task-time span { display: block; }
.task-time strong { font-size: 12px; }
.task-time span { margin-top: 4px; color: var(--muted); font-size: 9px; }
.task-icon { display: grid; width: 40px; height: 40px; place-items: center; border-radius: 13px; background: var(--surface-2); font-size: 19px; }
.task-content { min-width: 0; }
.task-content h3 { margin: 0; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.task-content p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }

.complete-button {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255,255,255,.15);
  border-radius: 50%;
  color: #07170f;
  background: transparent;
  font-weight: 900;
}
.complete-button:not(:disabled):active { transform: scale(.9); }
.task-card.done { opacity: .58; }
.task-card.done .complete-button { border-color: var(--green); background: var(--green); }
.task-card.done h3 { text-decoration: line-through; }
.task-card.missed:not(.done) { border-color: rgba(249,112,102,.22); }
.task-card.missed:not(.done) .task-content p { color: var(--red); }
.complete-button.loading { animation: pulse .7s infinite alternate; }
.complete-button.locked {
  border-color: rgba(249, 112, 102, .28);
  color: var(--red);
  background: rgba(249, 112, 102, .08);
  cursor: not-allowed;
}

.empty-state {
  padding: 32px 22px;
  border: 1px dashed rgba(255,255,255,.12);
  border-radius: 20px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.55;
}
.empty-state.error { color: var(--red); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  padding: 11px 16px;
  border-radius: 14px;
  opacity: 0;
  color: white;
  background: rgba(29,35,55,.94);
  box-shadow: 0 12px 35px rgba(0,0,0,.32);
  font-size: 12px;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: .22s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes pulse { to { opacity: .35; } }

@media (max-width: 365px) {
  .app-shell { padding-inline: 12px; }
  .hero-card { padding: 20px; }
  .progress-ring { width: 82px; height: 82px; flex-basis: 82px; }
  .progress-ring::before { width: 66px; height: 66px; }
  .stat-card { gap: 6px; padding-inline: 8px; }
  .discipline-card { padding-inline: 16px; }
  .weekly-chart { gap: 5px; }
  .task-card { grid-template-columns: 40px 38px minmax(0, 1fr) 30px; gap: 7px; padding-inline: 9px; }
  .task-icon { width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
