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

:root {
  --primary-bg: #0a0a0a;
  --secondary-bg: #1a1a1a;
  --accent-color: #00ffff;
  --text-color: #ffffff;
  --button-bg: rgba(255, 255, 255, 0.1);
  --button-hover: rgba(0, 255, 255, 0.2);
  --button-active: rgba(0, 255, 255, 0.4);
  --display-bg: rgba(0, 0, 0, 0.8);
  --glow-color: #00ffff;
  --error-color: #ff0080;
  --success-color: #00ff80;
}

[data-theme="light"] {
  --primary-bg: #f5f7fa;
  --secondary-bg: #ffffff;
  --accent-color: #6366f1;
  --text-color: #1f2937;
  --button-bg: rgba(99, 102, 241, 0.1);
  --button-hover: rgba(99, 102, 241, 0.2);
  --button-active: rgba(99, 102, 241, 0.3);
  --display-bg: rgba(255, 255, 255, 0.9);
  --glow-color: #6366f1;
  --error-color: #ef4444;
  --success-color: #10b981;
}

body {
  background: linear-gradient(135deg, var(--primary-bg), var(--secondary-bg));
  color: var(--text-color);
  font-family: "Courier New", monospace;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: all 0.3s ease;
}

.app-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  position: relative;
}

.calculator {
  background: var(--secondary-bg);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 25px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  width: 450px;
  position: relative;
  overflow: hidden;
}

.calculator::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(0, 255, 255, 0.03),
    transparent
  );
  animation: rotate 20s linear infinite;
  pointer-events: none;
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

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

.title {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--accent-color);
  text-shadow: 0 0 10px var(--glow-color);
}

.theme-toggle {
  background: var(--button-bg);
  border: 1px solid var(--accent-color);
  border-radius: 25px;
  padding: 8px 16px;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.theme-toggle:hover {
  background: var(--button-hover);
  box-shadow: 0 0 15px var(--glow-color);
}

.display {
  background: var(--display-bg);
  border: 1px solid var(--accent-color);
  border-radius: 15px;
  padding: 20px;
  margin-bottom: 20px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: inset 0 0 20px rgba(0, 255, 255, 0.1);
}

.expression {
  font-size: 1.2rem;
  color: var(--text-color);
  opacity: 0.7;
  min-height: 30px;
}

.result {
  font-size: 2rem;
  font-weight: bold;
  color: var(--accent-color);
  text-align: right;
  text-shadow: 0 0 10px var(--glow-color);
}

.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.control-btn {
  flex: 1;
  padding: 12px;
  background: var(--button-bg);
  border: 1px solid var(--accent-color);
  border-radius: 10px;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.control-btn:hover {
  background: var(--button-hover);
  box-shadow: 0 0 15px var(--glow-color);
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.btn {
  padding: 18px;
  background: var(--button-bg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 15px;
  color: var(--text-color);
  font-size: 1.2rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.btn:hover {
  background: var(--button-hover);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.btn:active {
  background: var(--button-active);
  transform: translateY(0);
}

.btn.operator {
  background: linear-gradient(
    135deg,
    var(--accent-color),
    rgba(0, 255, 255, 0.8)
  );
  color: var(--primary-bg);
  border-color: var(--accent-color);
}

.btn.equals {
  background: linear-gradient(
    135deg,
    var(--success-color),
    rgba(0, 255, 128, 0.8)
  );
  color: var(--primary-bg);
}

.btn.zero {
  grid-column: span 2;
}

.btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease;
}

.btn:active::before {
  width: 100px;
  height: 100px;
}

.history-panel {
  background: var(--secondary-bg);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 25px;
  width: 350px;
  max-height: 500px;
  overflow-y: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: none;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.history-panel.show {
  display: block;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

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

.close-history {
  background: var(--error-color);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.close-history:hover {
  background: #ff1a5e;
  transform: scale(1.1);
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 999;
  display: none;
}

.overlay.show {
  display: block;
}

.history-title {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--accent-color);
  margin-bottom: 20px;
  text-align: center;
}

.history-item {
  background: var(--button-bg);
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 10px;
  border-left: 3px solid var(--accent-color);
  transition: all 0.3s ease;
}

.history-item:hover {
  background: var(--button-hover);
  transform: translateX(5px);
}

.history-expression {
  font-size: 0.9rem;
  opacity: 0.7;
  margin-bottom: 5px;
}

.history-result {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--accent-color);
}

.clear-history {
  width: 100%;
  padding: 12px;
  background: var(--error-color);
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  margin-top: 15px;
  transition: all 0.3s ease;
}

.clear-history:hover {
  background: #ff1a5e;
  transform: translateY(-2px);
}

.error {
            color: var(--error-color) !important;
            animation: shake 0.5s ease-in-out;
        }

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

        .success-animation {
            animation: pulse 0.3s ease-in-out;
        }

        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }

        @media (max-width: 768px) {
            .calculator {
                width: 90%;
                max-width: 450px;
                margin: 0 auto;
            }
            
            .history-panel {
                width: 90%;
                max-width: 350px;
            }
        }

        /* Scroll styling */
        ::-webkit-scrollbar {
            width: 8px;
        }  

        ::-webkit-scrollbar-track {
            background: var(--primary-bg);
            border-radius: 10px;
        }

        ::-webkit-scrollbar-thumb {
            background: var(--accent-color);
            border-radius: 10px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: var(--glow-color);
        }
