:root {
  --rose: #ef476f;
  --coral: #ff7a59;
  --gold: #ffd166;
  --leaf: #2fbf71;
  --teal: #06b6d4;
  --violet: #5b4bff;
  --ink: #18212f;
  --muted: #667085;
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(24, 33, 47, 0.13);
  --shadow: 0 24px 72px rgba(24, 33, 47, 0.18);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(255, 209, 102, 0.48), transparent 19rem),
    radial-gradient(circle at 88% 10%, rgba(6, 182, 212, 0.32), transparent 23rem),
    radial-gradient(circle at 75% 88%, rgba(239, 71, 111, 0.25), transparent 26rem),
    linear-gradient(135deg, #fff7ec 0%, #eef8ff 46%, #fff0f6 100%);
  overflow-x: hidden;
}

body[data-theme="company"] {
  --rose: #d4af37;
  --coral: #f4c95d;
  --gold: #ffe08a;
  --leaf: #57c7b6;
  --teal: #5ac8fa;
  --violet: #1f2a44;
  --ink: #101623;
  background:
    radial-gradient(circle at 16% 14%, rgba(244, 201, 93, 0.35), transparent 21rem),
    radial-gradient(circle at 88% 18%, rgba(90, 200, 250, 0.2), transparent 25rem),
    linear-gradient(135deg, #f7f3e8 0%, #eef4f8 48%, #fefefe 100%);
}

body[data-theme="church"] {
  --rose: #d98c45;
  --coral: #f2b760;
  --gold: #f8d57e;
  --leaf: #6abf69;
  --teal: #62b6cb;
  --violet: #735d38;
}

body[data-theme="cny"] {
  --rose: #d90429;
  --coral: #f77f00;
  --gold: #ffd166;
  --leaf: #2a9d8f;
  --teal: #00b4d8;
  --violet: #7f1d1d;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
}

.ambient span {
  position: absolute;
  width: 10px;
  height: 18px;
  border-radius: 3px;
  background: var(--rose);
  opacity: 0.26;
  animation: driftDown 13s linear infinite;
}

.ambient span:nth-child(1) { left: 8%; animation-delay: -2s; background: var(--gold); }
.ambient span:nth-child(2) { left: 24%; animation-delay: -8s; background: var(--teal); }
.ambient span:nth-child(3) { left: 46%; animation-delay: -4s; background: var(--rose); }
.ambient span:nth-child(4) { left: 66%; animation-delay: -10s; background: var(--leaf); }
.ambient span:nth-child(5) { left: 82%; animation-delay: -6s; background: var(--coral); }
.ambient span:nth-child(6) { left: 93%; animation-delay: -1s; background: var(--violet); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(12px, 3vw, 30px);
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--rose), var(--violet));
  font-weight: 950;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.top-actions button,
.admin-actions button,
.danger-row button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: #fff;
  font-weight: 850;
}

.app-shell {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 50px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: viewIn 180ms ease both;
}

.hero,
.panel,
.info-grid article,
.phone-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: clamp(18px, 4vw, 48px);
  align-items: center;
  min-height: 560px;
  padding: clamp(22px, 6vw, 70px);
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  right: -48px;
  bottom: -60px;
  width: 270px;
  height: 270px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 42%, rgba(255, 255, 255, 0.88) 43%, rgba(255, 255, 255, 0.88) 57%, transparent 58%),
    linear-gradient(0deg, transparent 42%, rgba(255, 255, 255, 0.88) 43%, rgba(255, 255, 255, 0.88) 57%, transparent 58%),
    linear-gradient(135deg, var(--rose), var(--coral));
  transform: rotate(-10deg);
  opacity: 0.75;
  animation: giftFloat 4s ease-in-out infinite;
}

.hero-copy,
.phone-preview {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--violet);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p,
strong,
span {
  overflow-wrap: anywhere;
}

h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(3.3rem, 10vw, 7.2rem);
  line-height: 0.88;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  font-size: clamp(1.16rem, 2.4vw, 1.55rem);
}

.tagline {
  max-width: 650px;
  margin: 18px 0 0;
  color: #394253;
  font-size: clamp(1.05rem, 2.4vw, 1.34rem);
  font-weight: 650;
  line-height: 1.45;
}

.hero-actions,
.button-stack,
.danger-row,
.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-actions {
  margin-top: 28px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 18px;
  border: 0;
  font-weight: 950;
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.primary-button {
  color: #fff;
  background: linear-gradient(135deg, var(--rose), var(--violet));
  box-shadow: 0 16px 34px rgba(91, 75, 255, 0.22);
}

.secondary-button {
  color: var(--violet);
  background: #fff;
  border: 1px solid var(--line);
}

button:hover {
  transform: translateY(-1px);
  filter: saturate(1.06);
}

.phone-preview {
  min-height: 460px;
  padding: 36px 22px 24px;
  text-align: center;
  overflow: hidden;
}

.phone-notch {
  position: absolute;
  top: 12px;
  left: 50%;
  width: 96px;
  height: 18px;
  border-radius: 999px;
  background: #16202f;
  transform: translateX(-50%);
}

.gift-orbit {
  position: relative;
  display: grid;
  place-items: center;
  width: 150px;
  height: 150px;
  margin: 32px auto 18px;
  border-radius: 50%;
  background: rgba(255, 209, 102, 0.26);
}

.gift-orbit::before {
  content: "🎁";
  font-size: 4.4rem;
  animation: bounce 1.7s ease-in-out infinite;
}

.gift-orbit span {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--rose);
  animation: orbit 3.8s linear infinite;
}

.gift-orbit span:nth-child(2) {
  animation-delay: -1.2s;
  background: var(--teal);
}

.gift-orbit span:nth-child(3) {
  animation-delay: -2.4s;
  background: var(--gold);
}

.phone-preview h2 {
  font-size: 1.9rem;
}

.mock-field,
.mock-button,
.avatar-strip {
  margin-top: 14px;
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  font-weight: 900;
}

.mock-button {
  color: #fff;
  background: linear-gradient(135deg, var(--leaf), var(--teal));
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.info-grid article {
  padding: 22px;
}

.info-grid strong {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 15px;
  border-radius: 8px;
  color: #fff;
  background: var(--violet);
}

.info-grid p,
.muted,
.form-help {
  color: var(--muted);
}

.section-heading {
  margin: 12px 0 18px;
}

.form-grid,
.auth-panel {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--violet);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-size: 1rem;
  font-weight: 750;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(91, 75, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(91, 75, 255, 0.13);
}

.pin-preview {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 18px;
  margin-top: 16px;
  padding: 20px;
}

.pin-preview strong {
  display: inline-grid;
  place-items: center;
  min-width: 126px;
  min-height: 64px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  font-size: 1.8rem;
  letter-spacing: 0.12em;
}

.is-hidden {
  display: none !important;
}

.dashboard-layout,
.lobby-layout,
.join-layout {
  display: grid;
  gap: 18px;
}

.dashboard-layout {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.event-card,
.live-panel,
.join-card,
.lobby-main,
.expired-card {
  padding: 22px;
}

.status-stack {
  display: grid;
  gap: 8px;
  margin: 18px 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: #fff;
  background: var(--leaf);
  font-weight: 950;
}

.join-code-box,
.projector-code {
  display: grid;
  gap: 4px;
  margin: 14px 0;
  padding: 16px;
  border-radius: 8px;
  background: rgba(255, 209, 102, 0.35);
}

.join-code-box span,
.projector-code span {
  color: var(--muted);
  font-weight: 850;
}

.join-code-box strong,
.projector-code strong {
  font-size: 2.2rem;
  letter-spacing: 0.08em;
}

#qrCanvas,
#projectorQrCanvas {
  width: 100%;
  max-width: 260px;
  border: 8px solid #fff;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 30px rgba(24, 33, 47, 0.13);
}

.invite-link {
  padding: 10px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.security-hint {
  margin: 14px 0;
  padding: 12px;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  color: #263241;
  background: rgba(6, 182, 212, 0.1);
  font-weight: 750;
}

.participant-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.participant-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  animation: popIn 190ms ease both;
}

.participant-row .avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: rgba(255, 209, 102, 0.36);
  font-size: 1.45rem;
}

.participant-row strong,
.participant-row span {
  display: block;
}

.participant-row span {
  color: var(--muted);
  font-size: 0.88rem;
}

.row-actions {
  display: flex;
  gap: 7px;
}

.row-actions button,
.danger-row button {
  min-width: 42px;
}

.danger-row {
  justify-content: flex-end;
  margin-top: 18px;
}

.danger-row button:last-child {
  color: #9f1239;
  border-color: rgba(159, 18, 57, 0.2);
  background: rgba(255, 228, 230, 0.8);
}

.join-layout {
  grid-template-columns: minmax(0, 560px);
  justify-content: center;
}

.join-card form {
  display: grid;
  gap: 15px;
  margin-top: 18px;
}

.avatar-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.avatar-choices button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1.5rem;
}

.avatar-choices button.is-selected {
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(91, 75, 255, 0.13);
}

.lobby-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
}

.lobby-main {
  display: grid;
  place-items: center;
  min-height: 420px;
  text-align: center;
}

.waiting-message {
  margin: 26px 0;
  color: var(--violet);
  font-size: clamp(1.7rem, 5vw, 3.2rem);
  font-weight: 950;
}

.compact .participant-row {
  grid-template-columns: 42px minmax(0, 1fr);
}

.compact .row-actions {
  display: none;
}

.reveal-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(100vh - 150px);
  padding: clamp(20px, 5vw, 56px);
  text-align: center;
  overflow: hidden;
}

.reveal-stage.is-shaking {
  animation: shake 190ms linear 6;
}

.animation-stage {
  display: grid;
  place-items: center;
  gap: 18px;
  min-height: 290px;
  margin-top: 20px;
}

.mystery-gift {
  width: clamp(130px, 28vw, 220px);
  aspect-ratio: 1;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 41%, rgba(255,255,255,0.9) 42%, rgba(255,255,255,0.9) 58%, transparent 59%),
    linear-gradient(0deg, transparent 41%, rgba(255,255,255,0.9) 42%, rgba(255,255,255,0.9) 58%, transparent 59%),
    linear-gradient(135deg, var(--rose), var(--violet));
  box-shadow: 0 30px 70px rgba(91, 75, 255, 0.25);
  animation: spinGift 1.8s ease-in-out infinite;
}

.name-cycler {
  min-height: 58px;
  font-size: clamp(2rem, 7vw, 5rem);
  font-weight: 950;
}

.countdown {
  min-height: 76px;
  color: var(--rose);
  font-size: clamp(3rem, 12vw, 7rem);
  font-weight: 950;
  line-height: 1;
}

.reveal-result {
  width: min(760px, 100%);
  margin-top: 12px;
  padding: clamp(20px, 5vw, 42px);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(239, 71, 111, 0.2);
  animation: popIn 220ms ease both;
}

.reveal-result strong {
  display: block;
  margin: 12px 0;
  color: var(--rose);
  font-size: clamp(2.2rem, 9vw, 5.8rem);
  line-height: 0.95;
}

.projector-view {
  min-height: calc(100vh - 120px);
}

.projector-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 26px;
  align-items: center;
  padding: clamp(22px, 5vw, 58px);
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #18212f, #4c1d95 52%, #be123c);
  box-shadow: var(--shadow);
}

.projector-grid h2 {
  max-width: 760px;
  font-size: clamp(3rem, 9vw, 8rem);
}

.projector-grid .eyebrow,
.projector-grid p {
  color: rgba(255, 255, 255, 0.86);
}

.projector-grid aside {
  display: grid;
  gap: 18px;
  justify-items: center;
}

.projector-participants {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.projector-participants span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff;
  font-size: 1.3rem;
  font-weight: 950;
}

.expired-card {
  max-width: 680px;
  margin: 50px auto;
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: min(430px, calc(100% - 36px));
  padding: 13px 16px;
  border-radius: 8px;
  color: #fff;
  background: #18212f;
  box-shadow: 0 18px 44px rgba(24, 33, 47, 0.24);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: confettiFall 1.45s ease-out forwards;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
}

@keyframes driftDown {
  from { transform: translateY(-20vh) rotate(0deg); }
  to { transform: translateY(120vh) rotate(360deg); }
}

@keyframes giftFloat {
  50% { transform: rotate(-4deg) translateY(-14px); }
}

@keyframes orbit {
  from { transform: rotate(0deg) translateX(78px) rotate(0deg); }
  to { transform: rotate(360deg) translateX(78px) rotate(-360deg); }
}

@keyframes bounce {
  50% { transform: translateY(-8px) rotate(-4deg); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.96); }
}

@keyframes spinGift {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(8deg) scale(1.05); }
}

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes confettiFall {
  0% { opacity: 1; transform: translateY(-20px) rotate(0deg); }
  100% { opacity: 0; transform: translateY(105vh) rotate(540deg); }
}

@media (max-width: 920px) {
  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .hero,
  .dashboard-layout,
  .lobby-layout,
  .projector-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .projector-grid aside {
    justify-items: start;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 18px, 1200px);
    padding-top: 10px;
  }

  .top-actions button {
    flex: 1 1 120px;
  }

  .hero,
  .panel,
  .info-grid article {
    padding: 16px;
  }

  .form-grid,
  .pin-preview {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .hero-actions button,
  .button-stack button,
  .admin-actions button {
    width: 100%;
  }

  .participant-row {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .participant-row .row-actions {
    grid-column: 1 / -1;
  }

  .projector-participants {
    grid-template-columns: 1fr;
  }
}
