:root {
  --bg-0: #0a0e14;
  --bg-1: #12161f;
  --panel: #161b26;
  --screen: #060810;
  --accent: #00e5c7;
  --accent-glow: rgba(0, 229, 199, 0.35);
  --accent-2: #a855f7;
  --num-bg: #1e2432;
  --num-hover: #262d3d;
  --fn-bg: #1a2030;
  --fn-text: #7dd3fc;
  --op-bg: #0f3a37;
  --op-text: #00e5c7;
  --ctrl-bg: #3a1520;
  --ctrl-text: #ff6b8a;
  --text: #e8edf5;
  --text-dim: #5c6577;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Vazirmatn', sans-serif;
  background:
    radial-gradient(circle at 15% 15%, rgba(0,229,199,0.08), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(168,85,247,0.10), transparent 45%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
  min-height: 100vh;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
}

.app-wrap {
  width: 100%;
  max-width: 440px;
  margin-top: 12px;
}

.calc-card {
  background: linear-gradient(180deg, var(--panel), var(--bg-1));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 28px;
  padding: 18px;
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,0.7),
    0 0 0 1px rgba(0,229,199,0.04) inset;
  animation: rise 0.5s cubic-bezier(.2,.8,.2,1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.calc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.calc-title {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}
.title-icon { font-size: 18px; }

.mode-toggle {
  display: flex;
  background: var(--screen);
  border-radius: 999px;
  padding: 3px;
  border: 1px solid rgba(255,255,255,0.06);
  direction: ltr;
}
.mode-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 5px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn.mode-active {
  background: var(--accent);
  color: #04201d;
  box-shadow: 0 0 14px var(--accent-glow);
}

.display {
  position: relative;
  background: var(--screen);
  border-radius: 18px;
  padding: 18px 18px 16px;
  margin-bottom: 12px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border: 1px solid rgba(0,229,199,0.10);
  box-shadow: inset 0 2px 18px rgba(0,0,0,0.6);
  overflow: hidden;
  direction: ltr;
}
.display-mode {
  position: absolute;
  top: 10px;
  left: 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  opacity: 0.6;
  letter-spacing: 1px;
}
.display-expr {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  color: var(--text-dim);
  text-align: right;
  min-height: 20px;
  word-break: break-all;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.display-expr::-webkit-scrollbar { display: none; }
.display-result {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 40px;
  color: var(--text);
  text-align: right;
  word-break: break-all;
  line-height: 1.1;
  margin-top: 4px;
  text-shadow: 0 0 20px rgba(0,229,199,0.12);
}
.display-error {
  font-size: 22px;
  color: var(--ctrl-text);
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 700;
  text-shadow: none;
  direction: rtl;
  text-align: center;
}
.copy-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  background: rgba(255,255,255,0.05);
  border: none;
  border-radius: 8px;
  padding: 4px 7px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.15s;
}
.copy-btn:hover { opacity: 1; transform: scale(1.1); }

.history-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.hist-toggle {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: 'Vazirmatn', sans-serif;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 2px;
}
.hist-toggle:hover { color: var(--accent); }
.hist-clear {
  background: transparent;
  border: none;
  color: var(--ctrl-text);
  font-size: 11px;
  cursor: pointer;
  opacity: 0.7;
}
.hist-clear:hover { opacity: 1; }

.history-panel {
  max-height: 150px;
  overflow-y: auto;
  background: var(--screen);
  border-radius: 14px;
  margin-bottom: 12px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.05);
}
.history-empty {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 14px;
}
.history-item {
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  direction: ltr;
  text-align: right;
}
.history-item:hover { background: rgba(0,229,199,0.08); }
.hist-expr {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
}
.hist-eq {
  font-family: 'JetBrains Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.calc-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 18px;
  font-weight: 500;
  border: none;
  border-radius: 16px;
  padding: 0;
  height: 54px;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.08s, box-shadow 0.2s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.calc-btn:active { transform: scale(0.92); }

.btn-num { background: var(--num-bg); }
.btn-num:hover { background: var(--num-hover); }

.btn-fn {
  background: var(--fn-bg);
  color: var(--fn-text);
  font-size: 15px;
}
.btn-fn:hover { background: #212a3d; box-shadow: 0 0 12px rgba(125,211,252,0.15); }

.btn-op {
  background: var(--op-bg);
  color: var(--op-text);
  font-size: 22px;
  font-weight: 700;
}
.btn-op:hover { background: #12504b; box-shadow: 0 0 14px var(--accent-glow); }

.btn-ctrl {
  background: var(--ctrl-bg);
  color: var(--ctrl-text);
  font-weight: 700;
  font-size: 16px;
}
.btn-ctrl:hover { background: #4a1a29; }

.btn-zero { grid-column: span 2; }

.btn-eq {
  grid-column: span 2;
  font-family: 'JetBrains Mono', monospace;
  font-size: 24px;
  font-weight: 800;
  border: none;
  border-radius: 16px;
  height: 54px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #06b6a4);
  color: #032420;
  box-shadow: 0 0 20px var(--accent-glow);
  transition: transform 0.08s, box-shadow 0.2s;
}
.btn-eq:active { transform: scale(0.94); }
.btn-eq:hover { box-shadow: 0 0 30px var(--accent-glow); }

.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #04201d;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 8px 24px var(--accent-glow);
  animation: toastPop 0.3s cubic-bezier(.2,.8,.2,1);
  z-index: 50;
}
@keyframes toastPop {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.footer {
  text-align: center;
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-dim);
}
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

@media (max-width: 400px) {
  .calc-btn, .btn-eq { height: 48px; font-size: 16px; }
  .btn-op { font-size: 20px; }
  .display-result { font-size: 34px; }
  .calc-title { font-size: 13px; }
}