:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --success: #10b981;
  --error: #ef4444;
  --background-start: #ee7752;
  --background-end: #23a6d5;
  --text-main: #1f2937;
  --text-light: #6b7280;
  --glass: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  --font-family: 'Inter', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  /* Remove mobile gray tap box */
}

button,
.category-btn,
.option-btn,
.mode-btn,
.difficulty-btn {
  cursor: pointer;
  touch-action: manipulation;
  /* Improve touch response */
  user-select: none;
  /* Prevent text selection */
}

body {
  font-family: var(--font-family);
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-main);
  padding: 20px;
}

@keyframes gradientBG {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

#app {
  width: 100%;
  max-width: 500px;
  min-height: 600px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

/* Views Management */
.view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 30px;
  display: flex;
  flex-direction: column;
  transition: opacity 0.5s ease, transform 0.5s ease;
  transition: opacity 0.5s ease, transform 0.5s ease;
  opacity: 0;
  /* Removed pointer-events: none to prevent mobile blocking issues. 
     Visibility is handled by .hidden (display: none) anyway. */
  transform: scale(0.95);
  overflow-y: auto;
}

.view.active {
  opacity: 1;
  pointer-events: auto;
  /* explicit set */
  transform: scale(1);
  z-index: 10;
}

.hidden {
  display: none;
}

/* Start View */
h1,
h2 {
  text-align: center;
  margin-bottom: 20px;
  color: var(--primary);
}

h2 {
  font-size: 1.5rem;
  margin-top: 10px;
}

.subtitle {
  text-align: center;
  color: var(--text-light);
  margin-bottom: 30px;
}

.label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  margin-top: 20px;
}

.difficulty-container {
  display: flex;
  gap: 10px;
  margin-bottom: 30px;
}

#password-input {
  width: 100%;
  padding: 16px;
  border: 2px solid #ddd;
  border-radius: 12px;
  font-size: 1.1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  /* Fixes for typing issues */
  background: white !important;
  color: #000 !important;
  pointer-events: auto !important;
  z-index: 50;
  position: relative;
}

.difficulty-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid #ddd;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.difficulty-btn.active {
  border-color: var(--primary);
  background: #e0e7ff;
  color: var(--primary);
}

#category-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  overflow-y: auto;
  max-height: 300px;
}

.category-btn {
  padding: 16px;
  border: none;
  background: white;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.category-btn::after {
  content: '→';
  color: var(--text-light);
}

.category-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  color: var(--primary);
}

/* Game View */
.progress-container {
  margin-bottom: 30px;
  margin-top: 0;
}

/* Adjust Game View padding to make room for button */
#game-view {
  padding-top: 70px;
  /* More space at top */
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

#progress-text {
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 5px;
}

.question-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#word-display {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 40px;
  text-align: center;
  color: var(--text-main);
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  /* Default 2 columns */
  gap: 15px;
  width: 100%;
}

.option-btn {
  padding: 16px;
  border: none;
  background: white;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: all 0.2s;
  color: var(--text-main);
}

.option-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.option-btn.correct {
  background: var(--success);
  color: white;
  animation: pulse 0.5s;
}

.option-btn.wrong {
  background: var(--error);
  color: white;
  animation: shake 0.4s;
}

/* Multiplayer Styles */
.room-code {
  font-size: 3rem;
  letter-spacing: 5px;
  background: white;
  padding: 10px 30px;
  border-radius: 12px;
  margin: 10px 0;
  color: var(--primary);
  font-weight: 800;
  border: 3px dashed var(--primary);
}

.lobby-controls {
  background: rgba(255, 255, 255, 0.5);
  padding: 15px;
  border-radius: 12px;
  width: 100%;
}

.player-list-box {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 15px;
  width: 100%;
  margin: 20px 0;
  min-height: 100px;
  max-height: 200px;
  overflow-y: auto;
}

#lobby-player-list {
  list-style: none;
}

#lobby-player-list li {
  padding: 5px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  font-weight: 600;
}

.loader {
  border: 5px solid #f3f3f3;
  border-top: 5px solid var(--primary);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 30px auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Leaderboard */
#live-ranking {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-height: 400px;
  overflow-y: auto;
}

.rank-row {
  display: flex;
  align-items: center;
  background: white;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.rank-pos {
  font-size: 1.2rem;
  font-weight: 800;
  width: 40px;
  color: var(--primary);
}

.rank-name {
  flex: 1;
  font-weight: 600;
}

.rank-progress {
  font-size: 0.9rem;
  color: var(--text-light);
}

.rank-status.finished {
  color: var(--success);
  font-weight: bold;
}

.rank-status.playing {
  color: var(--primary);
}

.rank-status.restart {
  color: var(--error);
  animation: shake 0.4s;
}

.status-msg {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-light);
}

/* Mode Selection Styles */
.mode-container {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.mode-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid #ddd;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  text-align: center;
  font-size: 0.95rem;
}

.mode-btn.active {
  border-color: var(--primary);
  background: #e0e7ff;
  color: var(--primary);
}

/* Speaker Button */
.speaker-btn {
  background: white;
  border: 3px solid var(--primary);
  color: var(--primary);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  font-size: 2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 30px auto;
}

/* This brace was missing, closing .option-btn.wrong */

/* Multiplayer Styles */
.room-code {
  font-size: 3rem;
  letter-spacing: 5px;
  background: white;
  padding: 10px 30px;
  border-radius: 12px;
  margin: 10px 0;
  color: var(--primary);
  font-weight: 800;
  border: 3px dashed var(--primary);
}

.lobby-controls {
  background: rgba(255, 255, 255, 0.5);
  padding: 15px;
  border-radius: 12px;
  width: 100%;
}

.player-list-box {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 15px;
  width: 100%;
  margin: 20px 0;
  min-height: 100px;
  max-height: 200px;
  overflow-y: auto;
}

#lobby-player-list {
  list-style: none;
}

#lobby-player-list li {
  padding: 5px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  font-weight: 600;
}

.loader {
  border: 5px solid #f3f3f3;
  border-top: 5px solid var(--primary);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 30px auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Leaderboard */
#live-ranking {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-height: 400px;
  overflow-y: auto;
}

.rank-row {
  display: flex;
  align-items: center;
  background: white;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.rank-pos {
  font-size: 1.2rem;
  font-weight: 800;
  width: 40px;
  color: var(--primary);
}

.rank-name {
  flex: 1;
  font-weight: 600;
}

.rank-progress {
  font-size: 0.9rem;
  color: var(--text-light);
}

.rank-status.finished {
  color: var(--success);
  font-weight: bold;
}

.rank-status.playing {
  color: var(--primary);
}

.rank-status.restart {
  color: var(--error);
  animation: shake 0.4s;
}

.status-msg {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-light);
}

/* Mode Selection Styles */
.mode-container {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.mode-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid #ddd;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  text-align: center;
  font-size: 0.95rem;
}

.mode-btn.active {
  border-color: var(--primary);
  background: #e0e7ff;
  color: var(--primary);
}

/* Speaker Button */
.speaker-btn {
  background: white;
  border: 3px solid var(--primary);
  color: var(--primary);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  font-size: 2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 30px auto;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.speaker-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

.speaker-btn.playing {
  animation: pulse 1s infinite;
}

.option-btn:disabled {
  cursor: default;
  opacity: 0.7;
}

/* Summary View */
#summary-view {
  text-align: center;
}

.win-title {
  color: var(--success);
}

.lose-title {
  color: var(--primary);
  /* Encouraging color instead of red */
}

#summary-list {
  text-align: left;
  margin: 20px 0;
  flex: 1;
  overflow-y: auto;
  padding-right: 5px;
}

.summary-item {
  display: flex;
  align-items: center;
  background: white;
  /* slightly opaque */
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  border-left: 4px solid #ddd;
}

.summary-item.correct {
  border-left-color: var(--success);
}

.summary-item.wrong {
  border-left-color: var(--error);
}

.summary-num {
  font-weight: bold;
  color: var(--text-light);
  margin-right: 12px;
  width: 24px;
}

.summary-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
}

.summary-content span {
  font-size: 0.8rem;
  color: var(--text-light);
}

.summary-content .correction {
  color: var(--success);
  font-weight: 600;
}

.summary-icon {
  font-size: 1.2rem;
}

.primary-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 20px;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

/* Animations */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

/* Summary View */
#summary-view {
  text-align: center;
}

.win-title {
  color: var(--success);
}

.lose-title {
  color: var(--primary);
  /* Encouraging color instead of red */
}

#summary-list {
  text-align: left;
  margin: 20px 0;
  flex: 1;
  overflow-y: auto;
  padding-right: 5px;
}

.summary-item {
  display: flex;
  align-items: center;
  background: white;
  /* slightly opaque */
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  border-left: 4px solid #ddd;
}

.summary-item.correct {
  border-left-color: var(--success);
}

.summary-item.wrong {
  border-left-color: var(--error);
}

.summary-num {
  font-weight: bold;
  color: var(--text-light);
  margin-right: 12px;
  width: 24px;
}

.summary-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 0.9rem;
}

.summary-content span {
  font-size: 0.8rem;
  color: var(--text-light);
}

.summary-content .correction {
  color: var(--success);
  font-weight: 600;
}

.summary-icon {
  font-size: 1.2rem;
}

.primary-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 20px;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

/* Animations */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Floating Home Button */
.floating-home-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 8px 16px;
  border-radius: 20px;
  color: var(--text-main);
  font-weight: 600;
  cursor: pointer;
  z-index: 100;
  backdrop-filter: blur(5px);
  transition: all 0.2s;
  font-size: 0.9rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 6px;
}

.floating-home-btn:hover {
  background: rgba(255, 255, 255, 0.6);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

/* Responsive Mobile Styles - AGGRESSIVE FIXES */
@media (max-width: 600px) {
  body {
    padding: 0;
    display: block;
    /* Remove flex centering issues */
    height: auto;
    overflow-y: auto;
  }

  #app {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
    /* Disable glassmorphism on mobile to prevent hit-test bugs */
    -webkit-backdrop-filter: none;
    background: rgba(255, 255, 255, 0.95);
    /* Solid-ish background */
    box-shadow: none;
    transform: none !important;
    /* Disable any transforms */
  }

  .view {
    padding: 20px 10px;
    position: relative;
    /* Stack normally on mobile? No, keeping absolute but fixing props */
    width: 100%;
    height: 100%;
    opacity: 1 !important;
    /* Force visible if active check fails */
    transform: none !important;
    pointer-events: auto !important;
    /* FORCE CLICKABILITY */
  }

  .view.hidden {
    display: none !important;
  }

  h1 {
    font-size: 1.8rem;
    margin-top: 10px;
  }

  .options-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  button,
  .category-btn,
  .option-btn,
  .mode-btn,
  .difficulty-btn,
  .primary-btn {
    padding: 20px;
    font-size: 1.1rem;
    margin-bottom: 8px;
    min-height: 60px;
    /* Ensure big touch target */
    pointer-events: auto !important;
    cursor: pointer;
    z-index: 100;
    /* Force on top */
    position: relative;
  }

  .mode-container,
  .difficulty-container {
    flex-direction: column;
  }

  .room-code {
    font-size: 2rem;
  }
}