:root {
  --bg: #eef3f8;
  --phone: #ffffff;
  --ink: #1e3a5f;
  --muted: #5a7394;
  --bar: #d7ebf8;
  --green: #6fbf73;
  --green-d: #4caf50;
  --orange: #f3b14a;
  --blue: #5aa6e8;
  --purple: #9b7ed8;
  --pink: #ef7a8a;
  --shadow: 0 10px 28px rgba(30, 58, 95, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #f4f7fb 0%, #e8eef6 100%);
  color: var(--ink);
}

.stage {
  min-height: 100%;
  display: flex;
  justify-content: center;
  padding: 24px 12px;
}

.phone {
  width: 100%;
  max-width: 420px;
  min-height: min(860px, calc(100vh - 48px));
  background: var(--phone);
  border-radius: 36px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.topbar {
  background: var(--bar);
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 12px 48px;
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-align: center;
}
.back {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 12px;
}
.back:hover { background: rgba(255,255,255,0.5); }

main {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 96px;
}

.welcome {
  text-align: center;
  font-weight: 800;
  font-size: 1.05rem;
  margin: 4px 0 18px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.cat {
  aspect-ratio: 1;
  border: 0;
  border-radius: 28px;
  color: #fff;
  font-weight: 800;
  font-size: 1.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(30,58,95,0.12);
  text-decoration: none;
}
.cat .glyph { font-size: 2.4rem; line-height: 1; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.08)); }
.cat.science { background: linear-gradient(180deg, #8fd48a, #5cbc61); }
.cat.money { background: linear-gradient(180deg, #ffd36a, #f0a83a); }
.cat.faith { background: linear-gradient(180deg, #7ec4f2, #4aa3e4); }
.cat.fun { background: linear-gradient(180deg, #f59aa6, #ea6b7d); }

.stack { display: flex; flex-direction: column; gap: 14px; }

.pcard {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 12px;
  border-radius: 22px;
  color: #fff;
  box-shadow: 0 8px 16px rgba(30,58,95,0.12);
}
.pcard .art {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: rgba(255,255,255,0.22);
  display: grid;
  place-items: center;
  font-size: 2rem;
  flex-shrink: 0;
}
.pcard .meta { flex: 1; min-width: 0; }
.pcard h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  font-size: 0.85rem;
  color: #fff;
  background: rgba(255,255,255,0.28);
}
.btn:active { transform: scale(0.98); }
.btn.solid { background: #fff; color: var(--ink); }
.btn.green { background: var(--green-d); color: #fff; width: 100%; padding: 16px; font-size: 1.05rem; border-radius: 18px; }
.btn.full { width: 100%; }
.btn.ghost { background: #e8f3fb; color: var(--ink); }
.btn.small { padding: 8px 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.green { background: linear-gradient(90deg, #7ecf7a, #58b85e); }
.blue { background: linear-gradient(90deg, #6bb6ee, #4598dc); }
.orange { background: linear-gradient(90deg, #ffd36a, #f0a83a); }
.purple { background: linear-gradient(90deg, #b08ee6, #8a68d0); }
.pink { background: linear-gradient(90deg, #f59aa6, #ea6b7d); }

.ecard {
  background: #f7fbfe;
  border: 1px solid #e3eef7;
  border-radius: 18px;
  padding: 14px;
}
.ecard h3 { margin: 0 0 6px; font-size: 1rem; }
.ecard .sub { color: var(--muted); font-size: 0.82rem; margin-bottom: 8px; }
.ecard p { margin: 0 0 12px; color: #3d5473; font-size: 0.9rem; line-height: 1.35; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  border: 0;
  background: #e8f3fb;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}
.chip.on { background: var(--ink); color: #fff; }

.sync-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid #eef3f8;
}
.check {
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--green-d); color: #fff;
  display: grid; place-items: center; font-weight: 900; flex-shrink: 0;
}
.pill {
  margin-left: auto;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}
.pill.downloaded, .pill.copied { background: #d7f3d8; color: #2e7d32; }
.pill.ready { background: #ffe9b0; color: #8a5a00; }
.pill.failed { background: #ffd6d6; color: #b71c1c; }
.pill.downloading { background: #d7ebf8; color: #1565c0; }

.storage { margin: 18px 0 8px; font-weight: 800; }
.meter {
  height: 14px;
  background: #d7ebf8;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 18px;
}
.meter > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5aa6e8, #3b8fd4);
  width: 0%;
}

.hint { color: var(--muted); text-align: center; margin: 8px 0 18px; }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.form label { display: block; font-weight: 800; margin: 14px 0 6px; font-size: 0.9rem; }
.form input[type="text"], .form input[type="password"], .form input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #d5e3ef;
  font-size: 1rem;
}
.form .help { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.toggle { display: flex; align-items: center; gap: 10px; font-weight: 700; margin: 12px 0; }
.feed {
  background: #f7fbfe;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.feed code { display: block; word-break: break-all; color: #355; margin-top: 4px; }

.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bar);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 6px calc(10px + env(safe-area-inset-bottom));
}
.tab {
  text-decoration: none;
  color: #7a93b0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 800;
}
.tab.active { color: var(--ink); }
.tab-icon { font-size: 1.25rem; line-height: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  z-index: 20;
  max-width: 90vw;
}

.busy { opacity: 0.7; pointer-events: none; }

@media (max-width: 480px) {
  .stage { padding: 0; }
  .phone { max-width: none; min-height: 100vh; border-radius: 0; box-shadow: none; }
}
