/* =========================================
   Calculadora Pro — stylesheet
   ========================================= */

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

/* ---- Design tokens ---- */
:root {
  --clr-bg-a: #0f0c29;
  --clr-bg-b: #302b63;
  --clr-bg-c: #24243e;

  --clr-calc: rgba(28, 27, 40, 0.96);
  --clr-display: rgba(0, 0, 0, 0.28);

  --clr-number: #2a2a3c;
  --clr-number-h: #35354d;
  --clr-special: #636366;
  --clr-special-h: #757578;
  --clr-operator: #ff9f0a;
  --clr-operator-h: #ffb340;
  --clr-equals: #ff9f0a;
  --clr-equals-h: #ffb340;

  --clr-text: #ffffff;
  --clr-muted: rgba(255, 255, 255, 0.42);

  --radius-calc: 28px;
  --radius-btn: 50%;
  --btn-size: 66px;
  --btn-gap: 13px;

  --shadow-calc:
    0 32px 64px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.07);
  --shadow-op: 0 4px 18px rgba(255, 159, 10, 0.35);
  --shadow-num: 0 4px 12px rgba(0, 0, 0, 0.35);

  --ease-btn: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---- Base ---- */
body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(
    145deg,
    var(--clr-bg-a),
    var(--clr-bg-b),
    var(--clr-bg-c)
  );
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  overflow: hidden;
}

/* Decorative radial glow behind the calculator */
body::before {
  content: "";
  position: fixed;
  inset: -50%;
  background: radial-gradient(
    ellipse at 60% 40%,
    rgba(120, 70, 220, 0.18) 0%,
    transparent 55%
  );
  pointer-events: none;
}

/* ---- Wrapper ---- */
.calc-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* ---- Calculator card ---- */
.calculator {
  position: relative;
  background: var(--clr-calc);
  border-radius: var(--radius-calc);
  padding: 22px;
  width: 340px;
  box-shadow: var(--shadow-calc);
  backdrop-filter: blur(24px);
  overflow: hidden;
}

/* Subtle top-edge shine */
.calculator::before {
  content: "";
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.15),
    transparent
  );
}

/* ---- Display ---- */
.display {
  background: var(--clr-display);
  border-radius: 18px;
  padding: 20px 22px 18px;
  margin-bottom: 20px;
  min-height: 116px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 6px;
  overflow: hidden;
}

.expression {
  font-size: 14px;
  font-weight: 300;
  color: var(--clr-muted);
  text-align: right;
  min-height: 20px;
  word-break: break-all;
  letter-spacing: 0.4px;
  transition: opacity 0.2s;
}

.current-value {
  font-size: 56px;
  font-weight: 300;
  color: var(--clr-text);
  text-align: right;
  line-height: 1;
  word-break: break-all;
  letter-spacing: -1.5px;
  transition:
    font-size 0.15s ease,
    color 0.2s;
}

.current-value.font-md {
  font-size: 40px;
  letter-spacing: -0.5px;
}
.current-value.font-sm {
  font-size: 28px;
  letter-spacing: 0;
}
.current-value.error {
  color: #ff6b6b;
  font-size: 30px;
  letter-spacing: 0;
}

/* ---- Button grid ---- */
.buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--btn-gap);
}

/* ---- Base button ---- */
.btn {
  height: var(--btn-size);
  width: var(--btn-size);
  border: none;
  border-radius: var(--radius-btn);
  font-size: 20px;
  font-weight: 400;
  font-family: inherit;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    filter 0.12s var(--ease-btn),
    transform 0.1s var(--ease-btn);
}

/* Ripple overlay on press */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.18);
  opacity: 0;
  transition: opacity 0.18s;
}
.btn:active::after {
  opacity: 1;
}
.btn:active {
  transform: scale(0.91);
}

/* ---- Number buttons ---- */
.btn-number {
  background: var(--clr-number);
  color: var(--clr-text);
  box-shadow:
    var(--shadow-num),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.btn-number:hover {
  filter: brightness(1.25);
}

/* ---- Special buttons (AC, +/−, %) ---- */
.btn-special {
  background: var(--clr-special);
  color: var(--clr-text);
  font-size: 17px;
  box-shadow:
    var(--shadow-num),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-special:hover {
  filter: brightness(1.2);
}

/* ---- Operator buttons ---- */
.btn-operator {
  background: var(--clr-operator);
  color: #fff;
  font-size: 26px;
  box-shadow:
    var(--shadow-op),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.btn-operator:hover {
  background: var(--clr-operator-h);
  box-shadow: 0 6px 22px rgba(255, 159, 10, 0.45);
}

/* Active state: inverted colors while operator selected */
.btn-operator.active {
  background: #fff;
  color: var(--clr-operator);
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.15);
}

/* ---- Equals button ---- */
.btn-equals {
  background: var(--clr-equals);
  color: #fff;
  font-size: 26px;
  box-shadow:
    var(--shadow-op),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.btn-equals:hover {
  background: var(--clr-equals-h);
  box-shadow: 0 6px 22px rgba(255, 159, 10, 0.45);
}

/* ---- Zero button (spans 2 cols) ---- */
.btn-zero {
  grid-column: span 2;
  border-radius: 33px;
  width: 100%;
  text-align: left;
  padding-left: 26px;
}

/* ---- Pop animation on result ---- */
@keyframes pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}
.pop {
  animation: pop 0.22s var(--ease-btn);
}

/* =========================================
   History panel
   ========================================= */
.history-panel {
  position: absolute;
  inset: 0;
  background: rgba(13, 12, 30, 0.97);
  border-radius: var(--radius-calc);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateX(105%);
  transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(24px);
  z-index: 10;
}

.history-panel.open {
  transform: translateX(0);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--clr-text);
  font-size: 15px;
  font-weight: 500;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.clear-history {
  background: none;
  border: 1px solid rgba(255, 90, 90, 0.38);
  color: rgba(255, 110, 110, 0.85);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.2s,
    border-color 0.2s;
}
.clear-history:hover {
  background: rgba(255, 90, 90, 0.12);
  border-color: rgba(255, 90, 90, 0.7);
}

.history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  padding-right: 2px;
}

/* Scrollbar */
.history-list::-webkit-scrollbar {
  width: 4px;
}
.history-list::-webkit-scrollbar-track {
  background: transparent;
}
.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
}

.history-item {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition:
    background 0.18s,
    border-color 0.18s;
}
.history-item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.1);
}
.history-item .h-expr {
  font-size: 12px;
  color: var(--clr-muted);
  margin-bottom: 3px;
}
.history-item .h-result {
  font-size: 20px;
  font-weight: 300;
  color: var(--clr-text);
}

.history-empty {
  color: rgba(255, 255, 255, 0.28);
  font-size: 14px;
  text-align: center;
  margin: auto;
}

/* =========================================
   Controls below calculator
   ========================================= */
.history-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.13);
  color: rgba(255, 255, 255, 0.75);
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition:
    background 0.2s,
    transform 0.2s,
    color 0.2s;
}
.history-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  transform: translateY(-1px);
}

.keyboard-hint {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.22);
  text-align: center;
  letter-spacing: 0.3px;
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 400px) {
  .calculator {
    width: calc(100vw - 24px);
    padding: 16px;
  }
  :root {
    --btn-size: 58px;
    --btn-gap: 10px;
  }
  .current-value {
    font-size: 46px;
  }
  .btn-zero {
    padding-left: 22px;
  }
}
