@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@300;400;500&display=swap');

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

:root {
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.85);
  --glass-blur: 24px;

  --btn-glass: rgba(255, 255, 255, 0.60);
  --btn-hover: rgba(255, 255, 255, 0.90);
  --btn-active: rgba(240, 242, 248, 1.00);
  --btn-border: rgba(210, 215, 230, 0.80);

  --col-func: rgba(230, 232, 240, 0.75);
  --col-func-h: rgba(215, 218, 232, 0.95);
  --col-operator: rgba(210, 220, 245, 0.70);
  --col-operator-h: rgba(190, 205, 240, 0.95);
  --col-equals: rgba(60, 60, 80, 0.90);
  --col-equals-h: rgba(40, 40, 65, 1.00);
  --col-delete: rgba(245, 220, 220, 0.75);
  --col-delete-h: rgba(240, 195, 195, 0.95);

  --text-primary: rgba(30, 32, 48, 0.95);
  --text-secondary: rgba(100, 105, 130, 0.75);
  --text-operator: rgba(60, 80, 160, 0.90);
  --text-func: rgba(50, 55, 90, 0.85);
  --text-equals: #ffffff;

  --radius-calc: 32px;
  --radius-btn: 16px;
  --gap: 12px;

  --font-ui: 'Outfit', sans-serif;
  --font-display: 'JetBrains Mono', monospace;
  --transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-fast: all 0.12s ease;
}

html, body {
  width: 100%;
  min-height: 100%;
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  background: linear-gradient(145deg, #eef0f8 0%, #f8f9ff 40%, #e8ecf8 70%, #f0f2fa 100%);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
  animation: orbFloat 14s ease-in-out infinite alternate;
}

.orb-1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(200, 210, 255, 0.55), transparent 70%);
  top: -150px; left: -120px;
  animation-duration: 16s;
}

.orb-2 {
  width: 380px; height: 380px;
  background: radial-gradient(circle, rgba(215, 225, 255, 0.45), transparent 70%);
  bottom: -100px; right: -100px;
  animation-duration: 12s;
  animation-delay: -5s;
}

.orb-3 {
  width: 280px; height: 280px;
  background: radial-gradient(circle, rgba(230, 220, 255, 0.40), transparent 70%);
  top: 45%; left: 55%;
  animation-duration: 18s;
  animation-delay: -8s;
}

@keyframes orbFloat {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(25px, -18px) scale(1.05); }
  100% { transform: translate(-18px, 25px) scale(0.96); }
}

.scene {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.calculator {
  width: min(380px, 100%);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-calc);
  padding: 28px;
  box-shadow:
    0 20px 60px rgba(160, 170, 210, 0.30),
    0 4px 16px rgba(160, 170, 210, 0.20),
    0 1px 0 rgba(255,255,255,0.95) inset;
  animation: calcEntrance 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes calcEntrance {
  from { opacity: 0; transform: translateY(36px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.display {
  background: rgba(255, 255, 255, 0.70);
  border: 1.5px solid rgba(210, 215, 235, 0.80);
  border-radius: 20px;
  padding: 20px 22px 16px;
  margin-bottom: 22px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 5px;
  overflow: hidden;
  position: relative;
  box-shadow:
    0 2px 12px rgba(160, 170, 210, 0.15) inset,
    0 1px 0 rgba(255,255,255,1) inset;
}

.display::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 190, 230, 0.50), transparent);
}

.display-expression {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
  min-height: 1.2em;
  transition: var(--transition-fast);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.display-result {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1;
  transition: var(--transition-fast);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  font-size: clamp(2rem, 9vw, 2.9rem);
}

.display-result.large  { font-size: clamp(2.0rem, 9vw, 2.9rem); }
.display-result.medium { font-size: clamp(1.6rem, 6vw, 2.1rem); }
.display-result.small  { font-size: clamp(1.2rem, 4vw, 1.55rem); }

.display-result.error {
  color: rgba(190, 60, 60, 0.85);
  font-size: 1.25rem;
}

.display-result.pop {
  animation: resultPop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes resultPop {
  0%   { transform: scale(0.93); opacity: 0.6; }
  100% { transform: scale(1);    opacity: 1; }
}

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

.btn {
  position: relative;
  height: 68px;
  border: 1.5px solid var(--btn-border);
  border-radius: var(--radius-btn);
  background: var(--btn-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1.2rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow:
    0 4px 14px rgba(160, 170, 210, 0.18),
    0 1px 0 rgba(255,255,255,0.95) inset;
  overflow: hidden;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(145deg, rgba(255,255,255,0.80) 0%, transparent 55%);
  pointer-events: none;
}

.btn::after {
  content: '';
  position: absolute;
  width: 0; height: 0;
  border-radius: 50%;
  background: rgba(160, 170, 220, 0.25);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}

.btn.ripple::after {
  animation: ripple 0.45s ease-out forwards;
}

@keyframes ripple {
  0%   { width: 0; height: 0; opacity: 0.5; }
  100% { width: 200px; height: 200px; opacity: 0; }
}

.btn:hover {
  background: var(--btn-hover);
  border-color: rgba(190, 198, 228, 0.90);
  transform: translateY(-2px) scale(1.02);
  box-shadow:
    0 8px 24px rgba(150, 160, 210, 0.25),
    0 1px 0 rgba(255,255,255,1) inset;
}

.btn:active {
  transform: translateY(0) scale(0.96);
  background: var(--btn-active);
  box-shadow: 0 2px 6px rgba(150, 160, 210, 0.15);
}

.btn-func {
  background: var(--col-func);
  color: var(--text-func);
  font-weight: 600;
  font-size: 1.05rem;
}
.btn-func:hover { background: var(--col-func-h); }

.btn-operator {
  background: var(--col-operator);
  color: var(--text-operator);
  font-size: 1.45rem;
  font-weight: 600;
  border-color: rgba(180, 195, 240, 0.70);
}
.btn-operator:hover {
  background: var(--col-operator-h);
  border-color: rgba(160, 180, 235, 0.90);
}
.btn-operator.active-operator {
  background: rgba(60, 80, 180, 0.15);
  border-color: rgba(80, 100, 200, 0.55);
  color: rgba(40, 60, 160, 1.00);
  box-shadow: 0 0 18px rgba(80, 100, 200, 0.18), 0 4px 12px rgba(150, 160, 210, 0.20);
  transform: translateY(-1px);
}

.btn-delete {
  background: var(--col-delete);
  color: rgba(180, 60, 60, 0.90);
  font-size: 1.1rem;
  border-color: rgba(230, 190, 190, 0.80);
}
.btn-delete:hover {
  background: var(--col-delete-h);
  border-color: rgba(220, 170, 170, 0.95);
  color: rgba(160, 40, 40, 1.00);
}

.btn-equals {
  background: var(--col-equals);
  color: var(--text-equals);
  font-size: 1.5rem;
  font-weight: 600;
  border-color: rgba(40, 40, 70, 0.70);
  box-shadow:
    0 6px 20px rgba(40, 45, 80, 0.28),
    0 1px 0 rgba(255,255,255,0.15) inset;
}
.btn-equals::before {
  background: linear-gradient(145deg, rgba(255,255,255,0.12) 0%, transparent 60%);
}
.btn-equals:hover {
  background: var(--col-equals-h);
  border-color: rgba(20, 20, 50, 0.85);
  box-shadow:
    0 10px 28px rgba(30, 35, 70, 0.38),
    0 1px 0 rgba(255,255,255,0.18) inset;
  transform: translateY(-2px) scale(1.03);
}
.btn-equals:active {
  transform: scale(0.96);
  box-shadow: 0 3px 8px rgba(30, 35, 70, 0.25);
}

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

.btn:focus-visible {
  outline: 2px solid rgba(80, 100, 200, 0.55);
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .calculator { padding: 20px 16px; border-radius: 26px; }
  :root { --gap: 9px; --radius-btn: 14px; }
  .btn { height: 60px; font-size: 1.1rem; }
  .btn-operator { font-size: 1.3rem; }
  .btn-equals { font-size: 1.35rem; }
  .display { padding: 16px 18px 12px; min-height: 96px; margin-bottom: 18px; }
  .btn-zero { padding-left: 20px; }
}

@media (max-width: 360px) {
  .calculator { padding: 16px 12px; }
  :root { --gap: 8px; --radius-btn: 12px; }
  .btn { height: 54px; font-size: 1rem; }
  .display { min-height: 88px; padding: 14px 14px 10px; }
}

@media (min-width: 768px) {
  .calculator { width: 400px; }
  .btn { height: 72px; font-size: 1.25rem; }
  :root { --gap: 14px; --radius-btn: 18px; }
  .display { min-height: 118px; padding: 22px 26px 18px; margin-bottom: 24px; }
}

@media (min-width: 1024px) {
  .calculator { width: 420px; }
  .btn { height: 76px; }
  :root { --gap: 15px; }
}

@media (max-height: 680px) {
  .btn { height: 54px; }
  .display { min-height: 84px; margin-bottom: 14px; padding: 12px 18px 10px; }
  .scene { padding: 16px; }
}
