:root {
  --bg: #171a21;
  --bg2: #1f2430;
  --card: #242b38;
  --line: #333c4d;
  --text: #e8ecf3;
  --muted: #9aa6b8;
  --accent: #7bb6f0;
  --danger: #f28b82;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* ---------- Экран входа ---------- */
.gate {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
}
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  text-align: center;
}
.gate-logo {
  width: 64px; height: 64px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #10233b;
  border-radius: 18px; font-size: 34px; font-weight: 800;
}
.gate h1 { margin: 8px 0 6px; font-size: 24px; }
.gate-hint { color: var(--muted); font-size: 14px; margin: 0 0 18px; line-height: 1.4; }
.gate-note { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
#gateForm { display: flex; flex-direction: column; gap: 10px; }
#codeInput {
  width: 100%; padding: 14px 16px; font-size: 17px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
#codeInput:focus { border-color: var(--accent); }
.gate-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

button { font-family: inherit; cursor: pointer; border: none; }
.btn-primary {
  background: var(--accent); color: #10233b; font-weight: 700;
  padding: 13px 16px; border-radius: 12px; font-size: 16px;
}
.btn-primary:active { transform: scale(0.98); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px; font-size: 16px;
}

/* ---------- Основной экран ---------- */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(23,26,33,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right .btn-primary { padding: 9px 14px; font-size: 15px; }
.conn { font-size: 12px; color: var(--danger); transition: color .3s; }
.conn.online { color: #81c995; }

.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  align-content: start;
}

.empty { text-align: center; color: var(--muted); padding: 60px 20px; display: flex; flex-direction: column; gap: 16px; align-items: center; }

/* ---------- Карточка списка ---------- */
.list {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  display: flex; flex-direction: column;
  align-self: start;
}
.list.drag-over { outline: 2px dashed var(--accent); outline-offset: 2px; }
.list-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px 12px 14px;
  border-left: 6px solid var(--lc, #888);
}
.list-title {
  flex: 1; font-weight: 700; font-size: 16px;
  background: transparent; border: none; color: var(--text);
  outline: none; padding: 2px 0; min-width: 0;
}
.list-count { color: var(--muted); font-size: 13px; }
.list-menu-btn {
  background: transparent; color: var(--muted);
  font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 8px;
}
.list-menu-btn:hover { background: var(--bg2); }
.drag-handle { color: var(--muted); cursor: grab; font-size: 16px; padding: 0 2px; touch-action: none; }

.items { list-style: none; margin: 0; padding: 2px 6px 6px; }
.item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 8px; border-radius: 10px;
}
.item:hover { background: var(--bg2); }
.item.done .item-text { color: var(--muted); text-decoration: line-through; }
.check {
  flex: none; width: 22px; height: 22px; margin-top: 1px;
  border: 2px solid var(--line); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 14px; font-weight: 800; cursor: pointer;
}
.item.done .check { background: var(--lc, var(--accent)); border-color: var(--lc, var(--accent)); color: #10233b; }
.item-text {
  flex: 1; font-size: 15px; line-height: 1.35; outline: none;
  word-break: break-word; white-space: pre-wrap; min-width: 0;
}
.item-del {
  flex: none; background: transparent; color: var(--muted);
  opacity: 0; font-size: 16px; padding: 0 4px; border-radius: 6px;
}
.item:hover .item-del { opacity: 1; }
.item-del:hover { color: var(--danger); }

.add-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 14px;
}
.add-item input {
  flex: 1; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; font-size: 15px; outline: none;
}
.add-item input:focus { border-color: var(--accent); }

/* ---------- Меню списка ---------- */
.menu {
  position: fixed; z-index: 50;
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px; min-width: 200px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.menu-colors { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 6px 10px; }
.swatch { width: 28px; height: 28px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.swatch.active { border-color: var(--text); }
.menu-item {
  display: block; width: 100%; text-align: left;
  background: transparent; color: var(--text);
  padding: 11px 10px; border-radius: 9px; font-size: 15px;
}
.menu-item:hover { background: var(--card); }
.menu-item.danger { color: var(--danger); }

@media (max-width: 480px) {
  .board { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
}
