/* ===========================
   NEXUS CALCULATOR — style.css
   =========================== */

/* ---- Variables ---- */
:root {
  --bg: #0a0a0f;
  --surface: rgba(18, 14, 30, 0.85);
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(255, 255, 255, 0.08);
  --purple: #a855f7;
  --purple-dim: #7c3aed;
  --neon: #c084fc;
  --neon-glow: rgba(168, 85, 247, 0.35);
  --cyan: #22d3ee;
  --text-primary: #f1f0ff;
  --text-secondary: #9ca3af;
  --text-dim: #6b7280;
  --num-btn: rgba(30, 24, 48, 0.9);
  --op-btn: rgba(100, 40, 160, 0.55);
  --func-btn: rgba(40, 32, 60, 0.85);
  --eq-btn: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
  --sci-btn: rgba(34, 211, 238, 0.12);
  --shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
  --radius: 20px;
  --btn-radius: 14px;
  --transition: 0.18s ease;
  --font: 'Inter', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

.light-mode {
  --bg: #f0edf8;
  --surface: rgba(255, 255, 255, 0.88);
  --glass: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(100, 60, 180, 0.15);
  --text-primary: #1a0533;
  --text-secondary: #5b4b7c;
  --text-dim: #9980c0;
  --num-btn: rgba(240, 235, 255, 0.9);
  --op-btn: rgba(160, 100, 230, 0.25);
  --func-btn: rgba(210, 190, 255, 0.6);
  --sci-btn: rgba(34, 211, 238, 0.15);
  --neon-glow: rgba(124, 58, 237, 0.2);
  --shadow: 0 20px 50px rgba(80, 0, 180, 0.15);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
}

/* ---- Background Orbs ---- */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  pointer-events: none;
  animation: drift 12s ease-in-out infinite alternate;
}
.orb-1 { width: 500px; height: 500px; background: #7c3aed; top: -120px; left: -150px; animation-delay: 0s; }
.orb-2 { width: 350px; height: 350px; background: #22d3ee; bottom: -80px; right: -80px; animation-delay: -4s; }
.orb-3 { width: 280px; height: 280px; background: #a855f7; top: 40%; left: 55%; animation-delay: -8s; }

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(30px, 40px) scale(1.08); }
}

/* ---- App Wrapper ---- */
.app-wrapper {
  width: 100%;
  max-width: 920px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  animation: fadeInUp 0.5s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Top Bar ---- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.3rem;
}
.app-title {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.35em;
  background: linear-gradient(90deg, var(--purple), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.top-controls { display: flex; gap: 0.5rem; }
.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
  backdrop-filter: blur(10px);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { color: var(--neon); border-color: var(--purple); background: var(--neon-glow); transform: scale(1.08); }
.icon-btn.active { color: var(--neon); border-color: var(--purple); background: var(--neon-glow); }

/* ---- Main Layout ---- */
.main-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

/* ---- History Panel ---- */
.history-panel {
  width: 260px;
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  padding: 1rem;
  max-height: 580px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow);
  transform: translateX(-20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.history-panel.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: all;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--neon);
  letter-spacing: 0.05em;
}
.clear-history-btn {
  font-size: 0.72rem;
  color: var(--text-dim);
  background: none;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.clear-history-btn:hover { color: #f87171; border-color: #f87171; }
.history-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--purple-dim) transparent;
}
.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-thumb { background: var(--purple-dim); border-radius: 4px; }
.history-empty { color: var(--text-dim); font-size: 0.82rem; text-align: center; margin-top: 2rem; }
.history-item {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  animation: slideIn 0.2s ease both;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}
.history-item:hover { border-color: var(--purple); background: var(--neon-glow); }
.history-expr { font-size: 0.75rem; color: var(--text-dim); font-family: var(--mono); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-res  { font-size: 1rem; font-weight: 600; color: var(--text-primary); font-family: var(--mono); }

/* ---- Calculator ---- */
.calculator {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  padding: 1.2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* ---- Mode Bar ---- */
.mode-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.3rem;
}
.mode-btn {
  flex: 1;
  padding: 0.45rem;
  border: none;
  background: transparent;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.mode-btn.active { background: var(--op-btn); color: var(--neon); box-shadow: 0 0 12px var(--neon-glow); }
.deg-rad-wrap { display: flex; gap: 0.2rem; margin-left: auto; }
.deg-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--glass-border);
  background: transparent;
  border-radius: 7px;
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
}
.deg-btn.active { background: var(--neon-glow); color: var(--neon); border-color: var(--purple); }

/* ---- Display ---- */
.display-area {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.2rem 1.4rem;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  position: relative;
  overflow: hidden;
}
.display-area::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(168,85,247,0.05) 0%, transparent 60%);
  pointer-events: none;
}
.expression-display {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--text-dim);
  min-height: 1.2em;
  word-break: break-all;
  text-align: right;
  transition: all 0.2s ease;
  max-width: 100%;
}
.result-display {
  font-family: var(--mono);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  word-break: break-all;
  text-align: right;
  transition: all 0.15s ease;
  max-width: 100%;
}
.result-display.pulse {
  animation: pulse 0.2s ease;
}
@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}
.result-display.error { color: #f87171; }
.copy-btn {
  position: absolute;
  top: 10px; right: 12px;
  display: flex; align-items: center; gap: 4px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn svg { width: 12px; height: 12px; }
.copy-btn:hover { color: var(--neon); border-color: var(--purple); }
.copy-btn.copied { color: #4ade80; border-color: #4ade80; }

/* ---- Scientific Grid ---- */
.scientific-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  animation: fadeIn 0.25s ease;
}

/* ---- Basic Grid ---- */
.basic-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}
.zero-btn { grid-column: span 1; }

/* ---- Buttons ---- */
.btn {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  border-radius: var(--btn-radius);
  padding: 0;
  height: 62px;
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.93); }

.num-btn {
  background: var(--num-btn);
  color: var(--text-primary);
}
.num-btn:hover {
  background: rgba(50, 40, 80, 0.95);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

.op-btn {
  background: var(--op-btn);
  color: var(--neon);
  font-size: 1.3rem;
  border-color: rgba(168, 85, 247, 0.2);
}
.op-btn:hover {
  background: rgba(130, 60, 200, 0.7);
  box-shadow: 0 4px 20px var(--neon-glow);
  transform: translateY(-2px);
}

.func-btn {
  background: var(--func-btn);
  color: #c4b5fd;
  font-size: 0.95rem;
}
.func-btn:hover {
  background: rgba(60, 45, 90, 0.95);
  transform: translateY(-2px);
}

.sci-btn {
  background: var(--sci-btn);
  color: var(--cyan);
  font-size: 0.85rem;
  height: 48px;
  border-color: rgba(34, 211, 238, 0.15);
}
.sci-btn:hover {
  background: rgba(34, 211, 238, 0.22);
  box-shadow: 0 0 15px rgba(34, 211, 238, 0.2);
  transform: translateY(-2px);
}

.eq-btn {
  background: var(--eq-btn);
  color: white;
  font-size: 1.4rem;
  font-weight: 700;
  border: none;
  box-shadow: 0 4px 24px var(--neon-glow);
}
.eq-btn:hover {
  filter: brightness(1.15);
  box-shadow: 0 6px 30px rgba(168, 85, 247, 0.55);
  transform: translateY(-2px);
}

/* ---- Ripple ---- */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0);
  animation: rippleAnim 0.55s linear;
  pointer-events: none;
}
@keyframes rippleAnim {
  to { transform: scale(4); opacity: 0; }
}

/* ---- fadeIn utility ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Light mode overrides ---- */
.light-mode .num-btn { background: rgba(230, 220, 255, 0.85); color: #2a1050; }
.light-mode .num-btn:hover { background: rgba(215, 200, 255, 0.95); }
.light-mode .func-btn { background: rgba(200, 180, 240, 0.7); color: #5b2cae; }
.light-mode .func-btn:hover { background: rgba(185, 160, 230, 0.85); }
.light-mode .op-btn { background: rgba(160, 100, 230, 0.3); }
.light-mode .display-area { background: rgba(255,255,255,0.35); }
.light-mode .result-display { color: #1a0533; }
.light-mode .expression-display { color: #9980c0; }
.light-mode .calculator { background: rgba(255, 254, 255, 0.75); }
.light-mode .history-panel { background: rgba(255, 254, 255, 0.8); }
.light-mode .bg-orb { opacity: 0.12; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--purple-dim); border-radius: 4px; }

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .app-wrapper { padding: 0.75rem; }
  .main-layout { flex-direction: column-reverse; }
  .history-panel {
    width: 100%;
    min-width: unset;
    max-height: 220px;
    transform: translateY(-10px);
  }
  .history-panel.open { transform: translateY(0); }
  .btn { height: 56px; font-size: 1rem; }
  .sci-btn { height: 44px; font-size: 0.8rem; }
  .result-display { font-size: clamp(1.5rem, 6vw, 2.2rem); }
  .scientific-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (max-width: 400px) {
  .btn { height: 50px; border-radius: 11px; }
  .basic-grid { gap: 0.4rem; }
  .scientific-grid { gap: 0.35rem; }
  .app-title { font-size: 0.85rem; }
  .result-display { font-size: clamp(1.3rem, 7vw, 2rem); }
}
