/* Apple-inspired light glass interface */
:root {
  --canvas: #f5f5f7;
  --ink: #1d1d1f;
  --subtle-ink: #6e6e73;
  --faint-ink: #86868b;
  --black: #000;
  --glass: rgba(255, 255, 255, 0.66);
  --glass-solid: rgba(255, 255, 255, 0.84);
  --glass-border: rgba(255, 255, 255, 0.94);
  --hairline: rgba(29, 29, 31, 0.11);
  --shadow: 0 30px 80px rgba(27, 29, 36, 0.12), 0 3px 12px rgba(27, 29, 36, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.92);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --text-primary: var(--ink);
  --text-secondary: var(--subtle-ink);
  --text-muted: var(--faint-ink);
  --easing: var(--ease);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 7% 7%, rgba(255, 255, 255, 0.98) 0 0.5%, rgba(255, 255, 255, 0) 30%),
    radial-gradient(circle at 88% 13%, rgba(225, 234, 255, 0.62) 0, rgba(225, 234, 255, 0) 25%),
    radial-gradient(circle at 48% 100%, rgba(244, 232, 255, 0.54) 0, rgba(244, 232, 255, 0) 34%),
    linear-gradient(145deg, #fcfcfe 0%, #f3f4f8 48%, #eceef3 100%);
  background-attachment: fixed;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
  padding: 32px 20px;
  isolation: isolate;
}

.app-container::before,
.app-container::after {
  position: fixed;
  z-index: -1;
  width: min(46vw, 500px);
  aspect-ratio: 1;
  content: "";
  filter: blur(4px);
  pointer-events: none;
}

.app-container::before {
  top: -18vw;
  left: -15vw;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
}

.app-container::after {
  right: -19vw;
  bottom: -20vw;
  border-radius: 42% 58% 52% 48%;
  background: rgba(213, 225, 255, 0.34);
}

.glass-panel {
  display: none;
  width: min(100%, 648px);
  padding: 42px 38px;
  border: 1px solid var(--glass-border);
  border-radius: 30px;
  opacity: 0;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.8), var(--glass));
  box-shadow: var(--shadow);
  backdrop-filter: blur(34px) saturate(165%);
  -webkit-backdrop-filter: blur(34px) saturate(165%);
  transform: translateY(14px) scale(0.985);
  transition: opacity 520ms var(--ease), transform 520ms var(--ease), filter 420ms var(--ease);
}

.glass-panel.active { display: block; }
.glass-panel.visible { opacity: 1; transform: translateY(0) scale(1); }
.glass-panel.exit { opacity: 0; filter: blur(5px); transform: translateY(-16px) scale(0.985); }

h1, h2, h3, p { margin-top: 0; }
h2, h3 { color: var(--ink); letter-spacing: -0.03em; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Entrance */
#gate-stage { text-align: center; }

#gate-stage #gate-title {
  margin-bottom: 8px;
  font-size: clamp(36px, 8vw, 50px);
  font-weight: 760;
  letter-spacing: -0.07em;
}

#gate-stage #gate-subtitle {
  margin-bottom: 32px;
  color: var(--subtle-ink);
  font-size: 15px;
  letter-spacing: 0.08em;
}

#gate-stage #invite-code,
textarea#answer-input {
  width: 100%;
  border: 1px solid rgba(29, 29, 31, 0.1);
  outline: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.025), 0 2px 7px rgba(28, 28, 30, 0.025);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: border-color 220ms var(--ease), background 220ms var(--ease), box-shadow 220ms var(--ease);
}

#gate-stage #invite-code {
  display: block;
  padding: 15px 18px;
  margin: 0 0 20px;
  border-radius: 16px;
  text-align: center;
  font-size: 14px;
}

#gate-stage #invite-code::placeholder,
textarea#answer-input::placeholder { color: #98989d; }

#gate-stage #invite-code:focus,
textarea#answer-input:focus {
  border-color: rgba(0, 0, 0, 0.3);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.07), 0 8px 20px rgba(28, 28, 30, 0.06);
}

.consent-wrapper {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  margin: 23px 0 25px;
  color: var(--subtle-ink);
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
}

.consent-wrapper input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--black); }
.consent-wrapper a { color: var(--ink); font-weight: 600; text-underline-offset: 3px; }

.disclaimer {
  max-width: 440px;
  margin: 0 auto;
  color: var(--faint-ink);
  font-size: 12px;
  line-height: 1.65;
}

/* Buttons */
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  max-width: 320px;
  width: 100%;
  padding: 13px 25px;
  margin: 0 auto 12px;
  border: 1px solid rgba(0, 0, 0, 0.94);
  border-radius: 999px;
  color: #fff !important;
  background: linear-gradient(180deg, #252525 0%, #000 42%, #050505 100%) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 9px 20px rgba(0, 0, 0, 0.19);
  cursor: pointer;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.015em;
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), background 220ms var(--ease), opacity 220ms var(--ease);
}

.action-btn:hover {
  background: linear-gradient(180deg, #343434 0%, #111 45%, #171717 100%) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 13px 26px rgba(0, 0, 0, 0.25);
  transform: translateY(-2px);
}

.action-btn:active { box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.38); transform: translateY(1px) scale(0.985); }
.action-btn:focus-visible, .option-btn:focus-visible, .anchor-btn:focus-visible, .close-btn:focus-visible { outline: 3px solid rgba(0, 0, 0, 0.24); outline-offset: 3px; }
.action-btn:disabled { cursor: not-allowed; pointer-events: none; opacity: 0.43; }

/* Quiz */
#quiz-stage { overflow: hidden; }

.progress-bar-container {
  width: 100%;
  height: 6px;
  margin-bottom: 28px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  background: rgba(29, 29, 31, 0.08);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.07);
}

.progress-bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #000, #3c3c3e); box-shadow: 0 0 12px rgba(0, 0, 0, 0.28); transition: width 600ms var(--ease); }

.question-content { transform-origin: 50% 50%; }
.question-content.question-leaving { animation: question-out 270ms var(--ease) both; }
.question-content.question-entering { animation: question-in 510ms var(--ease) both; }

@keyframes question-out { to { opacity: 0; transform: translateX(-28px) scale(0.98); filter: blur(4px); } }
@keyframes question-in { from { opacity: 0; transform: translateX(34px) scale(0.98); filter: blur(5px); } 55% { opacity: 1; filter: blur(0); } to { opacity: 1; transform: translateX(0) scale(1); filter: blur(0); } }

.question-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 17px; color: var(--subtle-ink); font-size: 13px; font-weight: 600; letter-spacing: 0.01em; }
.feedback-text { max-width: 60%; color: var(--ink); font-weight: 650; line-height: 1.45; text-align: right; transition: opacity 250ms var(--ease); }

.question-text {
  margin: 0 0 28px;
  font-size: clamp(22px, 4vw, 27px);
  font-weight: 720;
  line-height: 1.42;
  text-wrap: balance;
}

.options-container { display: flex; flex-direction: column; gap: 11px; width: 100%; margin-bottom: 20px; }

.option-btn,
.anchor-btn {
  width: 100%;
  border: 1px solid var(--hairline);
  border-radius: 17px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.63);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82), 0 3px 10px rgba(30, 30, 32, 0.035);
  cursor: pointer;
  text-align: left;
  backdrop-filter: blur(18px) saturate(145%);
  -webkit-backdrop-filter: blur(18px) saturate(145%);
  transition: transform 220ms var(--ease), background 220ms var(--ease), border-color 220ms var(--ease), box-shadow 220ms var(--ease);
}

.option-btn { padding: 16px 20px; font-size: 15px; font-weight: 550; line-height: 1.48; }
.option-btn:hover, .anchor-btn:hover { border-color: rgba(0, 0, 0, 0.23); background: rgba(255, 255, 255, 0.94); box-shadow: inset 0 1px 0 #fff, 0 9px 18px rgba(30, 30, 32, 0.09); transform: translateY(-2px); }
.option-btn:active, .anchor-btn:active { transform: translateY(0) scale(0.992); }
.option-btn.selected { border-color: #000; color: #fff; background: #000; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 8px 18px rgba(0, 0, 0, 0.16); }

textarea#answer-input { display: block; min-height: 132px; padding: 16px 17px; border-radius: 18px; resize: vertical; font-size: 15px; line-height: 1.55; }
#next-btn { display: flex; margin-top: 22px; }

/* Selection and result */
#selection-stage h2 { margin-bottom: 18px; font-size: clamp(25px, 5vw, 31px); }
.summary-text, .selection-hint { color: var(--subtle-ink); font-size: 15px; line-height: 1.7; }
.summary-text strong { color: var(--ink); }
.selection-hint { margin-bottom: 22px; }
.anchor-buttons-container { display: flex; flex-direction: column; gap: 12px; }
.anchor-btn { padding: 16px 18px; font-size: 14px; line-height: 1.65; }
.anchor-tag { display: block; margin-bottom: 6px; color: var(--faint-ink); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }

.ai-badge {
  margin-bottom: 21px;
  padding: 10px 13px;
  border: 1px solid rgba(29, 29, 31, 0.09);
  border-radius: 13px;
  color: var(--subtle-ink);
  background: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  line-height: 1.5;
}

#llm-analysis { color: var(--ink); font-size: 15px; line-height: 1.8; }
#llm-analysis h1, #llm-analysis h2, #llm-analysis h3 { margin: 24px 0 10px; font-weight: 720; }
#llm-analysis h1 { font-size: 26px; }
#llm-analysis h2 { font-size: 22px; }
#llm-analysis h3 { font-size: 18px; }
#llm-analysis blockquote { margin: 18px 0; padding: 11px 16px; border-left: 3px solid var(--ink); border-radius: 0 12px 12px 0; background: rgba(255, 255, 255, 0.48); color: var(--subtle-ink); }
.loading-text, .error-text { text-align: center; color: var(--subtle-ink); }
.error-text { color: #bb2525; }
.ai-progress-container { width: 82%; margin: 22px auto 8px; }
.ai-progress-percentage { margin: 0; color: var(--ink); font-size: 12px; font-weight: 700; text-align: center; }
.result-actions { margin-top: 28px; text-align: center; }
.result-actions .action-btn { margin: 0 4px 10px; }
.secondary-btn { max-width: 260px; }

.footer-engagement-container { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--hairline); }
.feedback-card, .tipping-card { padding: 20px; border: 1px solid rgba(255, 255, 255, 0.86); border-radius: 20px; background: rgba(255, 255, 255, 0.5); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86); }
.tipping-card { margin-top: 14px; text-align: center; }
.feedback-title { margin-bottom: 8px; font-size: 17px; }
.feedback-desc, .qr-sub { margin-bottom: 12px; color: var(--subtle-ink); font-size: 13px; line-height: 1.65; }
.feedback-email-link { color: var(--ink); font-size: 13px; font-weight: 650; text-underline-offset: 3px; }
.qr-title { margin-bottom: 15px; font-size: 14px; font-weight: 650; line-height: 1.6; }
.qr-box { display: inline-flex; padding: 10px; border-radius: 18px; background: #fff; box-shadow: 0 7px 17px rgba(0, 0, 0, 0.07); }
.qr-image { display: block; width: min(180px, 62vw); height: auto; border-radius: 10px; }
.qr-sub { margin: 14px 0 0; }

/* Dialogs and share card */
.modal-overlay {
  position: fixed;
  z-index: 1000;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(244, 245, 248, 0.58);
  backdrop-filter: blur(20px) saturate(135%);
  -webkit-backdrop-filter: blur(20px) saturate(135%);
}

.modal-overlay .modal-content { display: block; width: min(100%, 550px); max-height: min(90vh, 700px); overflow: auto; opacity: 1; transform: none; }
.modal-content h3 { margin-bottom: 12px; }
.modal-body p:last-child { margin-bottom: 0; }

#poster-modal.modal { display: none; }
#poster-modal.modal.active, #poster-modal.modal.show {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: flex !important;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 32px 18px;
  background: rgba(241, 243, 248, 0.76);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
}

.poster-modal-content { position: relative; width: min(100%, 500px); margin: auto; }
.poster-card-canvas { padding: 30px 25px; border: 1px solid rgba(255, 255, 255, 0.96); border-radius: 28px; background: rgba(255, 255, 255, 0.82); box-shadow: 0 28px 70px rgba(30, 34, 45, 0.16), inset 0 1px 0 white; backdrop-filter: blur(30px) saturate(160%); -webkit-backdrop-filter: blur(30px) saturate(160%); }
.close-btn { position: absolute; z-index: 1; top: 12px; right: 12px; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; color: #fff; background: rgba(0, 0, 0, 0.78); cursor: pointer; font-size: 24px; line-height: 1; transition: transform 180ms var(--ease), background 180ms var(--ease); }
.close-btn:hover { background: #000; transform: scale(1.08); }
.poster-header, .poster-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.poster-header { padding-bottom: 15px; margin-bottom: 20px; border-bottom: 1px solid var(--hairline); }
.poster-badge { font-size: 16px; font-weight: 750; letter-spacing: -0.025em; }
.poster-date, .poster-footer-sub { color: var(--faint-ink); font-size: 11px; }
.poster-body-content { color: var(--ink); font-size: 14px; line-height: 1.75; }
.poster-body-content .gold-quote { color: var(--ink); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.poster-body-content .solution-tag { display: inline-block; padding: 2px 9px; border-radius: 999px; color: #fff; background: #000; font-size: 0.85em; font-weight: 650; }
.poster-body-content .phi-tag, .poster-body-content .soul-tag { display: inline-block; padding: 2px 9px; border: 1px solid var(--hairline); border-radius: 999px; background: rgba(255, 255, 255, 0.65); font-size: 0.85em; font-weight: 650; }
.poster-footer { padding-top: 17px; margin-top: 22px; border-top: 1px solid var(--hairline); }
.poster-footer-title { margin: 0; font-size: 12px; font-weight: 650; }
.poster-footer-sub { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.poster-actions { margin-top: 16px; text-align: center; }

@media (max-width: 560px) {
  .app-container { align-items: flex-start; padding: 18px 13px; }
  .glass-panel { padding: 31px 21px; border-radius: 25px; }
  #gate-stage { margin-top: 3vh; }
  .question-header { gap: 8px; }
  .feedback-text { max-width: 58%; font-size: 12px; }
  .question-text { margin-bottom: 23px; }
  .option-btn { padding: 15px 16px; }
  .poster-card-canvas { padding: 27px 20px; }
  .poster-header, .poster-footer { align-items: flex-start; flex-direction: column; }
  .poster-date { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
