* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #00d4ff;
  --secondary: #ff006e;
  --accent: #ffb703;
  --success: #00f5a0;
  --error: #ff4757;
  --dark: #0f172a;
  --darker: #020617;
  --glass: rgba(255, 255, 255, 0.05);
  --neon-glow: 0 0 20px rgba(0, 212, 255, 0.5);
  --enter-color: #00c9a7;
  --clear-color: #ff006e;
}

body {
  font-family: "Kanit", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 50%, #1e293b 100%);
  min-height: 100vh;
  color: white;
  overflow-x: hidden;
  position: relative;
}

.bg-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-animation::before {
  content: "";
  position: absolute;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(circle at 20% 50%, rgba(0, 212, 255, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(255, 0, 110, 0.15) 0%, transparent 50%);
  animation: bgMove 20s ease-in-out infinite;
}

@keyframes bgMove {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-5%, -5%); }
}

.grid-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
  background-size: 50px 50px;
  pointer-events: none;
  z-index: 1;
}

.app-container {
  position: relative;
  z-index: 10;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-header {
  text-align: center;
  padding: 30px 20px 20px;
}

.logo {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  letter-spacing: -2px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 30px rgba(0, 212, 255, 0.3);
}

.subtitle {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: 4px;
}

/* Login Status Badge */
.login-status {
  text-align: center;
  padding: 6px 16px;
  cursor: pointer;
}
.login-status span {
  display: inline-block;
  font-size: 0.8rem;
  padding: 4px 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
  transition: all 0.3s;
}
.login-status.logged-in span {
  background: rgba(0, 212, 255, 0.15);
  color: var(--primary);
}

/* Language Toggle */
.lang-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.75rem;
  z-index: 10;
}
.lang-btn {
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.4);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.2s;
}
.lang-btn.active {
  background: var(--primary);
  color: #000;
}

/* Theme Toggle */
.theme-toggle {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.75rem;
  z-index: 10;
}
.theme-btn {
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.4);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.2s;
}
.theme-btn.active {
  background: var(--primary);
  color: #000;
}

/* Main Menu */
.main-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 10px 20px 30px;
  gap: 15px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.menu-button {
  width: 100%;
  padding: 22px 25px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.menu-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--neon-glow), 0 10px 40px rgba(0, 0, 0, 0.4);
  border-color: var(--primary);
}

.menu-icon {
  width: 45px;
  height: 45px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: rgba(0, 0, 0, 0.3);
}

.btn-player .menu-icon { background: linear-gradient(135deg, #00d4ff, #0099cc); }
.btn-settings .menu-icon { background: linear-gradient(135deg, #ff006e, #cc0058); }
.btn-stats .menu-icon { background: linear-gradient(135deg, #ffb703, #cc9202); }
.btn-ranking .menu-icon { background: linear-gradient(135deg, #ffd700, #f59e0b); }

.menu-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.menu-label {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.menu-desc {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 400;
}

/* Screens */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.screen.active { transform: translateX(0); }

.screen-header {
  padding: 20px;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 15px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-btn {
  width: 45px;
  height: 45px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.screen-title {
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.screen-content {
  flex: 1;
  padding: 25px 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Level Selector */
.level-section { margin-bottom: 30px; }

.section-title {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.current-level {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.2rem;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.level-btn {
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
}

.level-btn::after {
  content: "";
  position: absolute;
  bottom: 8px;
  width: 20px;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
}

.level-btn[data-level="0"] { color: #86efac; }
.level-btn[data-level="1"] { color: #4ade80; }
.level-btn[data-level="2"] { color: #34d399; }
.level-btn[data-level="3"] { color: #2dd4bf; }
.level-btn[data-level="4"] { color: #38bdf8; }
.level-btn[data-level="5"] { color: #818cf8; }
.level-btn[data-level="6"] { color: #a78bfa; }
.level-btn[data-level="7"] { color: #f472b6; }
.level-btn[data-level="8"] { color: #fb7185; }

.level-btn.active {
  transform: scale(1.05);
  box-shadow: 0 0 20px currentColor;
  border-color: currentColor;
  background: rgba(255, 255, 255, 0.1);
}

.level-btn.active::after {
  opacity: 1;
  box-shadow: 0 0 10px currentColor;
}

.level-label {
  font-size: 0.6rem;
  opacity: 0.7;
  text-transform: uppercase;
}

/* Difficulty Description */
.difficulty-info {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 15px;
  margin-top: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.difficulty-icon { font-size: 1.5rem; }
.difficulty-text { flex: 1; }
.difficulty-name { font-weight: 700; margin-bottom: 2px; }
.difficulty-desc { font-size: 0.8rem; color: rgba(255, 255, 255, 0.6); }

/* Setting Items */
.setting-item {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-title { font-weight: 600; font-size: 1rem; }
.setting-desc { font-size: 0.8rem; color: rgba(255, 255, 255, 0.5); }

.toggle {
  width: 55px;
  height: 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.toggle.active {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.toggle.active .toggle-slider { transform: translateX(25px); }

/* Player & Stats */
.player-card {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.player-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  border: 3px solid rgba(255, 255, 255, 0.2);
}

.stat-card {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(255, 0, 110, 0.1));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 15px;
  text-align: center;
}

.stat-number {
  font-size: 2.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Animations */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in { animation: slideIn 0.5s ease-out forwards; }
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }

/* Start Game Button */
.start-game-btn {
  width: 100%;
  padding: 18px;
  margin-top: 20px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 2px;
  box-shadow: 0 4px 20px rgba(0, 212, 255, 0.3);
  transition: all 0.3s;
}

.start-game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(0, 212, 255, 0.5);
}

@media (max-width: 480px) {
  .level-grid { gap: 8px; }
  .level-btn { font-size: 1.1rem; }
}

/* ── Auth Modal ── */
.auth-field {
  margin-bottom: 14px;
  flex: 1;
}

.auth-label {
  display: block;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.auth-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: all 0.3s;
}

.auth-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
}

.auth-input:focus {
  border-color: var(--primary);
  background: rgba(0, 212, 255, 0.05);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.auth-row {
  display: flex;
  gap: 12px;
}

.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.5);
}

.auth-switch span {
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.auth-switch span:hover {
  text-decoration: underline;
}

.auth-loading {
  opacity: 0.6;
  pointer-events: none;
}

/* ── Status Banner ── */
.status-banner {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  transform: translateY(-100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.status-banner.show {
  transform: translateY(0);
}

.status-banner.warning {
  background: rgba(255, 183, 3, 0.15);
  border-bottom: 1px solid rgba(255, 183, 3, 0.3);
  color: #ffb703;
}

.status-banner.error {
  background: rgba(255, 71, 87, 0.15);
  border-bottom: 1px solid rgba(255, 71, 87, 0.3);
  color: #ff6b81;
}

.status-banner .banner-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.status-banner .banner-text {
  flex: 1;
  text-align: center;
}

.status-banner .banner-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.status-banner .banner-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Push content down when banner is visible */
.status-banner.show ~ .app-container {
  padding-top: 44px;
}

/* ══════════════════════════════════════ */
/*  LIGHT THEME                           */
/* ══════════════════════════════════════ */
[data-theme="light"] {
  --primary: #0088cc;
  --secondary: #d4005a;
  --accent: #e09600;
  --success: #00b377;
  --error: #d43545;
  --dark: #f1f5f9;
  --darker: #e2e8f0;
  --glass: rgba(0, 0, 0, 0.04);
  --neon-glow: 0 0 12px rgba(0, 136, 204, 0.25);
  --enter-color: #00a88a;
  --clear-color: #d4005a;
}
[data-theme="light"] body {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 50%, #f1f5f9 100%);
  color: #1e293b;
}
[data-theme="light"] .bg-animation::before {
  background:
    radial-gradient(circle at 20% 50%, rgba(0, 136, 204, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(212, 0, 90, 0.08) 0%, transparent 50%);
}
[data-theme="light"] .grid-overlay {
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
}
[data-theme="light"] .logo {
  background: linear-gradient(135deg, #0088cc, #d4005a);
  -webkit-background-clip: text;
  background-clip: text;
}
[data-theme="light"] .subtitle {
  color: rgba(0, 0, 0, 0.5);
}
/* Login status */
[data-theme="light"] .login-status span {
  background: rgba(0, 0, 0, 0.06);
  color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] .login-status.logged-in span {
  background: rgba(0, 136, 204, 0.12);
  color: var(--primary);
}
/* Menu */
[data-theme="light"] .menu-button {
  border-color: rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.7);
  color: #1e293b;
}
[data-theme="light"] .menu-button:hover,
[data-theme="light"] .menu-button:active {
  border-color: rgba(0, 136, 204, 0.3);
  background: rgba(255, 255, 255, 0.9);
}
[data-theme="light"] .menu-desc {
  color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] .start-game-btn {
  background: linear-gradient(135deg, #0088cc, #0066aa);
  color: white;
}
/* Screens */
[data-theme="light"] .screen {
  background: linear-gradient(180deg, #f1f5f9, #e2e8f0);
  color: #1e293b;
}
[data-theme="light"] .screen-header {
  background: rgba(255, 255, 255, 0.8);
  border-bottom-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .screen-title {
  color: #1e293b;
}
[data-theme="light"] .back-btn {
  color: var(--primary);
}
[data-theme="light"] .section-title span {
  color: rgba(0, 0, 0, 0.6);
}
/* Level buttons */
[data-theme="light"] .level-btn {
  border-color: rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.7);
  color: #1e293b;
}
[data-theme="light"] .level-btn.active {
  border-color: var(--primary);
  background: rgba(0, 136, 204, 0.1);
  color: var(--primary);
}
[data-theme="light"] .level-label {
  color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .level-btn.active .level-label {
  color: var(--primary);
}
[data-theme="light"] .difficulty-info {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .difficulty-name {
  color: #1e293b;
}
[data-theme="light"] .difficulty-desc {
  color: rgba(0, 0, 0, 0.5);
}
/* Settings */
[data-theme="light"] .setting-item {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .setting-title {
  color: #1e293b;
}
[data-theme="light"] .setting-desc {
  color: rgba(0, 0, 0, 0.45);
}
[data-theme="light"] .toggle {
  background: rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .toggle.active {
  background: var(--primary);
}
/* Auth */
[data-theme="light"] .auth-label {
  color: rgba(0, 0, 0, 0.55);
}
[data-theme="light"] .auth-input {
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.8);
  color: #1e293b;
}
[data-theme="light"] .auth-input::placeholder {
  color: rgba(0, 0, 0, 0.3);
}
[data-theme="light"] .auth-input:focus {
  border-color: var(--primary);
  background: rgba(0, 136, 204, 0.04);
}
[data-theme="light"] .auth-switch {
  color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] .auth-switch span {
  color: var(--primary);
}
/* Player card */
[data-theme="light"] .player-card {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(0, 0, 0, 0.08);
  color: #1e293b;
}
[data-theme="light"] .player-avatar {
  background: linear-gradient(135deg, #0088cc, #0066aa);
  color: white;
}
/* Stats */
[data-theme="light"] .stat-card {
  background: linear-gradient(135deg, rgba(0, 136, 204, 0.06), rgba(212, 0, 90, 0.06));
  border-color: rgba(0, 0, 0, 0.08);
}
/* Banner */
[data-theme="light"] .status-banner {
  background: rgba(255, 255, 255, 0.95);
  color: #1e293b;
  border-color: rgba(0, 0, 0, 0.1);
}
/* Lang/Theme toggles */
[data-theme="light"] .lang-toggle,
[data-theme="light"] .theme-toggle {
  border-color: rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .lang-btn,
[data-theme="light"] .theme-btn {
  background: rgba(0, 0, 0, 0.04);
  color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .lang-btn.active {
  background: var(--primary);
  color: white;
}
[data-theme="light"] .theme-btn.active {
  background: var(--primary);
  color: white;
}