/*
 * How Rare Are You? - Stylesheet
 * Neal.fun inspired: Pure white background, bold grotesque typography, 
 * tactile physics, generous whitespace, zero SaaS clutter.
 */

:root {
  --bg: #ffffff;
  --text: #111111;
  --text-muted: #767676;
  --border: #111111;
  --accent: #ff4757;
  --accent-green: #2ed573;
  --accent-blue: #1e90ff;
  --accent-yellow: #ffa502;
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Background Canvas - pointer-events: none ensures it NEVER intercepts clicks */
#humanity-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* Top Subtle Controls */
.top-controls {
  position: fixed;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}

.top-btn {
  pointer-events: auto;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 0 var(--border);
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.top-btn * {
  pointer-events: none;
}

.top-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 0 var(--border);
}

.top-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--border);
}

.top-btn.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}

/* Main Interactive Canvas Wrapper */
#app-container {
  position: relative;
  z-index: 10;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px 24px;
  pointer-events: auto;
}

/* Central Population Hero Block */
.population-hero {
  text-align: center;
  margin-bottom: 28px;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
}

.population-number-wrap {
  display: inline-block;
  position: relative;
}

.population-number {
  font-family: var(--font-main);
  font-weight: 900;
  font-size: clamp(3.2rem, 9vw, 6.8rem);
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  display: inline-block;
  transition: transform 0.12s ease;
}

.population-unit {
  display: block;
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 6px;
}

/* Deadpan Reaction Subtitle */
.deadpan-bubble {
  margin-top: 14px;
  font-size: clamp(1.1rem, 2.8vw, 1.45rem);
  font-weight: 700;
  color: var(--text);
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.deadpan-bubble.pop-in {
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Shake Animation for Dramatic Reductions */
.shake {
  animation: dramaticShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes dramaticShake {
  10%, 90% { transform: translate3d(-3px, 0, 0) rotate(-0.5deg); }
  20%, 80% { transform: translate3d(5px, 0, 0) rotate(0.8deg); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0) rotate(-1deg); }
  40%, 60% { transform: translate3d(6px, 0, 0) rotate(1deg); }
}

@keyframes popIn {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Views Section (Intro, Question, Result) */
#view-container {
  width: 100%;
  max-width: 680px;
  pointer-events: auto;
}

.view-panel {
  width: 100%;
  margin: 0 auto;
  text-align: center;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
}

.view-panel.slide-out {
  opacity: 0;
  transform: translateY(-16px) scale(0.98);
  pointer-events: none;
}

.view-panel.slide-in {
  animation: slideInUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes slideInUp {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Intro Screen */
.intro-subtext {
  font-size: clamp(1.2rem, 3.2vw, 1.65rem);
  font-weight: 500;
  color: var(--text);
  margin-bottom: 32px;
}

.big-playful-btn {
  font-family: var(--font-main);
  background: var(--text);
  color: var(--bg);
  border: 3px solid var(--border);
  border-radius: 999px;
  font-size: clamp(1.25rem, 3vw, 1.55rem);
  font-weight: 800;
  padding: 18px 46px;
  cursor: pointer;
  box-shadow: 0 6px 0 #444444;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
  user-select: none;
}

.big-playful-btn * {
  pointer-events: none;
}

.big-playful-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 9px 0 #333333;
}

.big-playful-btn:active {
  transform: translateY(4px) scale(0.98);
  box-shadow: 0 0 0 #333333;
}

/* Question Screen */
.question-title {
  font-size: clamp(1.4rem, 3.5vw, 1.95rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  line-height: 1.25;
}

.question-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* Options Grid */
.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 10px;
  pointer-events: auto;
}

.option-btn {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 16px 20px;
  color: var(--text);
  font-family: var(--font-main);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--border);
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.12s ease, background 0.12s ease, color 0.12s ease;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  text-align: left;
  position: relative;
  pointer-events: auto;
  user-select: none;
}

.option-btn * {
  pointer-events: none;
}

.option-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--border);
  background: #fbfbfb;
}

.option-btn:active, .option-btn.selected {
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 0 0 var(--border);
  background: var(--text);
  color: var(--bg);
}

.option-btn .opt-icon {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.option-btn .opt-text {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.option-btn .opt-label {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
}

.option-btn .opt-sublabel {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.75;
  margin-top: 3px;
}

/* Final Result Screen */
.result-header {
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.result-main-callout {
  font-size: clamp(1.8rem, 4.5vw, 2.75rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 6px;
}

.result-rarity-badge {
  display: inline-block;
  background: var(--text);
  color: var(--bg);
  padding: 8px 20px;
  border-radius: 999px;
  font-size: clamp(1.15rem, 2.5vw, 1.45rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 16px 0;
}

.result-comparison-box {
  background: #fbfbfb;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 20px 24px;
  margin: 20px 0;
  box-shadow: 0 4px 0 var(--border);
}

.result-comparison-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
  display: block;
}

.result-comparison-text {
  font-size: clamp(1.05rem, 2.5vw, 1.25rem);
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

/* Interactive Relative Scale Visualizer */
.result-scale-widget {
  background: #ffffff;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px;
  margin: 20px 0;
  box-shadow: 0 4px 0 var(--border);
  text-align: center;
}

.scale-widget-title {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.scale-sample-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.scale-tab-btn {
  background: #f4f4f4;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
  pointer-events: auto;
}

.scale-tab-btn * {
  pointer-events: none;
}

.scale-tab-btn:hover {
  background: #e8e8e8;
  transform: translateY(-1px);
}

.scale-tab-btn.active {
  background: var(--text);
  color: var(--bg);
}

.scale-dot-matrix {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  max-width: 360px;
  margin: 8px auto 14px;
  min-height: 48px;
  align-items: center;
}

.scale-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e4e4e4;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;
}

.scale-dot.match {
  background: var(--accent);
  transform: scale(1.35);
  box-shadow: 0 0 6px rgba(255, 71, 87, 0.6);
}

.scale-dot.you {
  background: #111111;
  outline: 2px solid #ff4757;
  transform: scale(1.5);
}

.scale-insight-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.result-disclaimer {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 24px;
}

.result-action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-bottom: 24px;
}

.action-btn {
  font-family: var(--font-main);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  user-select: none;
}

.action-btn * {
  pointer-events: none;
}

.action-btn.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: #111111;
  box-shadow: 0 4px 0 #111111;
}

.action-btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #111111;
}

.action-btn.primary:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 #111111;
}

.action-btn.secondary {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 4px 0 var(--border);
}

.action-btn.secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--border);
}

.action-btn.secondary:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--border);
}

/* User's Trait Summary Pills */
.trait-pills-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 24px;
}

.trait-pill {
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  background: #ffffff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.trait-pill.rare {
  background: #fff3e6;
  border-color: #ff9f43;
  color: #d35400;
}

/* Methodology link */
.methodology-trigger {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  transition: color 0.15s ease;
  pointer-events: auto;
}

.methodology-trigger:hover {
  color: var(--text);
}

/* Drawer / Modal for Methodology */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 540px;
  background: var(--bg);
  border-left: 3px solid var(--border);
  z-index: 101;
  padding: 36px 30px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.1);
  pointer-events: auto;
}

.drawer-panel.active {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.drawer-title {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.drawer-close {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
  pointer-events: auto;
}

.drawer-close:hover {
  transform: scale(1.1);
}

.drawer-content {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #333333;
}

.drawer-content h3 {
  font-size: 1.15rem;
  font-weight: 800;
  margin: 20px 0 8px;
  color: var(--text);
}

.drawer-content p {
  margin-bottom: 14px;
}

.drawer-content ul {
  padding-left: 20px;
  margin-bottom: 16px;
}

.drawer-content li {
  margin-bottom: 6px;
}

.source-item {
  border: 1.5px solid #eaeaea;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #fafafa;
}

.source-item a {
  color: var(--accent-blue);
  text-decoration: none;
  font-weight: 700;
}

.source-item a:hover {
  text-decoration: underline;
}

/* Share Modal */
.share-modal-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: 90%;
  max-width: 480px;
  background: var(--bg);
  border: 3px solid var(--border);
  border-radius: 20px;
  z-index: 102;
  padding: 28px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.share-modal-panel.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

/* Fix: the hidden share modal's buttons (pointer-events: auto) were sitting on
   top of the "Find out" button and swallowing clicks. Keep them inert while closed. */
.share-modal-panel:not(.active) * {
  pointer-events: none;
}

.share-preview-canvas {
  width: 100%;
  border-radius: 12px;
  border: 2px solid var(--border);
  margin: 16px 0;
  display: block;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111111;
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .shake {
    animation: none !important;
  }
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
  #app-container {
    padding: 24px 16px;
  }
  .population-hero {
    margin-bottom: 20px;
  }
  .options-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .option-btn {
    padding: 14px 16px;
  }
  .action-btn {
    width: 100%;
    justify-content: center;
  }
}
