/**
 * Participant Page Styles
 * Full-screen layout: 60% particle animation, 40% question cards
 */

/* ===== MAIN CONTAINER (No Scroll) ===== */
.main-container {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: visible; /* Allow bottom section to extend below */
  background-color: var(--color-background); /* Fill gaps between sections */
}

/* Prevent horizontal overscroll (allow pull-to-refresh) */
body {
  overscroll-behavior-x: none;
  background-color: var(--color-background); /* Fill any gaps with background color */
}

/* ===== ANIMATION SECTION (Top 75% - Particle animation is the STAR!) ===== */
.animation-section {
  position: relative;
  width: 100%;
  height: 100dvh; /* Use only dvh for mobile viewport */
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-background);
}

/* Three.js Canvas (hidden - using text morph instead) */
#particleCanvas {
  display: none;
}

/* Text Morph Container */
.morph-container {
  position: absolute;
  width: 100%; /* Changed from 100vw - prevents horizontal overflow */
  height: 100pt;
  top: 50vh;
  left: 0;
  transform: translateY(-50%);
  filter: url(#threshold) blur(0.6px);
  pointer-events: none;
}

/* Morph Text Styling */
#morphText1, #morphText2 {
  position: absolute;
  width: 100%;
  display: inline-block;

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', 'Arial', sans-serif;
  font-size: 4rem; /* 64px = 48pt */
  font-weight: 500;
  letter-spacing: -0.01em;

  text-align: center;
  color: var(--particle-color);

  user-select: none;
}

/* Start Overlay (Before Table Assignment) - Compact at top, particles fully visible! */
.start-overlay {
  position: absolute;
  top: 70px;
  left: 0;
  width: 100%;
  height: auto;
  max-height: 35%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--overlay-gradient);
  z-index: 10;
  padding: var(--spacing-lg) var(--spacing-xl) var(--spacing-2xl);
  text-align: center;
  pointer-events: none; /* Allow interaction with particles */
  transition: padding-top 0.5s ease;
}

/* Move overlay lower after assignment */
.start-overlay.after-assignment {
  padding-top: calc(var(--spacing-lg) + 8vh);
}

.welcome-title {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  margin-bottom: var(--spacing-md);
  text-shadow: var(--shadow-md);
}

.welcome-subtitle {
  font-size: var(--font-size-lg);
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-xl);
  max-width: 31.25rem; /* 500px */
}

/* Bigger subtitle after button disappears */
.welcome-subtitle.after-assignment {
  font-size: var(--font-size-2xl);
  margin-bottom: 0;
}

.btn-start {
  font-size: var(--font-size-base);
  padding: var(--spacing-sm) var(--spacing-lg);
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  box-shadow: var(--shadow-lg), 0 0 20px var(--glow-accent);
  pointer-events: all; /* Re-enable clicks on button */
}

.btn-start:hover {
  box-shadow: var(--shadow-xl), 0 0 30px var(--glow-accent);
}

/* Table Number Display (After Assignment) */
.table-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
  pointer-events: none; /* Allow interaction with particles behind */
}

.table-label {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: var(--spacing-sm);
}

.table-number {
  font-size: 8rem;
  font-weight: var(--font-weight-bold);
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 40px var(--glow-accent);
  line-height: 1;
}

/* ===== QUESTIONS SECTION (Bottom 31%) ===== */
.questions-section {
  position: fixed; /* Fixed to viewport - proper Chrome 135 fix */
  bottom: env(safe-area-inset-bottom, 0px); /* CRITICAL: Use safe-area-inset NOT 0 */
  left: 0;
  right: 0;
  width: 100%;
  height: 31dvh;
  min-height: calc(31dvh + env(safe-area-inset-bottom, 0px));
  background-color: var(--color-surface);
  padding: var(--spacing-md);
  padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  will-change: height;
}

/* Extend element below viewport to fill safe area (iOS Safari) */
.questions-section::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: env(safe-area-inset-bottom, 80px); /* 80px fallback for Android Chrome */
  background-color: var(--color-surface);
  z-index: 1;
  pointer-events: none;
}

/* Intermediate state (70%) */
.questions-section.intermediate {
  height: 70dvh;
  min-height: calc(70dvh + env(safe-area-inset-bottom, 0px));
}

/* Fully expanded state (90%) */
.questions-section.expanded {
  height: 90dvh;
  min-height: calc(90dvh + env(safe-area-inset-bottom, 0px));
}

/* Drag Handle */
.drag-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  z-index: 101;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Drag Grip Indicator */
.drag-grip {
  width: 2.5rem; /* 40px */
  height: 0.25rem; /* 4px */
  background-color: var(--color-text-tertiary);
  border-radius: var(--radius-full);
  opacity: 0.5;
  transition: all 0.2s ease;
}

.drag-handle:hover .drag-grip,
.drag-handle:active .drag-grip {
  opacity: 0.8;
  width: 3.75rem; /* 60px */
}

/* Bottom Gap Filler - for Android Chrome (doesn't support env()) */
.bottom-gap-filler {
  position: fixed;
  bottom: 0; /* Start from bottom of viewport */
  left: 0;
  right: 0;
  height: 100px; /* Extend below to fill gap */
  background-color: var(--color-surface);
  z-index: 999; /* Below questions section (1000) */
  pointer-events: none;
  transform: translateY(0); /* Ensure no transform offset */
}

/* Blur Backdrop - only visible when intermediate or expanded */
.questions-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.questions-backdrop.visible {
  opacity: 1;
  pointer-events: all;
}

/* Questions Header */
.questions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  margin-bottom: var(--spacing-sm);
}

.questions-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}

.questions-indicator {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.current-round {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  padding: var(--spacing-xs) var(--spacing-md);
  background-color: var(--color-primary-subtle);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
}

/* Questions Footer (Clon logo) - hidden in Phase 1 */
.questions-footer {
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-md) 0;
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
  opacity: 0.6;
}

/* Show footer only in Phase 2/3 (intermediate/expanded) */
.questions-section.intermediate .questions-footer,
.questions-section.expanded .questions-footer {
  display: flex;
}

.questions-footer .clon-logo {
  height: 1.5rem;
  opacity: 0.8;
}

[data-theme="light"] .questions-footer .clon-logo {
  filter: brightness(0.3);
}

/* Cards Container (Vertical Stack) */
.cards-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding-right: var(--spacing-xs);
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.cards-container::-webkit-scrollbar {
  width: 4px;
}

/* Question Card */
.question-card {
  flex: 0 0 auto; /* Auto height based on content */
  min-height: 4rem;
  width: 100%;
  background-color: var(--color-background);
  border-radius: var(--radius-md);
  padding: var(--spacing-sm);
  border: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto;
  gap: var(--spacing-xs);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.question-card:hover {
  border-color: var(--color-accent);
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.question-card.active {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-subtle), var(--shadow-md);
}

/* Remove expanded size changes - cards stay same size */

/* Question Card Content */
.question-card-number {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-accent);
  opacity: 0.6;
  line-height: 1;
  padding-left: var(--spacing-sm);
}

.question-card-text {
  grid-column: 1;
  grid-row: 1;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  line-height: var(--line-height-relaxed);
  z-index: 1;
  /* Multi-line ellipsis truncation - Phase 1 only */
  position: relative;
  max-height: calc(var(--line-height-relaxed) * 1em * 3); /* 3 lines height */
  overflow: hidden;
  /* Force-break long strings like "------" */
  white-space: normal;
  word-break: break-all;
  overflow-wrap: anywhere;
}

/* Ellipsis gradient overlay - only shows when .truncated class is added */
.question-card-text.truncated::after {
  content: '...';
  position: absolute;
  bottom: 0;
  right: 0;
  padding-left: 0.5rem;
  background: linear-gradient(to right, transparent, var(--color-background) 50%, var(--color-background));
  pointer-events: none;
}

/* Phase 2/3 - Show full text without truncation */
.questions-section.intermediate .question-card-text,
.questions-section.expanded .question-card-text {
  max-height: none; /* Remove height limit */
  overflow-y: auto; /* Enable scrolling if needed */
}

/* Remove ellipsis in Phase 2/3 */
.questions-section.intermediate .question-card-text::after,
.questions-section.expanded .question-card-text::after {
  display: none;
}

.question-card-footer {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--spacing-sm);
  border-top: 1px solid var(--color-divider);
  z-index: 1;
}

.question-card-hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.question-card-icon {
  width: 1.25rem; /* 20px */
  height: 1.25rem; /* 20px */
  color: var(--color-accent);
  transition: transform var(--transition-base);
}

/* No rotation - icon stays same */

/* Card Placeholder */
.card-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--color-text-tertiary);
  font-size: var(--font-size-base);
}

/* ===== MOBILE RESPONSIVENESS ===== */
@media (max-width: 768px) {
  .start-overlay {
    padding: 8vh var(--spacing-lg) var(--spacing-2xl);
    max-height: 38%;
  }

  .welcome-title {
    font-size: var(--font-size-3xl);
    margin-bottom: var(--spacing-sm);
  }

  .welcome-subtitle {
    font-size: var(--font-size-base);
    margin-bottom: var(--spacing-lg);
  }

  .welcome-subtitle.after-assignment {
    font-size: var(--font-size-xl);
    margin-bottom: 0;
  }

  .btn-start {
    font-size: var(--font-size-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
  }

  .table-number {
    font-size: 6rem;
  }

  .questions-title {
    font-size: var(--font-size-base);
  }

  .question-card-text {
    font-size: var(--font-size-sm);
  }

  .question-card-number {
    font-size: var(--font-size-xl);
  }
}

@media (max-width: 480px) {
  .animation-section {
    height: 69vh;
    height: 69dvh;
  }

  .questions-section {
    height: 31vh;
    height: 31dvh;
  }

  #particleCanvas {
    top: 5%;
    height: 115%;
  }

  .table-number {
    font-size: 5rem;
  }

  .question-card-text {
    font-size: var(--font-size-base);
  }

  .question-card-number {
    font-size: var(--font-size-xl);
  }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (max-height: 600px) and (orientation: landscape) {
  .animation-section {
    height: 100vh;
    height: 100dvh;
  }

  .questions-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    max-height: 50vh;
    background-color: var(--color-surface-overlay);
    backdrop-filter: blur(10px);
    z-index: 20;
  }
}
