:root {
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --line: #e6e3da;
  --line-strong: #d6d3c9;
  --bg-1: #fbfaf6;
  --bg-2: #f0ede4;
  --card: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 24px 48px rgba(15, 23, 42, 0.10);
  --radius: 20px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 0% 0%, rgba(251, 113, 133, 0.10), transparent 40%),
    radial-gradient(circle at 100% 0%, rgba(96, 165, 250, 0.10), transparent 42%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 36px 22px 72px;
}

/* loading */
.loading {
  min-height: 70vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #e7e3d8;
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* greeting header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.greeting .when {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.greeting h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.greeting h1 .name {
  background: linear-gradient(135deg, #f43f5e, #f59e0b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: white;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.icon-button:hover {
  background: #fafaf6;
  color: var(--ink);
  border-color: var(--line-strong);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

/* section title */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 4px 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-head .meta {
  font-size: 13px;
  color: var(--muted);
}

/* app grid */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 36px;
}

.app-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  color: inherit;
  min-height: 168px;
}

.app-card.live {
  cursor: pointer;
}

.app-card.live:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}

.app-card.planned {
  background: rgba(255, 255, 255, 0.72);
}

.app-card.planned .app-icon {
  filter: saturate(0.65);
}

.app-icon {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--c1, #60a5fa), var(--c2, #2563eb));
  box-shadow: 0 8px 18px var(--c-shadow, rgba(37, 99, 235, 0.22));
}

.app-icon svg {
  width: 28px;
  height: 28px;
}

.app-name {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-desc {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.55;
}

.app-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: auto;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.status-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status-chip.online { color: #047857; }
.status-chip.online .dot { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }

.status-chip.planned { color: #b45309; }
.status-chip.planned .dot { background: #f59e0b; }

.status-chip.error { color: #b91c1c; }
.status-chip.error .dot { background: #ef4444; }

.status-chip.offline { color: #64748b; }
.status-chip.offline .dot { background: #94a3b8; }

/* per-app theme colors */
.theme-ledger { --c1: #34d399; --c2: #059669; --c-shadow: rgba(5, 150, 105, 0.22); }
.theme-familybook { --c1: #fb7185; --c2: #e11d48; --c-shadow: rgba(225, 29, 72, 0.22); }
.theme-vault { --c1: #a78bfa; --c2: #7c3aed; --c-shadow: rgba(124, 58, 237, 0.22); }
.theme-tasks { --c1: #fbbf24; --c2: #f59e0b; --c-shadow: rgba(245, 158, 11, 0.22); }
.theme-default { --c1: #60a5fa; --c2: #2563eb; --c-shadow: rgba(37, 99, 235, 0.22); }

/* family card */
.family-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

.family-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
}

.family-head .titles h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.family-head .titles p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.invite-button {
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  padding: 0 16px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.invite-button:hover {
  background: #fafaf6;
  border-color: var(--line-strong);
}

.invite-button svg {
  width: 14px;
  height: 14px;
}

.members {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 22px;
}

.member-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  font-size: 15px;
  background: linear-gradient(135deg, var(--avatar-c1, #94a3b8), var(--avatar-c2, #64748b));
  flex-shrink: 0;
}

.member-info .member-name {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
}

.member-info .member-role {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

/* modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 16px;
  animation: fade 0.18s ease;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: white;
  border-radius: var(--radius);
  width: min(440px, 100%);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.22s ease;
}

@keyframes pop {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.modal-card .lead {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.invite-result {
  margin-top: 18px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #fff7ed, #fef3c7);
  border: 1px solid #fde68a;
}

.invite-result .label {
  font-size: 12px;
  color: #92400e;
  font-weight: 600;
  margin-bottom: 6px;
}

.invite-result .link {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--ink);
  word-break: break-all;
  cursor: text;
  user-select: all;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.copy-button {
  margin-top: 8px;
  height: 36px;
  border-radius: 999px;
  border: 0;
  background: var(--ink);
  color: white;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 500;
}

.copy-button.copied {
  background: #059669;
}

/* auth */
.auth-screen {
  min-height: 80vh;
  display: grid;
  place-items: center;
}

.auth-card {
  background: white;
  border-radius: var(--radius);
  width: min(420px, 100%);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
}

.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, #1f2937, #0f172a);
  display: grid;
  place-items: center;
  color: white;
  margin-bottom: 18px;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
}

.auth-logo svg {
  width: 28px;
  height: 28px;
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 26px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.auth-card .lead {
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-switch {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  padding: 0;
}

.text-button:hover {
  color: #2563eb;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
}

.input {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: white;
  color: var(--ink);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

.input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

.primary-button {
  height: 48px;
  border-radius: 12px;
  border: 0;
  background: linear-gradient(135deg, #1f2937, #0f172a);
  color: white;
  font-size: 15px;
  font-weight: 600;
  margin-top: 4px;
  transition: transform 0.1s ease, box-shadow 0.18s ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.18);
}

.ghost-button {
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: white;
  padding: 0 18px;
  color: var(--ink);
  font-size: 14px;
}

.ghost-button:hover {
  background: #fafaf6;
}

/* error banner */
.error-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}

/* mobile */
@media (max-width: 640px) {
  .shell { padding: 24px 16px 56px; }
  .topbar { margin-bottom: 26px; }
  .greeting h1 { font-size: 26px; }
  .apps-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .app-card { padding: 18px; min-height: 158px; }
  .app-icon { width: 48px; height: 48px; border-radius: 13px; }
  .app-icon svg { width: 24px; height: 24px; }
  .app-name { font-size: 16px; }
  .app-desc { font-size: 12.5px; line-height: 1.5; }
  .family-card { padding: 20px; }
  .members { gap: 14px 18px; }
}

@media (max-width: 380px) {
  .apps-grid { grid-template-columns: 1fr; }
}
