@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800;900&display=swap');

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

body {
  background: #0a0a1a;
  color: #fff;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */

#loginOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #0a0a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#loginOverlay.hidden {
  display: none !important;
}

.login-card {
  background: #12122a;
  border: 1px solid rgba(255, 50, 50, 0.2);
  border-radius: 20px;
  padding: 50px 45px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  animation: loginAppear 0.4s ease-out;
}

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

.login-icon {
  font-size: 56px;
  margin-bottom: 12px;
}

.login-title {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ff4444;
  text-shadow: 0 0 20px rgba(255, 50, 50, 0.4), 0 0 40px rgba(255, 50, 50, 0.2);
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 14px;
  color: rgba(255,255,255,0.35);
  margin-bottom: 30px;
  letter-spacing: 0.5px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form input {
  padding: 14px 18px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
  border-color: rgba(255, 60, 60, 0.5);
  box-shadow: 0 0 12px rgba(255, 50, 50, 0.15);
}

.login-form input::placeholder {
  color: rgba(255,255,255,0.25);
  font-weight: 400;
}

.login-btn {
  padding: 14px;
  font-size: 17px;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #cc0000, #ff3333);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  margin-top: 4px;
}

.login-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 24px rgba(255, 50, 50, 0.3);
}

.login-btn:active {
  transform: scale(0.98);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.login-error {
  color: #ff4444;
  font-size: 14px;
  font-weight: 600;
  min-height: 20px;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ============================================================
   PORTAL
   ============================================================ */

#portal {
  padding: 40px 20px;
  max-width: 1200px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 40px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.welcome-msg {
  font-size: 15px;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
}

.welcome-msg span {
  color: #ff4444;
  font-weight: 800;
}

.display-name-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: rgba(255,255,255,0.4);
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  white-space: nowrap;
}

.display-name-btn:hover {
  color: rgba(255,255,255,0.7);
  border-color: rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.04);
}

.logout-btn {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.logout-btn:hover {
  color: #ff4444;
  border-color: rgba(255, 50, 50, 0.4);
  background: rgba(255, 50, 50, 0.06);
}

.admin-btn {
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #d4820a, #f5a623);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

.admin-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(245, 166, 35, 0.35);
}

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

.arcade-title {
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #ff3333, #ff6b6b, #ffd93d, #ff3333);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 4s ease infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.arcade-subtitle {
  font-size: 18px;
  color: rgba(255,255,255,0.3);
  margin-top: 8px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-weight: 600;
}

/* ============================================================
   LEADERBOARD
   ============================================================ */

.leaderboard-section {
  background: #12122a;
  border: 1px solid rgba(255, 50, 50, 0.15);
  border-radius: 16px;
  padding: 24px 28px;
  margin-bottom: 40px;
  animation: loginAppear 0.4s ease-out;
}

.leaderboard-title {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #ff4444;
  text-align: center;
  margin-bottom: 18px;
  text-shadow: 0 0 12px rgba(255, 50, 50, 0.3);
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-loading {
  text-align: center;
  color: rgba(255,255,255,0.3);
  font-size: 14px;
  padding: 16px 0;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  transition: background 0.2s;
}

.lb-row:hover {
  background: rgba(255,255,255,0.06);
}

.lb-rank {
  font-size: 15px;
  font-weight: 800;
  color: rgba(255,255,255,0.4);
  min-width: 36px;
}

.lb-medal {
  font-size: 18px;
  min-width: 24px;
  display: inline-block;
}

.lb-name {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
}

.lb-score {
  font-size: 15px;
  font-weight: 800;
  color: rgba(255,255,255,0.5);
  font-variant-numeric: tabular-nums;
}

/* Gold — #1 */
.lb-gold {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.12), rgba(255, 180, 0, 0.06));
  border: 1px solid rgba(255, 215, 0, 0.25);
}

.lb-gold:hover {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.18), rgba(255, 180, 0, 0.10));
}

.lb-gold .lb-rank {
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

.lb-gold .lb-name {
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.lb-gold .lb-score {
  color: #ffd700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

/* Silver — #2 */
.lb-silver {
  background: linear-gradient(135deg, rgba(192, 192, 192, 0.08), rgba(192, 192, 192, 0.03));
  border: 1px solid rgba(192, 192, 192, 0.15);
}

.lb-silver:hover {
  background: linear-gradient(135deg, rgba(192, 192, 192, 0.12), rgba(192, 192, 192, 0.06));
}

.lb-silver .lb-rank {
  color: #c0c0c0;
}

.lb-silver .lb-name {
  color: #d4d4d4;
}

.lb-silver .lb-score {
  color: #c0c0c0;
}

/* Bronze — #3 */
.lb-bronze {
  background: linear-gradient(135deg, rgba(205, 127, 50, 0.08), rgba(205, 127, 50, 0.03));
  border: 1px solid rgba(205, 127, 50, 0.15);
}

.lb-bronze:hover {
  background: linear-gradient(135deg, rgba(205, 127, 50, 0.12), rgba(205, 127, 50, 0.06));
}

.lb-bronze .lb-rank {
  color: #cd7f32;
}

.lb-bronze .lb-name {
  color: #daa060;
}

.lb-bronze .lb-score {
  color: #cd7f32;
}

/* ============================================================
   GAME GRID
   ============================================================ */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 22px;
  padding: 0 10px;
}

.game-card {
  background: #12122a;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.3s ease;
  border: 1px solid rgba(255,255,255,0.06);
}

.game-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 12px 40px rgba(255, 50, 50, 0.12);
}

.game-card:active {
  transform: translateY(-2px) scale(0.99);
}

.card-thumbnail {
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.card-thumbnail::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, transparent 30%, rgba(0,0,0,0.3) 100%);
}

.card-icon {
  font-size: 56px;
  z-index: 1;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
  transition: transform 0.2s ease;
}

.game-card:hover .card-icon {
  transform: scale(1.15);
}

.card-info {
  padding: 16px 18px;
}

.card-info h3 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 3px;
  color: #ffffff;
}

.card-info p {
  font-size: 13px;
  color: rgba(255,255,255,0.4);
  line-height: 1.4;
}

/* ============================================================
   GAME VIEW (iframe)
   ============================================================ */

#gameView {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

#gameView.hidden {
  display: none !important;
}

#backBtn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 110;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  color: #fff;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  backdrop-filter: blur(8px);
}

#backBtn:hover {
  background: rgba(60,60,60,0.9);
  border-color: rgba(255,255,255,0.5);
}

#gameFrame {
  width: 100%;
  height: 100%;
  border: none;
  flex: 1;
}

/* ============================================================
   MODAL OVERLAY (shared for admin + display name)
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: #12122a;
  border: 1px solid rgba(255, 50, 50, 0.2);
  border-radius: 18px;
  padding: 0;
  max-width: 440px;
  width: 100%;
  animation: loginAppear 0.3s ease-out;
  overflow: hidden;
}

.admin-modal-card {
  border-color: rgba(245, 166, 35, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ff4444;
}

.admin-modal-card .modal-header h2 {
  color: #f5a623;
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  font-size: 22px;
  line-height: 32px;
  text-align: center;
  color: rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.05);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

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

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  margin-bottom: -4px;
}

.modal-input {
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-input:focus {
  border-color: rgba(255, 60, 60, 0.5);
  box-shadow: 0 0 12px rgba(255, 50, 50, 0.15);
}

.modal-input::placeholder {
  color: rgba(255,255,255,0.25);
  font-weight: 400;
}

.modal-select {
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%23888' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.modal-select:focus {
  border-color: rgba(245, 166, 35, 0.5);
  box-shadow: 0 0 12px rgba(245, 166, 35, 0.15);
}

.modal-select option {
  background: #1a1a3a;
  color: #fff;
}

.admin-change-pw-btn {
  padding: 12px;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #d4820a, #f5a623);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  margin-top: 4px;
}

.admin-change-pw-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 20px rgba(245, 166, 35, 0.3);
}

.admin-change-pw-btn:active {
  transform: scale(0.98);
}

.admin-change-pw-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.display-name-save-btn {
  padding: 12px;
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #cc0000, #ff3333);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  margin-top: 4px;
}

.display-name-save-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 20px rgba(255, 50, 50, 0.3);
}

.display-name-save-btn:active {
  transform: scale(0.98);
}

.display-name-save-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.admin-message {
  font-size: 14px;
  font-weight: 600;
  min-height: 20px;
  text-align: center;
}

.admin-message-success {
  color: #4caf50;
}

.admin-message-error {
  color: #ff4444;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
  .arcade-title {
    font-size: 32px;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  .card-thumbnail {
    height: 130px;
  }

  .login-card {
    padding: 35px 25px;
  }

  .login-title {
    font-size: 24px;
  }

  .header-top {
    flex-wrap: wrap;
    gap: 10px;
  }

  .header-left {
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-right {
    gap: 8px;
  }

  .leaderboard-section {
    padding: 18px 16px;
  }

  .leaderboard-title {
    font-size: 18px;
  }

  .lb-row {
    padding: 8px 10px;
    gap: 8px;
  }

  .lb-rank {
    font-size: 13px;
    min-width: 30px;
  }

  .lb-name {
    font-size: 13px;
  }

  .lb-score {
    font-size: 13px;
  }

  .modal-card {
    max-width: 100%;
  }
}
