:root {
  --bg-1: #2b1055;
  --bg-2: #7597de;
  --card: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.14);
  --text: #f5f3ff;
  --text-dim: #c9c3e0;
  --accent: #ff7ac6;
  --accent-2: #ffd166;
  --danger: #ff5d5d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, var(--bg-1), #4a2a7a 55%, var(--bg-2));
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app-header {
  padding: calc(14px + var(--safe-top)) 20px 10px;
  text-align: center;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.3rem;
  margin: 0 0 12px;
  letter-spacing: 0.02em;
}

.tabs {
  display: flex;
  gap: 8px;
  background: rgba(0,0,0,0.2);
  padding: 4px;
  border-radius: 14px;
  max-width: 360px;
  margin: 0 auto;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: #23103f;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px calc(24px + var(--safe-bottom));
  overflow-y: auto;
}

.view { display: none; flex: 1; flex-direction: column; }
.view.active { display: flex; }

/* GAME VIEW */
#gameView { align-items: center; justify-content: center; text-align: center; gap: 18px; }

.state-block {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.state-block.hidden { display: none; }

.hint {
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.4;
  margin: 0;
}

.hint.hidden { display: none; }

.category-count {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin: 0;
}

.category-count span { color: var(--accent-2); font-weight: 700; }

.primary-btn {
  background: var(--accent);
  color: #23103f;
  border: none;
  padding: 18px 36px;
  border-radius: 999px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 122, 198, 0.35);
  min-width: 220px;
}

.primary-btn:active { transform: scale(0.97); }

.primary-btn.small {
  padding: 12px 18px;
  font-size: 0.95rem;
  min-width: unset;
  box-shadow: none;
}

.secondary-btn {
  background: rgba(255,255,255,0.1);
  color: var(--text);
  border: 1px solid var(--card-border);
  padding: 14px 20px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  text-decoration: underline;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px;
}

.migrate-banner {
  margin: 4px 20px 0;
  padding: 14px 16px;
  background: rgba(255, 209, 102, 0.14);
  border: 1px solid var(--accent-2);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.migrate-banner p { margin: 0; }
.migrate-banner.hidden { display: none; }

.secondary-btn.small {
  padding: 10px 14px;
  font-size: 0.9rem;
}

.voice-block {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.voice-block.hidden { display: none; }

#codeText { word-break: break-all; color: var(--accent-2); user-select: all; }

#joinInput {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 0.95rem;
}

#joinInput::placeholder { color: var(--text-dim); }

.voice-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
}

.voice-row {
  display: flex;
  gap: 8px;
}

#voiceSelect {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 0.95rem;
  min-width: 0;
}

#voiceSelect option { color: #23103f; }

.progress-label {
  font-size: 1rem;
  color: var(--text-dim);
  margin: 0;
}

#roundNumber, #roundTotal { color: var(--accent-2); font-weight: 700; }

.round-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 300px;
}

.round-dots .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
}

.round-dots .dot.done { background: var(--accent-2); }
.round-dots .dot.current { background: var(--accent); transform: scale(1.3); }

.speak-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 22px 28px;
  border-radius: 20px;
  font-size: 1.05rem;
  min-height: 32px;
}

.speak-icon {
  font-size: 1.6rem;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

.play-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.finished-emoji { font-size: 3rem; margin: 0; }
.finished-text { font-size: 1.1rem; margin: 0; color: var(--text-dim); }

/* SETTINGS VIEW */
#settingsView { gap: 14px; }

.add-form {
  display: flex;
  gap: 8px;
}

.add-form input {
  flex: 1;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 1rem;
}

.add-form input::placeholder { color: var(--text-dim); }

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 13px 16px;
  border-radius: 14px;
}

.category-list li span { font-size: 1rem; }

.delete-btn {
  background: rgba(255, 93, 93, 0.15);
  border: none;
  color: var(--danger);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1a0f33;
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

.toast.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, 8px); }
