/* Telegram injects --tg-theme-* variables; fallbacks keep it usable in a browser */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e53935;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg2);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

.loading, .notice {
  padding: 48px 24px;
  text-align: center;
  color: var(--hint);
}

/* ---------- header: list picker ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 12px 16px;
  display: flex; gap: 8px; align-items: center;
  border-bottom: 1px solid rgba(128,128,128,0.15);
}
.topbar select {
  flex: 1;
  appearance: none;
  border: none;
  background: var(--bg2);
  color: var(--text);
  font-size: 16px; font-weight: 600;
  padding: 10px 12px;
  border-radius: 10px;
}
.iconbtn {
  border: none; background: var(--bg2); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px;
  font-size: 18px; cursor: pointer; flex-shrink: 0;
}
.iconbtn.active { background: var(--accent); color: var(--accent-text); }
.iconbtn:focus-visible, .topbar select:focus-visible,
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- items ---------- */
.items { padding: 8px 16px; }
.section-label {
  color: var(--hint);
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin: 16px 4px 8px;
}
.empty { padding: 40px 16px; text-align: center; color: var(--hint); }

.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg);
  padding: 8px 12px;
  border-bottom: 1px solid rgba(128,128,128,0.12);
}
/* round only the outer corners of each contiguous run of items */
.item:not(.item + .item) { border-top-left-radius: 12px; border-top-right-radius: 12px; }
.item:not(:has(+ .item)) {
  border-bottom: none;
  border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;
}

/* the signature: a satisfying tick + strike animation */
.check {
  flex-shrink: 0;
  width: 26px; height: 26px; margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--hint);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.check::after {
  content: '';
  position: absolute; left: 8px; top: 4px;
  width: 6px; height: 11px;
  border: solid var(--accent-text);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.18s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.item.done .check { background: var(--accent); border-color: var(--accent); }
.item.done .check::after { transform: rotate(45deg) scale(1); }

.item-body { flex: 1; min-width: 0; }
.item-body.editable { cursor: pointer; }
.item-name {
  font-weight: 500; word-break: break-word;
  position: relative; display: inline-block;
}
.item-name::after {
  content: '';
  position: absolute; left: 0; top: 55%;
  height: 2px; width: 0;
  background: var(--hint);
  transition: width 0.25s ease;
}
.item.done .item-name { color: var(--hint); }
.item.done .item-name::after { width: 100%; }

.item-desc { color: var(--hint); font-size: 14px; margin-top: 2px; word-break: break-word; }

/* right-hand column: adder over timestamp */
.item-aside {
  flex-shrink: 0;
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 1px;
  text-align: right;
  line-height: 1.25;
}
.item-adder { font-size: 12px; font-weight: 500; }
.item-time { color: var(--hint); font-size: 11px; }

.item-del {
  border: none; background: none; color: var(--hint);
  font-size: 18px; cursor: pointer; padding: 4px; line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  .check, .check::after, .item-name::after { transition: none; }
}

/* ---------- add bar ---------- */
.addbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  background: var(--bg);
  border-top: 1px solid rgba(128,128,128,0.15);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.addbar-inner { max-width: 560px; margin: 0 auto; }
.addbar form { display: flex; gap: 8px; }
.addbar input {
  flex: 1;
  border: none; background: var(--bg2); color: var(--text);
  font-size: 16px; padding: 12px; border-radius: 10px;
}
.addbar input::placeholder { color: var(--hint); }
.addbar button[type=submit] {
  border: none; background: var(--accent); color: var(--accent-text);
  font-size: 16px; font-weight: 600;
  padding: 0 18px; border-radius: 10px; cursor: pointer;
}
.desc-toggle {
  background: none; border: none; color: var(--link);
  font-size: 13px; margin-top: 6px; cursor: pointer; padding: 2px 0;
}
.desc-row { margin-top: 8px; display: none; }
.desc-row.open { display: block; }
.desc-row input { width: 100%; }

/* ---------- panel (share / list settings) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0,0,0,0.4);
  display: none;
}
.overlay.open { display: block; }
.panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  transform: translateY(100%);
  transition: transform 0.22s ease;
}
.panel.open { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .panel { transition: none; } }

.panel h2 { font-size: 17px; margin-bottom: 14px; }
.panel .row { display: flex; gap: 8px; margin-bottom: 12px; }
.panel input {
  flex: 1; border: none; background: var(--bg2); color: var(--text);
  font-size: 16px; padding: 12px; border-radius: 10px;
}
.panel-input {
  width: 100%;
  border: none; background: var(--bg2); color: var(--text);
  font-size: 16px; padding: 12px; border-radius: 10px;
  margin-bottom: 10px;
}
.panel-input::placeholder { color: var(--hint); }
.panel .btn {
  border: none; background: var(--accent); color: var(--accent-text);
  font-weight: 600; font-size: 15px;
  padding: 12px 16px; border-radius: 10px; cursor: pointer;
}
.panel .btn.secondary { background: var(--bg2); color: var(--text); }
.panel .btn.full { width: 100%; margin-top: 4px; }

.member {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid rgba(128,128,128,0.12);
}
.member .pending { color: var(--hint); font-size: 13px; }
.member button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; }

.hintline { color: var(--hint); font-size: 13px; margin: 10px 0; }
.toast {
  position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 20;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 0.92; }
