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

body {
  font-family: 'Nunito', sans-serif;
  background: #0a0a2e;
  min-height: 100vh;
  color: #fff;
  overflow-x: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bg-animation {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(147, 51, 234, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.08) 0%, transparent 50%);
  animation: bgShift 12s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0% { transform: scale(1) rotate(0deg); }
  100% { transform: scale(1.1) rotate(3deg); }
}

.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  padding: 20px;
  margin: 0 auto;
}

.screen {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* CARD */
.card {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 36px 28px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* LOGO */
.logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-icon {
  font-size: 52px;
  display: block;
  margin-bottom: 4px;
  animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.logo h1 {
  font-family: 'Fredoka', sans-serif;
  font-size: 42px;
  font-weight: 700;
  background: linear-gradient(135deg, #a855f7, #ec4899, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.subtitle {
  color: rgba(255, 255, 255, 0.5);
  font-size: 15px;
  font-weight: 600;
  margin-top: 4px;
}

/* BUTTONS */
.btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 17px;
  font-weight: 600;
  padding: 14px 28px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, #a855f7, #ec4899);
  color: #fff;
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 6px 28px rgba(168, 85, 247, 0.5);
  transform: translateY(-2px);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  color: #fff;
  box-shadow: 0 4px 20px rgba(6, 182, 212, 0.35);
}

.btn-secondary:hover {
  box-shadow: 0 6px 28px rgba(6, 182, 212, 0.5);
  transform: translateY(-2px);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

/* LOBBY */
.lobby-card {
  text-align: center;
}

.input-group {
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  display: block;
  font-family: 'Fredoka', sans-serif;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

input[type="text"] {
  font-family: 'Nunito', sans-serif;
  font-size: 18px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: #a855f7;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.3);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

.join-row {
  display: flex;
  gap: 10px;
}

.code-input {
  flex: 1;
  text-align: center;
  font-family: 'Fredoka', sans-serif !important;
  font-size: 22px !important;
  letter-spacing: 4px;
  text-transform: uppercase;
}

/* WAITING SCREEN */
.waiting-card {
  text-align: center;
  padding: 48px 28px;
}

.waiting-icon {
  font-size: 56px;
  margin-bottom: 8px;
  animation: pulse 2s ease-in-out infinite;
}

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

.room-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  margin-top: 16px;
  margin-bottom: 8px;
}

.room-code {
  font-family: 'Fredoka', sans-serif;
  font-size: 48px;
  letter-spacing: 10px;
  background: linear-gradient(135deg, #a855f7, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
  padding: 8px 0;
}

.waiting-hint {
  color: rgba(255, 255, 255, 0.4);
  font-size: 14px;
  margin-top: 4px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.08);
  border-top-color: #a855f7;
  border-radius: 50%;
  margin: 24px auto;
  animation: spin 1s linear infinite;
}

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

/* SET NUMBER SCREEN */
.set-card {
  text-align: center;
}

.set-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.set-hint {
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  margin: 4px 0 24px;
}

.digit-input-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}

.digit-box {
  width: 64px;
  height: 72px;
  text-align: center;
  font-family: 'Fredoka', sans-serif !important;
  font-size: 32px !important;
  font-weight: 700;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  outline: none;
  transition: all 0.2s;
  padding: 0 !important;
}

.digit-box:focus {
  border-color: #a855f7;
  box-shadow: 0 0 20px rgba(168, 85, 247, 0.3);
  transform: scale(1.05);
}

.digit-box.filled {
  border-color: rgba(168, 85, 247, 0.5);
  background: rgba(168, 85, 247, 0.12);
}

.set-status {
  color: rgba(255, 255, 255, 0.5);
  font-size: 14px;
  margin-bottom: 16px;
  min-height: 20px;
}

/* GAME SCREEN */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 12px 20px;
  margin-bottom: 12px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot-p1 { background: #a855f7; }
.dot-p2 { background: #06b6d4; }

.player-name {
  font-family: 'Fredoka', sans-serif;
  font-size: 15px;
  font-weight: 600;
}

.vs-badge {
  font-size: 18px;
}

.turn-counter {
  font-family: 'Fredoka', sans-serif;
  font-size: 14px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 14px;
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.turn-banner {
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 10px;
  font-family: 'Fredoka', sans-serif;
  font-size: 18px;
  font-weight: 600;
  transition: all 0.3s;
}

.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.stat-badge {
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.06);
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-badge.found-some {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
}

.stat-badge.found-all {
  color: #22d3ee;
  border-color: rgba(34, 211, 238, 0.3);
  text-shadow: 0 0 8px rgba(34, 211, 238, 0.3);
}

.btn-secret {
  font-size: 13px !important;
  padding: 5px 14px !important;
  border-radius: 20px !important;
  font-family: 'Nunito', sans-serif !important;
}

.turn-banner.your-turn {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.25), rgba(236, 72, 153, 0.2));
  border: 1px solid rgba(168, 85, 247, 0.3);
  animation: glowPulse 1.5s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 15px rgba(168, 85, 247, 0.15); }
  50% { box-shadow: 0 0 30px rgba(168, 85, 247, 0.3); }
}

.turn-banner.waiting {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
}

.game-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.guess-area {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
}

.btn-guess {
  width: 100%;
  margin-top: 12px;
}

/* NUMBER PAD */
.num-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 260px;
  margin: 12px auto 0;
}

.np-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 22px;
  font-weight: 700;
  padding: 12px 0;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transition: all 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.np-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.np-btn:active {
  transform: scale(0.92);
  background: rgba(168, 85, 247, 0.25);
}

.np-clear {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.5);
  font-size: 18px;
}

.np-clear:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* NUMBER PAD KEY STATES */
.np-btn.identified {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.np-btn.identified:hover {
  background: rgba(251, 191, 36, 0.3);
}

.np-btn.identified-all {
  background: rgba(34, 211, 238, 0.2);
  color: #22d3ee;
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.np-btn.identified-all:hover {
  background: rgba(34, 211, 238, 0.3);
}

.np-btn .np-badge {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  background: linear-gradient(135deg, #a855f7, #ec4899);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 5px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(168, 85, 247, 0.4);
}

.np-btn {
  position: relative;
}

.np-btn.has-badge .np-badge {
  display: flex;
}

.history-header {
  font-family: 'Fredoka', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 8px;
}

.history-list {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.history-list::-webkit-scrollbar {
  width: 4px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}

.history-empty {
  color: rgba(255, 255, 255, 0.25);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  animation: slideIn 0.3s ease-out;
  font-size: 15px;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.history-item .who {
  font-size: 13px;
  font-weight: 600;
  min-width: 60px;
}

.history-item .who.me { color: #a855f7; }
.history-item .who.opponent { color: #06b6d4; }

.history-item .guess-digits {
  font-family: 'Fredoka', sans-serif;
  font-size: 20px;
  letter-spacing: 3px;
  font-weight: 700;
}

.history-item .result {
  margin-left: auto;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}

.history-item .result.bad { color: #ef4444; }
.history-item .result.ok { color: #f59e0b; }
.history-item .result.good { color: #10b981; }
.history-item .result.perfect {
  color: #22d3ee;
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.5);
}

.history-item.win-item {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(34, 211, 238, 0.1));
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* GAME OVER SCREEN */
.gameover-card {
  text-align: center;
  padding: 48px 28px;
}

.gameover-icon {
  font-size: 72px;
  margin-bottom: 8px;
  animation: bounce 1.5s ease-in-out infinite;
}

.gameover-card h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 34px;
  margin-bottom: 16px;
}

.gameover-card.win h2 { color: #22d3ee; }
.gameover-card.lose h2 { color: #f472b6; }

.secret-reveal {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
}

.secret-reveal p {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.7);
  margin: 6px 0;
}

.secret-reveal strong {
  font-family: 'Fredoka', sans-serif;
  font-size: 24px;
  letter-spacing: 4px;
  color: #fff;
}

/* TOAST */
#toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  font-family: 'Fredoka', sans-serif;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  animation: toastIn 0.3s ease-out;
  pointer-events: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast.error {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
}

.toast.info {
  background: linear-gradient(135deg, #06b6d4, #3b82f6);
  color: #fff;
}

.toast.success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal-card {
  background: linear-gradient(135deg, #1a0533, #0d0d3b);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  padding: 36px 32px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  font-size: 18px;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.modal-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.modal-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.modal-card h3 {
  font-family: 'Fredoka', sans-serif;
  font-size: 22px;
  margin-bottom: 16px;
}

.modal-digits {
  font-family: 'Fredoka', sans-serif;
  font-size: 42px;
  letter-spacing: 8px;
  font-weight: 700;
  background: linear-gradient(135deg, #a855f7, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  padding: 12px 0;
}

.modal-hint {
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
  margin-top: 8px;
}

/* RESPONSIVE */
@media (max-width: 480px) {
  .container { padding: 12px; }
  .card { padding: 24px 16px; }
  .logo h1 { font-size: 32px; }
  .logo-icon { font-size: 40px; }
  .digit-box { width: 52px; height: 60px; font-size: 26px !important; }
  .room-code { font-size: 36px; letter-spacing: 6px; }
  .game-header { padding: 10px 14px; }
  .player-name { font-size: 13px; }
  .history-item { font-size: 13px; padding: 8px 12px; }
  .history-item .guess-digits { font-size: 17px; }
  .btn { font-size: 15px; padding: 12px 20px; }
  .turn-banner { font-size: 15px; padding: 10px; }
  .gameover-card h2 { font-size: 28px; }
  .gameover-icon { font-size: 56px; }
  .turn-counter { font-size: 12px; padding: 3px 10px; }
  .num-pad { max-width: 200px; gap: 6px; }
  .np-btn { font-size: 18px; padding: 10px 0; }
  .stats-row { flex-wrap: wrap; }
  .stat-badge { font-size: 12px; padding: 4px 10px; }
  .btn-secret { font-size: 12px !important; padding: 4px 10px !important; }
  .modal-digits { font-size: 34px; }
  .modal-card { padding: 28px 20px; }
}

@media (min-width: 768px) {
  .game-content {
    flex-direction: row;
    align-items: flex-start;
  }
  .game-left {
    flex: 1;
  }
  .game-right {
    flex: 1;
  }
  .history-list {
    max-height: 340px;
  }
}
