:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f7fa);
  --hint: var(--tg-theme-hint-color, #8b9aab);
  --btn: var(--tg-theme-button-color, #2aabee);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #232e3c);
  --line: color-mix(in srgb, var(--hint) 35%, transparent);
  --mark-b: #5eb0e0;
  --mark-h: #e07a6a;
  --mark-n: #6cbc8a;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
}

body {
  padding:
    calc(8px + env(safe-area-inset-top))
    12px
    calc(12px + env(safe-area-inset-bottom));
}

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.head {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.head h1 {
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  text-transform: capitalize;
}

.nav {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--sec);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  margin-bottom: 4px;
  color: var(--hint);
  font-size: 0.7rem;
  text-align: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
}

.cell {
  min-width: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  padding: 4px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font: inherit;
}

.cell:disabled {
  visibility: hidden;
}

.cell .num {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1;
}

.cell.today .num {
  background: var(--btn);
  color: var(--btn-text);
  font-weight: 700;
}

.cell.selected:not(.today) {
  background: var(--sec);
}

.cell.selected.today .num {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--btn-text) 55%, transparent);
}

.marks {
  display: flex;
  gap: 3px;
  min-height: 5px;
}

.mark {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.mark.b { background: var(--mark-b); }
.mark.h { background: var(--mark-h); }
.mark.n { background: var(--mark-n); }

.hint {
  margin: 10px 2px 0;
  color: var(--hint);
  font-size: 0.78rem;
}

.hint.err {
  color: var(--mark-h);
}

.day-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.day-panel h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.block {
  margin-top: 12px;
}

.block:first-child {
  margin-top: 0;
}

.block h3 {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--hint);
}

.block ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.block li {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--text);
}

.block li:first-child {
  border-top: 0;
  padding-top: 0;
}

.empty {
  margin: 0;
  color: var(--hint);
  font-size: 0.9rem;
}

.fold {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.fold summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--hint);
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.fold summary::-webkit-details-marker {
  display: none;
}

.fold summary::after {
  content: "▸";
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--hint);
}

.fold[open] summary::after {
  content: "▾";
}

.fold .count {
  min-width: 1.4em;
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--hint) 18%, transparent);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  text-align: center;
}

.fold ul {
  margin-top: 8px;
}
