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

:root {
  --primary-bg: #1a1a2e;
  --secondary-bg: #16213e;
  --accent-bg: #0f3460;
  --text-primary: #eee;
  --text-secondary: #bbb;
  --button-bg: #2a2a3e;
  --button-hover: #3a3a5e;
  --operator-bg: #ff6b35;
  --operator-hover: #ff8555;
  --equals-bg: #4caf50;
  --equals-hover: #66bb6a;
  --border-color: #333;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.theme-light {
  --primary-bg: #f5f5f5;
  --secondary-bg: #ffffff;
  --accent-bg: #e3f2fd;
  --text-primary: #333;
  --text-secondary: #666;
  --button-bg: #ffffff;
  --button-hover: #f0f0f0;
  --operator-bg: #2196f3;
  --operator-hover: #1976d2;
  --equals-bg: #4caf50;
  --equals-hover: #388e3c;
  --border-color: #e0e0e0;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.theme-neon {
  --primary-bg: #0a0a0a;
  --secondary-bg: #1a1a1a;
  --accent-bg: #2a0845;
  --text-primary: #00ff88;
  --text-secondary: #88ffaa;
  --button-bg: #1a1a2e;
  --button-hover: #2a2a4e;
  --operator-bg: #ff00aa;
  --operator-hover: #ff44bb;
  --equals-bg: #00ff88;
  --equals-hover: #44ffaa;
  --border-color: #00ff88;
  --shadow: 0 0 30px rgba(0, 255, 136, 0.3);
}

.theme-sunset {
  --primary-bg: #2d1b69;
  --secondary-bg: #11082f;
  --accent-bg: #5b2c87;
  --text-primary: #ffd89b;
  --text-secondary: #ffb347;
  --button-bg: #3d2b79;
  --button-hover: #4d3b89;
  --operator-bg: #ff6b9d;
  --operator-hover: #ff8bb5;
  --equals-bg: #19dced;
  --equals-hover: #39ecfd;
  --border-color: #5b2c87;
  --shadow: 0 8px 32px rgba(25, 220, 237, 0.2);
}

body {
  font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: linear-gradient(135deg, var(--primary-bg), var(--accent-bg));
  color: var(--text-primary);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px;
  transition: all 0.3s ease;
}

.calculator-container {
  display: flex;
  gap: 20px;
  max-width: 1200px;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.calculator {
  background: var(--secondary-bg);
  border-radius: 20px;
  padding: 25px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  min-width: 450px;
  width: 550px;
  height: fit-content;
  max-height: 100vh;
  transition: all 0.3s ease;
}

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

.title {
  font-size: 1.4rem;
  font-weight: 300;
  color: var(--text-primary);
}

.theme-selector {
  position: relative;
}

.theme-button {
  background: var(--button-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
}

.theme-button:hover {
  background: var(--button-hover);
}

.theme-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--secondary-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 0;
  min-width: 140px;
  box-shadow: var(--shadow);
  z-index: 1000;
  display: none;
}

.theme-dropdown.show {
  display: block;
}

.theme-option {
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-option:hover {
  background: var(--button-hover);
}

.theme-preview {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
}

.display {
  background: var(--accent-bg);
  border-radius: 15px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
  min-height: 90px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.expression {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: right;
  margin-bottom: 8px;
  min-height: 20px;
  word-break: break-all;
}

.result {
  font-size: 2.2rem;
  font-weight: 300;
  text-align: right;
  color: var(--text-primary);
  word-break: break-all;
}

.buttons {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.btn {
  background: var(--button-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 15px;
  border-radius: 12px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  user-select: none;
}

.btn:hover {
  background: var(--button-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: translateY(0);
}

.btn.operator {
  background: var(--operator-bg);
  color: white;
}

.btn.operator:hover {
  background: var(--operator-hover);
}

.btn.equals {
  background: var(--equals-bg);
  color: white;
  grid-column: span 2;
}

.btn.equals:hover {
  background: var(--equals-hover);
}

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

.btn.function {
  background: var(--accent-bg);
  font-size: 0.9rem;
}

.history-panel {
  background: var(--secondary-bg);
  border-radius: 20px;
  padding: 25px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  width: 350px;
  height: fit-content;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.history-title {
  font-size: 1.1rem;
  font-weight: 300;
}

.clear-history {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.clear-history:hover {
  background: var(--button-hover);
  color: var(--text-primary);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

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

.history-list::-webkit-scrollbar-track {
  background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.history-item {
  padding: 12px;
  margin-bottom: 8px;
  background: var(--accent-bg);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
}

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

.history-expression {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.history-result {
  font-size: 1.1rem;
  color: var(--text-primary);
  font-weight: 500;
}

.empty-history {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-style: italic;
}

@media (max-width: 768px) {
  .calculator-container {
    flex-direction: column;
    align-items: center;
  }

  .calculator {
    min-width: 320px;
    width: 100%;
    max-width: 400px;
  }

  .history-panel {
    width: 100%;
    max-width: 400px;
    max-height: 300px;
  }

  .buttons {
    grid-template-columns: repeat(4, 1fr);
  }

  .btn.function {
    font-size: 0.8rem;
  }
}

.error {
  color: #ff4444 !important;
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
