:root {
  --bg: #f3f7fb;
  --bg-accent: #e6f0f8;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe4ee;
  --primary: #0f4c81;
  --primary-hover: #0a3a63;
  --primary-soft: rgba(15, 76, 129, 0.1);
  --accent: #14b8a6;
  --ok: #0f766e;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.03), 0 10px 28px rgba(15, 76, 129, 0.07);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Sora", "Noto Sans SC", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(1000px 420px at 0% -5%, rgba(20, 184, 166, 0.12), transparent 55%),
    radial-gradient(900px 480px at 100% 0%, rgba(15, 76, 129, 0.12), transparent 52%),
    linear-gradient(180deg, #f8fbfe 0%, var(--bg) 42%, #eaf1f7 100%);
}

body {
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(28px + var(--safe-bottom));
}

button,
input {
  font: inherit;
}

.app {
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 18px 16px 40px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logos {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-shrink: 0;
}

.brand-logos img {
  width: 54px;
  height: auto;
  display: block;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.68rem;
  color: var(--muted);
}

.stat-chip strong {
  font-size: 1rem;
  color: var(--primary);
  line-height: 1;
}

.btn-logout {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-logout:hover {
  color: var(--primary);
  border-color: rgba(15, 76, 129, 0.28);
}

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + var(--safe-bottom));
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 22px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logos {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.login-logos img {
  width: 110px;
  height: auto;
  display: block;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  object-fit: contain;
}

.login-card h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
}

.login-card > p {
  margin: 8px 0 22px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.login-card .field {
  text-align: left;
}

.login-btn {
  width: 100%;
  margin-top: 14px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.tab {
  border: 0;
  border-radius: 10px;
  padding: 11px 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(15, 76, 129, 0.22);
}

.panel {
  display: none;
}

.panel.active {
  display: grid;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.hint,
.status {
  color: var(--muted);
  font-size: 0.78rem;
}

.status {
  min-height: 1.2em;
  margin: 10px 0 0;
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.template-option {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  padding: 0;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.template-option img {
  display: block;
  width: 100%;
  aspect-ratio: 576 / 1024;
  object-fit: cover;
}

.template-option span {
  display: block;
  padding: 8px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  background: #f8fafc;
  border-top: 1px solid var(--line);
}

.template-option.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.template-option.selected::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3.5 8.5L6.5 11.5L12.5 4.5' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  background: #fbfcfd;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: rgba(15, 76, 129, 0.45);
  box-shadow: 0 0 0 4px var(--primary-soft);
  background: #fff;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 12px;
  font-weight: 650;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, #155f9c 0%, var(--primary) 100%);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.secondary {
  background: #fff;
  color: var(--primary);
  border: 1px solid rgba(15, 76, 129, 0.18);
}

.btn.danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.preview-wrap {
  border-radius: 14px;
  overflow: hidden;
  background: #edf2f7;
  border: 1px solid var(--line);
}

#previewCanvas {
  display: block;
  width: 100%;
  height: auto;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat-box {
  text-align: center;
  padding: 12px 4px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.stat-box strong {
  display: block;
  font-size: 1.1rem;
  color: var(--ink);
}

.stat-box span {
  font-size: 0.68rem;
  color: var(--muted);
}

.invitee-list {
  display: grid;
  gap: 10px;
}

.invitee-item {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.invitee-item img {
  width: 72px;
  height: 128px;
  object-fit: cover;
  border-radius: 10px;
  background: #edf2f7;
}

.invitee-meta h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.invitee-meta p {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
}

.invitee-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.invitee-actions .btn {
  padding: 8px 6px;
  font-size: 0.74rem;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(90vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(21, 32, 43, 0.94);
  color: #f8fafc;
  font-size: 0.88rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.28);
}

@media (max-width: 380px) {
  .brand p {
    display: none;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .template-option {
    display: grid;
    grid-template-columns: 84px 1fr;
    align-items: center;
  }

  .template-option img {
    aspect-ratio: 576 / 1024;
    height: 140px;
    width: 84px;
  }

  .template-option span {
    border-top: 0;
    text-align: left;
    padding-left: 12px;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .invitee-actions {
    grid-template-columns: 1fr;
  }
}
