/* ==============================
   CSS RESET & DESIGN TOKENS
   ============================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg:              #0d0f1a;
  --clr-border:          rgba(255,255,255,0.08);
  --clr-border-bright:   rgba(255,255,255,0.18);
  --clr-text-primary:    #f0f2ff;
  --clr-text-secondary:  rgba(255,255,255,0.40);

  --clr-digit:           rgba(255,255,255,0.06);
  --clr-digit-hover:     rgba(255,255,255,0.13);
  --clr-digit-active:    rgba(255,255,255,0.20);

  --clr-op:              rgba(99,102,241,0.22);
  --clr-op-hover:        rgba(99,102,241,0.42);
  --clr-op-text:         #a5b4fc;

  --clr-clear:           rgba(239,68,68,0.20);
  --clr-clear-hover:     rgba(239,68,68,0.42);
  --clr-clear-text:      #fca5a5;

  --clr-equals:          #6366f1;
  --clr-equals-hover:    #4f52d1;
  --clr-equals-glow:     rgba(99,102,241,0.55);

  --radius-calc:  26px;
  --radius-btn:   15px;
  --gap:          11px;
  --transition:   0.17s ease;
  --font: 'Inter', sans-serif;
}

/* ==============================
   BASE
   ============================== */
html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ==============================
   BACKGROUND ORBS
   ============================== */
.background-orbs { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  animation: floatOrb 12s ease-in-out infinite alternate;
}
.orb-1 { width:500px;height:500px;background:rgba(99,102,241,0.18);top:-150px;left:-150px; }
.orb-2 { width:380px;height:380px;background:rgba(168,85,247,0.12);bottom:-100px;right:-100px;animation-delay:-4s;animation-duration:9s; }
.orb-3 { width:280px;height:280px;background:rgba(6,182,212,0.10);top:50%;left:50%;transform:translate(-50%,-50%);animation-delay:-7s;animation-duration:15s; }

@keyframes floatOrb {
  from { transform: translate(0,0) scale(1); }
  to   { transform: translate(35px,28px) scale(1.07); }
}

/* ==============================
   MATH BACKGROUND CANVAS
   ============================== */
#math-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ==============================
   CALCULATOR CARD
   ============================== */
.calculator-wrapper {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; width: 100%;
}

.calculator {
  background: rgba(14, 16, 33, 0.78);
  backdrop-filter: blur(22px) saturate(170%);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  border: 1px solid var(--clr-border-bright);
  border-radius: var(--radius-calc);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.60), 0 0 0 1px var(--clr-border);
  padding: 22px;
  width: min(375px, 100%);
  animation: slideUp 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(60px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==============================
   DISPLAY
   ============================== */
.display {
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid var(--clr-border);
  border-radius: 16px;
  padding: 18px 22px 14px;
  margin-bottom: 18px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  overflow: hidden;
  transition: border-color 0.3s ease;
}

.display-expression {
  font-size: 0.85rem;
  color: var(--clr-text-secondary);
  min-height: 18px;
  word-break: break-all;
  text-align: right;
  line-height: 1.4;
  font-weight: 400;
  letter-spacing: 0.02em;
  transition: opacity 0.2s ease;
}

.display-result {
  font-size: clamp(1.9rem, 8vw, 2.7rem);
  font-weight: 300;
  letter-spacing: -0.02em;
  color: var(--clr-text-primary);
  line-height: 1.15;
  word-break: break-all;
  text-align: right;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.display-result.pop { animation: resultPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.display-result.error { color: #fca5a5; font-size: clamp(1.1rem, 5vw, 1.6rem); }

@keyframes resultPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.shake { animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }

/* ==============================
   BUTTON GRID
   ============================== */
.button-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }

/* ==============================
   BUTTON BASE & ENTRANCE ANIMATION
   ============================== */
.btn {
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 500;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-btn);
  cursor: pointer;
  height: 68px;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  position: relative; overflow: hidden;
  transition: background 0.2s ease, border-color 0.2s ease,
              transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), 
              box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  -webkit-tap-highlight-color: transparent;
  outline: none;
  
  /* Reveal animation */
  animation: btnReveal 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes btnReveal {
  from { opacity: 0; transform: scale(0.6) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* Staggered entrance for buttons (19 buttons total) */
.btn:nth-child(1)  { animation-delay: 0.10s; }
.btn:nth-child(2)  { animation-delay: 0.13s; }
.btn:nth-child(3)  { animation-delay: 0.16s; }
.btn:nth-child(4)  { animation-delay: 0.19s; }
.btn:nth-child(5)  { animation-delay: 0.22s; }
.btn:nth-child(6)  { animation-delay: 0.25s; }
.btn:nth-child(7)  { animation-delay: 0.28s; }
.btn:nth-child(8)  { animation-delay: 0.31s; }
.btn:nth-child(9)  { animation-delay: 0.34s; }
.btn:nth-child(10) { animation-delay: 0.37s; }
.btn:nth-child(11) { animation-delay: 0.40s; }
.btn:nth-child(12) { animation-delay: 0.43s; }
.btn:nth-child(13) { animation-delay: 0.46s; }
.btn:nth-child(14) { animation-delay: 0.49s; }
.btn:nth-child(15) { animation-delay: 0.52s; }
.btn:nth-child(16) { animation-delay: 0.55s; }
.btn:nth-child(17) { animation-delay: 0.58s; }
.btn:nth-child(18) { animation-delay: 0.61s; }
.btn:nth-child(19) { animation-delay: 0.64s; }

.btn:focus-visible { outline: 2px solid var(--clr-op-text); outline-offset: 2px; }
.btn:hover { transform: translateY(-2px) scale(1.02); }
.btn:active { transform: translateY(0) scale(0.94); transition: transform 0.05s; }


/* ==============================
   BUTTON VARIANTS
   ============================== */
.btn-digit { background: var(--clr-digit); color: var(--clr-text-primary); }
.btn-digit:hover { background: var(--clr-digit-hover); border-color: rgba(255,255,255,0.13); }
.btn-digit:active { background: var(--clr-digit-active); }

.btn-zero { grid-column: span 2; justify-content: flex-start; padding-left: 26px; }

.btn-operator { background: var(--clr-op); color: var(--clr-op-text); border-color:rgba(99,102,241,0.18); font-size:1.25rem; }
.btn-operator:hover { background: var(--clr-op-hover); border-color:rgba(99,102,241,0.38); box-shadow:0 4px 16px rgba(99,102,241,0.22); }
.btn-operator.active-op { background: var(--clr-op-hover); box-shadow:0 0 0 2px rgba(99,102,241,0.38); }

.btn-clear { background: var(--clr-clear); color: var(--clr-clear-text); border-color:rgba(239,68,68,0.16); grid-column: span 2; }
.btn-clear:hover { background: var(--clr-clear-hover); border-color:rgba(239,68,68,0.36); box-shadow:0 4px 16px rgba(239,68,68,0.20); }

.btn-action { background: rgba(255,255,255,0.07); color: var(--clr-clear-text); font-size:1.2rem; }
.btn-action:hover { background: rgba(239,68,68,0.26); border-color:rgba(239,68,68,0.22); }

.btn-equals {
  background: var(--clr-equals); color:#fff; font-size:1.35rem; font-weight:600;
  border-color:transparent; box-shadow:0 8px 24px var(--clr-equals-glow);
}
.btn-equals:hover { background: var(--clr-equals-hover); box-shadow:0 10px 30px var(--clr-equals-glow); transform:translateY(-1px); }
.btn-equals:active { background:#3b3ebc; transform:scale(0.92); }

/* ==============================
   KEYBOARD HINT
   ============================== */
.keyboard-hint {
  text-align: center; font-size: 0.70rem; color: var(--clr-text-secondary);
  margin-top: 14px; letter-spacing: 0.05em; font-weight: 400;
}

/* ==============================
   RESPONSIVE
   ============================== */
@media (max-width: 420px) {
  .calculator { padding: 16px; border-radius: 20px; }
  .btn { height: 60px; font-size: 1rem; border-radius: 13px; }
  .button-grid { gap: 8px; }
  .display { min-height: 92px; padding: 14px 16px 12px; }
}
@media (max-width: 360px) {
  .btn { height: 54px; font-size: 0.9rem; }
}
