*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface-light: #25253d;
  --primary: #e94560;
  --primary-hover: #ff6b81;
  --secondary: #533483;
  --secondary-hover: #6c44a2;
  --text: #eaeaea;
  --text-muted: #8888aa;
  --border: #333355;
  --success: #2ed573;
  --success-hover: #3bde80;
  --radius: 8px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* Prevent double-tap zoom on all interactive elements */
button, input, .voting-tag, a {
  touch-action: manipulation;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reconnect banner */
.reconnect-banner:not([hidden]) {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  animation: reconnect-pulse 2s ease-in-out infinite;
}

@keyframes reconnect-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.reconnect-banner.success {
  background: var(--success);
  animation: none;
}

/* Utility */
.screen {
  display: none;
  height: 100%;
}
.screen.active {
  display: flex;
}

/* ---------- Lobby ---------- */
#screen-lobby {
  align-items: center;
  justify-content: center;
}

.lobby-container {
  width: 100%;
  max-width: 400px;
  padding: 2rem 1.5rem;
  text-align: center;
}

.logo {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--text);
}
.logo a {
  color: inherit;
  text-decoration: none;
}
.logo a:hover {
  opacity: 0.85;
}
.logo span {
  color: var(--primary);
}

.tagline {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-style: italic;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus {
  border-color: var(--primary);
}
input[type="text"]::placeholder {
  color: var(--text-muted);
}

#room-code {
  text-transform: uppercase;
  letter-spacing: 4px;
  text-align: center;
  font-weight: 700;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--secondary);
  color: #fff;
}
.btn-secondary:hover {
  background: var(--secondary-hover);
}
.btn-success {
  background: var(--success);
  color: var(--bg);
}
.btn-success:hover {
  background: var(--success-hover);
}
.btn-small {
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  background: var(--surface-light);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-small:hover {
  background: var(--border);
}
.btn-danger {
  background: rgba(233, 69, 96, 0.15);
  color: var(--primary);
  border-color: var(--primary);
}
.btn-danger:hover {
  background: rgba(233, 69, 96, 0.3);
}

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row {
  display: flex;
  gap: 0.5rem;
}
.join-row input {
  flex: 1;
}

.error-msg {
  margin-top: 0.75rem;
  color: var(--primary);
  font-size: 0.9rem;
}

/* Inline field validation */
.field-feedback {
  color: var(--primary);
  font-size: 0.82rem;
  margin-top: 0.25rem;
}
input[type="text"].input-invalid {
  border-color: var(--primary);
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---------- Lobby subviews (Create Game / Join Game) ---------- */
.lobby-buttons:not([hidden]) {
  display: flex;
  gap: 0.75rem;
}
.lobby-buttons .btn {
  flex: 1;
}

.lobby-subview:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  animation: fadeIn 0.2s ease;
}
.lobby-subview[hidden] {
  display: none;
}

.subview-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.subview-title-left {
  text-align: left;
}

.subview-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.subview-form .setting-group {
  margin-bottom: 0;
  text-align: left;
}

.join-code-section {
  text-align: left;
}

/* ---------- How to Play link ---------- */
.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.25rem 0;
  transition: color 0.2s;
}
.btn-link:hover {
  color: var(--primary);
}
.btn-how-to-play {
  margin-top: 1.5rem;
}

/* ---------- Invite join ---------- */
#invite-join {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
#invite-join[hidden] {
  display: none;
}
.lobby-form[hidden] {
  display: none;
}
.invite-msg {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 0.25rem;
}
.invite-code {
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 2px;
}

/* ---------- Share button ---------- */
#btn-share.copied {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* ---------- Room ---------- */
#screen-room {
  flex-direction: column;
}

.app-header:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-title {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.app-title-link {
  color: inherit;
  text-decoration: none;
}
.app-title-link span {
  color: var(--primary);
}
.app-title-link:hover {
  opacity: 0.85;
}
.room-code {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 2px;
  font-weight: 600;
}

.room-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Game area (left) */
.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.players-panel {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.players-panel h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  letter-spacing: 1px;
}
#player-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
#player-list li {
  background: var(--surface-light);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
}
#player-list li.host::before {
  content: '\2605 ';
  color: var(--primary);
}
#player-list li.me {
  background: var(--surface);
  font-weight: 700;
}
.player-score {
  color: var(--primary);
  font-weight: 700;
  margin-left: 0.35rem;
  font-size: 0.8em;
}

.game-panel {
  flex: 1;
  display: flex;
  padding: 1rem;
  overflow-y: auto;
}
.waiting-msg {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.lobby-countdown:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.lobby-countdown-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.lobby-countdown-row .hourglass-icon {
  width: 1.6rem;
  height: 1.6rem;
}
.lobby-countdown-number {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--primary);
  min-width: 1.5em;
  text-align: center;
}

.lobby-settings-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  width: 100%;
  max-width: 340px;
}
.lobby-settings-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.lobby-settings-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
}
.lobby-setting-label {
  color: var(--text-muted);
}
.lobby-setting-value {
  color: var(--text);
  text-align: right;
}

/* ---------- Game states ---------- */
.game-state {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 500px;
  gap: 1rem;
}
.game-state.active {
  display: flex;
  margin: auto;
}

.btn-large {
  padding: 0.85rem 2rem;
  font-size: 1.1rem;
}

/* Round header */
.round-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.5rem 0;
}
.round-header .timer:not([hidden]) {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--surface);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-width: 48px;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Prompt text (question) */
.prompt-text {
  font-size: 1.1rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.25rem 0 0;
}

/* Prompt word (highlighted element) */
.prompt-word {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text);
  text-align: center;
  padding: 0.5rem 0 1rem;
  letter-spacing: 1px;
  font-family: Georgia, 'Times New Roman', serif;
}

/* Answer input */
.answer-row {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}
.input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
}
.answer-row input {
  flex: 1;
  font-size: 1.1rem;
  padding: 0.75rem 3.5rem 0.75rem 1rem;
}
.inline-timer {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  pointer-events: none;
  user-select: none;
}
.hourglass-icon {
  animation: hourglass-rotate 2s ease-in-out infinite;
}
@keyframes hourglass-rotate {
  0% { transform: rotate(0deg); }
  40% { transform: rotate(180deg); }
  100% { transform: rotate(180deg); }
}

.locked-msg {
  color: var(--success);
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
}
.waiting-msg {
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
  margin-top: 0.5rem;
}
#btn-game-over-leave {
  margin-top: 0.75rem;
}

.submitted-list {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* Results prompt and word */
.results-prompt {
  font-size: 1rem;
  color: var(--text-muted);
  text-align: center;
}
.results-word {
  font-size: 1.2rem;
  color: var(--text);
  font-weight: 700;
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.results-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.results-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.results-table tr.correct td {
  color: var(--success);
}
.results-table tr.incorrect td {
  color: var(--text-muted);
}

/* Game over / leaderboard */
.game-over-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.leaderboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.leaderboard-entry.rank-1 {
  border-color: #ffd700;
  background: rgba(255, 215, 0, 0.08);
}
.leaderboard-entry.rank-2 {
  border-color: #c0c0c0;
  background: rgba(192, 192, 192, 0.06);
}
.leaderboard-entry.rank-3 {
  border-color: #cd7f32;
  background: rgba(205, 127, 50, 0.06);
}
.leaderboard-rank {
  font-size: 1.3rem;
  font-weight: 800;
  min-width: 32px;
  text-align: center;
}
.rank-1 .leaderboard-rank { color: #ffd700; }
.rank-2 .leaderboard-rank { color: #c0c0c0; }
.rank-3 .leaderboard-rank { color: #cd7f32; }
.leaderboard-name {
  flex: 1;
  font-weight: 600;
}
.leaderboard-pts {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
}

/* Confetti overlay */
.confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* Chat panel (right) */
.chat-panel {
  width: 280px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--surface);
}
.chat-panel[hidden] {
  display: none;
}
.chat-heading-desktop {
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.75rem 1rem 0.4rem;
  letter-spacing: 1px;
}

/* Chat toggle (mobile only, hidden on desktop) */
.chat-toggle {
  display: none;
}
.chat-badge {
  display: none;
}
.chat-toggle-icon {
  display: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}
.chat-messages .msg .author {
  font-weight: 600;
  color: var(--primary);
}
.chat-messages .msg.system {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.8rem;
  white-space: pre-line;
}

.chat-input-row {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
}

/* ---------- Header actions ---------- */
.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn-icon {
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.4rem 0.6rem;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}
.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.btn-close:hover {
  color: var(--text);
}

/* ---------- Tabs ---------- */
.settings-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.settings-tabs .tab {
  flex: 1;
  padding: 0.65rem 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.settings-tabs .tab:hover {
  color: var(--text);
}
.settings-tabs .tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.settings-tabs .tab.hidden {
  display: none;
}

.tab-content-container {
  overflow: hidden;
}

.tab-content {
  display: none;
  padding: 1.25rem;
}
.tab-content.active {
  display: block;
}

@keyframes slide-in-from-right {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slide-in-from-left {
  from { transform: translateX(-40px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}
.tab-content.slide-in-right {
  animation: slide-in-from-right 0.2s ease-out;
}
.tab-content.slide-in-left {
  animation: slide-in-from-left 0.2s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .tab-content.slide-in-right,
  .tab-content.slide-in-left {
    animation: none;
  }
}

/* ---------- Setting controls ---------- */
.setting-group {
  margin-bottom: 1.25rem;
}
.setting-group:last-child {
  margin-bottom: 0.5rem;
}

.setting-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.setting-row {
  display: flex;
  gap: 0.5rem;
}
.setting-row input[type="text"] {
  flex: 1;
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.setting-feedback {
  font-size: 0.8rem;
  margin-top: 0.35rem;
  color: var(--success);
}
.setting-feedback.error {
  color: var(--primary);
}

/* Slider */
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.slider-row input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--surface-light);
  border-radius: 3px;
  outline: none;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}
.slider-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 32px;
  text-align: right;
}

/* Speed selector */
.speed-selector {
  display: flex;
  gap: 0.5rem;
}
.speed-btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.speed-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}
.speed-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-light);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider {
  background: var(--primary);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 0.9rem;
  color: var(--text);
}

/* Checkbox group for question types */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.checkbox-label {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  column-gap: 0.5rem;
  row-gap: 0.15rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

/* ---------- Radio group (bot difficulty) ---------- */
.radio-group {
  display: flex;
  gap: 1rem;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}
.radio-label input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}
.radio-label input[type="radio"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Voting ---------- */
.voting-prompt {
  font-size: 1.1rem;
  color: var(--text-muted);
  text-align: center;
}
.voting-display-word {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 0.5rem;
  font-family: Georgia, 'Times New Roman', serif;
}

.voting-words {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  padding: 0.75rem 0;
}

.voting-tag {
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--surface-light);
  color: var(--text);
  transition: all 0.2s;
}
@media (hover: hover) {
  .voting-tag:hover:not(:disabled) {
    border-color: var(--primary);
    background: rgba(233, 69, 96, 0.12);
    transform: scale(1.05);
  }
}

.voting-tag.voting-correct {
  border-color: var(--success);
  color: var(--success);
}
.voting-tag.voting-incorrect {
  border-color: var(--primary);
  color: var(--text-muted);
  text-decoration: line-through;
  opacity: 0.7;
}

.voting-tag.voting-own {
  opacity: 0.5;
  cursor: not-allowed;
  position: relative;
}
.voting-tag.voting-own::after {
  content: '(you)';
  font-size: 0.65rem;
  font-weight: 400;
  margin-left: 0.3rem;
  color: var(--text-muted);
}

.voting-tag.voting-selected {
  border-color: #ffd700;
  background: rgba(255, 215, 0, 0.15);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.3);
  transform: scale(1.08);
}

.voting-tag:disabled:not(.voting-own) {
  opacity: 0.6;
  cursor: default;
}

.voting-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
  margin: 0;
}

.voting-status {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.2em;
}

/* Vote count badge in results */
.vote-count-badge {
  display: inline-block;
  background: rgba(255, 215, 0, 0.15);
  color: #ffd700;
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.3rem;
  vertical-align: middle;
}

/* ---------- Question type examples ---------- */
.setting-example {
  flex-basis: 100%;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
  margin-left: calc(16px + 0.5rem);
}

/* ---------- Help modal ---------- */
.help-modal {
  max-width: 800px;
}
.help-content {
  padding: 1.25rem;
  max-height: 70vh;
  overflow-y: auto;
}
.help-section {
  margin-bottom: 1.25rem;
}
.help-section:last-child {
  margin-bottom: 0;
}
.help-section h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.help-section p,
.help-section li {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.6;
}
.help-section ol,
.help-section ul {
  padding-left: 1.25rem;
  margin: 0;
}
.help-section ol li,
.help-section ul li {
  margin-bottom: 0.35rem;
}
.help-definitions {
  margin: 0;
}
.help-definitions-twists {
  margin-top: 0.75rem;
}
.help-definitions dt {
  font-weight: 700;
  color: var(--text);
  font-size: 0.88rem;
  margin-top: 0.5rem;
}
.help-definitions dt:first-child {
  margin-top: 0;
}
.help-definitions dd {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-left: 1rem;
  margin-bottom: 0.25rem;
}
.help-definitions dd em {
  color: var(--text-muted);
}

/* ---------- Loading / connection states ---------- */
.btn.loading {
  position: relative;
  pointer-events: none;
  color: transparent;
}
.btn.loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  margin-left: -9px;
  margin-top: -9px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Settings save confirmation ---------- */
.save-confirmation {
  display: none;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--success);
  font-weight: 600;
  margin-top: 0.5rem;
  animation: fadeIn 0.3s ease;
}
.save-confirmation.visible {
  display: flex;
}
.save-confirmation::before {
  content: '\2713';
  font-size: 1rem;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive (tablet) ---------- */
@media (max-width: 768px) and (min-width: 641px) {
  .chat-panel {
    width: 220px;
  }
  .modal {
    max-width: 380px;
  }
  .prompt-word {
    font-size: 2.2rem;
  }
  .leaderboard-entry {
    padding: 0.65rem 0.85rem;
  }
}

/* ---------- Responsive (mobile) ---------- */
@media (max-width: 640px) {
  .logo {
    font-size: 2.2rem;
  }

  /* Lobby: stack buttons and join row on mobile */
  .lobby-buttons:not([hidden]) {
    flex-direction: column;
  }
  .join-row {
    flex-direction: column;
  }
  .join-row .btn {
    width: 100%;
  }

  .room-body {
    flex-direction: column;
  }

  /* Room header: tighten spacing, allow wrapping if needed */
  .app-header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
  .app-title {
    font-size: 1rem;
    white-space: nowrap;
  }
  .header-actions {
    gap: 0.35rem;
  }

  .chat-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 45vh;
    overflow: hidden;
    transition: max-height 0.25s ease;
  }

  /* Hide desktop heading on mobile */
  .chat-heading-desktop {
    display: none;
  }

  /* Chat toggle bar (mobile only) */
  .chat-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    gap: 0.5rem;
  }
  .chat-toggle-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    font-weight: bold;
    pointer-events: none;
  }
  .chat-toggle-icon {
    display: inline-block;
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.25s ease;
  }
  .chat-toggle-icon::after {
    content: '\25B2';
  }
  .chat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    line-height: 1;
  }
  .chat-badge[hidden] {
    display: none;
  }

  /* Collapsed chat on mobile */
  .chat-panel.collapsed {
    max-height: 38px;
    overflow: hidden;
  }
  .chat-panel.collapsed .chat-toggle-icon::after {
    content: '\25B2';
  }
  .chat-panel:not(.collapsed) .chat-toggle-icon::after {
    content: '\25BC';
  }

  /* Chat: stack send button below input like lobby join */
  .chat-input-row {
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }
  .chat-input-row .btn {
    width: 100%;
    padding: 0.55rem 0.85rem;
  }

  .game-area {
    min-height: 0;
  }

  /* Game: stack answer submit row */
  .answer-row {
    flex-direction: column;
  }
  .input-wrapper {
    width: 100%;
  }
  .answer-row .btn {
    width: 100%;
  }

  /* Prompt word: scale down for small screens */
  .prompt-word {
    font-size: 1.8rem;
    padding: 0.5rem 0;
  }

  /* Results table: allow horizontal scroll if needed */
  .results-table {
    font-size: 0.8rem;
  }
  .results-table th,
  .results-table td {
    padding: 0.4rem 0.5rem;
  }

  /* Leaderboard entries: tighter */
  .leaderboard-entry {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
  }

  /* Voting tags: slightly smaller touch targets */
  .voting-tag {
    padding: 0.45rem 0.9rem;
    font-size: 0.9rem;
  }

  /* Game over title */
  .game-over-title {
    font-size: 1.6rem;
  }

  .modal {
    margin: 1rem;
    max-width: calc(100% - 2rem);
  }

  /* Chaos level buttons: allow 2-row layout on narrow screens */
  .chaos-btn {
    min-width: 3.8rem;
    font-size: 0.78rem;
    padding: 0.45rem 0.35rem;
  }

}

/* Ensure good touch targets on all interactive elements */
@media (pointer: coarse) {
  .btn {
    min-height: 44px;
  }
  .btn-small {
    min-height: 38px;
  }
  .voting-tag {
    min-height: 44px;
  }
  input[type="text"] {
    min-height: 44px;
  }
  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }
  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }
}

/* ===== Chaos Mode / Twist Indicator ===== */

/* Twist indicator bar above the question prompt */
.twist-indicator:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  margin-bottom: 0.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--primary);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.95rem;
}

.twist-icon {
  display: flex;
  align-items: center;
}

.twist-label {
  line-height: 1.3;
}

/* Pulse animation for twist reveal */
.twist-pulse {
  animation: twistPulse 1.2s ease-in-out;
}

@keyframes twistPulse {
  0%   { transform: scale(0.92); opacity: 0; box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
  15%  { transform: scale(1.06); opacity: 1; box-shadow: 0 0 12px 2px rgba(99, 102, 241, 0.25); }
  30%  { transform: scale(0.98); box-shadow: 0 0 4px 0 rgba(99, 102, 241, 0.1); }
  50%  { transform: scale(1.04); box-shadow: 0 0 10px 2px rgba(99, 102, 241, 0.2); }
  70%  { transform: scale(0.99); box-shadow: 0 0 2px 0 rgba(99, 102, 241, 0.05); }
  85%  { transform: scale(1.02); box-shadow: 0 0 6px 1px rgba(99, 102, 241, 0.15); }
  100% { transform: scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* Small inline twist icon (settings checkboxes, how-to-play) */
.twist-icon-inline {
  vertical-align: middle;
  margin-right: 0.15rem;
}

/* Chaos level selector (same pattern as speed selector) */
.chaos-selector {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.chaos-btn {
  flex: 1;
  min-width: 4.5rem;
  padding: 0.45rem 0.5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chaos-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}
.chaos-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.chaos-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Host Controls ---------- */
.host-controls:not([hidden]) {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 10;
}

.host-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius);
  background: var(--surface-light);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}
.host-control-btn:hover {
  background: var(--border);
}
.host-control-btn.btn-danger-icon {
  color: var(--primary);
  border-color: rgba(233, 69, 96, 0.4);
  background: rgba(233, 69, 96, 0.1);
}
.host-control-btn.btn-danger-icon:hover {
  background: rgba(233, 69, 96, 0.25);
}

/* ---------- Game Paused Overlay ---------- */
.game-paused-overlay:not([hidden]) {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.85);
  z-index: 50;
  border-radius: var(--radius);
}
.paused-content {
  text-align: center;
  color: var(--text-muted);
}
.paused-content p {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 0.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.paused-content svg {
  opacity: 0.6;
}

/* game-panel needs position:relative so the overlay can cover it */
.game-panel {
  position: relative;
}

/* ---------- Vote Modal ---------- */
.vote-content {
  padding: 1.5rem 1.25rem;
  text-align: center;
}
.vote-option-btn {
  width: 100%;
  margin-bottom: 0.75rem;
}

/* ---------- Vote Chat Message ---------- */
.vote-msg {
  background: rgba(83, 52, 131, 0.25);
  border: 1px solid rgba(108, 68, 162, 0.4);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0.25rem 0;
}
.vote-msg-header {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}
.vote-msg-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.vote-choice-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-light);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
}
.vote-choice-btn:hover:not(:disabled) {
  border-color: var(--text-muted);
}
.vote-choice-btn.vote-yes:hover:not(:disabled) {
  border-color: var(--success);
  background: rgba(46, 213, 115, 0.15);
}
.vote-choice-btn.vote-no:hover:not(:disabled) {
  border-color: var(--primary);
  background: rgba(233, 69, 96, 0.15);
}
.vote-choice-btn.selected.vote-yes {
  border-color: var(--success);
  background: rgba(46, 213, 115, 0.2);
}
.vote-choice-btn.selected.vote-no {
  border-color: var(--primary);
  background: rgba(233, 69, 96, 0.2);
}
.vote-choice-btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.vote-count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}
.vote-timer {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: auto;
}
.vote-result {
  margin-top: 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
}
.vote-result.vote-passed {
  color: var(--success);
}
.vote-result.vote-failed {
  color: var(--text-muted);
}
