* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
  transition: 0.3s ease background;
  color: #fff;
  background: #121212;
}

/* === THEMES === */
body.regular {
  background: #f0f0f0;
  color: #000;
}

body.regular .calculator,
body.regular .history {
  background: #fff;
  color: #000;
  border: 1px solid #ccc;
}

body.regular .display-box {
  background: #f9f9f9;
}

body.regular .preview {
  color: #666;
}

body.regular button {
  background: #e0e0e0;
  color: #000;
}

body.regular button:hover {
  background: #ccc;
}

body.dark {
  background: #1e1e2f;
  color: #fff;
}

body.dark .calculator,
body.dark .history {
  background: #2b2b3c;
  color: #fff;
}

body.dark .display-box {
  background: #111;
  color: #0f0;
}

body.dark .preview {
  color: #999;
}

body.dark button {
  background: #3c3c4c;
  color: #fff;
}

body.dark button:hover {
  background: #505062;
}

body.glass {
  background: url('https://images.unsplash.com/photo-1503264116251-35a269479413?auto=format&fit=crop&w=1350&q=80') no-repeat center center fixed;
  background-size: cover;
  color: #fff;
}

body.glass .calculator,
body.glass .history {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

body.glass .display-box {
  background: rgba(0, 0, 0, 0.4);
}

body.glass .preview {
  color: #ccc;
}

body.glass button {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  backdrop-filter: blur(8px);
}

body.glass button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* === LAYOUT === */
.wrapper {
  display: flex;
  flex-direction: row;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 80px;
}

.calculator,
.history {
  padding: 20px;
  border-radius: 16px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  width: 320px;
  flex: 1 1 300px;
  transition: all 0.3s ease;
}

.display-box {
  padding: 10px 15px;
  border-radius: 10px;
  margin-bottom: 20px;
}

.preview {
  font-size: 1em;
  text-align: right;
  height: 20px;
}

.input-display {
  font-size: 1.8em;
  text-align: right;
  word-break: break-word;
}

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

button {
  padding: 16px;
  font-size: 1.2em;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.2s;
}

.clear {
  background: #dc3545;
}

.backspace {
  background: #f39c12;
}

.equal {
  background: #28a745;
}

.operator {
  background: #007acc;
}

/* === HISTORY === */
.history {
  width: 220px;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex: 1 1 200px;
}

.history h2 {
  margin: 0 0 10px;
  font-size: 1.2em;
  border-bottom: 1px solid currentColor;
  padding-bottom: 8px;
}

.history-entry {
  font-size: 1em;
  margin-bottom: 8px;
  border-bottom: 1px solid currentColor;
  padding-bottom: 4px;
}

.clear-history-btn {
  margin-top: 10px;
  background: #6c757d;
  color: white;
  padding: 8px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
}

/* === TOP BAR === */
.top-bar {
  position: absolute;
  top: 20px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-bar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* === THEME SWITCH === */
.theme-switch {
  display: inline-flex;
  background: #333;
  border-radius: 30px;
  padding: 4px;
  position: relative;
  user-select: none;
  overflow: hidden;
}

.theme-switch input[type="radio"] {
  display: none;
}

.theme-switch label {
  color: white;
  padding: 8px 12px;
  font-size: 1em;
  cursor: pointer;
  z-index: 2;
  transition: color 0.2s ease;
}

.theme-switch .slider {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(100% / 3 - 8px);
  background: #007acc;
  border-radius: 30px;
  transition: left 0.3s ease;
  z-index: 1;
}

.theme-switch input#regular:checked ~ .slider {
  left: calc(100% / 3 + 4px);
}

.theme-switch input#glass:checked ~ .slider {
  left: calc(2 * 100% / 3 + 4px);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .wrapper {
    flex-direction: column;
    align-items: center;
  }

  .calculator,
  .history {
    width: 100%;
  }

  .history {
    max-height: 200px;
  }

  button {
    padding: 14px;
    font-size: 1em;
  }

  .input-display {
    font-size: 1.5em;
  }

  .preview {
    font-size: 0.9em;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
