:root {
  /* THEME 1 (Default) */
  --bg-main: hsl(222, 26%, 31%);
  --bg-toggle: hsl(223, 31%, 20%);
  --bg-screen: hsl(224, 36%, 15%);

  /* Keys */
  --key-bg-del: hsl(225, 21%, 49%);
  --key-shadow-del: hsl(224, 28%, 35%);

  --key-bg-equal: hsl(6, 63%, 50%);
  --key-shadow-equal: hsl(6, 70%, 34%);

  --key-bg-main: hsl(30, 25%, 89%);
  --key-shadow-main: hsl(28, 16%, 65%);

  /* Text */
  --text-main: hsl(221, 14%, 31%);
  --text-white: hsl(0, 0%, 100%);
  --text-del: hsl(0, 0%, 100%); /* White for DEL/RESET in Theme 1 */
  --text-equal: hsl(0, 0%, 100%); /* White for Equal in Theme 1 */

  /* Typography */
  --font-family: "League Spartan", sans-serif;
  --font-size-nums: 32px;
}

[data-theme="2"] {
  --bg-main: hsl(0, 0%, 90%);
  --bg-toggle: hsl(0, 5%, 81%);
  --bg-screen: hsl(0, 0%, 93%);

  /* Keys */
  --key-bg-del: hsl(185, 42%, 37%);
  --key-shadow-del: hsl(185, 58%, 25%);

  --key-bg-equal: hsl(25, 98%, 40%);
  --key-shadow-equal: hsl(25, 99%, 27%);

  --key-bg-main: hsl(45, 7%, 89%);
  --key-shadow-main: hsl(35, 11%, 61%);

  /* Text */
  --text-main: hsl(60, 10%, 19%);
  --text-white: hsl(0, 0%, 100%);
  --text-del: hsl(0, 0%, 100%);
  --text-equal: hsl(0, 0%, 100%);
}

[data-theme="3"] {
  --bg-main: hsl(268, 75%, 9%);
  --bg-toggle: hsl(268, 71%, 12%);
  --bg-screen: hsl(268, 71%, 12%);

  /* Keys */
  --key-bg-del: hsl(281, 89%, 26%); /* The purple key bg */
  --key-shadow-del: hsl(285, 91%, 52%); /* The vivid purple shadow */

  --key-bg-equal: hsl(176, 100%, 44%); /* Cyan key bg */
  --key-shadow-equal: hsl(177, 92%, 70%); /* Cyan shadow */

  --key-bg-main: hsl(268, 47%, 21%); /* Dark purple key bg */
  --key-shadow-main: hsl(290, 70%, 36%); /* Magenta shadow */

  /* Text */
  --text-main: hsl(52, 100%, 62%); /* Yellow text */
  --text-white: hsl(0, 0%, 100%);
  --text-del: hsl(0, 0%, 100%); /* DEL/RESET text is white */
  --text-equal: hsl(198, 20%, 13%); /* Equal text is dark blue */
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(
    --text-white
  ); /* Default text color for body, though most elements override */
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  transition: background-color 0.3s ease;
}

/* Layout */
.calculator-container {
  width: 100%;
  max-width: 500px;
  padding: 24px;
}

/* Header */
.calculator-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end; /* Align bottom to match */
  margin-bottom: 32px;
  color: var(--text-white); /* Theme 1 & 3 is white, Theme 2 is dark */
}

[data-theme="2"] .calculator-header {
  color: var(--text-main);
}

.theme-switcher {
  display: flex;
  align-items: center;
  gap: 24px;
}

.theme-label {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-right: 5px; /* Adjust spacing */
}

.theme-toggle-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.theme-numbers {
  display: flex;
  justify-content: space-between;
  width: 70px; /* Match switch width */
  margin-bottom: 5px;
  font-size: 12px;
  padding: 0 5px;
}

.toggle-switch {
  background-color: var(--bg-toggle);
  width: 70px;
  height: 26px;
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  padding: 5px;
}

.toggle-circle {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  position: absolute;
  top: 5px;
  left: 5px; /* Position 1 */
  background-color: var(--key-bg-equal); /* Red in theme 1 */
  transition: all 0.3s ease;
}

/* Toggle Positions */
[data-theme="1"] .toggle-circle {
  left: 5px;
}
[data-theme="2"] .toggle-circle {
  left: 27px;
}
[data-theme="3"] .toggle-circle {
  left: 49px;
}

/* Screen */
.calculator-screen {
  background-color: var(--bg-screen);
  border-radius: 10px;
  padding: 32px 32px; /* Large padding */
  margin-bottom: 24px;
  text-align: right;
}

#display {
  width: 100%;
  background: transparent;
  border: none;
  font-family: var(--font-family);
  font-size: 48px; /* Large font */
  color: var(--text-white); /* Usually white */
  text-align: right;
  outline: none;
}

[data-theme="2"] #display {
  color: var(--text-main);
}

/* Keypad */
.calculator-keypad {
  background-color: var(--bg-toggle); /* Defines the keypad background */
  padding: 30px;
  border-radius: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px; /* Space between keys */
}

.key {
  background-color: var(--key-bg-main);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 32px;
  padding: 15px 0; /* Vertical padding */
  border: none;
  border-radius: 10px; /* Soft extensive radius */
  box-shadow: 0 4px 0 var(--key-shadow-main);
  cursor: pointer;
  transition: filter 0.1s; /* Simple hover effect */
}

.key:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--key-shadow-main);
}
.key:hover {
  filter: brightness(1.2); /* Brightness increase on hover */
}

/* Special Keys */
.key-del,
.key-reset {
  background-color: var(--key-bg-del);
  color: var(--text-del);
  box-shadow: 0 4px 0 var(--key-shadow-del);
  font-size: 20px; /* Smaller font for text buttons */
  text-transform: uppercase;
}
.key-del:active,
.key-reset:active {
  box-shadow: 0 2px 0 var(--key-shadow-del);
}

.key-equal {
  background-color: var(--key-bg-equal);
  color: var(--text-equal);
  box-shadow: 0 4px 0 var(--key-shadow-equal);
  font-size: 20px;
}
.key-equal:active {
  box-shadow: 0 2px 0 var(--key-shadow-equal);
}

/* Span Columns */
.span-two {
  grid-column: span 2;
}

/* Attribution Footer */
.attribution {
  margin-top: 20px;
  font-size: 11px;
  text-align: center;
  color: var(--text-white); /* Make readable on dark bg */
}
[data-theme="2"] .attribution {
  color: var(--text-main);
}
.attribution a {
  color: var(--key-bg-equal);
  text-decoration: none;
}

/* Responsive */
@media screen and (max-width: 500px) {
  .calculator-container {
    max-width: 100%;
    padding: 24px;
  }

  .calculator-keypad {
    padding: 24px;
    gap: 16px; /* Smaller gap on mobile */
  }

  .key {
    font-size: 28px;
    padding: 12px 0;
  }
}
