:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #9aa3b2;
  --accent: #6c8cff;
  --accent-soft: #28304a;
  --done: #3ddc97;
  --partial: #e0b341;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.muted { color: var(--muted); }

/* ---------- Login ---------- */
.login-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.login-card input {
  padding: 0.7rem 0.9rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 1rem;
}
.login-card .error { color: #ff8585; margin: 0.5rem 0 0; }

button {
  cursor: pointer;
  font-size: 1rem;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  padding: 0.7rem 0.9rem;
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-weight: 500;
  font-size: 0.9rem;
}
.inline { display: inline; margin: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .title { font-weight: 700; }
.identity { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; color: var(--muted); }

/* ---------- Layout ---------- */
#app { max-width: 880px; margin: 0 auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.25rem;
}
.panel h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.panel-actions { display: flex; justify-content: flex-end; gap: 0.85rem; margin-bottom: 0.6rem; }

.viewtoggle {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: fit-content;
  min-width: 240px;
  margin: 1.1rem auto 0;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.vt-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid transparent;
  cursor: grab;
  user-select: none;
}
.vt-item:hover { border-color: var(--border); }
.vt-item.dragging { opacity: 0.45; cursor: grabbing; }
.vt-item.off { opacity: 0.5; }
.vt-grip { color: var(--muted); cursor: grab; font-size: 0.95rem; line-height: 1; }
.vt-name { flex: 1; font-weight: 600; }
.vt-eye {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.vt-eye.on { color: var(--text); }
.vt-eye:hover { color: var(--accent); }
.vt-eye svg { display: block; }

.caret { display: inline-block; width: 1.1em; color: var(--muted); flex: none; }

/* ---------- Shared checkbox ---------- */
.box {
  flex: none;
  width: 1.2em;
  height: 1.2em;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 5px;
  background: var(--panel-2);
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--done);
}
.box.partial { color: var(--partial); border-color: var(--partial); }
.box.all { color: var(--done); background: rgba(61, 220, 151, 0.16); border-color: var(--done); }

/* ---------- Everyone (ranked, one line each) ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-bottom: 0.9rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.lg { display: inline-flex; align-items: baseline; gap: 0.3rem; }
.lg-num { font-variant-numeric: tabular-nums; opacity: 0.55; }

.people { display: flex; flex-direction: column; }
.person {
  display: grid;
  grid-template-columns: minmax(92px, 23%) 1fr 3.8em;
  align-items: center;
  gap: 0.85rem;
  padding: 0.5rem 0.4rem;
}
.person + .person { border-top: 1px solid var(--border); }
.person.self { background: rgba(108, 140, 255, 0.07); border-radius: 8px; }
.person-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.person.self .person-name { color: var(--accent); }
.person-count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.82rem; white-space: nowrap; text-align: right; }
.done-n { color: var(--text); }

.seg-bar {
  display: flex;
  height: 18px;
  border-radius: 7px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid var(--border);
}
.seg { height: 100%; border-right: 2px solid var(--bg); }
.seg:last-child { border-right: none; }
.seg-fill { height: 100%; background: rgba(236, 238, 242, 0.95); transition: width 0.2s ease; }

.myprogress { margin-bottom: 0.6rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }

/* ---------- My checklist (single user) ---------- */
.checklist { display: flex; flex-direction: column; gap: 0.3rem; }
.cl-course {
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0.8rem 0 0.1rem;
}
.cl-course:first-child { margin-top: 0; }
.cl-chapter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem 0.45rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.cl-expand { display: flex; align-items: center; gap: 0.2rem; cursor: pointer; user-select: none; flex: 1; min-width: 0; }
.cl-expand:hover .cl-title { color: var(--accent); }
.cl-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chapter-check {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 3px 9px 3px 4px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
}
.chapter-check:hover { border-color: var(--accent); }
.chapter-check.partial { color: var(--partial); }
.chapter-check.all { color: var(--done); }
.cc-num { font-size: 1rem; }

.cl-lessons { display: flex; flex-direction: column; padding: 0.2rem 0 0.35rem 0.4rem; }
.cl-lesson {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.32rem 0.5rem;
  border-radius: 7px;
  cursor: pointer;
}
.cl-lesson:hover { background: var(--panel-2); }
.cl-lesson.on .cl-lesson-title { color: var(--muted); }
.cl-lesson-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Time left ---------- */
.tl-deadline { color: var(--muted); margin: 0 0 0.85rem; text-align: center; }
.tl-deadline strong { color: var(--text); }
.tl-grid { display: grid; grid-template-columns: repeat(2, 130px); justify-content: center; gap: 0.6rem; }
.tl-cell { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem 0.5rem; text-align: center; }
.tl-num { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tl-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; }

/* ---------- Picker overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; z-index: 20;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
}
.overlay-card h2 { margin: 0 0 0.25rem; }
.picker-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 1rem; }
.picker-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  text-align: left;
}
.picker-item:hover { border-color: var(--accent); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(2rem);
  background: #3a1d1d;
  border: 1px solid #ff8585;
  color: #ffd7d7;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .person { grid-template-columns: minmax(72px, 34%) 1fr 3.8em; gap: 0.55rem; }
  .picker-list { grid-template-columns: 1fr; }
}
