:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn-fg: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --danger: #e5484d;
  --accent: linear-gradient(135deg, #38a5ff, #7b5cff);
  --radius: 16px;
}

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

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

#app { max-width: 560px; margin: 0 auto; padding: 16px; }

.top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.top h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.count {
  background: var(--card);
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---------- composer ---------- */

.composer {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 22px;
}

.composer input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.composer input:focus { border-color: #7b5cff; }

#custom-mode { display: flex; flex-direction: column; gap: 8px; }
#custom-dt { color-scheme: light dark; }

.preview {
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 14px;
  animation: fade 0.15s ease-out;
}
.preview.bad { color: var(--hint); }
.preview .when { color: var(--link); font-weight: 700; }

.chips { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.chips button {
  border: none;
  background: var(--bg);
  color: var(--fg);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13.5px;
  cursor: pointer;
}
.chips button:active { transform: scale(0.96); }

.composer-actions { display: flex; gap: 8px; margin-top: 12px; }

.ghost {
  border: none;
  background: var(--bg);
  color: var(--fg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.ghost.active { outline: 2px solid #7b5cff; }

#create {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--btn-fg);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
#create:disabled { opacity: 0.4; cursor: default; }
#create:active:not(:disabled) { transform: scale(0.985); }

/* ---------- list ---------- */

.group-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--hint);
  margin: 18px 4px 8px;
}

.cards { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--hint) 14%, transparent);
  animation: fade 0.2s ease-out;
}
.card .body { flex: 1; min-width: 0; }
.card .text {
  font-size: 16px;
  font-weight: 650;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.card .origin {
  color: var(--hint);
  font-size: 13.5px;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card .origin a {
  color: var(--link);
  text-decoration: none;
}
.card .origin a:hover {
  text-decoration: underline;
}
.card .due {
  font-size: 13.5px;
  color: var(--hint);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.card .due.soon { color: var(--link); font-weight: 650; }

.card .controls { display: flex; flex-direction: column; gap: 8px; }
.card.expanded .controls { grid-column: 1 / -1; }
.primary-actions { display: flex; justify-content: flex-end; gap: 6px; }
.extra-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.card button {
  border: none;
  background: var(--bg);
  border-radius: 10px;
  min-height: 38px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  color: var(--link);
}
.card button:active { transform: scale(0.97); }
.card button:disabled { opacity: 0.45; }
.card .done { color: var(--btn-fg); background: var(--link); }
.card .more { color: var(--fg); }
.card .del { color: var(--danger); }

/* ---------- edit sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.36);
}
.sheet {
  width: min(100%, 528px);
  padding: 18px;
  border-radius: 18px;
  background: var(--bg);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.2);
  animation: sheet-up 0.18s ease-out;
}
.sheet h2 { margin-bottom: 14px; font-size: 19px; }
.sheet input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid color-mix(in srgb, var(--hint) 28%, transparent);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  font: inherit;
  outline: none;
}
.sheet input:focus { border-color: var(--link); }
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }
.sheet-actions button {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
}
#sheet-save { background: var(--accent); color: var(--btn-fg); }

@keyframes sheet-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.empty { color: var(--hint); text-align: center; margin-top: 36px; }

@keyframes fade {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}
