* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #ffffff);
  color: var(--tg-theme-text-color, #111111);
  padding-bottom: 72px;
}

#app { padding: 12px 14px; }

.screen { display: none; }
.screen.active { display: block; }

h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 18px; }
h3 { font-size: 14px; color: var(--tg-theme-hint-color, #8e8e93); margin: 16px 0 6px; }

.text-input {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid rgba(127,127,127,0.3);
  background: var(--tg-theme-bg-color, #ffffff);
  color: var(--tg-theme-text-color, #111111);
  font-size: 15px;
  margin-top: 8px;
}

.card {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.card:active { opacity: 0.85; }

.btn {
  display: block;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #ffffff);
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
  cursor: pointer;
}

.btn.secondary {
  background: transparent;
  border: 1px solid rgba(127,127,127,0.28);
  color: var(--tg-theme-text-color, #111111);
}

.btn.danger { background: transparent; border: 1px solid #e0535366; color: #e05353; }

.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

.muted { color: var(--tg-theme-hint-color, #8e8e93); font-size: 13px; }

.juz-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  margin: 10px 0;
}

.juz-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(127,127,127,0.18);
  background: var(--tg-theme-bg-color, #ffffff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  color: var(--tg-theme-text-color, #111);
  cursor: pointer;
}

.juz-cell::after {
  content: "";
  position: absolute;
  top: 3px; right: 3px;
  width: 5px; height: 5px;
  border-radius: 50%;
}

.juz-cell.empty { opacity: 0.55; }
.juz-cell.taken { background: #d99a1c14; border-color: #d99a1c55; }
.juz-cell.taken::after { background: #d99a1c; }
.juz-cell.mine-taken { background: #d99a1c14; border-color: var(--tg-theme-button-color, #2481cc); border-width: 1.5px; }
.juz-cell.mine-taken::after { background: #d99a1c; }
.juz-cell.done { background: #3fb95014; border-color: #3fb95055; }
.juz-cell.done::after { background: #2ea043; }

.legend { display: flex; gap: 12px; font-size: 11px; color: var(--tg-theme-hint-color, #8e8e93); margin: 6px 0 10px; }
.legend .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.legend .dot.empty { background: rgba(127,127,127,0.35); }
.legend .dot.taken { background: #d99a1c; }
.legend .dot.done { background: #2ea043; }

.juz-names { margin-top: 4px; padding: 2px 0; }
.juz-name-row { padding: 5px 2px; font-size: 13px; border-bottom: 1px solid rgba(127,127,127,0.1); }
.juz-name-row:last-child { border-bottom: none; }

.juz-cell.wish-neutral { opacity: 0.55; }
.juz-cell.wish-available { background: #3fb95014; border-color: #3fb95055; }
.juz-cell.wish-available::after { background: #2ea043; }
.juz-cell.wish-wished { border-color: var(--tg-theme-button-color, #2481cc); border-width: 1.5px; }
.juz-cell.wish-wished::after { background: var(--tg-theme-button-color, #2481cc); }

.legend .dot.wish-neutral { background: rgba(127,127,127,0.35); }
.legend .dot.wish-available { background: #2ea043; }
.legend .dot.wish-wished { background: #2481cc; }

.khatm-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 10px 0;
}

.khatm-cell {
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  background: var(--tg-theme-bg-color, #ffffff);
  border: 1px solid rgba(127,127,127,0.18);
}

.khatm-cell.khatm-mine { border-color: var(--tg-theme-button-color, #2481cc); border-width: 1.5px; }
.khatm-cell.khatm-done { background: #3fb95010; border-color: #3fb95040; }

.khatm-num { font-weight: 600; font-size: 13px; }
.khatm-ratio { font-size: 11px; margin-top: 1px; color: var(--tg-theme-hint-color, #8e8e93); }
.khatm-date { font-size: 10px; margin-top: 1px; color: var(--tg-theme-hint-color, #8e8e93); }

nav.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-top: 1px solid rgba(127,127,127,0.2);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
}

nav.tabbar button {
  flex: 1;
  background: none;
  border: none;
  font-size: 11px;
  color: var(--tg-theme-hint-color, #8e8e93);
  padding: 6px 0;
}

nav.tabbar button.active { color: var(--tg-theme-button-color, #2481cc); font-weight: 600; }
nav.tabbar .icon { display: block; margin: 0 auto 3px; width: 22px; height: 22px; }
nav.tabbar .icon svg { width: 100%; height: 100%; }
nav.tabbar button:not(.active) .icon svg { stroke-width: 1.6; }

.stat-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(127,127,127,0.15); }
.stat-row:last-child { border-bottom: none; }

.empty-state { text-align: center; padding: 40px 10px; color: var(--tg-theme-hint-color, #8e8e93); }

/* --- Stats dashboard --- */
.hero-figure { text-align: center; padding: 14px 0 6px; }
.hero-value {
  font-size: 44px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--tg-theme-text-color, #111);
  font-variant-numeric: normal;
}
.hero-label { font-size: 13px; color: var(--tg-theme-hint-color, #8e8e93); margin-top: 2px; }

.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.kpi-tile {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  padding: 10px 4px;
  text-align: center;
}
.kpi-value { font-size: 20px; font-weight: 700; color: var(--tg-theme-text-color, #111); }
.kpi-label { font-size: 11px; color: var(--tg-theme-hint-color, #8e8e93); margin-top: 2px; }

.streak-tile { display: flex; }
.streak-main { display: flex; align-items: center; gap: 10px; }
.streak-icon { font-size: 26px; }
.streak-value { font-size: 15px; font-weight: 600; color: var(--tg-theme-text-color, #111); }
.streak-value.streak-good { color: #0ca30c; }

.chart-title { font-size: 13px; font-weight: 600; color: var(--tg-theme-text-color, #111); margin: 0 0 8px; }

.trend-chart { width: 100%; height: auto; display: block; }
.trend-bar { fill: var(--tg-theme-button-color, #2a78d6); }
.trend-baseline { stroke: rgba(127,127,127,0.3); stroke-width: 1; }
.trend-value-label { font-size: 10px; font-weight: 600; fill: var(--tg-theme-text-color, #111); }
.trend-axis-label { font-size: 8px; fill: var(--tg-theme-hint-color, #898781); font-variant-numeric: tabular-nums; }

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(127,127,127,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--tg-theme-text-color, #111);
}
.heatmap-cell.heatmap-empty { opacity: 0.4; }

.ramp-legend { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 11px; color: var(--tg-theme-hint-color, #8e8e93); }
.ramp-swatch {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, rgba(42,120,214,0.12), rgba(42,120,214,0.8));
}
