:root {
  --bg: var(--tg-theme-bg-color, #f4f5f7);
  --bg2: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #3454d1);
  --btn: var(--tg-theme-button-color, #3454d1);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --study: #3454D1;
  --work: #B8860B;
  --sport: #C2185B;
  --other: #5C6B73;
  --green: #2E9E5B;
  --red: #D93025;
  --amber: #E39B0A;
  --grey: #c9ced3;
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior: none; }

.app {
  padding: 12px 14px calc(96px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--hint);
  background: var(--bg);
  z-index: 50;
}

/* alert strip */
.alert-strip {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--amber);
  text-align: left;
  cursor: pointer;
}
.alert-strip.overdue { background: var(--red); }

/* tabs */
.tabs {
  display: flex;
  background: var(--bg2);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 12px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-weight: 700;
  padding: 10px 0;
  border-radius: 11px;
  cursor: pointer;
}
.tab.active { background: var(--btn); color: var(--btn-text); }

/* cards */
.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 10px;
  font-weight: 800;
}

/* summary */
.summary { display: flex; align-items: center; gap: 16px; }
.ring-wrap { position: relative; width: 118px; height: 118px; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--grey); stroke-opacity: .45; stroke-width: 11; }
.ring-fg {
  fill: none;
  stroke: var(--btn);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .5s ease, stroke .3s;
}
.ring-fg.full { stroke: var(--green); }
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-pct { font-size: 26px; font-weight: 800; line-height: 1; }
.ring-sub { font-size: 11px; color: var(--hint); margin-top: 3px; }

.cat-counts { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.cat-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.cat-name { color: var(--hint); flex: 1; white-space: nowrap; }
.cat-num { font-weight: 800; }

/* chart */
.chart-wrap { width: 100%; overflow: hidden; }
.chart { width: 100%; height: auto; display: block; }
.bar-full { fill: var(--green); }
.bar-part { fill: var(--study); }
.bar-empty { fill: var(--grey); fill-opacity: .6; }
.bar-num { font-size: 9px; font-weight: 800; fill: var(--text); text-anchor: middle; }
.bar-label { font-size: 9px; fill: var(--hint); text-anchor: middle; font-weight: 700; }
.bar-today { font-weight: 800; fill: var(--text); }

/* chips */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 8px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1.5px solid var(--grey);
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.chip.active { background: var(--btn); border-color: var(--btn); color: var(--btn-text); }

/* list */
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid rgba(128,128,128,.15);
}
.item:first-child { border-top: 0; padding-top: 2px; }
.item:last-child { padding-bottom: 2px; }
.check {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--grey);
  background: transparent;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  color: #fff;
  font-size: 15px;
  transition: background .15s, border-color .15s;
}
.check.on { background: var(--green); border-color: var(--green); }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 15px; font-weight: 700; word-break: break-word; }
.item.done .item-title { text-decoration: line-through; color: var(--hint); }
.item-desc {
  font-size: 13px;
  color: var(--hint);
  margin-top: 3px;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.item-desc.open { display: block; -webkit-line-clamp: unset; }
.item-desc.rich { display: block; -webkit-line-clamp: unset; cursor: default; }
.item-desc ul { margin: 2px 0; padding-left: 16px; }
.item-desc li { margin: 1px 0; }
.sub { display: flex; align-items: flex-start; gap: 8px; margin: 3px 0; cursor: pointer; }
.sub input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--green); flex: none; }
.sub.done span { text-decoration: line-through; opacity: .7; }
.sub-count { font-weight: 800; color: var(--btn); }
.dept { font-weight: 700; }
.desc-tools { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.tool-btn {
  border: 1.5px solid var(--grey);
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.desc-hint { font-size: 11px; color: var(--hint); }
.seg-wrap { flex-wrap: wrap; }
.seg-wrap .seg-btn { flex: 1 1 30%; }
.item-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--hint); margin-top: 2px; }
.item-meta .cat-dot { width: 8px; height: 8px; }
.due { font-weight: 800; }
.due.soon { color: var(--green); }
.due.overdue { color: var(--red); }
div.item-actions { display: flex; gap: 2px; flex: none; }
.edit,
.del {
  border: 0;
  background: transparent;
  color: var(--hint);
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  flex: none;
}
.empty { color: var(--hint); font-size: 14px; padding: 6px 0; }

/* add button */
.add-btn {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  max-width: 532px;
  margin: 0 auto;
  border: 0;
  border-radius: 14px;
  background: var(--btn);
  color: var(--btn-text);
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  padding: 16px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  z-index: 10;
}

/* form */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  z-index: 40;
}
.sheet {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
}
.sheet-title { font-size: 19px; font-weight: 800; margin-bottom: 14px; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 6px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.field textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--grey);
  background: var(--bg);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 72px;
}
.field textarea:focus { border-color: var(--btn); }
.field input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid var(--grey);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.field input:focus { border-color: var(--btn); }
.seg {
  display: flex;
  background: var(--bg);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 4px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.seg-btn.active { background: var(--btn); color: var(--btn-text); }
.form-error { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.sheet-actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  padding: 14px;
  cursor: pointer;
}
.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-secondary { background: var(--bg); color: var(--text); }
.spacer { height: 8px; }
