*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root { --bg: #0a0a0a; --fg: #f0f0f0; --accent: #7c6af7; }
html, body {
  height: 100%; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
body { 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  height: 100svh;
  padding: 20px;
  padding-bottom: 80px;
}

.calculator {
  width: 100%;
  max-width: 320px;
  background: #1a1a1a;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.display {
  background: #2a2a2a;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  text-align: right;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.history {
  font-size: 1rem;
  color: #888;
  margin-bottom: 8px;
  min-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current {
  font-size: 2.5rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  min-height: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.btn {
  border: none;
  border-radius: 12px;
  padding: 20px;
  font-size: 1.4rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn:active {
  transform: scale(0.95);
}

.btn.number {
  background: #333;
  color: var(--fg);
}

.btn.number:hover {
  background: #444;
}

.btn.operation {
  background: var(--accent);
  color: white;
}

.btn.operation:hover {
  background: #8b7df8;
}

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

.btn.equals:hover {
  background: #8b7df8;
}

.btn.clear {
  background: #ff4444;
  color: white;
}

.btn.clear:hover {
  background: #ff5555;
}

.btn[onclick*="'0'"] {
  grid-column: span 1;
}

@media (max-width: 375px) {
  .calculator {
    padding: 20px;
  }
  
  .display {
    padding: 20px;
    min-height: 80px;
  }
  
  .current {
    font-size: 2rem;
    min-height: 40px;
  }
  
  .btn {
    padding: 16px;
    font-size: 1.2rem;
    min-height: 50px;
  }
  
  .buttons {
    gap: 10px;
  }
}

@media (max-height: 600px) {
  .display {
    min-height: 70px;
    padding: 16px;
  }
  
  .current {
    font-size: 1.8rem;
    min-height: 32px;
  }
  
  .btn {
    padding: 14px;
    min-height: 44px;
    font-size: 1.1rem;
  }
}