/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --color-primary: #6366f1;
  --color-primary-dark: #4f46e5;
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-bg: #ffffff;
  --color-surface: #ffffff;

  /* Ground shadows - elements stand upright casting shadow below */
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.15);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.25);
  --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.3);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --player-1: #f87171;
  --player-2: #34d399;
  --player-3: #fbbf24;
}

html, body {
  height: 100%;
}

body {
  font-family: "Ubuntu Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  font-optical-sizing: auto;
  font-weight: 100;
  font-style: normal;
  font-variation-settings: "wdth" 100;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app {
  width: 100%;
  max-width: 480px;
  min-width: 320px;
  margin: 0 auto;
  height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
}

/* Screen Management */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  text-align: center;
  padding: 24px 0;
}

.header__title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: -0.025em;
}

.header__subtitle {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* Stats */
.stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 32px;
}

.stat {
  text-align: center;
}

.stat__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
}

.stat__label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-xl);
}

.btn--primary {
  background: var(--color-primary);
  color: white;
}

.btn--primary:hover {
  background: var(--color-primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}

.btn--primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-md);
}

.btn--ghost {
  background: transparent;
  color: var(--color-primary);
  box-shadow: none;
  border: 2px solid var(--color-primary);
}

.btn--ghost:hover {
  background: var(--color-primary);
  color: white;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Landing Screen */
.landing {
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.landing__description {
  color: var(--color-text-muted);
  margin-bottom: 32px;
  line-height: 1.8;
}

/* Waiting Screen */
.waiting {
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.waiting__text {
  color: var(--color-text-muted);
}

.waiting__count {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 8px;
}

/* Chat Screen */
.chat {
  flex: 1;
  flex-direction: column;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.chat__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  margin-bottom: 12px;
}

.chat__player-info {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.chat__player-name {
  font-weight: 600;
  color: var(--color-primary);
}

.chat__countdown {
  font-size: 1.5rem;
  font-weight: 300;
  color: var(--color-text-muted);
  text-shadow: var(--shadow-sm);
}

.chat__countdown.warning {
  color: var(--color-danger);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.chat__message-count {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* Players Row */
.players-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  gap: 12px;
}

/* Player Avatars */
.avatar {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  cursor: default;
  transition: all 0.3s ease;
}

.avatar__circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
}

.avatar__circle--1 { background: var(--player-1); }
.avatar__circle--2 { background: var(--player-2); }
.avatar__circle--3 { background: var(--player-3); }

.avatar__name {
  font-size: 0.625rem;
  color: var(--color-text-muted);
  margin-top: 6px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* Voting State */
.avatar.voting {
  cursor: pointer;
}

.avatar.voting .avatar__circle {
  animation: voting-glow 1.5s ease-in-out infinite;
  transform: scale(1.1);
}

.avatar.voting:hover .avatar__circle {
  transform: scale(1.2);
}

.avatar.selected .avatar__circle {
  box-shadow: 0 0 0 3px var(--color-success), var(--shadow-lg);
  animation: none;
  transform: scale(1.1);
}

@keyframes voting-glow {
  0%, 100% { box-shadow: var(--shadow-lg); }
  50% { box-shadow: var(--shadow-xl), 0 0 15px rgba(99, 102, 241, 0.5); }
}

/* Messages Area */
.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.messages__list {
  height: 100%;
  overflow-y: auto;
  padding: 12px 8px;
}

/* Hide scrollbar until needed, style when visible */
.messages__list::-webkit-scrollbar {
  width: 4px;
}

.messages__list::-webkit-scrollbar-track {
  background: transparent;
}

.messages__list::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

.messages__list::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

.message {
  margin-bottom: 12px;
  animation: message-in 0.3s ease;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.message__sender {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.message__sender--1 { color: var(--player-1); }
.message__sender--2 { color: var(--player-2); }
.message__sender--3 { color: var(--player-3); }
.message__sender--self { color: var(--color-primary); }

.message__bubble {
  display: inline-block;
  padding: 10px 14px;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-width: 85%;
  word-wrap: break-word;
  font-weight: 300;
}

.message--self .message__bubble {
  background: var(--color-primary);
  color: white;
  box-shadow: var(--shadow-lg);
}

.message--system .message__bubble {
  background: transparent;
  color: var(--color-text-muted);
  font-style: italic;
  font-size: 0.875rem;
  box-shadow: none;
}

/* Chat Input */
.chat__input-area {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.chat__input-area.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.chat__input {
  flex: 1;
  padding: 14px 0;
  font-size: 1rem;
  border: none;
  background: transparent;
  border-bottom: 1px solid #e5e7eb;
  outline: none;
  transition: all 0.2s ease;
}

.chat__input:focus {
  border-bottom-color: var(--color-primary);
}

.chat__send-btn {
  width: 48px;
  height: 48px;
  border: none;
  background: var(--color-primary);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s ease;
}

.chat__send-btn:hover {
  background: var(--color-primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.chat__send-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-md);
}

/* Both AI Option - styled like avatars */
.both-ai-option {
  display: none;
  flex-direction: column;
  align-items: center;
  flex: 1;
  cursor: default;
  transition: all 0.3s ease;
  pointer-events: none;
}

.both-ai-option.voting,
.both-ai-option.selected {
  display: flex;
  pointer-events: auto;
  cursor: pointer;
}

.both-ai-option.selected {
  pointer-events: none; /* Already voted, no more clicks */
}

.both-ai-option__circle {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
}

.both-ai-option__title {
  font-weight: 600;
  font-size: 1rem;
}

.both-ai-option__subtitle {
  font-size: 0.625rem;
  color: var(--color-text-muted);
  margin-top: 6px;
  text-align: center;
}

.both-ai-option.voting .both-ai-option__circle {
  animation: voting-glow-purple 1.5s ease-in-out infinite;
  transform: scale(1.1);
}

.both-ai-option.voting:hover .both-ai-option__circle {
  transform: scale(1.2);
}

.both-ai-option.selected .both-ai-option__circle {
  box-shadow: 0 0 0 3px var(--color-success), var(--shadow-lg);
  animation: none;
  transform: scale(1.1);
}

@keyframes voting-glow-purple {
  0%, 100% { box-shadow: var(--shadow-lg); }
  50% { box-shadow: var(--shadow-xl), 0 0 15px rgba(139, 92, 246, 0.5); }
}

/* Vote Countdown */
.vote-countdown {
  text-align: center;
  color: var(--color-danger);
  font-weight: 300;
  font-size: 1rem;
  padding: 8px 0;
  opacity: 0;
  height: 0;
  overflow: hidden;
  transition: all 0.3s ease;
}

.vote-countdown.active {
  opacity: 1;
  height: auto;
}

/* Results Screen */
.results {
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.results__icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.results__title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.results__title--correct { color: var(--color-success); }
.results__title--wrong { color: var(--color-danger); }

.results__detail {
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.results__other {
  color: var(--color-primary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.results__stats {
  padding: 20px 24px;
  margin-bottom: 24px;
  min-width: 240px;
}

.results__stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
}

.results__stat-row:not(:last-child) {
  border-bottom: 1px solid #e5e7eb;
}

.results__stat-label {
  color: var(--color-text-muted);
}

.results__stat-value {
  font-weight: 600;
}

/* Share */
.share {
  margin-top: 24px;
}

.share__title {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 12px;
}

.share__buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.share__btn {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.share__btn--twitter {
  background: #1da1f2;
  color: white;
}

.share__btn--twitter:hover {
  background: #1a8cd8;
}

.share__btn--copy {
  background: #f3f4f6;
  color: var(--color-text);
}

.share__btn--copy:hover {
  background: #e5e7eb;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

/* Footer */
.footer {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.625rem;
  color: var(--color-text-muted);
  opacity: 0.6;
  z-index: 10;
}


.footer a {
  color: inherit;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.footer__dot {
  width: 2px;
  height: 2px;
  background: currentColor;
  border-radius: 50%;
}

/* Layout wrapper for desktop ads */
.layout {
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

/* Sidebar ads - hidden on mobile, visible on desktop */
.ad-sidebar {
  display: none;
  width: 160px;
  padding: 16px;
  flex-shrink: 0;
}

@media (min-width: 800px) {
  .ad-sidebar {
    display: block;
    position: sticky;
    top: 16px;
    height: fit-content;
  }
}

/* Ad placeholder styling */
.ad-placeholder {
  width: 160px;
  height: 600px;
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
  border: 2px dashed #d1d5db;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.ad-placeholder--large {
  width: 300px;
  height: 250px;
}

/* Mobile Ad Overlay */
.ad-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}

.ad-overlay.active {
  display: flex;
}

.ad-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.ad-overlay__ad {
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
}

.ad-overlay__skip {
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-full);
  background: white;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-md);
}

.ad-overlay__skip:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ad-overlay__skip:not(:disabled):hover {
  background: var(--color-primary);
  color: white;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

/* Responsive */
@media (max-width: 480px) {
  .app {
    padding: 12px;
  }

  .header__title {
    font-size: 1.5rem;
  }

  .avatar {
    width: 56px;
  }

  .avatar__circle {
    width: 40px;
    height: 40px;
    font-size: 0.875rem;
  }

  /* Hide header on results screen to save space */
  body.results-active .header {
    display: none;
  }

  /* Remove header padding during chat to maximize space */
  body.chat-active .header {
    padding: 8px 0;
  }
}
