/* Global Resets & Typography */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --font-family-title: 'Outfit', 'Inter', 'Noto Sans TC', sans-serif;
  --font-family-body: 'Inter', 'Noto Sans TC', sans-serif;
  
  /* Vibrant Neon Color Palette */
  --bg-color: #060410;
  --panel-bg: rgba(18, 14, 38, 0.45);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: #ffffff;
  --text-secondary: #a5a1c0;
  
  --color-primary: #a855f7; /* Purple */
  --color-primary-glow: rgba(168, 85, 247, 0.4);
  --color-secondary: #06b6d4; /* Cyan */
  --color-secondary-glow: rgba(6, 182, 212, 0.4);
  --color-accent: #ec4899; /* Pink */
  
  --color-danger: #ef4444;
  --color-danger-glow: rgba(239, 68, 68, 0.3);
  
  --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
  --glass-glow: 0 0 20px rgba(168, 85, 247, 0.15);
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-family-body);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* Background Animated Glows */
.bg-glow {
  position: fixed;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  filter: blur(140px);
  z-index: -1;
  opacity: 0.25;
  pointer-events: none;
  animation: float-glow 20s infinite alternate ease-in-out;
}

.bg-glow-1 {
  background: radial-gradient(circle, var(--color-primary) 0%, rgba(0,0,0,0) 70%);
  top: -10%;
  left: -10%;
}

.bg-glow-2 {
  background: radial-gradient(circle, var(--color-secondary) 0%, rgba(0,0,0,0) 70%);
  bottom: -10%;
  right: -10%;
  animation-delay: -10s;
}

@keyframes float-glow {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(80px, 50px) scale(1.15); }
}

/* App Container Layout */
.app-container {
  width: 100%;
  max-width: 1400px;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

/* Header Styling */
.app-header {
  text-align: center;
  margin-bottom: 8px;
}

.app-header .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}

.app-header h1 {
  font-family: var(--font-family-title);
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 30%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-header .logo i {
  font-size: 2.6rem;
  color: var(--color-secondary);
}

.icon-glow {
  text-shadow: 0 0 20px var(--color-secondary-glow);
  filter: drop-shadow(0 0 10px var(--color-secondary-glow));
}

.app-header .subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  font-weight: 300;
  letter-spacing: 0.5px;
}

/* Main Grid Layout */
.app-main {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 32px;
  align-items: start;
}

@media (max-width: 992px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

/* Glassmorphism Cards */
.glass-card {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--card-shadow), var(--glass-glow);
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
              transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
              max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
              padding 0.35s cubic-bezier(0.4, 0, 0.2, 1), 
              margin 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.3s ease,
              box-shadow 0.3s ease;
  max-height: 800px;
  opacity: 1;
  overflow: visible;
}

.glass-card.stats-card, .glass-card.help-card {
  padding: 22px 26px;
  gap: 16px;
}

.glass-card.hidden {
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  border-color: transparent !important;
  box-shadow: none !important;
  pointer-events: none !important;
  transform: scale(0.95) translateY(-10px) !important;
}

.glass-card:hover {
  border-color: rgba(168, 85, 247, 0.25);
  box-shadow: var(--card-shadow), 0 0 24px rgba(168, 85, 247, 0.25);
}

.card-header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.btn-card-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  transition: var(--transition-smooth);
}

.btn-card-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-danger);
  transform: scale(1.1);
}

/* Card Divider & Toggles */
.card-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08) 20%, rgba(255, 255, 255, 0.08) 80%, transparent);
  margin: 12px 0 2px 0;
}

.layout-toggles {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.toggle-title {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.switch-container {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  border-radius: 20px;
  transition: var(--transition-smooth);
}

.switch-container:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.switch-container input {
  display: none;
}

.switch-container .switch-label {
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.switch-container input:checked + .switch-label {
  color: #ffffff;
  font-weight: 500;
}

.switch-container::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.20);
  transition: var(--transition-smooth);
}

.switch-container:has(input:checked)::before {
  background: var(--color-secondary);
  box-shadow: 0 0 8px var(--color-secondary);
}

/* Custom Premium Slider Style */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  font-size: 0.85rem;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 8px 16px;
  border-radius: 20px;
  transition: var(--transition-smooth);
}

.slider-wrapper:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.slider-wrapper input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  height: 6px;
  border-radius: 3px;
  outline: none;
  transition: var(--transition-smooth);
}

.slider-wrapper input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-secondary);
  cursor: pointer;
  box-shadow: 0 0 10px var(--color-secondary-glow);
  transition: var(--transition-smooth);
}

.slider-wrapper input[type="range"]::-webkit-slider-thumb:hover {
  background: #ffffff;
  transform: scale(1.2);
  box-shadow: 0 0 15px #ffffff;
}

.slider-wrapper input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--color-secondary);
  cursor: pointer;
  box-shadow: 0 0 10px var(--color-secondary-glow);
  transition: var(--transition-smooth);
}

.slider-wrapper input[type="range"]::-moz-range-thumb:hover {
  background: #ffffff;
  transform: scale(1.2);
  box-shadow: 0 0 15px #ffffff;
}

#font-scale-value {
  color: var(--color-secondary);
  font-weight: 600;
  min-width: 36px;
  text-align: right;
}

.glass-card h2 {
  font-family: var(--font-family-title);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
  color: #ffffff;
}

.icon-margin {
  margin-right: 10px;
  font-size: 1.2rem;
}

.card-desc {
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Control Panel Section */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Form Styles */
.input-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.input-group {
  display: flex;
  gap: 12px;
}

.input-group input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 14px 18px;
  color: #ffffff;
  font-size: 0.95rem;
  outline: none;
  font-family: var(--font-family-body);
  transition: var(--transition-smooth);
}

.input-group input:focus {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--color-primary);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.char-limit {
  font-size: 0.8rem;
  color: rgba(165, 161, 192, 0.6);
  text-align: right;
  padding-right: 4px;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary) 0%, #7e22ce 100%);
  border: none;
  border-radius: 14px;
  color: #ffffff;
  padding: 14px 24px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-family-body);
  box-shadow: 0 4px 12px var(--color-primary-glow);
  transition: var(--transition-smooth);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.6);
  background: linear-gradient(135deg, #b55fe6 0%, #8b29e3 100%);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  color: var(--text-secondary);
  padding: 12px 20px;
  font-weight: 500;
  font-size: 0.92rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.15);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ffffff;
  border-color: var(--color-danger);
  box-shadow: 0 0 12px var(--color-danger-glow);
}

/* Statistics Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-val {
  font-family: var(--font-family-title);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--color-secondary);
  text-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

.stat-lbl {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.admin-actions {
  margin-top: 4px;
}

.admin-actions button {
  width: 100%;
}

/* Help Section */
.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.help-list li {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.help-list li i {
  margin-top: 3px;
  font-size: 0.95rem;
}

.text-glow-yellow {
  color: #f59e0b;
  text-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.text-glow-blue {
  color: #3b82f6;
  text-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.text-glow-pink {
  color: #ec4899;
  text-shadow: 0 0 8px rgba(236, 72, 153, 0.4);
}

/* Display Panel & Canvas Card */
.display-panel {
  height: 100%;
}

.canvas-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0; /* Remove padding to maximize canvas space */
  overflow: hidden;
}

.canvas-header {
  padding: 24px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--panel-border);
}

.canvas-header h3 {
  font-family: var(--font-family-title);
  font-size: 1.3rem;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.text-glow-purple {
  color: var(--color-primary);
  filter: drop-shadow(0 0 6px var(--color-primary-glow));
}

.canvas-actions {
  display: flex;
  gap: 10px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: var(--transition-smooth);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/* Canvas Container */
.canvas-container {
  flex: 1;
  position: relative;
  min-height: 520px;
  background: rgba(10, 8, 22, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#wordcloud-canvas {
  width: 100%;
  height: 100%;
  min-height: 480px;
  border-radius: 16px;
  background: transparent;
  display: block;
}

/* Spinner Overlay for Loading */
.canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 4, 16, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  z-index: 10;
  transition: opacity 0.4s ease;
  border-radius: 0 0 24px 24px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(168, 85, 247, 0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  box-shadow: 0 0 15px var(--color-primary-glow);
}

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

#overlay-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.5px;
}

/* Footer Styling */
.app-footer {
  text-align: center;
  padding: 20px 0 10px 0;
  font-size: 0.85rem;
  color: rgba(165, 161, 192, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.app-footer p {
  letter-spacing: 0.2px;
}

/* Questions List Sidebar Control Panel */
.questions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
  margin-top: 8px;
}

/* Custom scrollbar for premium feel */
.questions-list::-webkit-scrollbar {
  width: 6px;
}
.questions-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.01);
  border-radius: 3px;
}
.questions-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
.questions-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.question-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: var(--transition-smooth);
}

.question-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(4px);
}

.question-item.active {
  background: rgba(168, 85, 247, 0.07);
  border-color: rgba(168, 85, 247, 0.25);
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.12);
}

.question-item-text {
  font-size: 0.88rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.question-item.active .question-item-text {
  color: #ffffff;
}

.question-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

.question-type-badge {
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.7rem;
}

.badge-wordcloud {
  background: rgba(168, 85, 247, 0.12);
  color: #d8b4fe;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.badge-poll {
  background: rgba(6, 182, 212, 0.12);
  color: #cffafe;
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.badge-rating {
  background: rgba(245, 158, 11, 0.14);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.btn-broadcast {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition-smooth);
}

.btn-broadcast:hover {
  background: var(--color-secondary);
  border-color: var(--color-secondary);
  color: #ffffff;
  box-shadow: 0 0 10px var(--color-secondary-glow);
}

.btn-broadcast.broadcasting {
  background: #22c55e;
  border-color: #22c55e;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

/* Modal Overlays for QR Code and Import Textarea */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(4, 2, 10, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: var(--transition-smooth);
}

.modal-card {
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 30px rgba(168, 85, 247, 0.2);
  animation: scale-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scale-up {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Animated Glassmorphic Bar Charts */
.poll-results-container {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 10px;
  animation: fade-in-chart 0.5s ease;
  position: relative;
  z-index: 2;
}

@keyframes fade-in-chart {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.poll-bar-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.poll-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
}

.poll-bar-track {
  width: 100%;
  height: 24px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.poll-bar-fill {
  height: 100%;
  width: 0%; /* Dynamic */
  background: linear-gradient(90deg, var(--color-secondary) 0%, var(--color-primary) 100%);
  border-radius: 11px;
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.4);
  transition: width 0.8s cubic-bezier(0.1, 1, 0.1, 1);
}

.poll-bar-count {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-secondary);
}

/* Offline Fallback Banner Styles */
.offline-banner {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(245, 158, 11, 0.15) 100%);
  border-bottom: 1px solid rgba(245, 158, 11, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #f59e0b;
  padding: 12px 24px;
  text-align: center;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  z-index: 9999;
  width: 100%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transition: var(--transition-smooth);
}
.offline-banner.hidden {
  display: none !important;
}

/* Rating results: big average number on the teacher display */
.rating-average {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 18px;
}

.rating-average-num {
  font-family: var(--font-family-title);
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, #fde68a 0%, var(--color-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 24px rgba(6, 182, 212, 0.25);
}

.rating-average-lbl {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

