/* ── Reset & Base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg:          #0e0e10;
  --glass-bg:    rgba(255, 255, 255, 0.04);
  --glass-border:rgba(255, 255, 255, 0.10);
  --glass-shine: rgba(255, 255, 255, 0.06);

  --num-bg:      rgba(255, 255, 255, 0.08);
  --num-hover:   rgba(255, 255, 255, 0.14);
  --num-active:  rgba(255, 255, 255, 0.20);

  --func-bg:     rgba(255, 255, 255, 0.15);
  --func-hover:  rgba(255, 255, 255, 0.22);
  --func-active: rgba(255, 255, 255, 0.28);

  --op-bg:       #FF6B2B;
  --op-hover:    #FF8A52;
  --op-active:   #E55A1E;
  --op-selected: #FFB088;

  --eq-bg:       linear-gradient(135deg, #FF6B2B 0%, #FF9A5C 100%);
  --eq-hover:    linear-gradient(135deg, #FF8A52 0%, #FFB07A 100%);

  --text-primary:   #FFFFFF;
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-op:        #FFFFFF;
  --text-func:      #FFFFFF;

  --radius-btn:  50%;
  --radius-card: 40px;
  --gap:         12px;
  --btn-size:    72px;

  --shadow-card: 0 40px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.06);
  --shadow-btn:  0 4px 16px rgba(0,0,0,0.4);
  --shadow-op:   0 4px 20px rgba(255, 107, 43, 0.45);
  --shadow-eq:   0 8px 32px rgba(255, 107, 43, 0.55);
}

/* ── Background ── */
body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
}

.orb-1 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, #FF6B2B 0%, transparent 70%);
  top: -120px; right: -80px;
  animation: drift1 12s ease-in-out infinite alternate;
}

.orb-2 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, #7B2FFF 0%, transparent 70%);
  bottom: -80px; left: -60px;
  animation: drift2 15s ease-in-out infinite alternate;
}

.orb-3 {
  width: 200px; height: 200px;
  background: radial-gradient(circle, #FF3CAC 0%, transparent 70%);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.15;
  animation: drift3 20s ease-in-out infinite alternate;
}

@keyframes drift1 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(-30px, 40px) scale(1.1); }
}
@keyframes drift2 {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(40px, -30px) scale(1.15); }
}
@keyframes drift3 {
  from { transform: translate(-50%, -50%) scale(1); }
  to   { transform: translate(-50%, -50%) scale(1.4); }
}

/* ── App Shell ── */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
}

/* ── Calculator Card ── */
.calculator {
  width: 100%;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  padding: 28px 24px 32px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  position: relative;
  overflow: hidden;
  animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.calculator::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
}

.calculator::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 50%;
  background: var(--glass-shine);
  pointer-events: none;
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}

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

/* ── Display ── */
.display {
  padding: 16px 8px 28px;
  text-align: right;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  position: relative;
  z-index: 1;
}

.display-expression {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-secondary);
  min-height: 22px;
  letter-spacing: 0.02em;
  transition: opacity 0.2s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display-result {
  font-size: 64px;
  font-weight: 300;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.03em;
  transition: font-size 0.15s ease, transform 0.1s ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.display-result.shrink  { font-size: 44px; }
.display-result.shrink2 { font-size: 32px; }

.display-result.pop {
  animation: pop 0.15s ease;
}

@keyframes pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* ── Keypad ── */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  position: relative;
  z-index: 1;
}

/* ── Buttons ── */
.btn {
  height: var(--btn-size);
  border: none;
  border-radius: var(--radius-btn);
  font-family: 'Outfit', sans-serif;
  font-size: 22px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition:
    transform 0.1s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.15s ease,
    background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
  box-shadow: var(--shadow-btn);
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 0%, rgba(255,255,255,0.15), transparent 60%);
  pointer-events: none;
}

/* Number buttons */
.btn-num {
  background: var(--num-bg);
  color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.06);
}
.btn-num:hover  { background: var(--num-hover); }
.btn-num:active { background: var(--num-active); transform: scale(0.92); }

/* Function buttons (AC, +/-, %) */
.btn-func {
  background: var(--func-bg);
  color: var(--text-func);
  border: 1px solid rgba(255,255,255,0.10);
}
.btn-func:hover  { background: var(--func-hover); }
.btn-func:active { background: var(--func-active); transform: scale(0.92); }

/* Operator buttons */
.btn-op {
  background: var(--op-bg);
  color: var(--text-op);
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: var(--shadow-op);
  font-size: 26px;
  font-weight: 400;
}
.btn-op:hover  { background: var(--op-hover); }
.btn-op:active { background: var(--op-active); transform: scale(0.92); }
.btn-op.active {
  background: var(--op-selected);
  color: #1A1A1A;
  box-shadow: 0 4px 24px rgba(255, 176, 136, 0.6);
}

/* Equals button */
.btn-equals {
  background: var(--eq-bg);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-eq);
  font-size: 26px;
  font-weight: 400;
}
.btn-equals:hover  { background: var(--eq-hover); }
.btn-equals:active { transform: scale(0.92); opacity: 0.9; }

/* Zero button spans 2 columns */
.btn-zero {
  grid-column: span 2;
  border-radius: 36px;
  justify-content: flex-start;
  padding-left: 28px;
}

/* Press ripple */
.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  transform: scale(0);
  animation: ripple 0.4s linear;
  pointer-events: none;
}

@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

/* ── Responsive tweaks ── */
@media (max-height: 700px) {
  :root { --btn-size: 62px; --gap: 10px; }
  .display-result { font-size: 52px; }
  .display { min-height: 100px; padding-bottom: 20px; }
}

@media (max-width: 360px) {
  :root { --btn-size: 64px; --gap: 10px; }
  .app { padding: 12px; }
  .calculator { padding: 20px 16px 24px; }
}