.theme-1 {
  /* Backgrounds */
  --main-bg: hsl(222, 26%, 31%);
  --keypad-bg: hsl(223, 31%, 20%);
  --screen-bg: hsl(224, 36%, 15%);
  --toggle-bg: hsl(223, 31%, 20%);
  
  /* Keys */
  --key-bg-primary: hsl(30, 25%, 89%);
  --key-shadow-primary: hsl(28, 16%, 65%);
  
  --key-bg-secondary: hsl(225, 21%, 49%);
  --key-shadow-secondary: hsl(224, 28%, 35%);
  
  --key-bg-tertiary: hsl(6, 63%, 50%);
  --key-shadow-tertiary: hsl(6, 70%, 34%);
  
  /* Text */
  --text-primary: hsl(221, 14%, 31%);
  --text-secondary: hsl(0, 0%, 100%);
  --text-header: hsl(0, 0%, 100%);
  --text-tertiary: hsl(0, 0%, 100%);
}

.theme-2 {
  /* Backgrounds */
  --main-bg: hsl(0, 0%, 93%);
  --keypad-bg: hsl(0, 5%, 81%);
  --screen-bg: hsl(0, 0%, 97%);
  --toggle-bg: hsl(0, 5%, 81%);
  
  /* Keys */
  --key-bg-primary: hsl(45, 7%, 89%);
  --key-shadow-primary: hsl(35, 11%, 61%);
  
  --key-bg-secondary: hsl(185, 42%, 37%);
  --key-shadow-secondary: hsl(185, 58%, 25%);
  
  --key-bg-tertiary: hsl(25, 98%, 40%);
  --key-shadow-tertiary: hsl(25, 99%, 27%);
  
  /* Text */
  --text-primary: hsl(60, 10%, 19%);
  --text-secondary: #fff;
  --text-header: hsl(60, 10%, 19%);
  --text-tertiary: hsl(0, 0%, 100%);
}

.theme-3 {
  /* Backgrounds */
  --main-bg: hsl(268, 75%, 9%);
  --keypad-bg: hsl(268, 71%, 12%);
  --screen-bg: hsl(268, 71%, 12%);
  
  /* Keys */
  --key-bg-primary: hsl(268, 47%, 21%);
  --key-shadow-primary: hsl(290, 70%, 36%);
  
  --key-bg-secondary: hsl(281, 89%, 26%);
  --key-shadow-secondary: hsl(285, 91%, 52%);
  
  --key-bg-tertiary: hsl(176, 100%, 44%);
  --key-shadow-tertiary: hsl(177, 92%, 70%);
  
  /* Text */
  --text-primary: hsl(52, 100%, 62%);
  --text-secondary: hsl(0, 0%, 100%);
  --text-header: hsl(52, 100%, 62%);
}

:root {
    font-size: 16px; /* Base font size */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'League Spartan', sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

body {
    min-height: 100vh;
    background-color: var(--main-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    transition: background-color 0.3s ease;
}

.calculator {
    width: 100%;
    max-width: 33.75rem; /* 540px */
    margin: 0 auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 2rem;
    color: var(--text-header);
}

.header h1 {
    font-size: clamp(1.75rem, 5vw, 2rem); /* 28px to 32px */
    margin: 0;
}

.theme-switcher {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
}

.theme-switcher span {
    font-size: clamp(0.625rem, 2vw, 0.75rem); /* 10px to 12px */
    letter-spacing: 0.0625rem; /* 1px */
    color: var(--text-header);
}

.toggle {
    display: flex;
    flex-direction: column;
    gap: 0.3125rem;
}

.toggle-labels {
    display: flex;
    justify-content: space-between;
    padding: 0 0.25rem;
    font-size: clamp(0.625rem, 2vw, 0.75rem);
    color: var(--text-header);
    width: 100%;
}

.toggle-track {
    width: 4.375rem;
    height: 1.625rem;
    background-color: var(--keypad-bg);
    border-radius: 0.8125rem;
    padding: 0.3125rem;
    position: relative;
    cursor: pointer;
}

.toggle-thumb {
    width: 1rem;
    height: 1rem;
    background-color: var(--key-bg-tertiary);
    border-radius: 50%;
    position: absolute;
    transition: transform 0.3s ease;
    left: 0.3125rem; /* Initial position with padding */
}

.display {
    background-color: var(--screen-bg);
    padding: clamp(1.5rem, 5vw, 2.5rem) clamp(1.25rem, 4vw, 2rem);
    border-radius: 0.625rem;
    text-align: right;
    margin-bottom: clamp(1.25rem, 4vw, 1.5rem);
    font-size: clamp(2.5rem, 7vw, 3.5rem);
    color: var(--text-header);
    word-break: break-all;
    min-height: 7rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    line-height: 1;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    padding-left: 1rem;
}

.display:empty::before {
    content: "0";
}

.keypad {
    background-color: var(--keypad-bg);
    padding: clamp(1.25rem, 4vw, 2rem);
    border-radius: 0.625rem;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(0.75rem, 3vw, 1.5rem);
}

.keypad button {
    background-color: var(--key-bg-primary);
    color: var(--text-primary);
    border: none;
    border-radius: 0.625rem;
    padding: clamp(0.625rem, 2.5vw, 1.0625rem);
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 0.25rem 0 var(--key-shadow-primary);
    transition: all 0.2s ease;
    min-height: 3.75rem;
    width: 100%;
}

.keypad button.operator {
    background-color: var(--key-bg-secondary);
    color: var(--text-secondary);
    box-shadow: 0 0.25rem 0 var(--key-shadow-secondary);
    font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.keypad button.equals {
    background-color: var(--key-bg-tertiary);
    color: var(--text-secondary);
    box-shadow: 0 0.25rem 0 var(--key-shadow-tertiary);
    grid-column: span 2;
}

.keypad button.reset {
    background-color: var(--key-bg-secondary);
    color: var(--text-secondary);
    box-shadow: 0 0.25rem 0 var(--key-shadow-secondary);
    grid-column: span 2;
    font-size: clamp(1.25rem, 4vw, 1.75rem);
}

.theme-3 .keypad button {
    color: var(--text-primary);
}

.theme-3 .keypad button.operator,
.theme-3 .keypad button.reset {
    color: var(--text-secondary);
}

.theme-3 .keypad button.equals {
    color: hsl(198, 20%, 13%);
}

.theme-3 .keypad button:hover {
    filter: brightness(1.3);
}

.theme-3 .toggle-track {
    background-color: var(--keypad-bg);
}

.theme-3 .toggle-thumb {
    background-color: var(--key-bg-tertiary);
}

/* Mobile styles */
@media (max-width: 23.4375rem) { /* 375px */
    body {
        padding: 1rem;
    }

    .calculator {
        width: 100%;
    }

    .header {
        margin-bottom: 1.5rem;
    }

    .display {
        margin-bottom: 1rem;
    }

    .keypad {
        gap: 0.75rem;
    }

    .keypad button {
        min-height: 3.125rem;
    }

    .toggle-track {
        width: 4.25rem;
        height: 1.375rem;
    }

    .toggle-thumb {
        width: 0.875rem;
        height: 0.875rem;
        left: 0.25rem;
    }

    .theme-1 .toggle-thumb {
        transform: translateX(0);
    }

    .theme-2 .toggle-thumb {
        transform: translateX(0.75rem);
    }

    .theme-3 .toggle-thumb {
        transform: translateX(1.875rem);
    }
}

/* Tablet styles */
@media (min-width: 23.5rem) and (max-width: 48rem) { /* 376px to 768px */
    .calculator {
        width: 90%;
    }

    .keypad {
        gap: 1rem;
    }

    .toggle-track {
        width: 4rem;
        height: 1.5rem;
    }

    .toggle-thumb {
        width: 0.9375rem;
        height: 0.9375rem;
    }

    .theme-2 .toggle-thumb {
        transform: translateX(0.9375rem);
    }

    .theme-3 .toggle-thumb {
        transform: translateX(2.375rem);
    }
}

/* Desktop styles */
@media (min-width: 48.0625rem) { /* 769px */
    .calculator {
        width: 80%;
    }

    .toggle-track {
        width: 4.5rem;
    }

    .theme-2 .toggle-thumb {
        transform: translateX(3.5rem);
    }

    .theme-3 .toggle-thumb {
        transform: translateX(5rem);
    }

    .keypad button:hover {
        filter: brightness(1.1);
        transform: translateY(-0.125rem);
    }
}

/* Hover states */
@media (hover: hover) {
    .keypad button:hover {
        filter: brightness(1.1);
    }

    .theme-3 .keypad button:hover {
        filter: brightness(1.3);
    }
}

/* Active states */
.keypad button:active {
    transform: translateY(0.25rem);
    box-shadow: none;
}

/* Theme positions */
.theme-1 .toggle-thumb {
    transform: translateX(0);
}

.theme-2 .toggle-thumb {
    transform: translateX(1.4rem);
}

.theme-3 .toggle-thumb {
    transform: translateX(2.8rem);
}
