:root {
  --bg-primary: #1c1c1c;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #3a3a3a;
  --text-primary: #ffffff;
  --text-secondary: #b0b0b0;
  --accent-primary: #ff9500;
  --accent-secondary: #ff9500;
  --key-bg: #505050;
  --key-bg-hover: #5a5a5a;
  --key-bg-active: #6a6a6a;
  --key-number: #505050;
  --key-number-hover: #5a5a5a;
  --key-number-active: #6a6a6a;
  --key-operator: #505050;
  --key-operator-hover: #5a5a5a;
  --key-operator-active: #6a6a6a;
  --key-function: #ff3b30;
  --key-function-hover: #ff4b40;
  --key-function-active: #ff5b50;
  --key-equals: #ff9500;
  --key-equals-hover: #ffa520;
  --key-equals-active: #ffb540;
  --display-bg: #4a5568;
  --display-text: #ffffff;
  --display-error: #ff3b30;
  --border-color: #1a1a1a;
  --shadow-color: rgba(0, 0, 0, 0.4);
}

body.light-theme {
  --bg-primary: #f2f2f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e5e5ea;
  --text-primary: #000000;
  --text-secondary: #666666;
  --accent-primary: #ff9500;
  --accent-secondary: #ff9500;
  --key-bg: #d1d1d6;
  --key-bg-hover: #c1c1c6;
  --key-bg-active: #b1b1b6;
  --key-number: #d1d1d6;
  --key-number-hover: #c1c1c6;
  --key-number-active: #b1b1b6;
  --key-operator: #d1d1d6;
  --key-operator-hover: #c1c1c6;
  --key-operator-active: #b1b1b6;
  --key-function: #ff3b30;
  --key-function-hover: #ff4b40;
  --key-function-active: #ff5b50;
  --key-equals: #ff9500;
  --key-equals-hover: #ffa520;
  --key-equals-active: #ffb540;
  --display-bg: #f8f8f8;
  --display-text: #000000;
  --display-error: #ff3b30;
  --border-color: #e5e5ea;
  --shadow-color: rgba(0, 0, 0, 0.15);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(
    135deg,
    var(--bg-primary) 0%,
    var(--bg-secondary) 100%
  );
  color: var(--text-primary);
  min-height: 100vh;
  transition: all 0.3s ease;
}

.calculator-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  outline: none;
}

.calculator-container:focus {
  outline: none;
}

.calculator {
  background: var(--bg-secondary);
  border-radius: 24px;
  padding: 20px;
  box-shadow: 0 10px 40px var(--shadow-color),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  max-width: 360px;
  width: 100%;
  transition: all 0.3s ease;
}

.calculator:hover {
  box-shadow: 0 15px 50px var(--shadow-color),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.display {
  background: var(--display-bg);
  border-radius: 16px;
  padding: 24px 20px;
  margin-bottom: 16px;
  text-align: right;
  border: 1px solid rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

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

.display-text {
  font-size: 3.5rem;
  font-weight: 200;
  color: var(--display-text);
  word-wrap: break-word;
  word-break: break-all;
  line-height: 1;
  transition: color 0.3s ease;
  letter-spacing: 0.5px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    sans-serif;
}

.display.error .display-text {
  color: var(--display-error);
  font-size: 1.8rem;
}

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

.key {
  background: var(--key-bg);
  border: none;
  border-radius: 50%;
  aspect-ratio: 1;
  font-size: 1.8rem;
  font-weight: 400;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70px;
}

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

.key:active::before {
  width: 100%;
  height: 100%;
}

.key:hover {
  filter: brightness(1.1);
}

.key:active {
  filter: brightness(0.9);
  transform: scale(0.97);
}

.key.key-number {
  background: var(--key-number);
  color: var(--text-primary);
}

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

.key.key-function {
  background: var(--key-function);
  color: white;
  font-weight: 400;
}

.key.key-equals {
  background: var(--key-equals);
  color: white;
  font-size: 2.2rem;
  font-weight: 300;
}

.key.selected {
  box-shadow: 0 0 0 3px var(--accent-primary), 0 0 15px rgba(255, 149, 0, 0.6);
  filter: brightness(1.15);
  transform: scale(1.02);
  z-index: 10;
}

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  border-radius: 50px;
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.3s ease;
  z-index: 1000;
}

.theme-toggle:hover {
  background: var(--key-bg-hover);
  transform: scale(1.05);
}

.theme-toggle span {
  font-size: 1.2rem;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  10%,
  30%,
  50%,
  70%,
  90% {
    transform: translateX(-5px);
  }
  20%,
  40%,
  60%,
  80% {
    transform: translateX(5px);
  }
}

@media (max-width: 480px) {
  .calculator {
    padding: 16px;
    border-radius: 20px;
    max-width: 340px;
  }

  .display {
    padding: 20px 16px;
    margin-bottom: 12px;
    min-height: 70px;
  }

  .display-text {
    font-size: 3rem;
  }

  .key {
    font-size: 1.5rem;
    min-height: 60px;
  }

  .keypad {
    gap: 10px;
  }

  .theme-toggle {
    padding: 10px 16px;
    font-size: 0.9rem;
  }
}

@media (max-width: 360px) {
  .calculator {
    max-width: 300px;
    padding: 14px;
  }

  .display-text {
    font-size: 2.5rem;
  }

  .key {
    font-size: 1.3rem;
    min-height: 55px;
  }

  .keypad {
    gap: 8px;
  }

  .theme-toggle {
    padding: 8px 12px;
    font-size: 0.85rem;
  }
}
